java.lang.Object
is.codion.common.db.database.AbstractDatabase
- All Implemented Interfaces:
ConnectionFactory,Database
A default abstract implementation of the Database interface.
-
Nested Class Summary
Nested classes/interfaces inherited from interface is.codion.common.db.database.Database
Database.Operation, Database.QueryCounter, Database.Statistics -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringFOR UPDATEprotected static final StringFOR UPDATE NOWAITFields inherited from interface is.codion.common.db.database.Database
CONNECTION_VALIDITY_CHECK_TIMEOUT, COUNT_QUERIES, INIT_SCRIPTS, LOGIN_TIMEOUT, PASSWORD_PROPERTY, SELECT_FOR_UPDATE_NOWAIT, TRANSACTION_ISOLATION, URL, URL_SCOPED_INSTANCE, USER_PROPERTY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractDatabase(String url) Instantiates a new AbstractDatabase. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidcloseConnectionPool(String username) Closes and removes the pool associated with the given userfinal voidCloses and removes all available connection poolsfinal ConnectionPoolWrapperconnectionPool(String username) final Collection<String> final voidconnectionProvider(ConnectionProvider connectionProvider) Sets theConnectionProviderinstance to use when creating connections.final booleanconnectionValid(Connection connection) Validates the given connection.final booleancontainsConnectionPool(String username) final ConnectionCreates a connection.final ConnectioncreateConnection(User user) Creates a connection for the given user.final ConnectionPoolWrappercreateConnectionPool(ConnectionPoolFactory connectionPoolFactory, User poolUser) Creates a connection pool for the given user in this database.protected static StringcreateLimitOffsetClause(@Nullable Integer limit, @Nullable Integer offset) Creates a limit/offset clause of the formLIMIT {limit} OFFSET {offset}.protected static StringcreateOffsetFetchNextClause(@Nullable Integer limit, @Nullable Integer offset) Creates an offset/fetch next clause of the formOFFSET {offset} ROWS FETCH NEXT {limit} ROWS ONLY.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.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 exceptionintReturns the maximum number of prepared statement parameters, supported by this database.final Database.QueryCounterprotected static StringremoveUrlPrefixOptionsAndParameters(String url, String... prefixes) Removes the given prefixes along with any options and parameters from the given jdbc url.sequenceQuery(String sequenceName) Returns a query string for selecting the next value from the given sequence.final Database.StatisticsReturns statistics collected viaDatabase.queryCounter().booleanReturns true if this database requires that subqueries by aliased.final Stringurl()Returns the jdbc database url for this connection factory.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface is.codion.common.db.database.Database
autoIncrementQuery, limitOffsetClause, name, selectForUpdateClause
-
Field Details
-
FOR_UPDATE
FOR UPDATE- See Also:
-
FOR_UPDATE_NOWAIT
FOR UPDATE NOWAIT- See Also:
-
-
Constructor Details
-
AbstractDatabase
Instantiates a new AbstractDatabase.- Parameters:
url- the jdbc url
-
-
Method Details
-
url
Description copied from interface:ConnectionFactoryReturns the jdbc database url for this connection factory.- Specified by:
urlin interfaceConnectionFactory- Returns:
- the jdbc database url for this connection factory.
-
createConnection
Description copied from interface:ConnectionFactoryCreates a connection.- Specified by:
createConnectionin interfaceConnectionFactory- Returns:
- a new JDBC connection
-
createConnection
Description copied from interface:ConnectionFactoryCreates a connection for the given user.- Specified by:
createConnectionin interfaceConnectionFactory- Parameters:
user- the user for which to create a connection- Returns:
- a new JDBC connection
-
connectionValid
Description copied from interface:ConnectionFactoryValidates the given connection.- Specified by:
connectionValidin interfaceConnectionFactory- Parameters:
connection- the connection to validate- Returns:
- true if the connection is valid
-
queryCounter
- Specified by:
queryCounterin interfaceDatabase- Returns:
- the
Database.QueryCounterfor collecting query statistics
-
statistics
Description copied from interface:DatabaseReturns statistics collected viaDatabase.queryCounter(). Note that calling this method resets the counter.- Specified by:
statisticsin interfaceDatabase- Returns:
- collected statistics.
-
createConnectionPool
public final ConnectionPoolWrapper createConnectionPool(ConnectionPoolFactory connectionPoolFactory, User poolUser) Description copied from interface:DatabaseCreates a connection pool for the given user in this database.- Specified by:
createConnectionPoolin interfaceDatabase- Parameters:
connectionPoolFactory- the ConnectionPoolFactory implementation to usepoolUser- the user for which to create a connection pool- Returns:
- a new
ConnectionPoolWrapper
-
containsConnectionPool
- Specified by:
containsConnectionPoolin interfaceDatabase- Parameters:
username- the username- Returns:
- true if a connection pool exists for the given username
-
connectionPool
- Specified by:
connectionPoolin interfaceDatabase- Parameters:
username- the username- Returns:
- the connection pool for the given user
-
closeConnectionPool
Description copied from interface:DatabaseCloses and removes the pool associated with the given user- Specified by:
closeConnectionPoolin interfaceDatabase- Parameters:
username- the username of the pool that should be removed
-
closeConnectionPools
public final void closeConnectionPools()Description copied from interface:DatabaseCloses and removes all available connection pools- Specified by:
closeConnectionPoolsin interfaceDatabase
-
connectionPoolUsernames
- Specified by:
connectionPoolUsernamesin interfaceDatabase- Returns:
- the usernames of all available connection pools
-
connectionProvider
Description copied from interface:DatabaseSets theConnectionProviderinstance to use when creating connections.- Specified by:
connectionProviderin interfaceDatabase- Parameters:
connectionProvider- the connection provider
-
subqueryRequiresAlias
public boolean subqueryRequiresAlias()Description copied from interface:DatabaseReturns true if this database requires that subqueries by aliased.- Specified by:
subqueryRequiresAliasin interfaceDatabase- Returns:
- true if subqueries require an alias
-
maximumParameters
public int maximumParameters()Description copied from interface:DatabaseReturns the maximum number of prepared statement parameters, supported by this database. The default implementation simply returnsInteger.MAX_VALUE, as in, no limit.- Specified by:
maximumParametersin interfaceDatabase- Returns:
- the maximum number of prepared statement parameters, supported by this database.
-
sequenceQuery
Description copied from interface:DatabaseReturns a query string for selecting the next value from the given sequence.- Specified by:
sequenceQueryin interfaceDatabase- Parameters:
sequenceName- the name of the sequence- Returns:
- a query for selecting the next value from the given sequence
-
errorMessage
Description copied from interface:DatabaseReturns a user-friendly error message for the given exception, otherwise simply return the message fromexception- Specified by:
errorMessagein interfaceDatabase- Parameters:
exception- the underlying SQLExceptionoperation- the operation resulting in the exception- Returns:
- the message assigned to the given exception
-
isAuthenticationException
Description copied from interface:DatabaseReturns true if this exception represents a login credentials failure- Specified by:
isAuthenticationExceptionin interfaceDatabase- Parameters:
exception- the exception- Returns:
- true if this exception represents a login credentials failure
-
isReferentialIntegrityException
Description copied from interface:DatabaseReturns true if this exception is a referential integrity exception- Specified by:
isReferentialIntegrityExceptionin interfaceDatabase- Parameters:
exception- the exception- Returns:
- true if this exception is a referential integrity exception
-
isUniqueConstraintException
Description copied from interface:DatabaseReturns true if this exception is a unique key exception- Specified by:
isUniqueConstraintExceptionin interfaceDatabase- Parameters:
exception- the exception- Returns:
- true if this exception is a unique key exception
-
isTimeoutException
Description copied from interface:DatabaseReturns true if this exception is a timeout exception- Specified by:
isTimeoutExceptionin interfaceDatabase- Parameters:
exception- the exception- Returns:
- true if this exception is a timeout exception
-
exception
Description copied from interface:DatabaseMaps the given SQLException to a DatabaseException. -
createLimitOffsetClause
Creates a limit/offset clause of the formLIMIT {limit} OFFSET {offset}. Returns a partial clause if either value is null. If both values are null, an empty string is returned.- Parameters:
limit- the limit, may be nulloffset- the offset, may be null- Returns:
- a limit/offset clause
-
createOffsetFetchNextClause
protected static String createOffsetFetchNextClause(@Nullable Integer limit, @Nullable Integer offset) Creates an offset/fetch next clause of the formOFFSET {offset} ROWS FETCH NEXT {limit} ROWS ONLY. Returns a partial clause if either value is null. If both values are null, an empty string is returned.- Parameters:
limit- the limit, may be nulloffset- the offset, may be null- Returns:
- a limit/offset clause
-
removeUrlPrefixOptionsAndParameters
Removes the given prefixes along with any options and parameters from the given jdbc url.- Parameters:
url- the urlprefixes- the prefixes to remove- Returns:
- the given url without prefixes, options and parameters
-