|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javatools.database.Database javatools.database.PostgresDatabase
public class PostgresDatabase
This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools).
It is licensed under the Creative Commons Attribution License
(see http://creativecommons.org/licenses/by/3.0) by
the YAGO-NAGA team (see http://mpii.de/yago-naga).
The class PostgresDatabase implements the Database-interface for a
PostgreSQL data base. Make sure that the file "postgresql-version.jdbc3.jar" of the
Postgres distribution is in the classpath. When using Eclipse, add
the file via Project ->Properties ->JavaBuildPath ->Libraries
->ExternalJARFile.
Example:
Database d=new PostgresDatabase("user","password"); d.queryColumn("SELECT foodname FROM food WHERE origin=\"Italy\"") -> [ "Pizza Romana", "Spaghetti alla Bolognese", "Saltimbocca"] Database.describe(d.query("SELECT * FROM food WHERE origin=\"Italy\"") -> foodname |origin |calories | ------------------------------ Pizza Rom|Italy |10000 | Spaghetti|Italy |8000 | Saltimboc|Italy |8000 |This class also provides SQL datatypes (extensions of SQLType.java) that behave according to the conventions of Postgres. For example, VARCHAR string literals print inner quotes as doublequotes.
Nested Class Summary | |
---|---|
static class |
PostgresDatabase.Postgretext
|
static class |
PostgresDatabase.PostgreVarchar
|
Nested classes/interfaces inherited from class javatools.database.Database |
---|
Database.CommitTransactionSQLException, Database.ConnectionBrokenSQLException, Database.InitTransactionSQLException, Database.Inserter, Database.RollbackTransactionSQLException, Database.StartAutoCommitSQLException, Database.TransactionSQLException |
Field Summary | |
---|---|
static PostgresDatabase.Postgretext |
postgretext
|
static PostgresDatabase.PostgreVarchar |
postgrevarchar
|
Fields inherited from class javatools.database.Database |
---|
java2SQL, MINCOLUMNWIDTH, SCREENWIDTH, type2SQL |
Constructor Summary | |
---|---|
PostgresDatabase()
Constructs a non-functional PostgresDatabase for use of getSQLType |
|
PostgresDatabase(java.lang.String user,
java.lang.String password,
java.lang.String database,
java.lang.String host,
java.lang.String port)
|
|
PostgresDatabase(java.lang.String user,
java.lang.String password,
java.lang.String database,
java.lang.String host,
java.lang.String port,
boolean useSSL)
Constructs a new Database from a user, a password and a host |
|
PostgresDatabase(java.lang.String user,
java.lang.String password,
java.lang.String database,
java.lang.String host,
java.lang.String port,
java.lang.String schema)
Constructs a new Database from a user, a password and a host, setting also the (preferred) schema (public stays fallback schema) |
|
PostgresDatabase(java.lang.String user,
java.lang.String password,
java.lang.String database,
java.lang.String host,
java.lang.String port,
java.lang.String schema,
boolean useSSL)
Constructs a new Database from a user, a password and a host, setting also the (preferred) schema (public stays fallback schema) |
Method Summary | |
---|---|
java.lang.String |
autoincrementColumn()
Produces an SQL fragment representing column properties for an autoincrementing integer column s.t. |
java.lang.String |
cast(java.lang.String value,
java.lang.String type)
Produces an SQL fragment casting the given value to the given type * |
void |
connect()
connects to the database specified |
void |
createTable(java.lang.String name,
java.lang.Object... attributes)
Creates or rewrites an SQL table. |
java.lang.String |
getSQLStmntIFNULL(java.lang.String a,
java.lang.String b)
returns the database system specific expression for ifnull functionality i.e. |
boolean |
jarAvailable()
TRUE if the required JAR is there |
void |
lockTableReadAccess(java.util.Map<java.lang.String,java.lang.String> tablesAndAliases)
Locks a table in read mode, i.e. |
void |
lockTableWriteAccess(java.util.Map<java.lang.String,java.lang.String> tablesAndAliases)
Locks a table in write mode, i.e. |
static void |
main(java.lang.String[] args)
|
void |
releaseLocksAndEndTransaction()
releases all locks the connection holds, commits the current transaction and ends it |
void |
setExclusiveSchema(java.lang.String s)
Sets the default schema |
void |
setSchema(java.lang.String s)
Sets the default schema |
void |
startTransaction()
Initiates a transaction by disabling autocommit and enabling transaction mod Note: In Postgres transactions have a name e |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static PostgresDatabase.PostgreVarchar postgrevarchar
public static PostgresDatabase.Postgretext postgretext
Constructor Detail |
---|
public PostgresDatabase()
public PostgresDatabase(java.lang.String user, java.lang.String password, java.lang.String database, java.lang.String host, java.lang.String port, boolean useSSL) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.ClassNotFoundException, java.sql.SQLException
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.sql.SQLException
public PostgresDatabase(java.lang.String user, java.lang.String password, java.lang.String database, java.lang.String host, java.lang.String port) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.ClassNotFoundException, java.sql.SQLException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.ClassNotFoundException
java.sql.SQLException
public PostgresDatabase(java.lang.String user, java.lang.String password, java.lang.String database, java.lang.String host, java.lang.String port, java.lang.String schema, boolean useSSL) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.ClassNotFoundException, java.sql.SQLException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.ClassNotFoundException
java.sql.SQLException
public PostgresDatabase(java.lang.String user, java.lang.String password, java.lang.String database, java.lang.String host, java.lang.String port, java.lang.String schema) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.ClassNotFoundException, java.sql.SQLException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.ClassNotFoundException
java.sql.SQLException
Method Detail |
---|
public void connect() throws java.sql.SQLException
connect
in class Database
java.sql.SQLException
public void setSchema(java.lang.String s) throws java.sql.SQLException
java.sql.SQLException
public void setExclusiveSchema(java.lang.String s) throws java.sql.SQLException
java.sql.SQLException
public void createTable(java.lang.String name, java.lang.Object... attributes) throws java.sql.SQLException
createTable
in class Database
java.sql.SQLException
public boolean jarAvailable()
Database
jarAvailable
in class Database
public java.lang.String cast(java.lang.String value, java.lang.String type)
cast
in class Database
public java.lang.String getSQLStmntIFNULL(java.lang.String a, java.lang.String b)
getSQLStmntIFNULL
in class Database
public java.lang.String autoincrementColumn()
autoincrementColumn
in class Database
public void startTransaction() throws Database.InitTransactionSQLException
startTransaction
in class Database
Database.InitTransactionSQLException
public void lockTableWriteAccess(java.util.Map<java.lang.String,java.lang.String> tablesAndAliases) throws java.sql.SQLException
lockTableWriteAccess
in class Database
java.sql.SQLException
public void lockTableReadAccess(java.util.Map<java.lang.String,java.lang.String> tablesAndAliases) throws java.sql.SQLException
lockTableReadAccess
in class Database
java.sql.SQLException
public void releaseLocksAndEndTransaction() throws java.sql.SQLException
releaseLocksAndEndTransaction
in class Database
java.sql.SQLException
public static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |