Package io.mats3.util.wrappers
Class DataSourceWrapper
java.lang.Object
io.mats3.util.wrappers.DataSourceWrapper
- All Implemented Interfaces:
MatsFactory.MatsWrapper<DataSource>
,Wrapper
,CommonDataSource
,DataSource
- Direct Known Subclasses:
DeferredConnectionProxyDataSourceWrapper
public class DataSourceWrapper
extends Object
implements DataSource, MatsFactory.MatsWrapper<DataSource>
A base Wrapper for a JDBC
DataSource
, which simply implements DataSource, takes a DataSource instance and
forwards all calls to that. Meant to be extended to add extra functionality, e.g. Spring integration.-
Constructor Summary
ConstructorsConstructorDescriptionNo-args constructor, which implies that you either need to invokesetWrappee(DataSource)
before publishing the instance (making it available for other threads), or overrideunwrap()
to provide the desiredDataSource
instance.DataSourceWrapper
(DataSource targetDataSource) Standard constructor, taking the wrappedDataSource
instance. -
Method Summary
Modifier and TypeMethodDescriptiongetConnection
(String username, String password) int
boolean
isWrapperFor
(Class<?> iface) void
setLoginTimeout
(int seconds) void
setLogWriter
(PrintWriter out) void
setWrappee
(DataSource targetDataSource) Sets the wrappedDataSource
, e.g.toString()
unwrap()
<T> T
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder
Methods inherited from interface io.mats3.MatsFactory.MatsWrapper
unwrapFully, unwrapTo
-
Constructor Details
-
DataSourceWrapper
Standard constructor, taking the wrappedDataSource
instance.- Parameters:
targetDataSource
- theDataSource
instance whichunwrap()
will return (and hence all forwarded methods will use).
-
DataSourceWrapper
public DataSourceWrapper()No-args constructor, which implies that you either need to invokesetWrappee(DataSource)
before publishing the instance (making it available for other threads), or overrideunwrap()
to provide the desiredDataSource
instance. In these cases, make sure to honor memory visibility semantics - i.e. establish a happens-before edge between the setting of the instance and any other threads getting it.
-
-
Method Details
-
setWrappee
Sets the wrappedDataSource
, e.g. in case you instantiated it with the no-args constructor. Do note that the field holding the wrapped instance is not volatile nor synchronized. This means that if you want to set it after it has been published to other threads, you will have to override both this method andunwrap()
to provide for needed memory visibility semantics, i.e. establish a happens-before edge between the setting of the instance and any other threads getting it.- Specified by:
setWrappee
in interfaceMatsFactory.MatsWrapper<DataSource>
- Parameters:
targetDataSource
- theDataSource
which is returned byunwrap()
, unless that is overridden.
-
unwrap
- Specified by:
unwrap
in interfaceMatsFactory.MatsWrapper<DataSource>
- Returns:
- the wrapped
DataSource
. All forwarding methods invokes this method to get the wrappedDataSource
, thus if you want to get creative wrt. how and when the DataSource is decided, you can override this method.
-
getConnection
- Specified by:
getConnection
in interfaceDataSource
- Throws:
SQLException
-
getConnection
- Specified by:
getConnection
in interfaceDataSource
- Throws:
SQLException
-
getLogWriter
- Specified by:
getLogWriter
in interfaceCommonDataSource
- Specified by:
getLogWriter
in interfaceDataSource
- Throws:
SQLException
-
setLogWriter
- Specified by:
setLogWriter
in interfaceCommonDataSource
- Specified by:
setLogWriter
in interfaceDataSource
- Throws:
SQLException
-
setLoginTimeout
- Specified by:
setLoginTimeout
in interfaceCommonDataSource
- Specified by:
setLoginTimeout
in interfaceDataSource
- Throws:
SQLException
-
getLoginTimeout
- Specified by:
getLoginTimeout
in interfaceCommonDataSource
- Specified by:
getLoginTimeout
in interfaceDataSource
- Throws:
SQLException
-
getParentLogger
- Specified by:
getParentLogger
in interfaceCommonDataSource
- Throws:
SQLFeatureNotSupportedException
-
unwrap
- Specified by:
unwrap
in interfaceWrapper
- Throws:
SQLException
-
isWrapperFor
- Specified by:
isWrapperFor
in interfaceWrapper
- Throws:
SQLException
-
toString
-