diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java index 13d5bf3db..1249a3003 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java @@ -594,7 +594,8 @@ public final class SQLBuffer 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()); diff --git a/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestMySQLDictionary.java b/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestMySQLDictionary.java index dc1721e45..5bf5fcbde 100644 --- a/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestMySQLDictionary.java +++ b/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestMySQLDictionary.java @@ -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 @@ public class TestMySQLDictionary extends MockObjectTestCase { assertEquals(Integer.MIN_VALUE, db.getBatchFetchSize(1)); } + + /** *

- * Ensure thaqt a connection obtained from a MySQLDictionary sets the - * fetchBatchSize to Integer.MIN_VALUE + * Ensure that SQLBuffer.prepareStatement calls + * setFetchSize(Integer.MIN_VALUE) when using MySQL. *

* * @throws Exception @@ -67,4 +70,39 @@ public class TestMySQLDictionary extends MockObjectTestCase { sql.prepareStatement(mockConnection, fetch, -1, -1); } + + /** + *

+ * Ensure that SQLBuffer.prepareCall() calls + * setFetchSize(Integer.MIN_VALUE) when using MySQL. + *

+ * + * @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); + } }