Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

safejdbc
Class LoggingWrapper  view LoggingWrapper download LoggingWrapper.java

java.lang.Object
  extended bysafejdbc.LoggingWrapper
All Implemented Interfaces:
ConnectionProvider

public class LoggingWrapper
extends java.lang.Object
implements ConnectionProvider

If you want to log your SQL-Statements you just have to wrap your ConnectionProvider with a LoggingWrapper.


Field Summary
private  ConnectionProvider _conprovider
           
private  LogListener _loglistener
           
 
Constructor Summary
LoggingWrapper(ConnectionProvider conprovider)
          This constructor is for your convenience.
LoggingWrapper(ConnectionProvider conprovider, LogListener loglistener)
          Every SQL-Statement will be handed over to the LogListener.
 
Method Summary
 java.sql.Connection getConnection()
          This method is called to actually give the connection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_conprovider

private ConnectionProvider _conprovider

_loglistener

private LogListener _loglistener
Constructor Detail

LoggingWrapper

public LoggingWrapper(ConnectionProvider conprovider)
This constructor is for your convenience. All SQL-Statements are logged to System.out. What this constructor does inside is the following:
 this(conprovider,
      new LogListener() {
          public void log(String sqlstmt) {
              System.out.println(sqlstmt);
          }
      });
 


LoggingWrapper

public LoggingWrapper(ConnectionProvider conprovider,
                      LogListener loglistener)
Every SQL-Statement will be handed over to the LogListener. Assuming you want to integrate your own Logging-Service you could do the following:
 LogListener loglistener = new LogListener() {
     public void log(String sqlstmt) {
         MyLogger.log(sqlstmt);
     }
 };
 ConnectionProvider conprovider = new DataSourceAdapter(myDataSource);
 ConnectionProvider loggingconprovider = new LoggingWrapper(conprovider, loglistener);
 SQL sql = new SQLExecuter(loggingconprovider);
 // ... 
 

Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Description copied from interface: ConnectionProvider
This method is called to actually give the connection

Specified by:
getConnection in interface ConnectionProvider