com.triactive.jdo.jdbc.trace
Class Trace

java.lang.Object
  extended bycom.triactive.jdo.jdbc.trace.Trace

public class Trace
extends java.lang.Object

Provides tracing of JDBC activity.

A trace object is configured to enable or disable the logging of various kinds of JDBC activity, such as the execution time of SQL statements. The traceConnection() method is then used to apply the tracing to a given connection. A low-overhead wrapper is placed around the connection and its related objects to perform the logging. All log output is sent to a log category called "com.triactive.jdo.JdbcTrace".

Each trace option is a boolean that enables or disables logging of a particular kind of activity. The options can be set individually by setter methods or collectively with the setOptions() method.

Author:
Mike Martin

Field Summary
static java.lang.String LOG_CATEGORY
          The logging category to which all trace output is sent.
 
Constructor Summary
Trace()
          Constructs a new trace object.
Trace(java.lang.String options)
          Constructs a new trace object configured according to the given options string.
 
Method Summary
 boolean getLogExecutionFailures()
          When true, any SQL statement whose execution throws a SQLException is logged at ERROR level.
 boolean getLogExecutionTimes()
          When true, each SQL statement is logged at INFO level upon successful execution, along with the execution time in milliseconds.
 boolean getLogWarnings()
          When true, all SQLWarning objects occurring on a Connection, Statement, or ResultSet are logged at WARN level.
 void setLogExecutionFailures(boolean logExecutionFailures)
          When true, any SQL statement whose execution throws a SQLException is logged at ERROR level.
 void setLogExecutionTimes(boolean logExecutionTimes)
          When true, each SQL statement is logged at INFO level upon successful execution, along with the execution time in milliseconds.
 void setLogWarnings(boolean logWarnings)
          When true, all SQLWarning objects occurring on a Connection, Statement, or ResultSet are logged at WARN level.
 void setOptions(java.lang.String options)
          Enables the trace options specified in the given string.
 java.sql.Connection traceConnection(java.sql.Connection conn)
          Places a tracing wrapper around the specified connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_CATEGORY

public static final java.lang.String LOG_CATEGORY
The logging category to which all trace output is sent.

See Also:
Constant Field Values
Constructor Detail

Trace

public Trace()
Constructs a new trace object. All options are initially disabled.


Trace

public Trace(java.lang.String options)
Constructs a new trace object configured according to the given options string.

Parameters:
options - a comma-separated string containing the keywords of the options to be enabled.
Method Detail

setOptions

public void setOptions(java.lang.String options)
Enables the trace options specified in the given string. All options not specified are disabled.

Each trace option is enabled by including its keyword.

Option keyword Description
LogExecutionTimes Logs every executed SQL statement and its execution time in milliseconds
LogExecutionFailures Logs every SQL statement whose execution throws a SQLException
LogWarnings Logs every SQLWarning produced by a Connection, Statement, or ResultSet

Parameters:
options - a comma-separated string containing the keywords of the options to be enabled.

getLogExecutionTimes

public boolean getLogExecutionTimes()
When true, each SQL statement is logged at INFO level upon successful execution, along with the execution time in milliseconds.

Returns:
true if logging execution times

setLogExecutionTimes

public void setLogExecutionTimes(boolean logExecutionTimes)
When true, each SQL statement is logged at INFO level upon successful execution, along with the execution time in milliseconds.

Parameters:
logExecutionTimes - true to log execution times

getLogExecutionFailures

public boolean getLogExecutionFailures()
When true, any SQL statement whose execution throws a SQLException is logged at ERROR level.

Returns:
true if logging execution failures

setLogExecutionFailures

public void setLogExecutionFailures(boolean logExecutionFailures)
When true, any SQL statement whose execution throws a SQLException is logged at ERROR level.

Parameters:
logExecutionFailures - true to log execution failures

getLogWarnings

public boolean getLogWarnings()
When true, all SQLWarning objects occurring on a Connection, Statement, or ResultSet are logged at WARN level.

Returns:
true if logging SQL warnings

setLogWarnings

public void setLogWarnings(boolean logWarnings)
When true, all SQLWarning objects occurring on a Connection, Statement, or ResultSet are logged at WARN level.

Parameters:
logWarnings - true to log SQL warnings

traceConnection

public java.sql.Connection traceConnection(java.sql.Connection conn)
Places a tracing wrapper around the specified connection. The wrapper imposes a very low but non-zero amount of overhead.

Parameters:
conn - the connection to be traced
Returns:
a tracing wrapper around the specified connection


Copyright © 2001-2007 The TJDO Project All Rights Reserved.