public class PostgresDatabase extends Database
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.| Modifier and Type | Class and Description |
|---|---|
static class |
PostgresDatabase.Postgretext |
static class |
PostgresDatabase.PostgreVarchar |
Database.CommitTransactionSQLException, Database.ConnectionBrokenSQLException, Database.InitTransactionSQLException, Database.Inserter, Database.RollbackTransactionSQLException, Database.StartAutoCommitSQLException, Database.TransactionSQLException| Modifier and Type | Field and Description |
|---|---|
static PostgresDatabase.Postgretext |
postgretext |
static PostgresDatabase.PostgreVarchar |
postgrevarchar |
protected String |
schema
Holds the default schema
|
connection, description, driver, fetchsize, inserters, java2SQL, MINCOLUMNWIDTH, resultSetConcurrency, resultSetType, SCREENWIDTH, type2SQL| Constructor and Description |
|---|
PostgresDatabase()
Constructs a non-functional PostgresDatabase for use of getSQLType
|
PostgresDatabase(String user,
String password,
String database,
String host,
String port) |
PostgresDatabase(String user,
String password,
String database,
String host,
String port,
boolean useSSL)
Constructs a new Database from a user, a password and a host
|
PostgresDatabase(String user,
String password,
String database,
String host,
String port,
String schema)
Constructs a new Database from a user, a password and a host, setting also the (preferred) schema (public stays fallback schema)
|
PostgresDatabase(String user,
String password,
String database,
String host,
String port,
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)
|
| Modifier and Type | Method and Description |
|---|---|
String |
autoincrementColumn()
Produces an SQL fragment representing column properties for an autoincrementing integer column
s.t.
|
String |
cast(String value,
String type)
Produces an SQL fragment casting the given value to the given type *
|
protected void |
commitTransaction()
commits the transaction aggregated so far
if the commit fails the transaction is rolled back!
|
void |
connect()
connects to the database specified
|
void |
createTable(String name,
Object... attributes)
Creates or rewrites an SQL table.
|
String |
getSQLStmntIFNULL(String a,
String b)
returns the database system specific expression for ifnull functionality
i.e.
|
boolean |
jarAvailable()
TRUE if the required JAR is there
|
void |
lockTableReadAccess(Map<String,String> tablesAndAliases)
Locks a table in read mode, i.e.
|
void |
lockTableWriteAccess(Map<String,String> tablesAndAliases)
Locks a table in write mode, i.e.
|
static void |
main(String[] args) |
void |
releaseLocksAndEndTransaction()
releases all locks the connection holds, commits the current transaction and ends it
|
void |
setExclusiveSchema(String s)
Sets the default schema
|
void |
setSchema(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
|
appendFixedLen, attemptReconnect, close, close, close, close, connected, createIndex, createIndexCommand, createIndices, createPrimaryKey, createView, describe, describe, dumpCSV, dumpQueryAsCSV, endTransaction, endTransaction, executeQuery, executeUpdate, executeUpdateQuery, exists, existsTable, finalize, flush, format, formatNullToNull, getConnection, getFetchsize, getResultSetConcurrency, getResultSetType, getSQLType, getSQLType, getSQLType, getValidityCheckTimeout, indexName, isAutoReconnectingOnSelect, isAutoReconnectingOnUpdate, limit, loadCSV, makeCSV, makeCSVForQuery, newInserter, newInserter, newInserter, offset, prepareQuery, query, query, query, query, queryValue, reconnect, resetTransaction, runInterface, setAutoReconnectOnSelect, setAutoReconnectOnUpdate, setFetchsize, setResultSetConcurrency, setResultSetType, setValidityCheckTimeout, toStringprotected String schema
public static PostgresDatabase.PostgreVarchar postgrevarchar
public static PostgresDatabase.Postgretext postgretext
public PostgresDatabase()
public PostgresDatabase(String user, String password, String database, String host, String port, boolean useSSL) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
public PostgresDatabase(String user, String password, String database, String host, String port) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
public PostgresDatabase(String user, String password, String database, String host, String port, String schema, boolean useSSL) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
public PostgresDatabase(String user, String password, String database, String host, String port, String schema) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
public void connect()
throws SQLException
connect in class DatabaseSQLExceptionpublic void setSchema(String s) throws SQLException
SQLExceptionpublic void setExclusiveSchema(String s) throws SQLException
SQLExceptionpublic void createTable(String name, Object... attributes) throws SQLException
createTable in class DatabaseSQLExceptionpublic boolean jarAvailable()
DatabasejarAvailable in class Databasepublic String cast(String value, String type)
public String getSQLStmntIFNULL(String a, String b)
getSQLStmntIFNULL in class Databasepublic String autoincrementColumn()
autoincrementColumn in class Databasepublic void startTransaction()
throws Database.InitTransactionSQLException
startTransaction in class DatabaseDatabase.InitTransactionSQLExceptionprotected void commitTransaction()
throws Database.TransactionSQLException
commitTransaction in class DatabaseDatabase.TransactionSQLExceptionpublic void lockTableWriteAccess(Map<String,String> tablesAndAliases) throws SQLException
lockTableWriteAccess in class DatabaseSQLExceptionpublic void lockTableReadAccess(Map<String,String> tablesAndAliases) throws SQLException
lockTableReadAccess in class DatabaseSQLExceptionpublic void releaseLocksAndEndTransaction()
throws SQLException
releaseLocksAndEndTransaction in class DatabaseSQLExceptionpublic static void main(String[] args)
Copyright © 2018. All rights reserved.