public class PostgresDB extends DBDatabase implements SupportsPolygonDatatype
Support DBvolution at Patreon
| Modifier and Type | Field and Description |
|---|---|
static int |
POSTGRES_DEFAULT_PORT
The default port number used by PostgreSQL.
|
static String |
POSTGRES_DEFAULT_USERNAME
The default username used by PostgreSQL.
|
static long |
serialVersionUID |
storedConnection| Modifier | Constructor and Description |
|---|---|
protected |
PostgresDB()
Provides a convenient constructor for DBDatabases that have configuration
details hardwired or are able to automatically retrieve the details.
|
|
PostgresDB(DataSource ds)
Creates a PostgreSQL connection for the DataSource.
|
|
PostgresDB(String hostname,
int port,
String databaseName,
String username,
String password)
Creates a PostgreSQL connection to the server on the port supplied, using
the username and password supplied.
|
|
PostgresDB(String hostname,
int port,
String databaseName,
String username,
String password,
String urlExtras)
Creates a PostgreSQL connection to the server on the port supplied, using
the username and password supplied.
|
|
PostgresDB(String jdbcURL,
String username,
String password)
Creates a PostgreSQL connection for the JDBC URL, username, and password.
|
|
PostgresDB(String databaseName,
String username,
String password,
String urlExtras)
Creates a PostgreSQL connection to local computer("localhost") on the
default port(5432) using the username and password supplied.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addDatabaseSpecificFeatures(Statement stmnt)
Used By Subclasses To Inject Datatypes, Functions, Etc Into the Database.
|
DBDatabase |
clone()
Clones the DBDatabase.
|
void |
createDatabase(String databaseName)
Create a new database/schema on this database server.
|
void |
createUser(String username,
String password)
Create a new database/schema on this database server.
|
<TR extends DBRow> |
dropTableNoExceptions(TR tableRow)
Drops a table from the database.
|
int |
loadFromCSVFile(DBRow table,
File file,
String delimiter,
String nullValue,
String escapeCharacter,
String quoteCharacter)
Assumes that the database and application are on the the same machine.
|
addFeatureToFixException, batchSQLStatementsWhenPossible, createForeignKeyConstraints, createIndexesOnAllFields, createTable, createTableNoExceptions, createTableNoExceptions, createTablesNoExceptions, createTablesNoExceptions, createTablesWithForeignKeysNoExceptions, createTableWithForeignKeys, delete, delete, discardConnection, doCommit, doReadOnlyTransaction, doRollback, doTransaction, doTransaction, dropAnyAssociatedDatabaseObjects, dropDatabase, dropDatabase, dropTable, equals, executeDBAction, executeDBQuery, get, get, get, get, get, getAllRows, getByExample, getByExample, getByExamples, getConnection, getConnectionFromDriverManager, getDatabaseName, getDBMigration, getDBQuery, getDBQuery, getDBQueryInsert, getDBStatement, getDBTable, getDefinition, getDriverName, getJdbcURL, getLowLevelStatement, getPassword, getRows, getSQLForCreateTable, getSQLForDBQuery, getUsername, hashCode, implement, insert, insert, isPrintSQLBeforeExecuting, preventDroppingOfDatabases, preventDroppingOfTables, print, printSQLIfRequested, removeForeignKeyConstraints, setBatchSQLStatementsWhenPossible, setDatabaseName, setDefinition, setDriverName, setExplicitCommitAction, setJdbcURL, setPassword, setPrintSQLBeforeExecuting, setUsername, supportsPooledConnections, tableExists, test, unusedConnection, update, update, willCreateBlankQuerypublic static final long serialVersionUID
public static final int POSTGRES_DEFAULT_PORT
public static final String POSTGRES_DEFAULT_USERNAME
protected PostgresDB()
This constructor creates an empty DBDatabase with only the default
settings, in particular with no driver, URL, username, password, or
DBDefinition
Most programmers should not call this constructor directly. Instead you should define a no-parameter constructor that supplies the details for creating an instance using a more complete constructor.
DBDatabase encapsulates the knowledge of the database, in particular the syntax of the database in the DBDefinition and the connection details from a DataSource.
DBDefinitionpublic PostgresDB(DataSource ds)
ds - dspublic PostgresDB(String jdbcURL, String username, String password)
jdbcURL - jdbcURLusername - usernamepassword - passwordpublic PostgresDB(String hostname, int port, String databaseName, String username, String password)
hostname - hostnameport - portdatabaseName - databaseNameusername - usernamepassword - passwordpublic PostgresDB(String hostname, int port, String databaseName, String username, String password, String urlExtras)
Extra parameters to be added to the JDBC URL can be included in the urlExtras parameter.
hostname - hostnamepassword - passworddatabaseName - databaseNameport - portusername - usernameurlExtras - urlExtraspublic PostgresDB(String databaseName, String username, String password, String urlExtras)
Extra parameters to be added to the JDBC URL can be included in the urlExtras parameter.
databaseName - databaseNameusername - usernamepassword - passwordurlExtras - urlExtraspublic DBDatabase clone() throws CloneNotSupportedException
DBDatabaseSupport DBvolution at Patreon
clone in class DBDatabaseCloneNotSupportedException - not likelypublic int loadFromCSVFile(DBRow table, File file, String delimiter, String nullValue, String escapeCharacter, String quoteCharacter) throws SQLException
table - the table to be loadedfile - the file to load data fromdelimiter - the separator between the values of each rownullValue - the string that represents NULL in this file.escapeCharacter - the character that escapes special valuesquoteCharacter - the character the surrounds strings.
Support DBvolution at Patreon
SQLException - database exceptions may be thrown.public void createDatabase(String databaseName) throws SQLException
Generally requires all sorts of privileges and is best performed by database administrator (DBA).
databaseName - the name of the new databaseSQLException - database exceptions may be thrownpublic void createUser(String username, String password) throws SQLException
Generally requires all sorts of privileges and is best performed by database administrator (DBA).
username - The user to be createdpassword - the password the user will use.SQLException - database exceptions may be throwns.public <TR extends DBRow> void dropTableNoExceptions(TR tableRow) throws AccidentalDroppingOfTableException, AutoCommitActionDuringTransactionException
DBDatabaseThe easy way to drop a table that might not exist. Will still throw a AutoCommitActionDuringTransactionException if you use it during a transaction or AccidentalDroppingOfTableException if dropping tables is being prevented by DBvolution.
An even worse idea than DBDatabase.dropTable(nz.co.gregs.dbvolution.DBRow)
In General NEVER USE THIS METHOD.
Seriously NEVER USE THIS METHOD.
Your DBA will murder you.
dropTableNoExceptions in class DBDatabaseTR - DBRow typetableRow - tableRowAccidentalDroppingOfTableExceptionAutoCommitActionDuringTransactionExceptionprotected void addDatabaseSpecificFeatures(Statement stmnt) throws SQLException
DBDatabaseaddDatabaseSpecificFeatures in class DBDatabasestmnt - the statement to use when adding features, DO NOT CLOSE
THIS STATEMENT.SQLException - database exceptions may occurPostgresDB,
H2DB,
SQLiteDB,
OracleDB,
MSSQLServerDB,
MySQLDBCopyright © 2018. All Rights Reserved.