- All Superinterfaces:
ConnectionFactory
- All Known Implementing Classes:
AbstractDatabase
Defines DBMS specific functionality as well as basic database configuration settings.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
Specifies common database operations.static interface
Counts queries for statistics.static interface
Encapsulates basic database usage statistics. -
Field Summary
Modifier and TypeFieldDescriptionstatic final PropertyValue<Integer>
Specifies the timeout (in seconds) to use when checking if database connections are valid.static final PropertyValue<Boolean>
Specifies whether database queries should be counted for collecting statistics.static final PropertyValue<String>
A comma separated list of paths to scripts to run when initializing the database, implementation specificstatic final PropertyValue<String>
Specifies the jdbc url of the database.static final PropertyValue<Integer>
Specifies the default login timeout (in seconds).static final String
The constant used to denote the password value in the connection propertiesstatic final PropertyValue<Boolean>
Specifies whether 'select for update' should be NOWAIT, if supported by the database.
A database implementation may disregard this.static final PropertyValue<Integer>
Specifies the transaction isolation to set for created connections Value type: Integer Default value: nullstatic final String
The 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 sourcevoid
closeConnectionPool
(String username) Closes and removes the pool associated with the given uservoid
Closes and removes all available connection poolsconnectionPool
(String username) void
connectionProvider
(ConnectionProvider connectionProvider) Sets theConnectionProvider
instance used when creating connections.boolean
containsConnectionPool
(String username) createConnectionPool
(ConnectionPoolFactory connectionPoolFactory, 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 fromexception
exception
(SQLException exception, Database.Operation operation) Maps the given SQLException to a DatabaseException.static Database
instance()
Returns aDatabase
instance based on the currently configured JDBC URL (DATABASE_URL
).boolean
isAuthenticationException
(SQLException exception) Returns true if this exception represents a login credentials failureboolean
isReferentialIntegrityException
(SQLException exception) Returns true if this exception is a referential integrity exceptionboolean
isTimeoutException
(SQLException exception) Returns true if this exception is a timeout exceptionboolean
isUniqueConstraintException
(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.int
Returns 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()
.boolean
Returns 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 caseidSource
is 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 casesequenceName
is 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 caseexception
oroperation
is null
-
exception
Maps the given SQLException to a DatabaseException.- Parameters:
exception
- the SQL exceptionoperation
- the current operation- Returns:
- a DatabaseException
- Throws:
NullPointerException
- in caseexception
oroperation
is 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 caseexception
is 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 caseexception
is 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 caseexception
is 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 caseexception
is null
-
queryCounter
Database.QueryCounter queryCounter()- Returns:
- the
Database.QueryCounter
for 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, 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 theConnectionProvider
instance used when creating connections.- Parameters:
connectionProvider
- the connection provider
-
instance
Returns aDatabase
instance 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:
-