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
Nested ClassesModifier and TypeClassDescriptionprotected classThis class proxies the underlying FailoverConnection class.protected classThis class is reponsible for creating swimmers who swim in the Datasource Pool. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected FailoverConfigconfig()protected voiddestroy()Get the configured connection.getConnection(String username, String password) Get the configured connection.intbooleanisWrapperFor(Class<?> iface) protected intprotected voidoverrideObjectPool(org.apache.commons.pool.impl.GenericObjectPool p) voidsetLoginTimeout(int loginTimeout) voidsetLogWriter(PrintWriter logWriter) protected long<T> Tprotected static SQLClientInfoExceptionprotected static SQLExceptionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilderMethods 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:
getConnectionin 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:
getConnectionin interfaceDataSource- Throws:
SQLException- See Also:
-
setLoginTimeout
- Specified by:
setLoginTimeoutin interfaceCommonDataSource- Specified by:
setLoginTimeoutin interfaceDataSource- Throws:
SQLException- See Also:
-
getLoginTimeout
- Specified by:
getLoginTimeoutin interfaceCommonDataSource- Specified by:
getLoginTimeoutin interfaceDataSource- Throws:
SQLException- See Also:
-
setLogWriter
- Specified by:
setLogWriterin interfaceCommonDataSource- Specified by:
setLogWriterin interfaceDataSource- Throws:
SQLException- See Also:
-
getLogWriter
- Specified by:
getLogWriterin interfaceCommonDataSource- Specified by:
getLogWriterin interfaceDataSource- Throws:
SQLException- See Also:
-
isWrapperFor
- Specified by:
isWrapperForin interfaceWrapper- Throws:
SQLException- See Also:
-
unwrap
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException- See Also:
-
getParentLogger
- Specified by:
getParentLoggerin interfaceCommonDataSource- Throws:
SQLFeatureNotSupportedException
-
wrapSQLClientInfoException
-
wrapSQLException
-