001    /**
002     * Copyright 2007-2008 Arthur Blake
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *    http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package net.sf.log4jdbc;
017    
018    /**
019     * Delegates Spy events to a logger.
020     * This interface is used for all logging activity used by log4jdbc and hides the specific implementation
021     * of any given logging system from log4jdbc.
022     *
023     * @author Arthur Blake
024     */
025    public interface SpyLogDelegator
026    {
027      /**
028       * Determine if any of the jdbc or sql loggers are turned on.
029       *
030       * @return true if any of the jdbc or sql loggers are enabled at error level or higher.
031       */
032      public boolean isJdbcLoggingEnabled();
033    
034      /**
035       * Called when a spied upon method throws an Exception.
036       *
037       * @param spy        the Spy wrapping the class that threw an Exception.
038       * @param methodCall a description of the name and call parameters of the method generated the Exception.
039       * @param e          the Exception that was thrown.
040       * @param sql        optional sql that occured just before the exception occured.
041       * @param execTime   optional amount of time that passed before an exception was thrown when sql was being executed.
042       *                   caller should pass -1 if not used
043       */
044      public void exceptionOccured(Spy spy, String methodCall, Exception e, String sql, long execTime);
045    
046      /**
047       * Called when spied upon method call returns.
048       *
049       * @param spy        the Spy wrapping the class that called the method that returned.
050       * @param methodCall a description of the name and call parameters of the method that returned.
051       * @param returnMsg  return value converted to a String for integral types, or String representation for Object
052       *                   return types this will be null for void return types.
053       */
054      public void methodReturned(Spy spy, String methodCall, String returnMsg);
055    
056      /**
057       * Called when a spied upon object is constructed.
058       *
059       * @param spy              the Spy wrapping the class that called the method that returned.
060       * @param constructionInfo information about the object construction
061       */
062      public void constructorReturned(Spy spy, String constructionInfo);
063    
064      /**
065       * Special call that is called only for JDBC method calls that contain SQL.
066       *
067       * @param spy        the Spy wrapping the class where the SQL occured.
068       * @param methodCall a description of the name and call parameters of the method that generated the SQL.
069       * @param sql        sql that occured.
070       */
071      public void sqlOccured(Spy spy, String methodCall, String sql);
072    
073      /**
074       * Similar to sqlOccured, but reported after SQL executes and used to report timing stats on the SQL
075       *
076       * @param spy the    Spy wrapping the class where the SQL occured.
077       * @param execTime   how long it took the sql to run, in msec.
078       * @param methodCall a description of the name and call parameters of the method that generated the SQL.
079       * @param sql        sql that occured.
080       */
081      public void sqlTimingOccured(Spy spy, long execTime, String methodCall, String sql);
082    
083      /**
084       * Called whenever a new connection spy is created.
085       * 
086       * @param spy ConnectionSpy that was created.
087       */
088      public void connectionOpened(Spy spy);
089    
090      /**
091       * Called whenever a connection spy is closed.
092       * 
093       * @param spy ConnectionSpy that was closed.
094       */
095      public void connectionClosed(Spy spy);
096    
097      /**
098       * Log a Setup and/or administrative log message for log4jdbc.
099       *
100       * @param msg message to log.
101       */
102      public void debug(String msg);
103    
104    }