- All Superinterfaces:
ConnectionFactory
- All Known Implementing Classes:
AbstractDatabase
Defines DBMS specific functionality as well as basic database configuration settings.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumSpecifies common database operations.static interfaceCounts queries for statistics.static interfaceEncapsulates basic database usage statistics. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final is.codion.common.property.PropertyValue<Integer>Specifies the timeout (in seconds) to use when checking if database connections are valid.static final is.codion.common.property.PropertyValue<Boolean>Specifies whether database queries should be counted for collecting statistics.
Value type: Boolean
Default value: falsestatic final is.codion.common.property.PropertyValue<String>A comma separated list of paths to scripts to run when initializing the database, implementation specificstatic final is.codion.common.property.PropertyValue<String>Specifies the jdbc url of the database.static final is.codion.common.property.PropertyValue<Integer>Specifies the default login timeout (in seconds).
Value type: Integer
Default value: 2static final StringThe constant used to denote the password value in the connection propertiesstatic final is.codion.common.property.PropertyValue<Boolean>Specifies whether 'select for update' should be NOWAIT, if supported by the database.
A database implementation may disregard this.
Value type: Boolean
Default value: truestatic final is.codion.common.property.PropertyValue<Integer>Specifies the transaction isolation to set for created connections.
Value type: Integer
Default value: nullstatic final StringThe constant used to denote the username value in the connection properties -
Method Summary
Modifier and TypeMethodDescriptionautoIncrementQuery(String idSource) Returns a query string for retrieving the last automatically generated id from the given id sourcevoidcloseConnectionPool(String username) Closes and removes the pool associated with the given uservoidCloses and removes all available connection poolsconnectionPool(String username) voidconnectionProvider(ConnectionProvider connectionProvider) Sets theConnectionProviderinstance used when creating connections.booleancontainsConnectionPool(String username) createConnectionPool(ConnectionPoolFactory connectionPoolFactory, is.codion.common.user.User poolUser) Creates a connection pool for the given user in this database.errorMessage(SQLException exception, Database.Operation operation) Returns a user-friendly error message for the given exception, otherwise simply return the message fromexceptionexception(SQLException exception, Database.Operation operation) Maps the given SQLException to a DatabaseException.static Databaseinstance()Returns aDatabaseinstance based on the currently configured JDBC URL (DATABASE_URL).booleanisAuthenticationException(SQLException exception) Returns true if this exception represents a login credentials failurebooleanisReferentialIntegrityException(SQLException exception) Returns true if this exception is a referential integrity exceptionbooleanisTimeoutException(SQLException exception) Returns true if this exception is a timeout exceptionbooleanisUniqueConstraintException(SQLException exception) Returns true if this exception is a unique key exceptionlimitOffsetClause(Integer limit, Integer offset) Returns a limit/offset clause variation for this database, based on the given limit and offset values.intReturns the maximum number of prepared statement parameters, supported by this database.name()Returns a select for update clause, an empty string if not supported.sequenceQuery(String sequenceName) Returns a query string for selecting the next value from the given sequence.Returns statistics collected viaqueryCounter().booleanReturns true if this database requires that subqueries by aliased.Methods inherited from interface is.codion.common.db.connection.ConnectionFactory
connectionValid, createConnection, url
-
Field Details
-
DATABASE_URL
Specifies the jdbc url of the database. -
DATABASE_INIT_SCRIPTS
A comma separated list of paths to scripts to run when initializing the database, implementation specific -
CONNECTION_VALIDITY_CHECK_TIMEOUT
Specifies the timeout (in seconds) to use when checking if database connections are valid. Value type: Integer
Default value: 2 -
COUNT_QUERIES
Specifies whether database queries should be counted for collecting statistics.
Value type: Boolean
Default value: false -
SELECT_FOR_UPDATE_NOWAIT
Specifies whether 'select for update' should be NOWAIT, if supported by the database.
A database implementation may disregard this.
Value type: Boolean
Default value: true -
LOGIN_TIMEOUT
Specifies the default login timeout (in seconds).
Value type: Integer
Default value: 2 -
TRANSACTION_ISOLATION
Specifies the transaction isolation to set for created connections.
Value type: Integer
Default value: null- See Also:
-
USER_PROPERTY
The constant used to denote the username value in the connection properties- See Also:
-
PASSWORD_PROPERTY
The constant used to denote the password value in the connection properties- See Also:
-
-
Method Details
-
name
String name()- Returns:
- a name identifying this database
-
autoIncrementQuery
Returns a query string for retrieving the last automatically generated id from the given id source- Parameters:
idSource- the source for the id, for example a sequence name or in the case of Derby, the name of the table auto generating the value- Returns:
- a query string for retrieving the last auto-increment value from idSource
- Throws:
NullPointerException- in caseidSourceis required and is null
-
sequenceQuery
Returns a query string for selecting the next value from the given sequence.- Parameters:
sequenceName- the name of the sequence- Returns:
- a query for selecting the next value from the given sequence
- Throws:
UnsupportedOperationException- in case the underlying database does not support sequencesNullPointerException- in casesequenceNameis null
-
selectForUpdateClause
String selectForUpdateClause()Returns a select for update clause, an empty string if not supported.- Returns:
- a select for update clause
-
limitOffsetClause
Returns a limit/offset clause variation for this database, based on the given limit and offset values. If both are null an empty string should be returned.- Parameters:
limit- the limitoffset- the offset- Returns:
- a limit/offset clause
-
subqueryRequiresAlias
boolean subqueryRequiresAlias()Returns true if this database requires that subqueries by aliased.- Returns:
- true if subqueries require an alias
-
maximumNumberOfParameters
int maximumNumberOfParameters()Returns the maximum number of prepared statement parameters, supported by this database. The default implementation simply returnsInteger.MAX_VALUE, as in, no limit.- Returns:
- the maximum number of prepared statement parameters, supported by this database.
-
errorMessage
Returns a user-friendly error message for the given exception, otherwise simply return the message fromexception- Parameters:
exception- the underlying SQLExceptionoperation- the operation resulting in the exception- Returns:
- the message assigned to the given exception
- Throws:
NullPointerException- in caseexceptionoroperationis null
-
exception
Maps the given SQLException to a DatabaseException.- Parameters:
exception- the SQL exceptionoperation- the current operation- Returns:
- a DatabaseException
- Throws:
NullPointerException- in caseexceptionoroperationis null- See Also:
-
isAuthenticationException
Returns true if this exception represents a login credentials failure- Parameters:
exception- the exception- Returns:
- true if this exception represents a login credentials failure
- Throws:
NullPointerException- in caseexceptionis null
-
isReferentialIntegrityException
Returns true if this exception is a referential integrity exception- Parameters:
exception- the exception- Returns:
- true if this exception is a referential integrity exception
- Throws:
NullPointerException- in caseexceptionis null
-
isUniqueConstraintException
Returns true if this exception is a unique key exception- Parameters:
exception- the exception- Returns:
- true if this exception is a unique key exception
- Throws:
NullPointerException- in caseexceptionis null
-
isTimeoutException
Returns true if this exception is a timeout exception- Parameters:
exception- the exception- Returns:
- true if this exception is a timeout exception
- Throws:
NullPointerException- in caseexceptionis null
-
queryCounter
Database.QueryCounter queryCounter()- Returns:
- the
Database.QueryCounterfor collecting query statistics
-
statistics
Database.Statistics statistics()Returns statistics collected viaqueryCounter(). Note that calling this method resets the counter.- Returns:
- collected statistics.
-
createConnectionPool
ConnectionPoolWrapper createConnectionPool(ConnectionPoolFactory connectionPoolFactory, is.codion.common.user.User poolUser) throws DatabaseException Creates a connection pool for the given user in this database.- Parameters:
connectionPoolFactory- the ConnectionPoolFactory implementation to usepoolUser- the user for which to create a connection pool- Throws:
DatabaseException- in case of a database exception
-
containsConnectionPool
- Parameters:
username- the username- Returns:
- true if a connection pool exists for the given username
-
connectionPool
- Parameters:
username- the username- Returns:
- the connection pool for the given user, null if none exists
- Throws:
IllegalArgumentException- in case no connection pool exists for the given user
-
connectionPoolUsernames
Collection<String> connectionPoolUsernames()- Returns:
- the usernames of all available connection pools
-
closeConnectionPool
Closes and removes the pool associated with the given user- Parameters:
username- the username of the pool that should be removed
-
closeConnectionPools
void closeConnectionPools()Closes and removes all available connection pools -
connectionProvider
Sets theConnectionProviderinstance used when creating connections.- Parameters:
connectionProvider- the connection provider
-
instance
Returns aDatabaseinstance based on the currently configured JDBC URL (DATABASE_URL). Subsequent calls to this method return the same instance, until the JDBC URL changes, then a new instance is created.- Returns:
- a Database instance based on the current jdbc url
- Throws:
IllegalArgumentException- in case an unsupported database type is specifiedRuntimeException- in case of an exception occurring while instantiating the database implementation- See Also:
-