public interface Database
Modifier and Type | Interface and Description |
---|---|
static interface |
Database.Statistics
Encapsulates basic database usage statistics.
|
static class |
Database.Type
The available database types
|
Modifier and Type | Field and Description |
---|---|
static PropertyValue<java.lang.Boolean> |
DATABASE_EMBEDDED
Specifies whether or not the database should be run in embedded mode, if applicable
Values: "true"/"false" Default: "false" |
static PropertyValue<java.lang.Boolean> |
DATABASE_EMBEDDED_IN_MEMORY
Specifies whether or not the database should be run in in-memory mode
Values: "true"/"false" Default: "false" |
static PropertyValue<java.lang.String> |
DATABASE_HOST
Specifies the machine hosting the database, in the case of embedded databases
this specifies the name of the database
|
static PropertyValue<java.lang.String> |
DATABASE_INIT_SCRIPT
A comma separated list of paths to scripts to run when initializing the database, implementation specific
|
static PropertyValue<java.lang.Integer> |
DATABASE_PORT
Specifies the database port
|
static PropertyValue<java.lang.String> |
DATABASE_SID
Specifies the database sid (used for dbname for MySQL, SQLServer and Derby server connections)
|
static PropertyValue<java.lang.String> |
DATABASE_TYPE
Specifies the database type by name, this property is case insensitive
|
static int |
DEFAULT_LOGIN_TIMEOUT
The default connection login timeout
|
static java.lang.String |
PASSWORD_PROPERTY
The constant used to denote the password value in the connection properties
|
static java.lang.String |
USER_PROPERTY
The constant used to denote the username value in the connection properties
|
Modifier and Type | Method and Description |
---|---|
java.util.Properties |
addConnectionProperties(java.util.Properties properties)
Adds any dbms specific connection properties to the given properties map,
called each time a connection is created
|
java.sql.Connection |
createConnection(User user)
Creates a connection for the given user.
|
java.lang.String |
getAuthenticationInfo(java.util.Properties connectionProperties)
In the case of embedded databases the user login info can be appended
to the connection url, this method should return that string in case
the dbms requires it and
connectionProperties contains
the username and password info, otherwise it should be safe to return null. |
java.lang.String |
getAutoIncrementQuery(java.lang.String idSource)
Returns a query string for retrieving the last automatically generated id from the given id source
|
java.lang.String |
getCheckConnectionQuery()
Returns a query to use when checking if the connection is valid,
this is used in cases where the dbms does not support the isValid() call.
|
static Database.Type |
getDatabaseType() |
java.lang.String |
getDriverClassName() |
java.lang.String |
getErrorMessage(java.sql.SQLException exception)
Returns a user friendly error message for the given exception,
otherwise simply return the message from
exception |
java.lang.String |
getHost() |
java.lang.Integer |
getPort() |
java.lang.String |
getSequenceQuery(java.lang.String sequenceName) |
java.lang.String |
getSid() |
Database.Type |
getType() |
java.lang.String |
getURL(java.util.Properties connectionProperties) |
java.lang.String |
getUrlAppend() |
boolean |
isAuthenticationException(java.sql.SQLException exception) |
boolean |
isEmbedded() |
boolean |
isReferentialIntegrityException(java.sql.SQLException exception) |
boolean |
isUniqueConstraintException(java.sql.SQLException exception) |
void |
setUrlAppend(java.lang.String urlAppend) |
void |
shutdownEmbedded(java.util.Properties connectionProperties)
This should shutdown the database in case it is an embedded one
and if that is applicable, such as for Derby.
|
boolean |
supportsIsValid() |
boolean |
supportsNowait()
Returns true if the dbms supports the select for update NOWAIT option
|
boolean |
supportsSelectForUpdate() |
static final PropertyValue<java.lang.String> DATABASE_TYPE
static final PropertyValue<java.lang.String> DATABASE_HOST
static final PropertyValue<java.lang.String> DATABASE_SID
static final PropertyValue<java.lang.Integer> DATABASE_PORT
static final PropertyValue<java.lang.Boolean> DATABASE_EMBEDDED
static final PropertyValue<java.lang.Boolean> DATABASE_EMBEDDED_IN_MEMORY
static final PropertyValue<java.lang.String> DATABASE_INIT_SCRIPT
static final java.lang.String USER_PROPERTY
static final java.lang.String PASSWORD_PROPERTY
static final int DEFAULT_LOGIN_TIMEOUT
DriverManager.setLoginTimeout(int)
,
Constant Field ValuesDatabase.Type getType()
java.lang.String getHost()
java.lang.Integer getPort()
java.lang.String getSid()
boolean isEmbedded()
void setUrlAppend(java.lang.String urlAppend)
urlAppend
- a string to append to the connection URLjava.lang.String getUrlAppend()
java.lang.String getAutoIncrementQuery(java.lang.String idSource)
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 valuejava.lang.NullPointerException
- in case idSource
is required and is nulljava.lang.String getSequenceQuery(java.lang.String sequenceName)
sequenceName
- the name of the sequencejava.lang.UnsupportedOperationException
- in case the underlying database does not support sequencesjava.lang.NullPointerException
- in case sequenceName
is nulljava.lang.String getURL(java.util.Properties connectionProperties)
connectionProperties
- the connection properties, used primarily to provide
embedded databases with user info for authentication purposesjava.lang.String getAuthenticationInfo(java.util.Properties connectionProperties)
connectionProperties
contains
the username and password info, otherwise it should be safe to return null.
This method is usually used in getURL()
and onDisconnect()
.connectionProperties
- the connection propertiesvoid shutdownEmbedded(java.util.Properties connectionProperties)
connectionProperties
- the connection propertiesboolean supportsIsValid()
boolean supportsSelectForUpdate()
boolean supportsNowait()
java.lang.String getCheckConnectionQuery()
supportsIsValid()
java.lang.String getErrorMessage(java.sql.SQLException exception)
exception
exception
- the underlying SQLExceptionboolean isAuthenticationException(java.sql.SQLException exception)
exception
- the exceptionboolean isReferentialIntegrityException(java.sql.SQLException exception)
exception
- the exceptionboolean isUniqueConstraintException(java.sql.SQLException exception)
exception
- the exceptionjava.util.Properties addConnectionProperties(java.util.Properties properties)
properties
- the properties map to add tojava.sql.Connection createConnection(User user) throws DatabaseException
user
- the user for which to create a connectionDatabaseException
- in case of a connection errorAuthenticationException
- in case of an authentication errorjava.lang.String getDriverClassName()
static Database.Type getDatabaseType()
DATABASE_TYPE