Class DelegatingDataSource
java.lang.Object
org.springframework.jdbc.datasource.DelegatingDataSource
- All Implemented Interfaces:
Wrapper
,CommonDataSource
,DataSource
,org.springframework.beans.factory.InitializingBean
- Direct Known Subclasses:
LazyConnectionDataSourceProxy
,TransactionAwareDataSourceProxy
,UserCredentialsDataSourceAdapter
public class DelegatingDataSource
extends Object
implements DataSource, org.springframework.beans.factory.InitializingBean
JDBC
DataSource
implementation that delegates all calls
to a given target DataSource
.
This class is meant to be subclassed, with subclasses overriding only
those methods (such as getConnection()
) that should not simply
delegate to the target DataSource.
- Since:
- 1.1
- Author:
- Juergen Hoeller
- See Also:
-
Constructor Summary
ConstructorDescriptionCreate a new DelegatingDataSource.DelegatingDataSource
(DataSource targetDataSource) Create a new DelegatingDataSource. -
Method Summary
Modifier and TypeMethodDescriptionvoid
getConnection
(String username, String password) int
Return the target DataSource that this DataSource should delegate to.boolean
isWrapperFor
(Class<?> iface) protected DataSource
Obtain the targetDataSource
for actual use (nevernull
).void
setLoginTimeout
(int seconds) void
setLogWriter
(PrintWriter out) void
setTargetDataSource
(DataSource targetDataSource) Set the target DataSource that this DataSource should delegate to.<T> T
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
-
Constructor Details
-
DelegatingDataSource
public DelegatingDataSource()Create a new DelegatingDataSource. -
DelegatingDataSource
Create a new DelegatingDataSource.- Parameters:
targetDataSource
- the target DataSource
-
-
Method Details
-
setTargetDataSource
Set the target DataSource that this DataSource should delegate to. -
getTargetDataSource
Return the target DataSource that this DataSource should delegate to. -
obtainTargetDataSource
Obtain the targetDataSource
for actual use (nevernull
).- Since:
- 5.0
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-
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
-
getLoginTimeout
- Specified by:
getLoginTimeout
in interfaceCommonDataSource
- Specified by:
getLoginTimeout
in interfaceDataSource
- Throws:
SQLException
-
setLoginTimeout
- Specified by:
setLoginTimeout
in interfaceCommonDataSource
- Specified by:
setLoginTimeout
in interfaceDataSource
- Throws:
SQLException
-
unwrap
- Specified by:
unwrap
in interfaceWrapper
- Throws:
SQLException
-
isWrapperFor
- Specified by:
isWrapperFor
in interfaceWrapper
- Throws:
SQLException
-
getParentLogger
- Specified by:
getParentLogger
in interfaceCommonDataSource
-