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 20:31:13 UTC
svn commit: r779715 - in /openjpa/trunk: ./ openjpa-jdbc/
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/
openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/
openjpa-project/src/doc/manual/
Author: mikedd
Date: Thu May 28 18:31:12 2009
New Revision: 779715
URL: http://svn.apache.org/viewvc?rev=779715&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/trunk/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestMySQLDictionary.java (with props)
Modified:
openjpa/trunk/openjpa-jdbc/pom.xml
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java
openjpa/trunk/openjpa-project/src/doc/manual/supported_databases.xml
openjpa/trunk/pom.xml
Modified: openjpa/trunk/openjpa-jdbc/pom.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/pom.xml?rev=779715&r1=779714&r2=779715&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/pom.xml (original)
+++ openjpa/trunk/openjpa-jdbc/pom.xml Thu May 28 18:31:12 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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=779715&r1=779714&r2=779715&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java Thu May 28 18:31:12 2009
@@ -3273,6 +3273,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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java?rev=779715&r1=779714&r2=779715&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java Thu May 28 18:31:12 2009
@@ -29,7 +29,6 @@
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 @@
val.appendTo(buf);
buf.append("')");
}
+
+ public int getBatchFetchSize(int batchFetchSize) {
+ return Integer.MIN_VALUE;
+ }
+
}
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=779715&r1=779714&r2=779715&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 18:31:12 2009
@@ -534,7 +534,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/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=779715&view=auto
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestMySQLDictionary.java (added)
+++ openjpa/trunk/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestMySQLDictionary.java Thu May 28 18:31:12 2009
@@ -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);
+ }
+}
Propchange: openjpa/trunk/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestMySQLDictionary.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openjpa/trunk/openjpa-project/src/doc/manual/supported_databases.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-project/src/doc/manual/supported_databases.xml?rev=779715&r1=779714&r2=779715&view=diff
==============================================================================
--- openjpa/trunk/openjpa-project/src/doc/manual/supported_databases.xml (original)
+++ openjpa/trunk/openjpa-project/src/doc/manual/supported_databases.xml Thu May 28 18:31:12 2009
@@ -819,6 +819,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/trunk/pom.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/pom.xml?rev=779715&r1=779714&r2=779715&view=diff
==============================================================================
--- openjpa/trunk/pom.xml (original)
+++ openjpa/trunk/pom.xml Thu May 28 18:31:12 2009
@@ -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>