mirror of https://github.com/apache/openjpa.git
OPENJPA-1054 committing patch from Rick Curtis and Fay Wang. Testcase has been updated to use jMock instead of creating its own mock objects
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@779715 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b2a8732a8b
commit
3c88ac3d20
|
@ -64,5 +64,15 @@
|
|||
<artifactId>ant</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jmock</groupId>
|
||||
<artifactId>jmock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jmock</groupId>
|
||||
<artifactId>jmock-junit3</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -3273,6 +3273,10 @@ public class DBDictionary
|
|||
buf.append(")");
|
||||
return new String[]{ buf.toString() };
|
||||
}
|
||||
|
||||
public int getBatchFetchSize(int batchFetchSize) {
|
||||
return batchFetchSize;
|
||||
}
|
||||
|
||||
protected StringBuffer comment(StringBuffer buf, String comment) {
|
||||
return buf.append("-- ").append(comment);
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.apache.commons.lang.StringUtils;
|
|||
import org.apache.openjpa.jdbc.kernel.JDBCStore;
|
||||
import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
|
||||
import org.apache.openjpa.jdbc.schema.Column;
|
||||
import org.apache.openjpa.jdbc.schema.ForeignKey;
|
||||
import org.apache.openjpa.jdbc.schema.Index;
|
||||
import org.apache.openjpa.jdbc.schema.PrimaryKey;
|
||||
import org.apache.openjpa.jdbc.schema.Table;
|
||||
|
@ -311,4 +310,9 @@ public class MySQLDictionary
|
|||
val.appendTo(buf);
|
||||
buf.append("')");
|
||||
}
|
||||
|
||||
public int getBatchFetchSize(int batchFetchSize) {
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -534,7 +534,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());
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.openjpa.jdbc.sql;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
|
||||
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfigurationImpl;
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.integration.junit3.MockObjectTestCase;
|
||||
|
||||
public class TestMySQLDictionary extends MockObjectTestCase {
|
||||
public void testDBDictionaryGetBatchFetchSize() throws Exception {
|
||||
DBDictionary db = new MySQLDictionary();
|
||||
assertEquals(Integer.MIN_VALUE, db.getBatchFetchSize(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* <P>
|
||||
* Ensure thaqt a connection obtained from a MySQLDictionary sets the
|
||||
* fetchBatchSize to Integer.MIN_VALUE
|
||||
* </P>
|
||||
*
|
||||
* @throws Exception
|
||||
* If any of the expectations are not met or any unexpected
|
||||
* method calls are made
|
||||
*/
|
||||
public void testPreparedStatementGetFetchBatchSize() throws Exception {
|
||||
DBDictionary db = new MySQLDictionary();
|
||||
SQLBuffer sql = new SQLBuffer(db);
|
||||
|
||||
final PreparedStatement mockStatement = mock(PreparedStatement.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).prepareStatement(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.prepareStatement(mockConnection, fetch, -1, -1);
|
||||
}
|
||||
}
|
|
@ -819,6 +819,16 @@ being able to interrogate the database for foreign keys. Version 3.0.14 (or
|
|||
higher) of the MySQL driver is required in order to get around this bug.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
When using large result sets with MySQL there are a number of documented limitations.
|
||||
Please read the section titled "ResultSet" in the "MySQL JDBC API Implementation Notes".
|
||||
The net of these limitations is that you will have to read all of the rows of a
|
||||
result set (or close the connection) before you can issue any other queries on
|
||||
the connection, or an exception will be thrown. Setting openjpa.FetchBatchSize
|
||||
to any value greater than zero will enable streaming result sets.
|
||||
</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</section>
|
||||
</section>
|
||||
|
|
10
pom.xml
10
pom.xml
|
@ -494,6 +494,16 @@
|
|||
<artifactId>ant</artifactId>
|
||||
<version>1.6.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jmock</groupId>
|
||||
<artifactId>jmock</artifactId>
|
||||
<version>2.5.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jmock</groupId>
|
||||
<artifactId>jmock-junit3</artifactId>
|
||||
<version>2.5.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<dependencies>
|
||||
|
|
Loading…
Reference in New Issue