Spring Framework

org.springframework.jdbc.datasource
Class DelegatingDataSource

java.lang.Object
  extended by org.springframework.jdbc.datasource.DelegatingDataSource
All Implemented Interfaces:
java.sql.Wrapper, javax.sql.CommonDataSource, javax.sql.DataSource, InitializingBean
Direct Known Subclasses:
LazyConnectionDataSourceProxy, TransactionAwareDataSourceProxy, UserCredentialsDataSourceAdapter

public class DelegatingDataSource
extends java.lang.Object
implements javax.sql.DataSource, 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:
getConnection()

Constructor Summary
DelegatingDataSource()
          Create a new DelegatingDataSource.
DelegatingDataSource(javax.sql.DataSource targetDataSource)
          Create a new DelegatingDataSource.
 
Method Summary
 void afterPropertiesSet()
          Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
 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()
           
 javax.sql.DataSource getTargetDataSource()
          Return the target DataSource that this DataSource should delegate to.
 boolean isWrapperFor(java.lang.Class<?> iface)
           
 void setLoginTimeout(int seconds)
           
 void setLogWriter(java.io.PrintWriter out)
           
 void setTargetDataSource(javax.sql.DataSource targetDataSource)
          Set the target DataSource that this DataSource should delegate to.
<T> T
unwrap(java.lang.Class<T> iface)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelegatingDataSource

public DelegatingDataSource()
Create a new DelegatingDataSource.

See Also:
setTargetDataSource(javax.sql.DataSource)

DelegatingDataSource

public DelegatingDataSource(javax.sql.DataSource targetDataSource)
Create a new DelegatingDataSource.

Parameters:
targetDataSource - the target DataSource
Method Detail

setTargetDataSource

public void setTargetDataSource(javax.sql.DataSource targetDataSource)
Set the target DataSource that this DataSource should delegate to.


getTargetDataSource

public javax.sql.DataSource getTargetDataSource()
Return the target DataSource that this DataSource should delegate to.


afterPropertiesSet

public void afterPropertiesSet()
Description copied from interface: InitializingBean
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.

Specified by:
afterPropertiesSet in interface InitializingBean

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection(java.lang.String username,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException

getLogWriter

public java.io.PrintWriter getLogWriter()
                                 throws java.sql.SQLException
Specified by:
getLogWriter in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
                  throws java.sql.SQLException
Specified by:
setLogWriter in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

getLoginTimeout

public int getLoginTimeout()
                    throws java.sql.SQLException
Specified by:
getLoginTimeout in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

setLoginTimeout

public void setLoginTimeout(int seconds)
                     throws java.sql.SQLException
Specified by:
setLoginTimeout in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

unwrap

public <T> T unwrap(java.lang.Class<T> iface)
         throws java.sql.SQLException
Specified by:
unwrap in interface java.sql.Wrapper
Throws:
java.sql.SQLException

isWrapperFor

public boolean isWrapperFor(java.lang.Class<?> iface)
                     throws java.sql.SQLException
Specified by:
isWrapperFor in interface java.sql.Wrapper
Throws:
java.sql.SQLException

getParentLogger

public java.util.logging.Logger getParentLogger()

Spring Framework