db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r385550 - /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformOracle9iImpl.java
Date Mon, 13 Mar 2006 13:46:09 GMT
Author: arminw
Date: Mon Mar 13 05:46:07 2006
New Revision: 385550

URL: http://svn.apache.org/viewcvs?rev=385550&view=rev
Log:
add fix for OJB-101, source out unwrap of connections and statements to a helper class

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformOracle9iImpl.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformOracle9iImpl.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformOracle9iImpl.java?rev=385550&r1=385549&r2=385550&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformOracle9iImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformOracle9iImpl.java
Mon Mar 13 05:46:07 2006
@@ -15,12 +15,6 @@
  * limitations under the License.
  */
 
-import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
-import org.apache.ojb.broker.metadata.ConnectionPoolDescriptor;
-import org.apache.ojb.broker.util.ClassHelper;
-import org.apache.ojb.broker.util.logging.Logger;
-import org.apache.ojb.broker.util.logging.LoggerFactory;
-
 import java.io.ByteArrayInputStream;
 import java.lang.reflect.Method;
 import java.sql.Connection;
@@ -32,6 +26,13 @@
 import java.util.Map;
 import java.util.WeakHashMap;
 
+import org.apache.ojb.broker.metadata.ConnectionPoolDescriptor;
+import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
+import org.apache.ojb.broker.util.ClassHelper;
+import org.apache.ojb.broker.util.UnwrapHelper;
+import org.apache.ojb.broker.util.logging.Logger;
+import org.apache.ojb.broker.util.logging.LoggerFactory;
+
 /**
  * This class is a concrete implementation of <code>Platform</code>. Provides
  * an implementation that works around some issues with Oracle in general and
@@ -122,48 +123,10 @@
     protected static boolean ORA_CLOB_HANDLING_AVAILABLE;
     protected static boolean ORA_BLOB_HANDLING_AVAILABLE;
 
-    /** Method names used by {@link #unwrapConnection}. */
-    protected static final String UNWRAP_CONN_METHOD_NAMES[] =
-            {
-                "unwrapCompletely"          /* Oracle 10g */,
-                "getInnermostDelegate"      /* Commons DBCP */,
-                "getUnderlyingConnection"   /* JBoss */,
-                "getVendorConnection"       /* BEA WebLogic */,
-                "getJDBC"                   /* P6Spy */
-            };
-    /**
-     * Method parameter signature used by {@link #unwrapConnection} for corresponding
-     * {@link #UNWRAP_CONN_METHOD_NAMES}-index.
-     * If signature is not {@link #PARAM_TYPE_EMPTY}, the actual connection object
-     * will be passed at runtime. (NB: Requires special handling of param type in constructor.)
-     */
-    protected static final Class[][] UNWRAP_CONN_PARAM_TYPES =
-            {
-                null  /* Index 0 reserved for Oracle 10g - initialized in constructor */,
-                PARAM_TYPE_EMPTY            /* Commons DBCP */,
-                PARAM_TYPE_EMPTY            /* JBoss */,
-                PARAM_TYPE_EMPTY            /* BEA WebLogic */,
-                PARAM_TYPE_EMPTY            /* P6Spy */
-            };
-    /** Method names used by {@link #unwrapStatement}. */
-    protected static final String UNWRAP_PS_METHOD_NAMES[] =
-            {
-                "getInnermostDelegate"      /* Commons DBCP */,
-                "getUnderlyingStatement"    /* JBoss */,
-                "getJDBC"                   /* P6Spy */
-            };
-    /**
-     * Method parameter signature used by {@link #unwrapStatement} for corresponding
-     * {@link #UNWRAP_PS_METHOD_NAMES}-index.
-     * If signature is not {@link #PARAM_TYPE_EMPTY}, the actual Statement object
-     * will be passed at runtime. (NB: Requires special handling of param type in constructor.)
-     */
-    protected static final Class[][] UNWRAP_PS_PARAM_TYPES =
-            {
-                PARAM_TYPE_EMPTY            /* Commons DBCP */,
-                PARAM_TYPE_EMPTY            /* JBoss */,
-                PARAM_TYPE_EMPTY            /* P6Spy */
-            };
+    /**
+     * Helper to unwrap connections and statements.
+     */
+    protected UnwrapHelper unwrapHelper = new UnwrapHelper();
 
 
     /**
@@ -466,8 +429,7 @@
      */
     protected Connection unwrapConnection(Connection conn)
     {
-        final Object unwrapped;
-        unwrapped = genericUnwrap(ORA_CONN_CLASS, conn, UNWRAP_CONN_METHOD_NAMES, UNWRAP_CONN_PARAM_TYPES);
+        final Connection unwrapped = unwrapHelper.unwrapConnection(ORA_CONN_CLASS, conn);
         if (unwrapped == null)
         {
             // mkalen:  only log this as debug since it will be logged for every connection
@@ -478,7 +440,7 @@
                              ", Oracle-extensions disabled.");
             }
         }
-        return (Connection) unwrapped;
+        return unwrapped;
     }
 
     /**
@@ -488,8 +450,7 @@
      */
     protected Statement unwrapStatement(Statement ps)
     {
-        final Object unwrapped;
-        unwrapped = genericUnwrap(ORA_PS_CLASS, ps, UNWRAP_PS_METHOD_NAMES, UNWRAP_PS_PARAM_TYPES);
+        final Statement unwrapped = unwrapHelper.unwrapStatement(ORA_PS_CLASS, ps);
         if (unwrapped == null)
         {
             // mkalen:  only log this as debug since it will be logged for every connection
@@ -500,60 +461,7 @@
                              ", large CLOB/BLOB support disabled.");
             }
         }
-        return (Statement) unwrapped;
-    }
-    
-    protected Object genericUnwrap(Class classToMatch, Object toUnwrap,
-                                   String[] methodNameCandidates,
-                                   Class[][] methodTypeCandidates)
-    {
-        if (classToMatch == null)
-        {
-            return null;
-        }
-
-        Object unwrapped;
-        final Class psClass = toUnwrap.getClass();
-        if (classToMatch.isAssignableFrom(psClass))
-        {
-            return toUnwrap;
-        }
-        try
-        {
-            String methodName;
-            Class[] paramTypes;
-            Object[] args;
-            for (int i = 0; i < methodNameCandidates.length; i++)
-            {
-                methodName = methodNameCandidates[i];
-                paramTypes = methodTypeCandidates[i];
-                final Method method = ClassHelper.getMethod(toUnwrap, methodName, paramTypes);
-                if (method != null)
-                {
-                    args = paramTypes == PARAM_TYPE_EMPTY ? PARAM_EMPTY : new Object[]{ toUnwrap
};
-                    unwrapped = method.invoke(toUnwrap, args);
-                    if (unwrapped != null)
-                    {
-                        if (classToMatch.isAssignableFrom(unwrapped.getClass()))
-                        {
-                            return unwrapped;
-                        }
-                        // When using eg both DBCP and P6Spy we have to recursively unwrap
-                        return genericUnwrap(classToMatch, unwrapped,
-                                methodNameCandidates, methodTypeCandidates);
-                    }
-                }
-            }
-        }
-        catch (Exception e)
-        {
-            // ignore
-            if (logger.isDebugEnabled())
-            {
-                logger.debug("genericUnwrap failed", e);
-            }
-        }
-        return null;
+        return unwrapped;
     }
 
     /**
@@ -578,8 +486,14 @@
             PARAM_TYPE_INT_ORACLOB = new Class[]{ Integer.TYPE, ORA_CLOB_CLASS };
             PARAM_TYPE_INT_ORABLOB = new Class[]{ Integer.TYPE, ORA_BLOB_CLASS };
 
-            // Index 0 reserved for Oracle 10g
-            UNWRAP_CONN_PARAM_TYPES[0] = new Class[]{ ORA_CONN_CLASS };
+            /*
+            The unwrap pattern used in {@link org.apache.ojb.broker.util.UnwrapHelper}
+            to unwrap connection instance to Oracle's specific connection implementation
class.
+            */
+            Object[] oracleUnwrapPattern = new Object[] {"oracle 10g", UnwrapHelper.TYPE_METHOD,
+                    new Class[]{ORA_CONN_CLASS}, "unwrapCompletely", null, null, null};
+            // add the oracle unwrap pattern
+            unwrapHelper.addUnwrapPattern(oracleUnwrapPattern);
 
             METHOD_SET_STATEMENT_CACHE_SIZE =
                     ClassHelper.getMethod(ORA_CONN_CLASS, "setStatementCacheSize", PARAM_TYPE_INTEGER);
@@ -610,4 +524,4 @@
         }
     }
 
-}
+}
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message