mirror of
https://github.com/encounter/log4jdbc.git
synced 2026-03-30 11:27:21 -07:00
Compare commits
38 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ee5468cfe6 | |||
| 88f90f8131 | |||
| 7f7d2f0f3b | |||
| d430b481a4 | |||
| 48154128a9 | |||
| dbc63df301 | |||
| 59ecc4ac8b | |||
| d10afb244f | |||
| c183dc2b5d | |||
| a3ac1c68c1 | |||
| 46c13d8498 | |||
| 6906f31ba5 | |||
| d3a48845f3 | |||
| 7355247886 | |||
| 00369eba9f | |||
| a02f682e7c | |||
| a5290edf4b | |||
| 9769dbc6dd | |||
| b0b69fdc64 | |||
| 1dd40a2f76 | |||
| bbf255e0b4 | |||
| 4ee6d5f745 | |||
| c83e89c194 | |||
| 5ac146eb77 | |||
| cab8caa20a | |||
| 6484ab0c10 | |||
| de7d4acc84 | |||
| 108d89b8bc | |||
| 076a585184 | |||
| 1d455b77e6 | |||
| e33eb5534f | |||
| 15a798c27a | |||
| e227d3ca26 | |||
| 98f98d605c | |||
| c19443a574 | |||
| de256617a2 | |||
| eac61725f6 | |||
| f7fa0cdaf4 |
+61
@@ -1,3 +1,64 @@
|
||||
2012-02-17 1.2 Release
|
||||
|
||||
o escape single quotes in PreparedStatement/CallableStatement bind variables (Issue 36.)
|
||||
|
||||
o process SQL consistently when the sql is dumped because an exception occurred.
|
||||
|
||||
o new SQL formatter to more reliably dump sql that can be run for MySql (Issue 34.)
|
||||
|
||||
o don't show debug info in sql timing dump unless debug is enabled on the logger
|
||||
(to make the sql timing dump consistent with the way other the loggers work)
|
||||
|
||||
o add new option, log4jdbc.trim.sql.extrablanklines for removing
|
||||
extra blank lines from sql output.
|
||||
|
||||
o fix issue where extra connection was being created when
|
||||
ResultSet.getStatement was being called (Issue 33.)
|
||||
|
||||
o performance enhancement when logging not enabled (Issue 29.)
|
||||
|
||||
2010-06-09 1.2 beta 2 Release
|
||||
|
||||
o add new option, log4jdbc.auto.load.popular.drivers for
|
||||
disabling auto-loading of drivers
|
||||
|
||||
o look first for log4jdbc property settings in optional
|
||||
log4jdbc.properties file in the classpath.
|
||||
|
||||
o Fix non-threadsafe usage of SimpleDateFormat (Issue 18)
|
||||
|
||||
o add new option, log4jdbc.trim.sql to trim the SQL before logging
|
||||
it.
|
||||
|
||||
o add new option, log4jdbc.suppress.generated.keys.exception that
|
||||
will ignore any exception produced by the method,
|
||||
Statement.getGeneratedKeys(). This flag is useful in Coldfusion
|
||||
environments which typically call this method after every update,
|
||||
even if unwarranted, and ignoring the exception, thus clogging up
|
||||
the logs with these exception reports.
|
||||
|
||||
o add support for the newer oracle.jdbc.OracleDriver driver (the
|
||||
older oracle.jdbc.driver.OracleDriver driver is still supported
|
||||
as well) and add corrected date formatting for Oracle.
|
||||
|
||||
o fix possible null pointer issue with setBlob and setClob (Issue 21)
|
||||
|
||||
2010-03-20 1.2 beta 1 Release
|
||||
|
||||
o Check for exception that should not, but in some cases could
|
||||
occur when trying to format parameter arguments.
|
||||
|
||||
o Use only one type of date format so that time portion of Date
|
||||
types is not dropped!
|
||||
|
||||
o use to_date function for Oracle (Issue 14)
|
||||
|
||||
o performance improvements
|
||||
|
||||
o fix: respect DumpSqlMaxLineLength option.
|
||||
|
||||
o various other fixes (including Issues 8 and 9)
|
||||
|
||||
2009-02-26 1.2 alpha 2 Release
|
||||
|
||||
o (Issue 1) fix bug where batch of logged SQL wasn't cleared
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
log4jdbc is open source software, released under the Apache License, Version 2.0:
|
||||
|
||||
Copyright 2007-2008 Arthur Blake
|
||||
Copyright 2007-2011 Arthur Blake
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use log4jdbc except in compliance with the License.
|
||||
|
||||
@@ -18,3 +18,5 @@ o review dumpedSql method - make auto line breaking option (& num chars used) b
|
||||
o need log4jdbc.debug.stack.regex so that the stack matching can take place via regex
|
||||
|
||||
o maven2 repository support
|
||||
|
||||
o this may be a better solution to SimpleDateFormat contention issue: http://www.javaspecialists.eu/archive/Issue172.html
|
||||
|
||||
Binary file not shown.
Binary file not shown.
+4
-4
@@ -1,5 +1,5 @@
|
||||
To build log4jdbc, you must have Ant 1.6.5 or later installed,
|
||||
and JDK 1.4 and JDK 1.6 installed.
|
||||
log4jdbc is built with Ant 1.8.x, JDK 1.4.x and JDK 1.6.x
|
||||
|
||||
The build.cmd file is useful for building both the jdbc 3 version (JDK 1.4) and the jdbc 4 version (under JDK 1.6) under windows.
|
||||
The javadoc.cmd file is useful for building javadoc (requires the 3rd party ydoc tool)
|
||||
The build.cmd file is useful for building both the jdbc 3 version (JDK 1.4) and
|
||||
the jdbc 4 version (under JDK 1.6) under windows. The javadoc.cmd file is
|
||||
useful for building javadoc (requires the 3rd party ydoc tool)
|
||||
|
||||
+8
-3
@@ -4,15 +4,20 @@ setlocal
|
||||
REM invoke the 1.4 and the 1.6 jvm each in turn
|
||||
REM for JDBC 3 and JDBC 4 versions respectively
|
||||
|
||||
set ANT_HOME=c:\apache-ant-1.6.5
|
||||
REM BTW, It's not actually necessary to use JDK 1.4
|
||||
REM if you don't happen to have it laying around,
|
||||
REM as the ant script properly sets the source
|
||||
REM and target java versions anyway.
|
||||
|
||||
set JAVA_HOME=C:\jdk\1.4.2_18
|
||||
set ANT_HOME=c:\apache-ant-1.8.2
|
||||
|
||||
set JAVA_HOME=C:\jdk\1.4.2_19
|
||||
set PATH=%JAVA_HOME%\bin;%ANT_HOME%\bin
|
||||
|
||||
call java -version
|
||||
call ant -Djdbc.level=3 -Djvm.ver=1.4 all
|
||||
|
||||
set JAVA_HOME=C:\jdk\1.6.0_11
|
||||
set JAVA_HOME=C:\jdk\1.6.0_30
|
||||
set PATH=%JAVA_HOME%\bin;%ANT_HOME%\bin
|
||||
|
||||
call java -version
|
||||
|
||||
+10
-15
@@ -9,7 +9,7 @@
|
||||
built with jdk 1.4.2_13 (for use with jdbc3)
|
||||
and/or jdk 1.6.0 (for use with jdbc4)
|
||||
|
||||
Copyright 2007-2009 Arthur Blake
|
||||
Copyright 2007-2012 Arthur Blake
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -49,7 +49,7 @@
|
||||
|
||||
|
||||
<!-- release version -->
|
||||
<property name="version" value="1.2alpha2"/>
|
||||
<property name="version" value="1.2"/>
|
||||
|
||||
<target name="all" depends="cleancompile,compile,cleanjar,jar"/>
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
|
||||
<target name="compile" description="compile all the source code">
|
||||
<javac source="${jvm.ver}" target="${jvm.ver}" srcdir="${src}" destdir="${classes}"
|
||||
deprecation="true" debug="true">
|
||||
deprecation="true" debug="true" includeAntRuntime="false">
|
||||
<classpath>
|
||||
<pathelement location="$src"/>
|
||||
<fileset dir="lib">
|
||||
@@ -95,26 +95,21 @@
|
||||
</target>
|
||||
|
||||
|
||||
<target name="cleanjavadoc">
|
||||
<target name="cleanjavadoc" description="clean javadoc">
|
||||
<delete dir="${apidocs}" />
|
||||
<mkdir dir="${apidocs}" />
|
||||
</target>
|
||||
|
||||
<target name="cleanrelease">
|
||||
|
||||
<target name="cleanrelease" description="clean up any release files">
|
||||
<delete file="../log4jdbc-${version}.zip"/>
|
||||
<delete file="../log4jdbc-${version}.tar"/>
|
||||
<delete file="../log4jdbc-${version}.tar.gz"/>
|
||||
</target>
|
||||
|
||||
<target name="clean" depends="cleanrelease,cleanjavadoc,cleanjar,cleancompile" description="clean up all build artifacts"/>
|
||||
|
||||
<target name="release" depends="cleanrelease" description="make a complete release distribution (a .jar zip and tar.gz file for release)">
|
||||
<zip destfile="../log4jdbc-${version}.zip">
|
||||
<zipfileset dir="." prefix="log4jdbc-${version}" excludes="*.zip,*.tar.gz,*,iml,*.ipr,*.iws,thirdparty-stuff/**,classes*/**"/>
|
||||
</zip>
|
||||
<tar destfile="../log4jdbc-${version}.tar">
|
||||
<tarfileset dir="." prefix="log4jdbc-${version}" excludes="*.zip,*.tar.gz,*,iml,*.ipr,*.iws,thirdparty-stuff/**,classes*/**"/>
|
||||
</tar>
|
||||
<gzip destfile="../log4jdbc-${version}.tar.gz" src="../log4jdbc-${version}.tar"/>
|
||||
<delete file="../log4jdbc-${version}.tar"/>
|
||||
</target>
|
||||
|
||||
<!-- make the javadoc (or ydoc which includes UML diagrams) -->
|
||||
@@ -164,7 +159,7 @@
|
||||
<!-- note that the jdk source code is referenced here so that javadoc will be generated from
|
||||
interface class methods when none is specified in the implementation -->
|
||||
|
||||
<sourcepath path="/jdk/1.4.2_18/src"/>
|
||||
<sourcepath path="/jdk/1.4.2_19/src"/>
|
||||
<link href="http://java.sun.com/j2se/1.4.2/docs/api/"/>
|
||||
<!--
|
||||
<link href="http://java.sun.com/j2ee/1.4/docs/api/"/>
|
||||
@@ -211,7 +206,7 @@
|
||||
<!-- note that the jdk source code is referenced here so that javadoc will be generated from
|
||||
interface class methods when none is specified in the implementation -->
|
||||
|
||||
<sourcepath path="/jdk/1.6.0_11/src"/>
|
||||
<sourcepath path="/jdk/1.6.0_21/src"/>
|
||||
<link href="http://java.sun.com/javase/6/docs/api/"/>
|
||||
<link href="http://www.slf4j.org/api/"/>
|
||||
|
||||
|
||||
+3
-3
@@ -4,16 +4,16 @@ setlocal
|
||||
REM invoke the 1.4 and the 1.6 jvm each in turn
|
||||
REM for JDBC 3 and JDBC 4 versions respectively
|
||||
|
||||
set ANT_HOME=c:\apache-ant-1.6.5
|
||||
set ANT_HOME=c:\apache-ant-1.8.2
|
||||
set ANT_OPTS=-Xmx512m
|
||||
|
||||
set JAVA_HOME=C:\jdk\1.4.2_18
|
||||
set JAVA_HOME=C:\jdk\1.4.2_19
|
||||
set PATH=%JAVA_HOME%\bin;%ANT_HOME%\bin
|
||||
|
||||
call java -version
|
||||
call ant -Djdbc.level=3 -Djvm.ver=1.4 ydoc.3
|
||||
|
||||
set JAVA_HOME=c:\jdk\1.6.0_11
|
||||
set JAVA_HOME=c:\jdk\1.6.0_30
|
||||
set PATH=%JAVA_HOME%\bin;%ANT_HOME%\bin
|
||||
|
||||
call java -version
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
|
||||
rem *************************************************************************************************
|
||||
rem * *
|
||||
rem * Copyright 2007-2009 Arthur Blake *
|
||||
rem * Copyright 2007-2012 Arthur Blake *
|
||||
rem * *
|
||||
rem * Licensed under the Apache License, Version 2.0 (the "License"); *
|
||||
rem * you may not use this file except in compliance with the License. *
|
||||
@@ -25,4 +25,4 @@ rem * profiling output report.
|
||||
rem * *
|
||||
rem *************************************************************************************************
|
||||
|
||||
java -Xmx1024m -classpath ..\build\log4jdbc3-1.2alpha2.jar net.sf.log4jdbc.PostLogProfilerProcessor %*
|
||||
java -Xmx1024m -classpath ..\build\log4jdbc3-1.2.jar net.sf.log4jdbc.PostLogProfilerProcessor %*
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
|
||||
# *************************************************************************************************
|
||||
# * *
|
||||
# * Copyright 2007-2009 Arthur Blake *
|
||||
# * Copyright 2007-2012 Arthur Blake *
|
||||
# * *
|
||||
# * Licensed under the Apache License, Version 2.0 (the "License"); *
|
||||
# * you may not use this file except in compliance with the License. *
|
||||
@@ -25,4 +25,4 @@
|
||||
# * *
|
||||
# *************************************************************************************************
|
||||
|
||||
java -Xmx1024m -classpath ../build/log4jdbc3-1.2alpha2.jar net.sf.log4jdbc.PostLogProfilerProcessor $@
|
||||
java -Xmx1024m -classpath ../build/log4jdbc3-1.2.jar net.sf.log4jdbc.PostLogProfilerProcessor $@
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright 2007-2009 Arthur Blake
|
||||
* Copyright 2007-2012 Arthur Blake
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright 2007-2009 Arthur Blake
|
||||
* Copyright 2007-2012 Arthur Blake
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright 2007-2009 Arthur Blake
|
||||
* Copyright 2007-2012 Arthur Blake
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package net.sf.log4jdbc;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.Driver;
|
||||
@@ -33,9 +35,11 @@ import java.util.TreeSet;
|
||||
* A JDBC driver which is a facade that delegates to one or more real underlying
|
||||
* JDBC drivers. The driver will spy on any other JDBC driver that is loaded,
|
||||
* simply by prepending <code>jdbc:log4</code> to the normal jdbc driver URL
|
||||
* used by any other JDBC driver. The driver also loads several well known
|
||||
* drivers at class load time, so that this driver can be "dropped in" to any
|
||||
* java program that uses these drivers without making any code changes.
|
||||
* used by any other JDBC driver. The driver, by default, also loads several
|
||||
* well known drivers at class load time, so that this driver can be
|
||||
* "dropped in" to any Java program that uses these drivers without making any
|
||||
* code changes.
|
||||
* <p/>
|
||||
* The well known driver classes that are loaded are:
|
||||
* <p/>
|
||||
* <p/>
|
||||
@@ -58,10 +62,15 @@ import java.util.TreeSet;
|
||||
* </code>
|
||||
* <p/>
|
||||
* <p/>
|
||||
* Additional drivers can be set via a system property: <b>log4jdbc.drivers</b>
|
||||
* Additional drivers can be set via a property: <b>log4jdbc.drivers</b>
|
||||
* This can be either a single driver class name or a list of comma separated
|
||||
* driver class names.
|
||||
* <p/>
|
||||
* The autoloading behavior can be disabled by setting a property:
|
||||
* <b>log4jdbc.auto.load.popular.drivers</b> to false. If that is done, then
|
||||
* the only drivers that log4jdbc will attempt to load are the ones specified
|
||||
* in <b>log4jdbc.drivers</b>.
|
||||
* <p/>
|
||||
* If any of the above driver classes cannot be loaded, the driver continues on
|
||||
* without failing.
|
||||
* <p/>
|
||||
@@ -190,17 +199,43 @@ public class DriverSpy implements Driver
|
||||
static boolean DumpFullDebugStackTrace;
|
||||
|
||||
/**
|
||||
* Get a Long option from a system property and
|
||||
* Attempt to Automatically load a set of popular JDBC drivers?
|
||||
*/
|
||||
static boolean AutoLoadPopularDrivers;
|
||||
|
||||
/**
|
||||
* Trim SQL before logging it?
|
||||
*/
|
||||
static boolean TrimSql;
|
||||
|
||||
/**
|
||||
* Remove extra Lines in the SQL that consist of only white space?
|
||||
* Only when 2 or more lines in a row like this occur, will the extra lines (beyond 1)
|
||||
* be removed.
|
||||
*/
|
||||
static boolean TrimExtraBlankLinesInSql;
|
||||
|
||||
/**
|
||||
* Coldfusion typically calls PreparedStatement.getGeneratedKeys() after
|
||||
* every SQL update call, even if it's not warranted. This typically produces
|
||||
* an exception that is ignored by Coldfusion. If this flag is true, then
|
||||
* any exception generated by this method is also ignored by log4jdbc.
|
||||
*/
|
||||
static boolean SuppressGetGeneratedKeysException;
|
||||
|
||||
/**
|
||||
* Get a Long option from a property and
|
||||
* log a debug message about this.
|
||||
*
|
||||
* @param propName System property key.
|
||||
* @param props Properties to get option from.
|
||||
* @param propName property key.
|
||||
*
|
||||
* @return the value of that System property key, converted
|
||||
* @return the value of that property key, converted
|
||||
* to a Long. Or null if not defined or is invalid.
|
||||
*/
|
||||
private static Long getLongOption(String propName)
|
||||
private static Long getLongOption(Properties props, String propName)
|
||||
{
|
||||
String propValue = System.getProperty(propName);
|
||||
String propValue = props.getProperty(propName);
|
||||
Long longPropValue = null;
|
||||
if (propValue == null)
|
||||
{
|
||||
@@ -223,21 +258,24 @@ public class DriverSpy implements Driver
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Long option from a system property and
|
||||
* Get a Long option from a property and
|
||||
* log a debug message about this.
|
||||
*
|
||||
* @param propName System property key.
|
||||
* @param props Properties to get option from.
|
||||
* @param propName property key.
|
||||
*
|
||||
* @return the value of that System property key, converted
|
||||
* @return the value of that property key, converted
|
||||
* to a Long. Or null if not defined or is invalid.
|
||||
*/
|
||||
private static Long getLongOption(String propName, long defaultValue)
|
||||
private static Long getLongOption(Properties props, String propName,
|
||||
long defaultValue)
|
||||
{
|
||||
String propValue = System.getProperty(propName);
|
||||
String propValue = props.getProperty(propName);
|
||||
Long longPropValue;
|
||||
if (propValue == null)
|
||||
{
|
||||
log.debug("x " + propName + " is not defined (using default of " + defaultValue +")");
|
||||
log.debug("x " + propName + " is not defined (using default of " +
|
||||
defaultValue +")");
|
||||
longPropValue = new Long(defaultValue);
|
||||
}
|
||||
else
|
||||
@@ -258,15 +296,16 @@ public class DriverSpy implements Driver
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a String option from a system property and
|
||||
* Get a String option from a property and
|
||||
* log a debug message about this.
|
||||
*
|
||||
* @param propName System property key.
|
||||
* @return the value of that System property key.
|
||||
* @param props Properties to get option from.
|
||||
* @param propName property key.
|
||||
* @return the value of that property key.
|
||||
*/
|
||||
private static String getStringOption(String propName)
|
||||
private static String getStringOption(Properties props, String propName)
|
||||
{
|
||||
String propValue = System.getProperty(propName);
|
||||
String propValue = props.getProperty(propName);
|
||||
if (propValue == null || propValue.length()==0)
|
||||
{
|
||||
log.debug("x " + propName + " is not defined");
|
||||
@@ -280,18 +319,20 @@ public class DriverSpy implements Driver
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a boolean option from a system property and
|
||||
* Get a boolean option from a property and
|
||||
* log a debug message about this.
|
||||
*
|
||||
* @param props Properties to get option from.
|
||||
* @param propName property name to get.
|
||||
* @param defaultValue default value to use if undefined.
|
||||
*
|
||||
* @return boolean value found in property, or defaultValue if no property
|
||||
* found.
|
||||
*/
|
||||
private static boolean getBooleanOption(String propName, boolean defaultValue)
|
||||
private static boolean getBooleanOption(Properties props, String propName,
|
||||
boolean defaultValue)
|
||||
{
|
||||
String propValue = System.getProperty(propName);
|
||||
String propValue = props.getProperty(propName);
|
||||
boolean val;
|
||||
if (propValue == null)
|
||||
{
|
||||
@@ -320,18 +361,52 @@ public class DriverSpy implements Driver
|
||||
{
|
||||
log.debug("... log4jdbc initializing ...");
|
||||
|
||||
// look for additional driver specified in system properties
|
||||
DebugStackPrefix = getStringOption("log4jdbc.debug.stack.prefix");
|
||||
InputStream propStream =
|
||||
DriverSpy.class.getResourceAsStream("/log4jdbc.properties");
|
||||
|
||||
Properties props = new Properties(System.getProperties());
|
||||
if (propStream != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
props.load(propStream);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log.debug("ERROR! io exception loading " +
|
||||
"log4jdbc.properties from classpath: " + e.getMessage());
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
propStream.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log.debug("ERROR! io exception closing property file stream: " +
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
log.debug(" log4jdbc.properties loaded from classpath");
|
||||
}
|
||||
else
|
||||
{
|
||||
log.debug(" log4jdbc.properties not found on classpath");
|
||||
}
|
||||
|
||||
// look for additional driver specified in properties
|
||||
DebugStackPrefix = getStringOption(props, "log4jdbc.debug.stack.prefix");
|
||||
TraceFromApplication = DebugStackPrefix != null;
|
||||
|
||||
Long thresh = getLongOption("log4jdbc.sqltiming.warn.threshold");
|
||||
Long thresh = getLongOption(props, "log4jdbc.sqltiming.warn.threshold");
|
||||
SqlTimingWarnThresholdEnabled = (thresh != null);
|
||||
if (SqlTimingWarnThresholdEnabled)
|
||||
{
|
||||
SqlTimingWarnThresholdMsec = thresh.longValue();
|
||||
}
|
||||
|
||||
thresh = getLongOption("log4jdbc.sqltiming.error.threshold");
|
||||
thresh = getLongOption(props, "log4jdbc.sqltiming.error.threshold");
|
||||
SqlTimingErrorThresholdEnabled = (thresh != null);
|
||||
if (SqlTimingErrorThresholdEnabled)
|
||||
{
|
||||
@@ -339,54 +414,71 @@ public class DriverSpy implements Driver
|
||||
}
|
||||
|
||||
DumpBooleanAsTrueFalse =
|
||||
getBooleanOption("log4jdbc.dump.booleanastruefalse",false);
|
||||
getBooleanOption(props, "log4jdbc.dump.booleanastruefalse",false);
|
||||
|
||||
DumpSqlMaxLineLength = getLongOption("log4jdbc.dump.sql.maxlinelength", 90L).
|
||||
intValue();
|
||||
DumpSqlMaxLineLength = getLongOption(props,
|
||||
"log4jdbc.dump.sql.maxlinelength", 90L).intValue();
|
||||
|
||||
DumpFullDebugStackTrace =
|
||||
getBooleanOption("log4jdbc.dump.fulldebugstacktrace",false);
|
||||
getBooleanOption(props, "log4jdbc.dump.fulldebugstacktrace",false);
|
||||
|
||||
StatementUsageWarn =
|
||||
getBooleanOption("log4jdbc.statement.warn",false);
|
||||
getBooleanOption(props, "log4jdbc.statement.warn",false);
|
||||
|
||||
DumpSqlSelect = getBooleanOption("log4jdbc.dump.sql.select",true);
|
||||
DumpSqlInsert = getBooleanOption("log4jdbc.dump.sql.insert",true);
|
||||
DumpSqlUpdate = getBooleanOption("log4jdbc.dump.sql.update",true);
|
||||
DumpSqlDelete = getBooleanOption("log4jdbc.dump.sql.delete",true);
|
||||
DumpSqlCreate = getBooleanOption("log4jdbc.dump.sql.create",true);
|
||||
DumpSqlSelect = getBooleanOption(props, "log4jdbc.dump.sql.select",true);
|
||||
DumpSqlInsert = getBooleanOption(props, "log4jdbc.dump.sql.insert",true);
|
||||
DumpSqlUpdate = getBooleanOption(props, "log4jdbc.dump.sql.update",true);
|
||||
DumpSqlDelete = getBooleanOption(props, "log4jdbc.dump.sql.delete",true);
|
||||
DumpSqlCreate = getBooleanOption(props, "log4jdbc.dump.sql.create",true);
|
||||
|
||||
DumpSqlFilteringOn = !(DumpSqlSelect && DumpSqlInsert && DumpSqlUpdate &&
|
||||
DumpSqlDelete && DumpSqlCreate);
|
||||
|
||||
DumpSqlAddSemicolon = getBooleanOption("log4jdbc.dump.sql.addsemicolon",false);
|
||||
DumpSqlAddSemicolon = getBooleanOption(props,
|
||||
"log4jdbc.dump.sql.addsemicolon", false);
|
||||
|
||||
AutoLoadPopularDrivers = getBooleanOption(props,
|
||||
"log4jdbc.auto.load.popular.drivers", true);
|
||||
|
||||
TrimSql = getBooleanOption(props, "log4jdbc.trim.sql", true);
|
||||
|
||||
TrimExtraBlankLinesInSql = getBooleanOption(props, "log4jdbc.trim.sql.extrablanklines", true);
|
||||
|
||||
SuppressGetGeneratedKeysException =
|
||||
getBooleanOption(props, "log4jdbc.suppress.generated.keys.exception",
|
||||
false);
|
||||
|
||||
// The Set of drivers that the log4jdbc driver will preload at instantiation
|
||||
// time. The driver can spy on any driver type, it's just a little bit
|
||||
// easier to configure log4jdbc if it's one of these types!
|
||||
|
||||
Set subDrivers = new TreeSet();
|
||||
subDrivers.add("oracle.jdbc.driver.OracleDriver");
|
||||
subDrivers.add("com.sybase.jdbc2.jdbc.SybDriver");
|
||||
subDrivers.add("net.sourceforge.jtds.jdbc.Driver");
|
||||
|
||||
// MS driver for Sql Server 2000
|
||||
subDrivers.add("com.microsoft.jdbc.sqlserver.SQLServerDriver");
|
||||
if (AutoLoadPopularDrivers)
|
||||
{
|
||||
subDrivers.add("oracle.jdbc.driver.OracleDriver");
|
||||
subDrivers.add("oracle.jdbc.OracleDriver");
|
||||
subDrivers.add("com.sybase.jdbc2.jdbc.SybDriver");
|
||||
subDrivers.add("net.sourceforge.jtds.jdbc.Driver");
|
||||
|
||||
// MS driver for Sql Server 2005
|
||||
subDrivers.add("com.microsoft.sqlserver.jdbc.SQLServerDriver");
|
||||
// MS driver for Sql Server 2000
|
||||
subDrivers.add("com.microsoft.jdbc.sqlserver.SQLServerDriver");
|
||||
|
||||
subDrivers.add("weblogic.jdbc.sqlserver.SQLServerDriver");
|
||||
subDrivers.add("com.informix.jdbc.IfxDriver");
|
||||
subDrivers.add("org.apache.derby.jdbc.ClientDriver");
|
||||
subDrivers.add("org.apache.derby.jdbc.EmbeddedDriver");
|
||||
subDrivers.add("com.mysql.jdbc.Driver");
|
||||
subDrivers.add("org.postgresql.Driver");
|
||||
subDrivers.add("org.hsqldb.jdbcDriver");
|
||||
subDrivers.add("org.h2.Driver");
|
||||
// MS driver for Sql Server 2005
|
||||
subDrivers.add("com.microsoft.sqlserver.jdbc.SQLServerDriver");
|
||||
|
||||
// look for additional driver specified in system properties
|
||||
String moreDrivers = getStringOption("log4jdbc.drivers");
|
||||
subDrivers.add("weblogic.jdbc.sqlserver.SQLServerDriver");
|
||||
subDrivers.add("com.informix.jdbc.IfxDriver");
|
||||
subDrivers.add("org.apache.derby.jdbc.ClientDriver");
|
||||
subDrivers.add("org.apache.derby.jdbc.EmbeddedDriver");
|
||||
subDrivers.add("com.mysql.jdbc.Driver");
|
||||
subDrivers.add("org.postgresql.Driver");
|
||||
subDrivers.add("org.hsqldb.jdbcDriver");
|
||||
subDrivers.add("org.h2.Driver");
|
||||
}
|
||||
|
||||
// look for additional driver specified in properties
|
||||
String moreDrivers = getStringOption(props, "log4jdbc.drivers");
|
||||
|
||||
if (moreDrivers != null)
|
||||
{
|
||||
@@ -395,7 +487,7 @@ public class DriverSpy implements Driver
|
||||
for (int i = 0; i < moreDriversArr.length; i++)
|
||||
{
|
||||
subDrivers.add(moreDriversArr[i]);
|
||||
log.debug (" will look for additional driver " + moreDriversArr[i]);
|
||||
log.debug (" will look for specific driver " + moreDriversArr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,16 +527,19 @@ public class DriverSpy implements Driver
|
||||
}
|
||||
|
||||
SqlServerRdbmsSpecifics sqlServer = new SqlServerRdbmsSpecifics();
|
||||
OracleRdbmsSpecifics oracle = new OracleRdbmsSpecifics();
|
||||
MySqlRdbmsSpecifics mySql = new MySqlRdbmsSpecifics();
|
||||
|
||||
/** create lookup Map for specific rdbms formatters */
|
||||
rdbmsSpecifics = new HashMap();
|
||||
rdbmsSpecifics.put("oracle.jdbc.driver.OracleDriver",
|
||||
new OracleRdbmsSpecifics());
|
||||
rdbmsSpecifics.put("oracle.jdbc.driver.OracleDriver", oracle);
|
||||
rdbmsSpecifics.put("oracle.jdbc.OracleDriver", oracle);
|
||||
rdbmsSpecifics.put("net.sourceforge.jtds.jdbc.Driver", sqlServer);
|
||||
rdbmsSpecifics.put("com.microsoft.jdbc.sqlserver.SQLServerDriver",
|
||||
sqlServer);
|
||||
rdbmsSpecifics.put("weblogic.jdbc.sqlserver.SQLServerDriver", sqlServer);
|
||||
|
||||
rdbmsSpecifics.put("com.mysql.jdbc.Driver", mySql);
|
||||
|
||||
log.debug("... log4jdbc initialized! ...");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright 2007-2012 Arthur Blake
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.sf.log4jdbc;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
/**
|
||||
* RDBMS specifics for the MySql db.
|
||||
*
|
||||
* @author Arthur Blake
|
||||
*/
|
||||
class MySqlRdbmsSpecifics extends RdbmsSpecifics
|
||||
{
|
||||
MySqlRdbmsSpecifics()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
String formatParameterObject(Object object)
|
||||
{
|
||||
if (object instanceof java.sql.Time)
|
||||
{
|
||||
return "'" + new SimpleDateFormat("HH:mm:ss").format(object) + "'";
|
||||
}
|
||||
else if (object instanceof java.sql.Date)
|
||||
{
|
||||
return "'" + new SimpleDateFormat("yyyy-MM-dd").format(object) + "'";
|
||||
}
|
||||
else if (object instanceof java.util.Date) // (includes java.sql.Timestamp)
|
||||
{
|
||||
return "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(object) + "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.formatParameterObject(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright 2007-2009 Arthur Blake
|
||||
* Copyright 2007-2012 Arthur Blake
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,6 +15,10 @@
|
||||
*/
|
||||
package net.sf.log4jdbc;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* RDBMS specifics for the Oracle DB.
|
||||
*
|
||||
@@ -26,4 +30,22 @@ class OracleRdbmsSpecifics extends RdbmsSpecifics
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
String formatParameterObject(Object object)
|
||||
{
|
||||
if (object instanceof Timestamp)
|
||||
{
|
||||
return "to_timestamp('" + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss.SSS").
|
||||
format(object) + "', 'mm/dd/yyyy hh24:mi:ss.ff3')";
|
||||
}
|
||||
else if (object instanceof Date)
|
||||
{
|
||||
return "to_date('" + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").
|
||||
format(object) + "', 'mm/dd/yyyy hh24:mi:ss')";
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.formatParameterObject(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright 2007-2009 Arthur Blake
|
||||
* Copyright 2007-2012 Arthur Blake
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright 2007-2009 Arthur Blake
|
||||
* Copyright 2007-2012 Arthur Blake
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -62,7 +62,22 @@ public class PreparedStatementSpy extends StatementSpy implements PreparedStatem
|
||||
*/
|
||||
protected void argTraceSet(int i, String typeHelper, Object arg)
|
||||
{
|
||||
String tracedArg = rdbmsSpecifics.formatParameterObject(arg);
|
||||
String tracedArg;
|
||||
try
|
||||
{
|
||||
tracedArg = rdbmsSpecifics.formatParameterObject(arg);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
// rdbmsSpecifics should NEVER EVER throw an exception!!
|
||||
// but just in case it does, we trap it.
|
||||
log.debug("rdbmsSpecifics threw an exception while trying to format a " +
|
||||
"parameter object [" + arg + "] this is very bad!!! (" +
|
||||
t.getMessage() + ")");
|
||||
|
||||
// backup - so that at least we won't harm the application using us
|
||||
tracedArg = arg==null?"null":arg.toString();
|
||||
}
|
||||
|
||||
i--; // make the index 0 based
|
||||
synchronized (argTrace)
|
||||
@@ -289,7 +304,8 @@ public class PreparedStatementSpy extends StatementSpy implements PreparedStatem
|
||||
public void setBlob(int i, Blob x) throws SQLException
|
||||
{
|
||||
String methodCall = "setBlob(" + i + ", " + x + ")";
|
||||
argTraceSet(i, "(Blob)", "<Blob of size " + x.length() + ">");
|
||||
argTraceSet(i, "(Blob)",
|
||||
x==null?null:("<Blob of size " + x.length() + ">"));
|
||||
try
|
||||
{
|
||||
realPreparedStatement.setBlob(i, x);
|
||||
@@ -305,7 +321,8 @@ public class PreparedStatementSpy extends StatementSpy implements PreparedStatem
|
||||
public void setClob(int i, Clob x) throws SQLException
|
||||
{
|
||||
String methodCall = "setClob(" + i + ", " + x + ")";
|
||||
argTraceSet(i, "(Clob)", "<Clob of size " + x.length() + ">");
|
||||
argTraceSet(i, "(Clob)",
|
||||
x==null?null:("<Clob of size " + x.length() + ">"));
|
||||
try
|
||||
{
|
||||
realPreparedStatement.setClob(i, x);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright 2007-2009 Arthur Blake
|
||||
* Copyright 2007-2012 Arthur Blake
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package net.sf.log4jdbc;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
/**
|
||||
* Encapsulate sql formatting details about a particular relational database management system so that
|
||||
@@ -33,6 +33,8 @@ class RdbmsSpecifics
|
||||
{
|
||||
}
|
||||
|
||||
protected static final String dateFormat = "MM/dd/yyyy HH:mm:ss.SSS";
|
||||
|
||||
/**
|
||||
* Format an Object that is being bound to a PreparedStatement parameter, for display. The goal is to reformat the
|
||||
* object in a format that can be re-run against the native SQL client of the particular Rdbms being used. This
|
||||
@@ -52,16 +54,11 @@ class RdbmsSpecifics
|
||||
{
|
||||
if (object instanceof String)
|
||||
{
|
||||
// todo: need to handle imbedded quotes??
|
||||
return "'" + object + "'";
|
||||
return "'" + escapeString((String)object) + "'";
|
||||
}
|
||||
else if (object instanceof Date)
|
||||
{
|
||||
return object.toString();
|
||||
}
|
||||
else if (object instanceof Timestamp)
|
||||
{
|
||||
return object.toString();
|
||||
return "'" + new SimpleDateFormat(dateFormat).format(object) + "'";
|
||||
}
|
||||
else if (object instanceof Boolean)
|
||||
{
|
||||
@@ -76,4 +73,26 @@ class RdbmsSpecifics
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure string is escaped properly so that it will run in a SQL query analyzer tool.
|
||||
* At this time all we do is double any single tick marks.
|
||||
* Do not call this with a null string or else an exception will occur.
|
||||
*
|
||||
* @return the input String, escaped.
|
||||
*/
|
||||
String escapeString(String in)
|
||||
{
|
||||
StringBuffer out = new StringBuffer();
|
||||
for (int i=0, j=in.length(); i < j; i++)
|
||||
{
|
||||
char c = in.charAt(i);
|
||||
if (c == '\'')
|
||||
{
|
||||
out.append(c);
|
||||
}
|
||||
out.append(c);
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright 2007-2009 Arthur Blake
|
||||
* Copyright 2007-2012 Arthur Blake
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -1335,16 +1335,7 @@ public class ResultSetSpy implements ResultSet, Spy
|
||||
String methodCall = "getStatement()";
|
||||
try
|
||||
{
|
||||
Statement s = realResultSet.getStatement();
|
||||
if (s == null)
|
||||
{
|
||||
return (Statement) reportReturn(methodCall, s);
|
||||
}
|
||||
else
|
||||
{
|
||||
//todo: what's going on here?
|
||||
return (Statement) reportReturn(methodCall, new StatementSpy(new ConnectionSpy(s.getConnection()), s));
|
||||
}
|
||||
return (Statement) reportReturn(methodCall, realResultSet.getStatement());
|
||||
}
|
||||
catch (SQLException s)
|
||||
{
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user