Class DatabaseConnection
- All Implemented Interfaces:
AdaptrisComponent,AdaptrisConnection,ComponentLifecycle,ComponentLifecycleExtension,StateManagedComponent
- Direct Known Subclasses:
FailoverJdbcConnection,JdbcConnection,JdbcPooledConnectionImpl
Abstract class containing configuration for JDBC Connection classes.
-
Field Summary
Fields inherited from class com.adaptris.core.AdaptrisConnectionImp
log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanExpose this DatabaseConnection as a DataSourcebooleanprotected voidprotected final voidClose the underlying connection.protected abstract voidInitialise the underlying database connection.final Connectionconnect()Returns the underlyingSQLConnection.protected Propertiesbooleanabstract booleanForce implementations to over-ride equals with a semantic implementation.Returns whether to always validate the database connection.Returns whether to auto-commit.protected abstract StringReturns a name for this connection for logging purposes.Get any additional connection properties that have been configured.Returns this connection's debug mode.abstract inthashCode()Force implementations to over-ride hashcode.protected final voidInitialisation ensures that the configured driver implementation is available for use.protected abstract voidInitialise the underlying database connection.protected static voidloadDriverClass(String clazz) protected abstract ConnectionMake the connection.protected voidvoidSet whether to always validate the database connection.voidSets whether to auto-commit.voidSet any additional connection properties.voidsetDebugMode(Boolean dbg) Set this connection's debug mode.voidSet the password used to access the database.voidSet the username used to access the database.protected final voidStarting this connection means that an initial attempt is made to connect to the database.protected abstract voidInitialise the underlying database connection.protected final voidStop the underlying connection.protected abstract voidInitialise the underlying database connection.Methods inherited from class com.adaptris.core.AllowsRetriesConnection
connectionAttempts, connectionRetryInterval, createLoggingStatement, getConnectionAttempts, getConnectionRetryInterval, logWarning, setConnectionAttempts, setConnectionRetryIntervalMethods inherited from class com.adaptris.core.AdaptrisConnectionImp
addExceptionListener, addMessageConsumer, addMessageProducer, changeState, cloneForTesting, close, connectionErrorHandler, connectionStateHandler, getConnectionErrorHandler, getConnectionStateHandler, getRuntimeComponent, getUniqueId, getWorkersFirstOnShutdown, init, prepare, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, retrieveConnection, retrieveExceptionListeners, retrieveMessageConsumers, retrieveMessageProducers, setConnectionErrorHandler, setConnectionStateHandler, setRuntimeComponent, setUniqueId, setWorkersFirstOnShutdown, start, stop, workersFirstOnShutdown
-
Constructor Details
-
DatabaseConnection
public DatabaseConnection()
-
-
Method Details
-
prepareConnection
- Specified by:
prepareConnectionin classAdaptrisConnectionImp- Throws:
CoreException
-
initConnection
Initialisation ensures that the configured driver implementation is available for use. It does not perform connection verification. This is done by
startor upon the first call toprepareStatement()- Specified by:
initConnectionin classAdaptrisConnectionImp- Throws:
CoreException- if the driver implementation was not available.
-
loadDriverClass
-
startConnection
Starting this connection means that an initial attempt is made to connect to the database. The connection could previously have been started by a call to
getConnection- Specified by:
startConnectionin classAdaptrisConnectionImp- Throws:
CoreException- if the connection could not be started.- See Also:
-
stopConnection
protected final void stopConnection()Description copied from class:AdaptrisConnectionImpStop the underlying connection.- Specified by:
stopConnectionin classAdaptrisConnectionImp- See Also:
-
closeConnection
protected final void closeConnection()Description copied from class:AdaptrisConnectionImpClose the underlying connection.- Specified by:
closeConnectionin classAdaptrisConnectionImp
-
setAutoCommit
Sets whether to auto-commit.
- Parameters:
b- whether to auto-commit; default is true.
-
getAutoCommit
Returns whether to auto-commit.
- Returns:
- whether to auto-commit
-
autoCommit
public boolean autoCommit() -
setDebugMode
Set this connection's debug mode.
In debug mode there is additional logging for reconnection attempts.
- Parameters:
dbg- this connection's debug mode
-
getDebugMode
Returns this connection's debug mode.
- Returns:
- this connection's debug mode
-
debugMode
public boolean debugMode() -
asDataSource
Expose this DatabaseConnection as a DataSource- Returns:
- a DataSource implementation
- Throws:
SQLException- See Also:
-
connect
Returns the underlying
SQLConnection.- Returns:
- the underlying
SQLConnection - Throws:
SQLException- if the connection was not valid, and reconnection failed
-
makeConnection
Make the connection.
This abstract method should be implemented by concrete sub-classes to make or check the current connection to the Jdbc source.
- Returns:
- a java.sql.Connection
- Throws:
SQLException- if the connection could not be made.- See Also:
-
initialiseDatabaseConnection
Initialise the underlying database connection.
This abstract method should be implemented by concrete sub-classes to initialise any components other than the DriverManager.
- Throws:
CoreException- wrapping any underlying exception.
-
startDatabaseConnection
Initialise the underlying database connection.
This abstract method should be implemented by concrete sub-classes to initialise any components other than the DriverManager.
- Throws:
CoreException- wrapping any underlying exception.
-
stopDatabaseConnection
protected abstract void stopDatabaseConnection()Initialise the underlying database connection.
This abstract method should be implemented by concrete sub-classes to stop any components other than the DriverManager.
-
closeDatabaseConnection
protected abstract void closeDatabaseConnection()Initialise the underlying database connection.
This abstract method should be implemented by concrete sub-classes to close any components.
-
getConnectionName
Returns a name for this connection for logging purposes.
- Returns:
- a name for this connection for logging purposes
-
checkInternalState
- Throws:
SQLException
-
setAlwaysValidateConnection
Set whether to always validate the database connection.
Validating the connection means that the test-statement is executed every time
connect()is invoked. Depending on the test statement in question this might have an impact upon performance.- Parameters:
b- whether to always validate the database connection; defaults to false.
-
getAlwaysValidateConnection
Returns whether to always validate the database connection.
- Returns:
- whether to always validate the database connection
-
alwaysValidateConnection
public boolean alwaysValidateConnection() -
equals
Force implementations to over-ride equals with a semantic implementation.
-
hashCode
public abstract int hashCode()Force implementations to over-ride hashcode.
-
getUsername
-
setUsername
Set the username used to access the database.- Parameters:
s-
-
getPassword
-
setPassword
Set the password used to access the database.- Parameters:
s- the password which might be encoded using an available password scheme fromPassword
-
getConnectionProperties
Get any additional connection properties that have been configured.- Returns:
- any additional properties
-
setConnectionProperties
Set any additional connection properties.If additional connection properties are set, then any configured username/password will be applied to the connection properties against the key
'user'and'password'respectively. If you have configured thos properties in the connection-properties element, then make sure that you do not configuresetUsername(String)orsetPassword(String).- Parameters:
p- any additional properties over and above username/password.
-
connectionProperties
- Throws:
PasswordException
-