You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by mi...@apache.org on 2009/05/28 22:45:20 UTC

svn commit: r779764 - in /openjpa/trunk/openjpa-jdbc/src: main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java test/java/org/apache/openjpa/jdbc/sql/TestMySQLDictionary.java

Author: mikedd
Date: Thu May 28 20:45:19 2009
New Revision: 779764

URL: http://svn.apache.org/viewvc?rev=779764&view=rev
Log:
OPENJPA-1054. Added testcase for callable statements and fixed typo.

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java
    openjpa/trunk/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestMySQLDictionary.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java?rev=779764&r1=779763&r2=779764&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java Thu May 28 20:45:19 2009
@@ -594,7 +594,8 @@
             setParameters(stmnt);
             if (fetch != null) {
                 if (fetch.getFetchBatchSize() > 0)
-                    stmnt.setFetchSize(fetch.getFetchBatchSize());
+                    stmnt.setFetchSize(
+                        _dict.getBatchFetchSize(fetch.getFetchBatchSize()));
                 if (rsType != ResultSet.TYPE_FORWARD_ONLY
                     && fetch.getFetchDirection() != ResultSet.FETCH_FORWARD)
                     stmnt.setFetchDirection(fetch.getFetchDirection());

Modified: openjpa/trunk/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestMySQLDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestMySQLDictionary.java?rev=779764&r1=779763&r2=779764&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestMySQLDictionary.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestMySQLDictionary.java Thu May 28 20:45:19 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.openjpa.jdbc.sql;
 
+import java.sql.CallableStatement;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -33,10 +34,12 @@
         assertEquals(Integer.MIN_VALUE, db.getBatchFetchSize(1));
     }
 
+    
+    
     /**
      * <P>
-     * Ensure thaqt a connection obtained from a MySQLDictionary sets the
-     * fetchBatchSize to Integer.MIN_VALUE
+     * Ensure that <code>SQLBuffer.prepareStatement</code> calls 
+     * <code>setFetchSize(Integer.MIN_VALUE)</code> when using MySQL. 
      * </P>
      * 
      * @throws Exception
@@ -67,4 +70,39 @@
 
         sql.prepareStatement(mockConnection, fetch, -1, -1);
     }
+    
+    /**
+     * <P>
+     * Ensure that <code>SQLBuffer.prepareCall()</code> calls 
+     * <code>setFetchSize(Integer.MIN_VALUE)</code> when using MySQL. 
+     * </P>
+     * 
+     * @throws Exception
+     *             If any of the expectations are not met or any unexpected
+     *             method calls are made
+     */
+    public void testPreparedCallGetFetchBatchSize() throws Exception {
+        DBDictionary db = new MySQLDictionary();
+        SQLBuffer sql = new SQLBuffer(db);
+        
+        final CallableStatement mockStatement = mock(CallableStatement.class);
+        final Connection mockConnection = mock(Connection.class);
+
+        // Expected method calls on the mock objects above. If any of these are 
+        // do not occur, or if any other methods are invoked on the mock objects
+        // an exception will be thrown and the test will fail. 
+        checking(new Expectations() {
+            {
+                oneOf(mockConnection).prepareCall(with(any(String.class)));
+                will(returnValue(mockStatement));
+                oneOf(mockStatement).setFetchSize(Integer.MIN_VALUE);
+            }
+        });
+        
+        JDBCFetchConfiguration fetch = new JDBCFetchConfigurationImpl();
+        fetch.setResultSetType(ResultSet.TYPE_FORWARD_ONLY);
+        fetch.setFetchBatchSize(1);
+
+        sql.prepareCall(mockConnection, fetch, -1, -1);
+    }
 }