net.sf.log4jdbc
Class Log4jdbcProxyDataSource

java.lang.Object
  extended by net.sf.log4jdbc.Log4jdbcProxyDataSource
All Implemented Interfaces:
Wrapper, CommonDataSource, DataSource

public class Log4jdbcProxyDataSource
extends Object
implements DataSource

A proxy datasource that can be used to wrap a real data source allowing log4jdbc to do its work on the real data source. Inspired by http://groups.google.com/group/log4jdbc/browse_thread/thread/0706611d1b85e210 This can be useful in a Spring context. Imagine your spring context includes this datasource definition

  
      
       
       
       
       
       
       
       
   
 
You can get log4jdbc to work on this using the following config changes
  
      
       
       
       
       
       
       
       
   
   
   
     
   
 

Author:
tim.azzopardi

Constructor Summary
Log4jdbcProxyDataSource(DataSource realDataSource)
           
 
Method Summary
 Connection getConnection()
           
 Connection getConnection(String username, String password)
           
 SpyLogDelegator getLogFormatter()
           
 int getLoginTimeout()
           
 PrintWriter getLogWriter()
           
 boolean isWrapperFor(Class<?> iface)
           
 void setLogFormatter(SpyLogDelegator spyLogDelegator)
          Set a custom SpyLogDelegator (default is usually Slf4jSpyLogDelegator)
 void setLoginTimeout(int seconds)
           
 void setLogWriter(PrintWriter out)
           
<T> T
unwrap(Class<T> iface)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Log4jdbcProxyDataSource

public Log4jdbcProxyDataSource(DataSource realDataSource)
Method Detail

getLogFormatter

public SpyLogDelegator getLogFormatter()

setLogFormatter

public void setLogFormatter(SpyLogDelegator spyLogDelegator)
Set a custom SpyLogDelegator (default is usually Slf4jSpyLogDelegator)

Parameters:
spyLogDelegator -

getConnection

public Connection getConnection()
                         throws SQLException
Specified by:
getConnection in interface DataSource
Throws:
SQLException

getConnection

public Connection getConnection(String username,
                                String password)
                         throws SQLException
Specified by:
getConnection in interface DataSource
Throws:
SQLException

getLoginTimeout

public int getLoginTimeout()
                    throws SQLException
Specified by:
getLoginTimeout in interface CommonDataSource
Throws:
SQLException

getLogWriter

public PrintWriter getLogWriter()
                         throws SQLException
Specified by:
getLogWriter in interface CommonDataSource
Throws:
SQLException

isWrapperFor

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

setLoginTimeout

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

setLogWriter

public void setLogWriter(PrintWriter out)
                  throws SQLException
Specified by:
setLogWriter in interface CommonDataSource
Throws:
SQLException

unwrap

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


Copyright © 2012. All Rights Reserved.