public class DataSourceWrapper extends java.lang.Object implements javax.sql.DataSource, MatsFactory.MatsWrapper<javax.sql.DataSource>
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 and Description |
---|
DataSourceWrapper()
No-args constructor, which implies that you either need to invoke
setWrappee(DataSource) before
publishing the instance (making it available for other threads), or override unwrap() to provide the
desired DataSource instance. |
DataSourceWrapper(javax.sql.DataSource targetDataSource)
Standard constructor, taking the wrapped
DataSource instance. |
Modifier and Type | Method and Description |
---|---|
java.sql.Connection |
getConnection() |
java.sql.Connection |
getConnection(java.lang.String username,
java.lang.String password) |
int |
getLoginTimeout() |
java.io.PrintWriter |
getLogWriter() |
java.util.logging.Logger |
getParentLogger() |
boolean |
isWrapperFor(java.lang.Class<?> iface) |
void |
setLoginTimeout(int seconds) |
void |
setLogWriter(java.io.PrintWriter out) |
void |
setWrappee(javax.sql.DataSource targetDataSource)
Sets the wrapped
DataSource , e.g. |
java.lang.String |
toString() |
javax.sql.DataSource |
unwrap() |
<T> T |
unwrap(java.lang.Class<T> iface) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
unwrapFully, unwrapTo
public DataSourceWrapper(javax.sql.DataSource targetDataSource)
DataSource
instance.targetDataSource
- the DataSource
instance which unwrap()
will return (and hence all forwarded methods
will use).public DataSourceWrapper()
setWrappee(DataSource)
before
publishing the instance (making it available for other threads), or override unwrap()
to provide the
desired DataSource
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.public void setWrappee(javax.sql.DataSource targetDataSource)
DataSource
, 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 and
unwrap()
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.setWrappee
in interface MatsFactory.MatsWrapper<javax.sql.DataSource>
targetDataSource
- the DataSource
which is returned by unwrap()
, unless that is overridden.public javax.sql.DataSource unwrap()
unwrap
in interface MatsFactory.MatsWrapper<javax.sql.DataSource>
DataSource
. All forwarding methods invokes this method to get the wrapped
DataSource
, thus if you want to get creative wrt. how and when the DataSource is decided, you can
override this method.public java.sql.Connection getConnection() throws java.sql.SQLException
getConnection
in interface javax.sql.DataSource
java.sql.SQLException
public java.sql.Connection getConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLException
getConnection
in interface javax.sql.DataSource
java.sql.SQLException
public java.io.PrintWriter getLogWriter() throws java.sql.SQLException
getLogWriter
in interface javax.sql.CommonDataSource
java.sql.SQLException
public void setLogWriter(java.io.PrintWriter out) throws java.sql.SQLException
setLogWriter
in interface javax.sql.CommonDataSource
java.sql.SQLException
public void setLoginTimeout(int seconds) throws java.sql.SQLException
setLoginTimeout
in interface javax.sql.CommonDataSource
java.sql.SQLException
public int getLoginTimeout() throws java.sql.SQLException
getLoginTimeout
in interface javax.sql.CommonDataSource
java.sql.SQLException
public java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException
getParentLogger
in interface javax.sql.CommonDataSource
java.sql.SQLFeatureNotSupportedException
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException
unwrap
in interface java.sql.Wrapper
java.sql.SQLException
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException
isWrapperFor
in interface java.sql.Wrapper
java.sql.SQLException
public java.lang.String toString()
toString
in class java.lang.Object