DBUTILS-106 - DBUtils can't build using JDK 1.7 - DriverProxy needs to implement getParentLogger() Add dynamic invocation.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/dbutils/branches/2_0@1482460 13f79535-47bb-0310-9956-ffa450edef68 Project: http://git-wip-us.apache.org/repos/asf/commons-dbutils/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-dbutils/commit/d9e63eed Tree: http://git-wip-us.apache.org/repos/asf/commons-dbutils/tree/d9e63eed Diff: http://git-wip-us.apache.org/repos/asf/commons-dbutils/diff/d9e63eed Branch: refs/heads/2_0 Commit: d9e63eed98002d71a2df868b14a0fae60f6cb171 Parents: 949c5d9 Author: Sebastian Bazley <[email protected]> Authored: Tue May 14 17:00:33 2013 +0000 Committer: Sebastian Bazley <[email protected]> Committed: Tue May 14 17:00:33 2013 +0000 ---------------------------------------------------------------------- src/changes/changes.xml | 4 ++++ .../org/apache/commons/dbutils2/DbUtils.java | 21 +++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/d9e63eed/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index a19d1ed..788596f 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -48,6 +48,10 @@ The <action> type attribute can be add,update,fix,remove. This is the first release of the 2.x branch of the Commons DbUtils package, DbUtils2. The motivation for creating DbUtils2 was two-fold: a number of deprecated methods in the original DbUtils, and the desire to support named parameters (DBUTILS-105). "> + <action dev="sebb" type="fix" issue="DBUTILS-106"> + DBUtils can't build using JDK 1.7 - DriverProxy needs to implement getParentLogger() + Add dynamic invocation. + </action> <action dev="sebb" type="fix" issue="DBUTILS-109"> AbstractExecutor.currentPosition should be an int </action> http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/d9e63eed/src/main/java/org/apache/commons/dbutils2/DbUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/dbutils2/DbUtils.java b/src/main/java/org/apache/commons/dbutils2/DbUtils.java index 47f9ace..530ddb9 100644 --- a/src/main/java/org/apache/commons/dbutils2/DbUtils.java +++ b/src/main/java/org/apache/commons/dbutils2/DbUtils.java @@ -21,6 +21,7 @@ import static java.sql.DriverManager.registerDriver; import java.io.PrintWriter; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.sql.Connection; import java.sql.Driver; import java.sql.DriverPropertyInfo; @@ -347,6 +348,8 @@ public final class DbUtils { */ private static final class DriverProxy implements Driver { + private boolean parentLoggerSupported = true; + /** * The adapted JDBC Driver loaded dynamically. */ @@ -395,7 +398,23 @@ public final class DbUtils { * Java 1.7 method. */ public Logger getParentLogger() throws SQLFeatureNotSupportedException { - throw new SQLFeatureNotSupportedException(); + if (parentLoggerSupported) { + try { + Method method = adapted.getClass().getMethod("getParentLogger", new Class[0]); + return (Logger)method.invoke(adapted, new Object[0]); + } catch (NoSuchMethodException e) { + parentLoggerSupported = false; + throw new SQLFeatureNotSupportedException(e); + } catch (IllegalAccessException e) { + parentLoggerSupported = false; + throw new SQLFeatureNotSupportedException(e); + } catch (InvocationTargetException e) { + parentLoggerSupported = false; + throw new SQLFeatureNotSupportedException(e); + } + } else { + throw new SQLFeatureNotSupportedException(); + } } }
