Class DelegatingDataSource

  • All Implemented Interfaces:
    java.sql.Wrapper, javax.sql.CommonDataSource, javax.sql.DataSource

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

      Constructors 
      Constructor Description
      DelegatingDataSource​(javax.sql.DataSource targetDataSource)
      Create a new DelegatingDataSource.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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()  
      javax.sql.DataSource getTargetDataSource()  
      boolean isWrapperFor​(java.lang.Class<?> iface)  
      void setLoginTimeout​(int seconds)  
      void setLogWriter​(java.io.PrintWriter out)  
      <T> T unwrap​(java.lang.Class<T> iface)  
      static javax.sql.DataSource unwrapDataSource​(javax.sql.DataSource dataSource)
      Unwraps the data source obtaining the target.
      • 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 Detail

      • DelegatingDataSource

        public DelegatingDataSource​(@NonNull
                                    javax.sql.DataSource targetDataSource)
        Create a new DelegatingDataSource.
        Parameters:
        targetDataSource - the target DataSource
    • Method Detail

      • getTargetDataSource

        @NonNull
        public final javax.sql.DataSource getTargetDataSource()
        Returns:
        Return the target DataSource that this DataSource should delegate to.
      • 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
        Specified by:
        getLogWriter in interface javax.sql.DataSource
        Throws:
        java.sql.SQLException
      • setLogWriter

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

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

        public void setLoginTimeout​(int seconds)
                             throws java.sql.SQLException
        Specified by:
        setLoginTimeout in interface javax.sql.CommonDataSource
        Specified by:
        setLoginTimeout in interface javax.sql.DataSource
        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()
        Specified by:
        getParentLogger in interface javax.sql.CommonDataSource
      • unwrapDataSource

        @NonNull
        public static javax.sql.DataSource unwrapDataSource​(@NonNull
                                                            javax.sql.DataSource dataSource)
        Unwraps the data source obtaining the target.
        Parameters:
        dataSource - The data source
        Returns:
        The target