db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r385121 - in /db/ojb/branches/OJB_1_0_RELEASE/src: java/org/apache/ojb/broker/util/UnwrapHelper.java test/org/apache/ojb/broker/UnwrapHelperTest.java
Date Sat, 11 Mar 2006 18:35:04 GMT
Author: arminw
Date: Sat Mar 11 10:35:02 2006
New Revision: 385121

URL: http://svn.apache.org/viewcvs?rev=385121&view=rev
Log:
improve

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/UnwrapHelper.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/UnwrapHelperTest.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/UnwrapHelper.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/UnwrapHelper.java?rev=385121&r1=385120&r2=385121&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/UnwrapHelper.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/UnwrapHelper.java
Sat Mar 11 10:35:02 2006
@@ -20,6 +20,8 @@
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.Statement;
+import java.util.List;
+import java.util.ArrayList;
 
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.builder.ToStringBuilder;
@@ -29,8 +31,18 @@
 
 /**
  * This a helper class make available methods to unwrap {@link java.sql.Connection} and
- * {@link java.sql.PreparedStatement} instances of connection-pool libraries,
+ * {@link java.sql.Statement} instances of connection-pool libraries,
  * application server and other.
+ * <p/>
+ * This class supports predefined unwrap patterns for:
+ * <ul>
+ *     <li>commons-DBCP</li>
+ *     <li>JBoss</li>
+ *     <li>enhydra.XAPool</li>
+ *     <li>BEA Weblogic</li>
+ *     <li>p6spy</li>
+ * </ul>
+ * To add new unwrap patterns use method {@link #addUnwrapPattern(Object[])}.
  *
  * @version $Id: $
  */
@@ -40,8 +52,8 @@
 
     private static final int UNWARP_CONNECTION = 1;
     private static final int UNWARP_STATEMENT = 2;
-    public static final Object[] EMPTY_ARG = new Object[]{};
-    public static final Class[] PARAM_TYPE_EMPTY = new Class[]{};
+    private static final Object[] EMPTY_ARG = new Object[]{};
+    public static final Class[] EMPTY_TYPE = new Class[]{};
     public static final Integer TYPE_METHOD = new Integer(5);
     public static final Integer TYPE_FIELD = new Integer(6);
     /**
@@ -49,115 +61,251 @@
      * and {@link java.sql.PreparedStatement} instances of popular connection-pool libraries,
      * application server and other libraries.
      * <p/>
-     * The array have to be a [n][5] object array. The following arguments will be expected:
+     * The array have to be a [n][7] length object array. The following arguments will be
expected:
      * <ul>
-     * <li>unwrapInfo[i][0] = the vendor, product name as {@link String}</li>
+     * <li>predefinedPatterns[i][0] = the vendor, product name as {@link String}</li>
      *
-     * <li>unwrapInfo[i][1] = use {@link #TYPE_METHOD} if access to the wrapped connection
via method call
+     * <li>predefinedPatterns[i][1] = use {@link #TYPE_METHOD} if access to the wrapped
connection via method call
      * is possible, use {@link #TYPE_FIELD} if access to a field can be used</li>
-     * <li>unwrapInfo[i][2] = use {@link #PARAM_TYPE_EMPTY} if a no-arg method call
is needed, otherwise
-     * specify the argument type class array (at runtime)</li>
-     * <li>unwrapInfo[i][3] = the name of the method/field to lookup the wrapped connection
-     * as {@link String}</li>
+     * <li>predefinedPatterns[i][2] = use {@link #EMPTY_TYPE} if a no-arg method call
is needed, otherwise
+     * specify the argument type class array - in this case always a single argument
+     * type is expected and the source object (object to unwarp) was used as argument object
when
+     * calling {@link #unwrapConnection(Class, java.sql.Connection)} or
+     * {@link #unwrapStatement(Class, java.sql.Statement)}</li>
+     * <li>predefinedPatterns[i][3] = the name of the method/field to lookup the wrapped
connection
+     * as {@link String}<br/><br/></li>
      *
-     * <li>unwrapInfo[i][4] = use {@link #TYPE_METHOD} if access to the wrapped statment
via method call
+     * <li>predefinedPatterns[i][4] = use {@link #TYPE_METHOD} if access to the wrapped
statment via method call
      * is possible, use {@link #TYPE_FIELD} if access to a field can be used</li></li>
-     * <li>unwrapInfo[i][5] = use {@link #PARAM_TYPE_EMPTY} if a no-arg method call
is needed, otherwise
-     * specify the argument type class array (at runtime)</li>
-     * <li>unwrapInfo[i][6] = the name of the method/field to unwrap the statement</li>
+     * <li>predefinedPatterns[i][5] = use {@link #EMPTY_TYPE} if a no-arg method call
is needed, otherwise
+     * specify the argument type class array - in this case always a single argument
+     * type is expected and the source object (object to unwarp) was used as argument object
when
+     * calling {@link #unwrapConnection(Class, java.sql.Connection)} or
+     * {@link #unwrapStatement(Class, java.sql.Statement)}</li>
+     * <li>predefinedPatterns[i][6] = the name of the method/field to unwrap the statement<br/><br/></li>
      * </ul>
      * Example:
-     * <pre>
-     * protected static Object[][] unwrapInfo = {
+     * <code>
+     * protected static Object[][] predefinedPatterns = {
      * {"common-DBCP", TYPE_METHOD, PARAM_TYPE_EMPTY, "getInnermostDelegate", TYPE_METHOD,
PARAM_TYPE_EMPTY, "getInnermostDelegate"},
      * {"enhydra.XAPool", TYPE_FIELD, null, "con", TYPE_FIELD, null, "ps"},
      * ....
-     * </pre>
+     * </code>
      */
-    protected Object[][] unwrapInfo = {
-        {"common-DBCP", TYPE_METHOD, PARAM_TYPE_EMPTY, "getInnermostDelegate", TYPE_METHOD,
PARAM_TYPE_EMPTY, "getInnermostDelegate"},
-        {"JBoss", TYPE_METHOD, PARAM_TYPE_EMPTY, "getUnderlyingConnection", TYPE_METHOD,
PARAM_TYPE_EMPTY, "getUnderlyingStatement"},
+    private static final Object[][] predefinedPatterns = {
+        {"common-DBCP", TYPE_METHOD, EMPTY_TYPE, "getInnermostDelegate", TYPE_METHOD, EMPTY_TYPE,
"getInnermostDelegate"},
+        {"JBoss", TYPE_METHOD, EMPTY_TYPE, "getUnderlyingConnection", TYPE_METHOD, EMPTY_TYPE,
"getUnderlyingStatement"},
         {"enhydra.XAPool", TYPE_FIELD, null, "con", TYPE_FIELD, null, "ps"},
-        {"BEA Weblogic", TYPE_METHOD, PARAM_TYPE_EMPTY, "getVendorConnection", null, null,
null},
-        {"p6spy", TYPE_METHOD, PARAM_TYPE_EMPTY, "getJDBC", TYPE_METHOD, PARAM_TYPE_EMPTY,
"getJDBC"}
+        {"BEA Weblogic", TYPE_METHOD, EMPTY_TYPE, "getVendorConnection", null, null, null},
+        {"p6spy", TYPE_METHOD, EMPTY_TYPE, "getJDBC", TYPE_METHOD, EMPTY_TYPE, "getJDBC"}
     };
 
     /**
+     * The active unwrap patterns.
+     */
+    private Object[][] unwrapPatterns = new Object[][]{};
+    private Object[][] matchedPatterns;
+    private boolean optimized;
+
+
+    /**
+     * Default constructor, use predefined unwrap patterns and optimized
+     * search, see {@link #UnwrapHelper(boolean, boolean)}.
+     */
+    public UnwrapHelper()
+    {
+        this(true, true);
+    }
+
+    /**
+     * Alternative constructor.
+     * @param usePredefined If <em>true</em> the predefined unwrap patterns will
be used,
+     * else no patterns are provided (add pattern with {@link #addUnwrapPattern(Object[])}).
+     * @param optimized If <em>true</em> all matching patterns will be bundled
and used to unwrap,
+     * if <em>false</em> always all patterns are used to search for a unwrap
match.
+     */
+    public UnwrapHelper(boolean usePredefined, boolean optimized)
+    {
+        resetMatchedPatterns();
+        this.optimized = optimized;
+        if(usePredefined)
+        {
+            if(log.isDebugEnabled()) log.debug("Activate predefined unwrap patterns");
+            for(int i = 0; i < predefinedPatterns.length; i++)
+            {
+                Object[] pattern = predefinedPatterns[i];
+                addUnwrapPattern(pattern);
+            }
+        }
+    }
+
+    /** Return the current unwrap patterns. */
+    public Object[][] getUnwrapPatterns()
+    {
+        return unwrapPatterns;
+    }
+
+    /**
      * Add a new unwrap pattern. The object array of length 7 have to be
-     * the following arguments:
+     * the following arguments (a vendor string, 3 arguments to unwrap connections,
+     * 3 arguments to unwrap statements):<br/><br/>
      * <ul>
-     * <li>pattern[0] = the vendor, product name as {@link String}</li>
+     * <li>
+     * pattern[0] = the vendor, product name as {@link String}.<br/><br/>
+     * </li>
      *
-     * <li>pattern[1] = use {@link #TYPE_METHOD} if access to the wrapped connection
via method call
-     * is possible, use {@link #TYPE_FIELD} if access to a field can be used</li>
-     * <li>pattern[2] = use {@link #PARAM_TYPE_EMPTY} if a no-arg method call is needed,
otherwise
-     * specify the argument type class array (at runtime)</li>
-     * <li>pattern[3] = the name of the method/field to lookup the wrapped connection
-     * as {@link String}</li>
+     * <li>
+     * pattern[1] = use {@link #TYPE_METHOD} if access to the wrapped connection is done
via
+     * method call or use {@link #TYPE_FIELD} to specify access via field.
+     * </li>
+     * <li>
+     * pattern[2] = specify the method argument for connection unwrap. Only two types are
+     * supported: non-argument methods and single argument type methods. If field access
+     * is used nullify this argument.
+     * <br/>
+     * Non argument methods can use {@link #EMPTY_TYPE} or simply <em>null</em>.
+     * <br/>
+     * The single argument type (specified as class, class array or full qualified
+     * class name string) use the source object (object to unwarp)  as argument
+     * object when calling
+     * {@link #unwrapConnection(Class, java.sql.Connection)}.
+     * </li>
+     * <li>
+     * pattern[3] = the name of the method/field to unwrap the connection.<br/><br/>
+     * </li>
      *
-     * <li>pattern[4] = use {@link #TYPE_METHOD} if access to the wrapped statment
via method call
-     * is possible, use {@link #TYPE_FIELD} if access to a field can be used</li></li>
-     * <li>pattern[5] = use {@link #PARAM_TYPE_EMPTY} if a no-arg method call is needed,
otherwise
-     * specify the argument type class array (at runtime)</li>
-     * <li>pattern[6] = the name of the method/field to unwrap the statement as {@link
String}</li>
+     * <li>
+     * pattern[4] = use {@link #TYPE_METHOD} if access to the wrapped statment via method
call
+     * is possible, use {@link #TYPE_FIELD} if access to a field can be used
+     * </li>
+     * <li>
+     * pattern[5] = specify the method argument for statement unwrap. Only two types are
+     * supported: non-argument methods and single argument type methods. If field access
+     * is used nullify this argument.
+     * <br/>
+     * Non argument methods can use {@link #EMPTY_TYPE} or simply <em>null</em>.
+     * <br/>
+     * The single argument type (specified as class, class array or full qualified
+     * class name string) use the source object (object to unwarp) as argument
+     * object when calling {@link #unwrapStatement(Class, java.sql.Statement)}.
+     * </li>
+     * <li>
+     * pattern[6] = the name of the method/field to unwrap the statement.<br/><br/>
+     * </li>
      * </ul>
      * Here is an example how to use this method:
-     * <pre>
-     * Object test = new Object[]{"common-DBCP", TYPE_METHOD, PARAM_TYPE_EMPTY, "getInnermostDelegate",
-     * TYPE_METHOD, PARAM_TYPE_EMPTY, "getInnermostDelegate"};
-     * unwarpHelper.addUnwrapPattern(test);
-     * </pre>
+     * <code>
+     * Object pattern = new Object[]{"JBoss", TYPE_METHOD, EMPTY_TYPE, "getUnderlyingConnection",
+     * TYPE_METHOD, EMPTY_TYPE, "getUnderlyingStatement"};
+     * unwarpHelper.addUnwrapPattern(pattern);
+     * </code>
      *
      * @param pattern The unwrap pattern array.
      */
-    public void addUnwrapPattern(Object[] pattern)
+    public void addUnwrapPattern(final Object[] pattern)
     {
+        // check connection method argument
+        Object argType = pattern[2];
+        if(argType == null)
+        {
+            pattern[2] = EMPTY_TYPE;
+        }
+        else if(argType instanceof String)
+        {
+            String arg = (String) argType;
+            try
+            {
+                Class tmp = ClassHelper.getClass(arg);
+                pattern[2] = new Class[]{tmp};
+            }
+            catch(ClassNotFoundException e)
+            {
+                log.error("Can't lookup method argument type "
+                        + arg + " of pattern " + ArrayUtils.toString(pattern), e);
+            }
+        }
+        else if(argType instanceof Class)
+        {
+            pattern[2] = new Class[]{(Class)argType};
+        }
+        // check statement method argument
+        argType = pattern[5];
+        if(argType == null)
+        {
+            pattern[5] = EMPTY_TYPE;
+        }
+        else if(argType instanceof String)
+        {
+            String arg = (String) argType;
+            try
+            {
+                Class tmp = ClassHelper.getClass(arg);
+                pattern[5] = new Class[]{tmp};
+            }
+            catch(ClassNotFoundException e)
+            {
+                log.error("Can't lookup method argument type "
+                        + arg + " of pattern " + ArrayUtils.toString(pattern), e);
+            }
+        }
+        else if(argType instanceof Class)
+        {
+            pattern[5] = new Class[]{(Class)argType};
+        }
+
         Object[][] tmp = new Object[][]{pattern};
-        unwrapInfo = (Object[][]) ArrayUtils.addAll(unwrapInfo, tmp);
+        unwrapPatterns = (Object[][]) ArrayUtils.addAll(unwrapPatterns, tmp);
+        // force synchronization of optimized patterns
+        if(optimized) resetMatchedPatterns();
     }
 
-    /** Return the current unwrap patterns. */
-    public Object[][] getUnwrapPatterns()
+    protected Object genericUnwrap(final Class classToMatch, final Object toUnwrap, final
int type)
     {
-        return unwrapInfo;
+        Object result;
+        if(optimized)
+        {
+            if(matchedPatterns.length == 0)
+            {
+                ArrayList matches = new ArrayList();
+                result = loopUnwrap(unwrapPatterns, classToMatch, toUnwrap, type, matches);
+                matchedPatterns = (Object[][]) matches.toArray(new Object[matches.size()][]);
+            }
+            else
+            {
+                result = loopUnwrap(matchedPatterns, classToMatch, toUnwrap, type, null);
+            }
+        }
+        else
+        {
+            result = loopUnwrap(unwrapPatterns, classToMatch, toUnwrap, type, null);
+        }
+        return result;
     }
 
-    protected Object genericUnwrap(final Class classToMatch, final Object toUnwrap, int type)
+    protected Object loopUnwrap(Object[][] patterns, final Class classToMatch, final Object
toUnwrap, final int type, final List matchedPatterns)
     {
         if(classToMatch == null)
         {
             return null;
         }
-
-        Object unwrapped = null;
         if(classToMatch.isAssignableFrom(toUnwrap.getClass()))
         {
             return toUnwrap;
         }
+        Object unwrapped = null;
+
         int i = 0;
         try
         {
-            for(; i < unwrapInfo.length; i++)
+            for(; i < patterns.length; i++)
             {
-                Object[] info = unwrapInfo[i];
-                if(type == UNWARP_CONNECTION && info[3] != null)
-                {
-                    unwrapped = reflectObject(toUnwrap, info[1].equals(TYPE_METHOD), (Class[])
info[2], (String) info[3]);
-                }
-                else if(type == UNWARP_STATEMENT && info[6] != null)
-                {
-                    unwrapped = reflectObject(toUnwrap, info[4].equals(TYPE_METHOD), (Class[])
info[5], (String) info[6]);
-                }
+                Object[] pattern = patterns[i];
+                unwrapped = unwrap(pattern, toUnwrap, type);
                 if(unwrapped != null)
                 {
-                    if(classToMatch.isAssignableFrom(unwrapped.getClass()))
+                    if(matchedPatterns != null)
                     {
-                        // Bingo!
-                    }
-                    else
-                    {
-                        // When using e.g. both DBCP and P6Spy we have to recursively unwrap
-                        unwrapped = genericUnwrap(classToMatch, unwrapped, type);
+                        matchedPatterns.add(pattern);
                     }
                     break;
                 }
@@ -171,18 +319,54 @@
             {
                 if(type == UNWARP_CONNECTION)
                 {
-                    log.debug("Unwrap of connection failed using unwrap rule for " + unwrapInfo[i][0]
+ " connections", e);
+                    log.debug("Unwrap of connection failed using unwrap rule for " + unwrapPatterns[i][0]
+ " connections", e);
                 }
                 else
                 {
-                    log.debug("Unwrap of prepared stmt failed using unwrap rule for " + unwrapInfo[i][0]
+ " statements", e);
+                    log.debug("Unwrap of prepared stmt failed using unwrap rule for " + unwrapPatterns[i][0]
+ " statements", e);
                 }
             }
         }
+
+        if(unwrapped != null)
+        {
+            if(classToMatch.isAssignableFrom(unwrapped.getClass()))
+            {
+                // Bingo!
+            }
+            else
+            {
+                // When using e.g. both DBCP and P6Spy we have to recursively unwrap
+                unwrapped = loopUnwrap(patterns, classToMatch, unwrapped, type, matchedPatterns);
+            }
+        }
         return unwrapped;
     }
 
-    private Object reflectObject(Object source, boolean methodType, Class[] paramType, String
fieldOrMethodName) throws Exception
+    private Object unwrap(final Object[] pattern, final Object toUnwrap, final int type)
throws Exception
+    {
+        Object unwrapped = null;
+        if(type == UNWARP_CONNECTION && pattern[3] != null)
+        {
+            unwrapped = reflectObject(toUnwrap, pattern[1].equals(TYPE_METHOD), (Class[])
pattern[2], (String) pattern[3]);
+        }
+        else if(type == UNWARP_STATEMENT && pattern[6] != null)
+        {
+            unwrapped = reflectObject(toUnwrap, pattern[4].equals(TYPE_METHOD), (Class[])
pattern[5], (String) pattern[6]);
+        }
+        else
+        {
+            if(log.isDebugEnabled())
+            {
+                log.debug("Can't use the specified pattern to unwarp "
+                        + (type == UNWARP_CONNECTION ? "connection" : "statement")
+                        + ": " + ArrayUtils.toString(pattern));
+            }
+        }
+        return unwrapped;
+    }
+
+    private Object reflectObject(final Object source, final boolean methodType, final Class[]
paramType, final String fieldOrMethodName) throws Exception
     {
         Object unwrapped = null;
         if(methodType)
@@ -195,7 +379,8 @@
                 {
                     method.setAccessible(true);
                 }
-                unwrapped = method.invoke(source, EMPTY_ARG);
+                Object[] arg = (paramType == null || paramType.length == 0) ? EMPTY_ARG :
new Object[]{source};
+                unwrapped = method.invoke(source, arg);
             }
         }
         else
@@ -222,7 +407,7 @@
      * @param source The wrapped connection instance.
      * @return The unwrapped connection or <em>null</em> if no match is possible.
      */
-    public Connection unwrapConnection(Class target, Connection source)
+    public Connection unwrapConnection(final Class target, final Connection source)
     {
         Connection result = (Connection) genericUnwrap(target, source, UNWARP_CONNECTION);
         if(result == null && log.isDebugEnabled())
@@ -241,7 +426,7 @@
      * @param source The wrapped statement instance.
      * @return The unwrapped statement or <em>null</em> if no match is possible.
      */
-    public Statement unwrapStatement(Class target, Statement source)
+    public Statement unwrapStatement(final Class target, final Statement source)
     {
         Statement result = (Statement) genericUnwrap(target, source, UNWARP_STATEMENT);
         if(result == null && log.isDebugEnabled())
@@ -260,24 +445,23 @@
      * @param source The wrapped statement instance.
      * @return The unwrapped statement or <em>null</em> if no match is possible.
      */
-    public PreparedStatement unwrapStatement(Class target, PreparedStatement source)
+    public PreparedStatement unwrapStatement(final Class target, final PreparedStatement
source)
     {
-        PreparedStatement result = (PreparedStatement) genericUnwrap(target, source, UNWARP_STATEMENT);
-        if(result == null && log.isDebugEnabled())
-        {
-            log.debug("Could not unwrap source " + source.getClass().getName()
-                    + " to target class " + target.getName());
-        }
-        return result;
+        return (PreparedStatement) unwrapStatement(target, (Statement) source);
+    }
+
+    private void resetMatchedPatterns()
+    {
+        matchedPatterns = new Object[][]{};
     }
 
     public String toString()
     {
         ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
         buf.append("Supported unwrap pattern: ");
-        for(int i = 0; i < unwrapInfo.length; i++)
+        for(int i = 0; i < unwrapPatterns.length; i++)
         {
-            buf.append(ArrayUtils.toString(unwrapInfo[i]));
+            buf.append(ArrayUtils.toString(unwrapPatterns[i]));
         }
         return buf.toString();
     }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/UnwrapHelperTest.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/UnwrapHelperTest.java?rev=385121&r1=385120&r2=385121&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/UnwrapHelperTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/UnwrapHelperTest.java Sat
Mar 11 10:35:02 2006
@@ -63,8 +63,9 @@
         int length = helper.getUnwrapPatterns().length;
         Object[] pattern = helper.getUnwrapPatterns()[0];
         helper.addUnwrapPattern(pattern);
+        helper.addUnwrapPattern(new Object[][]{null, null, null, null, null, null, null});
         //System.out.println("## " + helper.toString());
-        assertEquals(length + 1, helper.getUnwrapPatterns().length);
+        assertEquals(length + 2, helper.getUnwrapPatterns().length);
     }
 
     public void testUnwrapConnection() throws Exception
@@ -99,7 +100,7 @@
     /**
      * Test useful for development.
      */
-    public void XXXtestUnwrapLoop() throws Exception
+    public void testUnwrapLoop() throws Exception
     {
         Platform pf = broker.serviceConnectionManager().getSupportedPlatform();
         if(!PlatformHsqldbImpl.class.isAssignableFrom(pf.getClass()))
@@ -110,8 +111,53 @@
         PreparedStatement ps = con.prepareStatement(selectExample);
         Class targetC = ClassHelper.getClass(connectionClassName);
         Class targetS = ClassHelper.getClass(statementClassName);
-        long t = System.currentTimeMillis();
         int loops = 5000;
+        long t = System.currentTimeMillis();
+        for(int i = 0;i<loops;i++)
+        {
+            Connection resultC = helper.unwrapConnection(targetC, con);
+            assertNotNull(resultC);
+            PreparedStatement resultS = helper.unwrapStatement(targetS, ps);
+            assertNotNull(resultS);
+        }
+        t = System.currentTimeMillis() - t;
+        System.out.println("Unwarp " + loops + " con/stmt (optimized mode): " + t + " ms");
+
+        Object[] pattern = helper.getUnwrapPatterns()[0];
+        helper.addUnwrapPattern(pattern);
+        helper.addUnwrapPattern(new Object[][]{null, null, null, null, null, null, null});
+        //System.out.println("Patterns: " + helper);
+
+        t = System.currentTimeMillis();
+        for(int i = 0;i<loops;i++)
+        {
+            Connection resultC = helper.unwrapConnection(targetC, con);
+            assertNotNull(resultC);
+            PreparedStatement resultS = helper.unwrapStatement(targetS, ps);
+            assertNotNull(resultS);
+        }
+        t = System.currentTimeMillis() - t;
+        System.out.println("Unwarp " + loops + " con/stmt (optimized mode): " + t + " ms");
+
+
+        helper = new UnwrapHelper(true, false);
+        t = System.currentTimeMillis();
+        for(int i = 0;i<loops;i++)
+        {
+            Connection resultC = helper.unwrapConnection(targetC, con);
+            assertNotNull(resultC);
+            PreparedStatement resultS = helper.unwrapStatement(targetS, ps);
+            assertNotNull(resultS);
+        }
+        t = System.currentTimeMillis() - t;
+        System.out.println("Unwarp " + loops + " con/stmt (search all patterns): " + t +
" ms");
+
+        pattern = helper.getUnwrapPatterns()[0];
+        helper.addUnwrapPattern(pattern);
+        helper.addUnwrapPattern(new Object[][]{null, null, null, null, null, null, null});
+        //System.out.println("Patterns: " + helper);
+
+        t = System.currentTimeMillis();
         for(int i = 0;i<loops;i++)
         {
             Connection resultC = helper.unwrapConnection(targetC, con);
@@ -120,6 +166,6 @@
             assertNotNull(resultS);
         }
         t = System.currentTimeMillis() - t;
-        System.out.println("Unwarp " + loops + " con/stmt: " + t + " ms");
+        System.out.println("Unwarp " + loops + " con/stmt (search all patterns): " + t +
" ms");
     }
 }



---------------------------------------------------------------------
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