Class DelegatingDataSource
java.lang.Object
org.springframework.jdbc.datasource.DelegatingDataSource
- All Implemented Interfaces:
Wrapper
,CommonDataSource
,DataSource
,InitializingBean
- Direct Known Subclasses:
LazyConnectionDataSourceProxy
,ShardingKeyDataSourceAdapter
,TransactionAwareDataSourceProxy
,UserCredentialsDataSourceAdapter
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
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.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. -
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()Description copied from interface:InitializingBean
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- Specified by:
afterPropertiesSet
in interfaceInitializingBean
-
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
-