Author: mikedd
Date: Thu May 28 20:45:46 2009
New Revision: 779765
URL: http://svn.apache.org/viewvc?rev=779765&view=rev
Log:
OPENJPA-1054 committing patch from Rick Curtis and Fay Wang. Testcase has been
updated to use jMock instead of creating its own mock objects.
Added:
openjpa/branches/1.3.x/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestMySQLDictionary.java
(with props)
Modified:
openjpa/branches/1.3.x/openjpa-jdbc/pom.xml
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java
openjpa/branches/1.3.x/openjpa-project/src/doc/manual/supported_databases.xml
openjpa/branches/1.3.x/pom.xml
Modified: openjpa/branches/1.3.x/openjpa-jdbc/pom.xml
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-jdbc/pom.xml?rev=779765&r1=779764&r2=779765&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-jdbc/pom.xml (original)
+++ openjpa/branches/1.3.x/openjpa-jdbc/pom.xml Thu May 28 20:45:46 2009
@@ -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>
Modified:
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=779765&r1=779764&r2=779765&view=diff
==============================================================================
---
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Thu May 28 20:45:46 2009
@@ -3165,6 +3165,10 @@
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);
Modified:
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java?rev=779765&r1=779764&r2=779765&view=diff
==============================================================================
---
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
(original)
+++
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
Thu May 28 20:45:46 2009
@@ -309,4 +309,9 @@
val.appendTo(buf);
buf.append("')");
}
+
+ public int getBatchFetchSize(int batchFetchSize) {
+ return Integer.MIN_VALUE;
+ }
+
}
Modified:
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java?rev=779765&r1=779764&r2=779765&view=diff
==============================================================================
---
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java
(original)
+++
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java
Thu May 28 20:45:46 2009
@@ -492,7 +492,7 @@
}
/**
- * Create and populate the parameters of a prepred statement using the
+ * Create and populate the parameters of a prepared statement using the
* SQL in this buffer and the given fetch configuration.
*/
public PreparedStatement prepareStatement(Connection conn,
@@ -515,7 +515,8 @@
setParameters(stmnt, parms);
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());
@@ -574,7 +575,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());
Added:
openjpa/branches/1.3.x/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestMySQLDictionary.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestMySQLDictionary.java?rev=779765&view=auto
==============================================================================
---
openjpa/branches/1.3.x/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestMySQLDictionary.java
(added)
+++
openjpa/branches/1.3.x/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestMySQLDictionary.java
Thu May 28 20:45:46 2009
@@ -0,0 +1,108 @@
+/*
+ * 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.CallableStatement;
+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 that <code>SQLBuffer.prepareStatement</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 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);
+ }
+
+ /**
+ * <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);
+ }
+}
Propchange:
openjpa/branches/1.3.x/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestMySQLDictionary.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
openjpa/branches/1.3.x/openjpa-project/src/doc/manual/supported_databases.xml
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-project/src/doc/manual/supported_databases.xml?rev=779765&r1=779764&r2=779765&view=diff
==============================================================================
---
openjpa/branches/1.3.x/openjpa-project/src/doc/manual/supported_databases.xml
(original)
+++
openjpa/branches/1.3.x/openjpa-project/src/doc/manual/supported_databases.xml
Thu May 28 20:45:46 2009
@@ -817,6 +817,16 @@
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>
Modified: openjpa/branches/1.3.x/pom.xml
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/pom.xml?rev=779765&r1=779764&r2=779765&view=diff
==============================================================================
--- openjpa/branches/1.3.x/pom.xml (original)
+++ openjpa/branches/1.3.x/pom.xml Thu May 28 20:45:46 2009
@@ -519,6 +519,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>