public abstract class AbstractDatabase extends java.lang.Object implements Database
Database.Statistics, Database.Type
DATABASE_EMBEDDED, DATABASE_EMBEDDED_IN_MEMORY, DATABASE_HOST, DATABASE_INIT_SCRIPT, DATABASE_PORT, DATABASE_SID, DATABASE_TYPE, DEFAULT_LOGIN_TIMEOUT, PASSWORD_PROPERTY, USER_PROPERTY
Constructor and Description |
---|
AbstractDatabase(Database.Type databaseType,
java.lang.String driverClassName)
Instantiates a new AbstractDatabase using host/port/sid/embedded settings specified by system properties
|
AbstractDatabase(Database.Type databaseType,
java.lang.String driverClassName,
java.lang.String host)
Instantiates a new AbstractDatabase using port/sid/embedded settings specified by system properties
|
AbstractDatabase(Database.Type databaseType,
java.lang.String driverClassName,
java.lang.String host,
java.lang.Integer port)
Instantiates a new AbstractDatabase using sid/embedded settings specified by system properties
|
AbstractDatabase(Database.Type databaseType,
java.lang.String driverClassName,
java.lang.String host,
java.lang.Integer port,
java.lang.String sid)
Instantiates a new AbstractDatabase using the embedded settings specified by the system property
|
AbstractDatabase(Database.Type databaseType,
java.lang.String driverClassName,
java.lang.String host,
java.lang.Integer port,
java.lang.String sid,
boolean embedded)
Instantiates a new AbstractDatabase
|
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)
Returns a string containing authentication info to append to the connection URL,
based on the values found in
connectionProperties . |
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.
|
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() |
protected int |
getLoginTimeout() |
java.lang.Integer |
getPort() |
java.lang.String |
getSequenceQuery(java.lang.String sequenceName) |
java.lang.String |
getSid() |
Database.Type |
getType() |
java.lang.String |
getUrlAppend() |
boolean |
isAuthenticationException(java.sql.SQLException exception)
This default implementation returns false
|
boolean |
isEmbedded() |
boolean |
isReferentialIntegrityException(java.sql.SQLException exception)
This default implementation returns false
|
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() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getAutoIncrementQuery, getDatabaseType, getURL
public AbstractDatabase(Database.Type databaseType, java.lang.String driverClassName)
databaseType
- the database typedriverClassName
- the database driver class nameDatabase.DATABASE_HOST
,
Database.DATABASE_PORT
,
Database.DATABASE_SID
,
Database.DATABASE_EMBEDDED
public AbstractDatabase(Database.Type databaseType, java.lang.String driverClassName, java.lang.String host)
databaseType
- the database typedriverClassName
- the database driver class namehost
- the database host name or path to the database files in case of an embedded databaseDatabase.DATABASE_PORT
,
Database.DATABASE_SID
,
Database.DATABASE_EMBEDDED
public AbstractDatabase(Database.Type databaseType, java.lang.String driverClassName, java.lang.String host, java.lang.Integer port)
databaseType
- the database typedriverClassName
- the database driver class namehost
- the database host name or path to the database files in case of an embedded databaseport
- the database server portDatabase.DATABASE_SID
,
Database.DATABASE_EMBEDDED
public AbstractDatabase(Database.Type databaseType, java.lang.String driverClassName, java.lang.String host, java.lang.Integer port, java.lang.String sid)
databaseType
- the database typedriverClassName
- the database driver class namehost
- the database host name or path to the database files in case of an embedded databaseport
- the database server portsid
- the service identifierDatabase.DATABASE_EMBEDDED
public AbstractDatabase(Database.Type databaseType, java.lang.String driverClassName, java.lang.String host, java.lang.Integer port, java.lang.String sid, boolean embedded)
databaseType
- a the database typedriverClassName
- the database driver class namehost
- the database host name or path to the database files in case of an embedded databaseport
- the database server portsid
- the service identifierembedded
- true if the database is embeddedpublic final Database.Type getType()
public final java.lang.String getDriverClassName()
getDriverClassName
in interface Database
public final java.lang.String getHost()
public final java.lang.Integer getPort()
public final java.lang.String getSid()
public final boolean isEmbedded()
isEmbedded
in interface Database
public final void setUrlAppend(java.lang.String urlAppend)
setUrlAppend
in interface Database
urlAppend
- a string to append to the connection URLpublic final java.lang.String getUrlAppend()
getUrlAppend
in interface Database
public final java.sql.Connection createConnection(User user) throws DatabaseException
createConnection
in interface Database
user
- the user for which to create a connectionDatabaseException
- in case of a connection errorAuthenticationException
- in case of an authentication errorpublic boolean supportsSelectForUpdate()
supportsSelectForUpdate
in interface Database
public boolean supportsNowait()
supportsNowait
in interface Database
public boolean supportsIsValid()
supportsIsValid
in interface Database
public java.lang.String getCheckConnectionQuery()
getCheckConnectionQuery
in interface Database
Database.supportsIsValid()
public void shutdownEmbedded(java.util.Properties connectionProperties)
shutdownEmbedded
in interface Database
connectionProperties
- the connection propertiespublic java.lang.String getSequenceQuery(java.lang.String sequenceName)
getSequenceQuery
in interface Database
sequenceName
- the name of the sequencepublic java.lang.String getAuthenticationInfo(java.util.Properties connectionProperties)
connectionProperties
.
This default implementation returns the following assuming that connectionProperties
contains values for both "user" and "password" keys:
user=scott;password=tiger
The password clause is not included if no password is providedgetAuthenticationInfo
in interface Database
connectionProperties
- the connection propertiespublic java.lang.String getErrorMessage(java.sql.SQLException exception)
exception
getErrorMessage
in interface Database
exception
- the underlying SQLExceptionpublic boolean isAuthenticationException(java.sql.SQLException exception)
isAuthenticationException
in interface Database
exception
- the exceptionpublic boolean isReferentialIntegrityException(java.sql.SQLException exception)
isReferentialIntegrityException
in interface Database
exception
- the exceptionpublic boolean isUniqueConstraintException(java.sql.SQLException exception)
isUniqueConstraintException
in interface Database
exception
- the exceptionpublic java.util.Properties addConnectionProperties(java.util.Properties properties)
addConnectionProperties
in interface Database
properties
- the properties map to add toprotected int getLoginTimeout()
Database.DEFAULT_LOGIN_TIMEOUT