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
,ShardingKeyDataSourceAdapter
,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
ConstructorsConstructorDescriptionCreate 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
(@Nullable DataSource targetDataSource) Set the target DataSource that this DataSource should delegate to.<T> T
-
Constructor Details
-
DelegatingDataSource
public DelegatingDataSource()Create a new DelegatingDataSource.- See Also:
-
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
-
createConnectionBuilder
- Specified by:
createConnectionBuilder
in interfaceDataSource
- Throws:
SQLException
-
createShardingKeyBuilder
- Specified by:
createShardingKeyBuilder
in interfaceCommonDataSource
- 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
-
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
-
getParentLogger
- Specified by:
getParentLogger
in interfaceCommonDataSource
-
unwrap
- Specified by:
unwrap
in interfaceWrapper
- Throws:
SQLException
-
isWrapperFor
- Specified by:
isWrapperFor
in interfaceWrapper
- Throws:
SQLException
-