public class FailoverDataSource
extends java.lang.Object
implements javax.sql.DataSource
Because of we want to failover to an alternate database, the implementation
of getConnection(String username, String password)
simply discards the username and password and relies on the
configuration that was supplied when constructing this class. This is the
desired behaviour.
The underlying pool implementation is a
org.apache.commons.pool.impl.GenericObjectPool
. The default size
of the pool is 10 with a wait time of 20seconds. If the pool is exhausted,
then a NoSuchElementException will be thrown after the wait time.
DataSource
,
FailoverConnection
,
FailoverConfig
Modifier and Type | Class and Description |
---|---|
protected class |
FailoverDataSource.ConnectionProxy
This class proxies the underlying FailoverConnection class.
|
protected class |
FailoverDataSource.PoolAttendant
This class is reponsible for creating swimmers who swim in the Datasource
Pool.
|
Modifier and Type | Field and Description |
---|---|
protected org.slf4j.Logger |
logR |
static java.lang.String |
POOL_MAX_SIZE
Resource Key for the maximum size of the pool.
|
static java.lang.String |
POOL_TIME_TO_WAIT
Resource Key for the time to wait for an available connection.
|
Constructor and Description |
---|
FailoverDataSource(java.util.Properties p) |
Modifier and Type | Method and Description |
---|---|
protected FailoverConfig |
config() |
protected void |
destroy() |
java.sql.Connection |
getConnection()
Get the configured connection.
|
java.sql.Connection |
getConnection(java.lang.String username,
java.lang.String password)
Get the configured connection.
|
int |
getLoginTimeout() |
java.io.PrintWriter |
getLogWriter() |
java.util.logging.Logger |
getParentLogger() |
boolean |
isWrapperFor(java.lang.Class<?> iface) |
protected int |
maxPoolSize() |
protected void |
overrideObjectPool(org.apache.commons.pool.impl.GenericObjectPool p) |
void |
setLoginTimeout(int loginTimeout) |
void |
setLogWriter(java.io.PrintWriter logWriter) |
protected long |
timeToWait() |
<T> T |
unwrap(java.lang.Class<T> iface) |
protected static java.sql.SQLClientInfoException |
wrapSQLClientInfoException(java.lang.Exception e) |
protected static java.sql.SQLException |
wrapSQLException(java.lang.Exception e) |
public static final java.lang.String POOL_MAX_SIZE
public static final java.lang.String POOL_TIME_TO_WAIT
protected transient org.slf4j.Logger logR
protected FailoverConfig config()
protected int maxPoolSize()
protected long timeToWait()
protected void overrideObjectPool(org.apache.commons.pool.impl.GenericObjectPool p) throws java.lang.Exception
java.lang.Exception
protected void destroy() throws java.lang.Exception
java.lang.Exception
public java.sql.Connection getConnection() throws java.sql.SQLException
getConnection
in interface javax.sql.DataSource
java.sql.SQLException
DataSource.getConnection()
public java.sql.Connection getConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLException
This class will ignore the supplied credentials, relying on the configuration used to create this source instead.
This can be considered breaking the javax.sql.DataSource contract, however, this is the desired behaviour when you are failing over to multiple databases.
getConnection
in interface javax.sql.DataSource
java.sql.SQLException
DataSource.getConnection(String, String)
public void setLoginTimeout(int loginTimeout) throws java.sql.SQLException
setLoginTimeout
in interface javax.sql.CommonDataSource
java.sql.SQLException
CommonDataSource.setLoginTimeout(int)
public int getLoginTimeout() throws java.sql.SQLException
getLoginTimeout
in interface javax.sql.CommonDataSource
java.sql.SQLException
CommonDataSource.getLoginTimeout()
public void setLogWriter(java.io.PrintWriter logWriter) throws java.sql.SQLException
setLogWriter
in interface javax.sql.CommonDataSource
java.sql.SQLException
CommonDataSource.setLogWriter(java.io.PrintWriter)
public java.io.PrintWriter getLogWriter() throws java.sql.SQLException
getLogWriter
in interface javax.sql.CommonDataSource
java.sql.SQLException
CommonDataSource.getLogWriter()
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException
isWrapperFor
in interface java.sql.Wrapper
java.sql.SQLException
Wrapper.isWrapperFor(java.lang.Class)
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException
unwrap
in interface java.sql.Wrapper
java.sql.SQLException
Wrapper.unwrap(java.lang.Class)
public java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException
getParentLogger
in interface javax.sql.CommonDataSource
java.sql.SQLFeatureNotSupportedException
protected static java.sql.SQLClientInfoException wrapSQLClientInfoException(java.lang.Exception e)
protected static java.sql.SQLException wrapSQLException(java.lang.Exception e)