OPENJPA-1054. Added testcase for callable statements and fixed typo.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@779764 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Dick 2009-05-28 20:45:27 +00:00
parent 3c88ac3d20
commit 0d6f1a0214
2 changed files with 42 additions and 3 deletions

View File

@ -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());

View File

@ -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));
}
/**
* <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 @@ public class TestMySQLDictionary extends MockObjectTestCase {
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);
}
}