Class FailoverDataSource
- All Implemented Interfaces:
Wrapper
,CommonDataSource
,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.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
This class proxies the underlying FailoverConnection class.protected class
This class is reponsible for creating swimmers who swim in the Datasource Pool. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected FailoverConfig
config()
protected void
destroy()
Get the configured connection.getConnection
(String username, String password) Get the configured connection.int
boolean
isWrapperFor
(Class<?> iface) protected int
protected void
overrideObjectPool
(org.apache.commons.pool.impl.GenericObjectPool p) void
setLoginTimeout
(int loginTimeout) void
setLogWriter
(PrintWriter logWriter) protected long
<T> T
protected static SQLClientInfoException
protected static SQLException
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
Field Details
-
POOL_MAX_SIZE
Resource Key for the maximum size of the pool.- See Also:
-
POOL_TIME_TO_WAIT
Resource Key for the time to wait for an available connection.- See Also:
-
logR
protected transient org.slf4j.Logger logR
-
-
Constructor Details
-
FailoverDataSource
-
-
Method Details
-
config
-
maxPoolSize
protected int maxPoolSize() -
timeToWait
protected long timeToWait() -
overrideObjectPool
protected void overrideObjectPool(org.apache.commons.pool.impl.GenericObjectPool p) throws Exception - Throws:
Exception
-
destroy
- Throws:
Exception
-
getConnection
Get the configured connection.- Specified by:
getConnection
in interfaceDataSource
- Throws:
SQLException
- See Also:
-
getConnection
Get the configured connection.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.
- Specified by:
getConnection
in interfaceDataSource
- Throws:
SQLException
- See Also:
-
setLoginTimeout
- Specified by:
setLoginTimeout
in interfaceCommonDataSource
- Specified by:
setLoginTimeout
in interfaceDataSource
- Throws:
SQLException
- See Also:
-
getLoginTimeout
- Specified by:
getLoginTimeout
in interfaceCommonDataSource
- Specified by:
getLoginTimeout
in interfaceDataSource
- Throws:
SQLException
- See Also:
-
setLogWriter
- Specified by:
setLogWriter
in interfaceCommonDataSource
- Specified by:
setLogWriter
in interfaceDataSource
- Throws:
SQLException
- See Also:
-
getLogWriter
- Specified by:
getLogWriter
in interfaceCommonDataSource
- Specified by:
getLogWriter
in interfaceDataSource
- Throws:
SQLException
- See Also:
-
isWrapperFor
- Specified by:
isWrapperFor
in interfaceWrapper
- Throws:
SQLException
- See Also:
-
unwrap
- Specified by:
unwrap
in interfaceWrapper
- Throws:
SQLException
- See Also:
-
getParentLogger
- Specified by:
getParentLogger
in interfaceCommonDataSource
- Throws:
SQLFeatureNotSupportedException
-
wrapSQLClientInfoException
-
wrapSQLException
-