Author: hthomann
Date: Thu May 17 22:31:10 2012
New Revision: 1339899
URL: http://svn.apache.org/viewvc?rev=1339899&view=rev
Log:
OPENJPA-1376: Applied Helen Xu's changes where she back ported changes from
1.2.x
Added:
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityE2.java
(with props)
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java
(with props)
Modified:
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java
openjpa/branches/1.0.x/openjpa-project/src/doc/manual/jpa_overview_mapping.xml
openjpa/branches/1.0.x/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml
openjpa/branches/1.0.x/openjpa-project/src/doc/manual/ref_guide_optimization.xml
openjpa/branches/1.0.x/openjpa-project/src/doc/manual/ref_guide_runtime.xml
Modified:
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java?rev=1339899&r1=1339898&r2=1339899&view=diff
==============================================================================
---
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java
(original)
+++
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java
Thu May 17 22:31:10 2012
@@ -53,6 +53,8 @@ import serp.util.Strings;
/**
* {@link JDBCSeq} implementation that uses a database sequences
* to generate numbers.
+ * Supports allocation (caching). In order for allocation to work properly,
the database sequence must be defined
+ * with INCREMENT BY value equal to allocate * increment.
*
* @see JDBCSeq
* @see AbstractJDBCSeq
@@ -71,9 +73,12 @@ public class NativeJDBCSeq
private String _seqName = "OPENJPA_SEQUENCE";
private int _increment = 1;
private int _initial = 1;
- private int _allocate = 0;
+ private int _allocate = 50;
private Sequence _seq = null;
private String _select = null;
+ private long _nextValue = 0;
+ private long _maxValue = -1;
+
// for deprecated auto-configuration support
private String _format = null;
@@ -188,27 +193,74 @@ public class NativeJDBCSeq
public void endConfiguration() {
buildSequence();
-
- DBDictionary dict = _conf.getDBDictionaryInstance();
- if (_format == null) {
- _format = dict.nextSequenceQuery;
- if (_format == null)
- throw new MetaDataException(_loc.get("no-seq-sql", _seqName));
- }
+
if (_tableName == null)
_tableName = "DUAL";
+ DBDictionary dict = _conf.getDBDictionaryInstance();
String name = dict.getFullName(_seq);
- Object[] subs = (_subTable) ? new Object[]{ name, _tableName }
+
+ if (dict.useNativeSequenceCache){
+ if (_format == null) {
+ _format = dict.nextSequenceQuery;
+ if (_format == null)
+ throw new MetaDataException(_loc.get("no-seq-sql",
_seqName));
+ }
+
+ Object[] subs = (_subTable) ? new Object[]{ name, _tableName }
: new Object[]{ name };
- _select = MessageFormat.format(_format, subs);
+ _select = MessageFormat.format(_format, subs);
+ }
+ else {
+ String format = dict.nextSequenceQuery;
+ if (format == null) {
+ throw new MetaDataException(_loc.get("no-seq-sql", _seqName));
+ }
+
+ // Increment step is needed for Firebird which uses non-standard
sequence fetch syntax.
+ // Use String.valueOf to get rid of possible locale-specific
number formatting.
+ _select = MessageFormat.format(format, new Object[]{name,
String.valueOf(_allocate * _increment)});
+ }
+
+ type = dict.nativeSequenceType;
}
- protected Object nextInternal(JDBCStore store, ClassMapping mapping)
+ protected synchronized Object nextInternal(JDBCStore store, ClassMapping
mapping)
throws SQLException {
+ DBDictionary dict = _conf.getDBDictionaryInstance();
+
+ //To maintain existing behavior call allocateInternal to get the next
+ //sequence value, which it stores in _nextValue, and simply return the
value.
+ if (dict.useNativeSequenceCache){
+ allocateInternal(0, store, mapping);
+ return Numbers.valueOf(_nextValue);
+ }
+
+ if (_nextValue < _maxValue) {
+ long result = _nextValue;
+ _nextValue += _increment;
+ return Numbers.valueOf(result);
+ }
+
+ allocateInternal(0, store, mapping);
+ long result = _nextValue;
+ _nextValue += _increment;
+ return Numbers.valueOf(result);
+ }
+
+ /**
+ * Allocate additional sequence values.
+ * @param additional ignored - the allocation size is fixed and determined
by allocate and increment properties.
+ * @param store used to obtain connection
+ * @param mapping ignored
+ */
+ protected synchronized void allocateInternal(int additional, JDBCStore
store, ClassMapping mapping)
+ throws SQLException {
+
Connection conn = getConnection(store);
try {
- return Numbers.valueOf(getSequence(conn));
+ _nextValue = getSequence(conn);
+ _maxValue = _nextValue + _allocate * _increment;
} finally {
closeConnection(conn);
}
@@ -272,9 +324,7 @@ public class NativeJDBCSeq
ResultSet rs = null;
try {
stmnt = conn.prepareStatement(_select);
- synchronized(this) {
- rs = stmnt.executeQuery();
- }
+ rs = stmnt.executeQuery();
if (rs.next())
return rs.getLong(1);
@@ -299,8 +349,8 @@ public class NativeJDBCSeq
* Where the following options are recognized.
* <ul>
* <li><i>-properties/-p <properties file or resource></i>: The
- * path or resource name of a OpenJPA properties file containing
- * information such as the license key and connection data as
+ * path or resource name of an OpenJPA properties file containing
+ * information such as connection data as
* outlined in {@link JDBCConfiguration}. Optional.</li>
* <li><i>-<property name> <property value></i>: All bean
* properties of the OpenJPA {@link JDBCConfiguration} can be set by
Modified:
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java?rev=1339899&r1=1339898&r2=1339899&view=diff
==============================================================================
---
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
(original)
+++
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
Thu May 17 22:31:10 2012
@@ -164,11 +164,14 @@ public class DB2Dictionary
append(" ROWS ONLY");
}
- public String[] getCreateSequenceSQL(Sequence seq) {
- String[] sql = super.getCreateSequenceSQL(seq);
- if (seq.getAllocate() > 1)
- sql[0] += " CACHE " + seq.getAllocate();
- return sql;
+ public String[] getCreateSequenceSQL(Sequence seq) {
+ String[] sql = super.getCreateSequenceSQL(seq);
+
+ if (seq.getAllocate() > 1 && useNativeSequenceCache){
+ sql[0] += " CACHE " + seq.getAllocate();
+ }
+
+ return sql;
}
protected String getSequencesSQL(String schemaName, String sequenceName) {
Modified:
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=1339899&r1=1339898&r2=1339899&view=diff
==============================================================================
---
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Thu May 17 22:31:10 2012
@@ -83,6 +83,7 @@ import org.apache.openjpa.jdbc.schema.Se
import org.apache.openjpa.jdbc.schema.Table;
import org.apache.openjpa.jdbc.schema.Unique;
import org.apache.openjpa.kernel.Filters;
+import org.apache.openjpa.kernel.Seq;
import org.apache.openjpa.lib.conf.Configurable;
import org.apache.openjpa.lib.conf.Configuration;
import org.apache.openjpa.lib.jdbc.ConnectionDecorator;
@@ -305,6 +306,8 @@ public class DBDictionary
public String sequenceSQL = null;
public String sequenceSchemaSQL = null;
public String sequenceNameSQL = null;
+ public int nativeSequenceType= Seq.TYPE_TRANSACTIONAL;
+ public boolean useNativeSequenceCache = true;
protected JDBCConfiguration conf = null;
protected Log log = null;
@@ -2943,8 +2946,14 @@ public class DBDictionary
buf.append(getFullName(seq));
if (seq.getInitialValue() != 0)
buf.append(" START WITH ").append(seq.getInitialValue());
- if (seq.getIncrement() > 1)
- buf.append(" INCREMENT BY ").append(seq.getIncrement());
+
+ if (seq.getIncrement() > 1 && useNativeSequenceCache){
+ buf.append(" INCREMENT BY ").append(seq.getIncrement());
+ }
+ else if ((seq.getIncrement() > 1) || (seq.getAllocate() > 1)){
+ buf.append(" INCREMENT BY ").append(seq.getIncrement() *
seq.getAllocate());
+ }
+
return new String[]{ buf.toString() };
}
Modified:
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java?rev=1339899&r1=1339898&r2=1339899&view=diff
==============================================================================
---
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
(original)
+++
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
Thu May 17 22:31:10 2012
@@ -846,12 +846,15 @@ public class OracleDictionary
sql[create.length + i] = (String) seqs.get(i);
return sql;
}
-
- public String[] getCreateSequenceSQL(Sequence seq) {
- String[] sql = super.getCreateSequenceSQL(seq);
- if (seq.getAllocate() > 1)
- sql[0] += " CACHE " + seq.getAllocate();
- return sql;
+
+ public String[] getCreateSequenceSQL(Sequence seq) {
+ String[] sql = super.getCreateSequenceSQL(seq);
+
+ if (seq.getAllocate() > 1 && useNativeSequenceCache){
+ sql[0] += " CACHE " + seq.getAllocate();
+ }
+
+ return sql;
}
protected String getSequencesSQL(String schemaName, String sequenceName) {
Modified:
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java?rev=1339899&r1=1339898&r2=1339899&view=diff
==============================================================================
---
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
(original)
+++
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
Thu May 17 22:31:10 2012
@@ -267,11 +267,15 @@ public class PostgresDictionary
public String[] getCreateSequenceSQL(Sequence seq) {
String[] sql = super.getCreateSequenceSQL(seq);
- if (seq.getAllocate() > 1)
+
+ if (seq.getAllocate() > 1 && useNativeSequenceCache){
sql[0] += " CACHE " + seq.getAllocate();
+ }
+
return sql;
}
+
protected boolean supportsDeferredUniqueConstraints() {
// Postgres only supports deferred foreign key constraints.
return false;
Added:
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityE2.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityE2.java?rev=1339899&view=auto
==============================================================================
---
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityE2.java
(added)
+++
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityE2.java
Thu May 17 22:31:10 2012
@@ -0,0 +1,73 @@
+/*
+ * 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.persistence.generationtype;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="primary_entityE2")
+public class EntityE2 {
+ @Id
+ @SequenceGenerator(name="entityE2_seq_gen_name",
+ sequenceName="entityE2_seq_gen")
+ @GeneratedValue(strategy=GenerationType.SEQUENCE,
+ generator="entityE2_seq_gen_name")
+ private int id;
+ @Column(name="e_name")
+ private String name;
+
+ public EntityE2(){
+
+ }
+
+ public EntityE2(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the id
+ */
+ public int getId() {
+ return id;
+ }
+ /**
+ * @param id the id to set
+ */
+ public void setId(int id) {
+ this.id = id;
+ }
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Propchange:
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/EntityE2.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java?rev=1339899&view=auto
==============================================================================
---
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java
(added)
+++
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java
Thu May 17 22:31:10 2012
@@ -0,0 +1,82 @@
+/*
+ * 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.persistence.generationtype;
+
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+
+public class TestNativeSeqGenerator extends SQLListenerTestCase {
+ OpenJPAEntityManager em;
+ JDBCConfiguration conf;
+ DBDictionary dict;
+
+ EntityE2 entityE2;
+ private boolean supportsNativeSequence;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp(EntityE2.class, CLEAR_TABLES,
"openjpa.jdbc.DBDictionary", "useNativeSequenceCache=false");
+ assertNotNull(emf);
+ conf = (JDBCConfiguration) emf.getConfiguration();
+ dict = conf.getDBDictionaryInstance();
+ //Run the tests only if the given DB supports Native Sequences.
+ supportsNativeSequence = dict.nextSequenceQuery != null;
+ if (supportsNativeSequence) {
+ em = emf.createEntityManager();
+ assertNotNull(em);
+ } else {
+ getLog().trace(this + " is disabled because " +
dict.getClass().getSimpleName() +
+ " does not support native sequences.");
+ }
+ }
+
+ public void createEntityE2() {
+ entityE2 = new EntityE2("e name");
+ }
+
+ /**
+ * Asserts native sequence generator allocates values in memory
+ * and requests sequence values from database only when necessary.
+ */
+ public void testAllocationSize() {
+ //Run this test only if the user has elected to not use the Native
Sequence Cache.
+ if (supportsNativeSequence && !dict.useNativeSequenceCache){
+ em.getTransaction().begin();
+ resetSQL();
+ for (int i = 0; i < 51; i++) {
+ createEntityE2();
+ em.persist(entityE2);
+ }
+ em.getTransaction().commit();
+
+ // Since allocationSize has a default of 50, we expect 2
sequence fetches and 51 INSERTs.
+ assertEquals("53 statements should be executed.", 53,
getSQLCount());
+ String[] statements = new String[53];
+ statements[0] = ".*";
+ statements[1] = ".*";
+ for (int i = 2; i < 53; i++) {
+ statements[i] = "INSERT .*";
+ }
+ assertAllExactSQLInOrder(statements);
+ em.close();
+ }
+ }
+}
Propchange:
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java?rev=1339899&r1=1339898&r2=1339899&view=diff
==============================================================================
---
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java
(original)
+++
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java
Thu May 17 22:31:10 2012
@@ -20,7 +20,6 @@ package org.apache.openjpa.persistence.t
import java.util.List;
import java.util.ArrayList;
-import java.util.Map;
import org.apache.openjpa.lib.jdbc.AbstractJDBCListener;
import org.apache.openjpa.lib.jdbc.JDBCEvent;
@@ -33,9 +32,9 @@ import org.apache.openjpa.lib.jdbc.JDBCL
*/
public abstract class SQLListenerTestCase
extends SingleEMFTestCase {
-
+ private static String _nl = System.getProperty("line.separator");
protected List<String> sql = new ArrayList<String>();
-
+
@Override
public void setUp(Object... props) {
Object[] copy = new Object[props.length + 2];
@@ -92,14 +91,96 @@ public abstract class SQLListenerTestCas
fail("Expected regular expression <" + sqlExp + "> to be"
+ " contained in SQL statements: " + sql);
}
+
+ /**
+ * Gets the number of SQL issued since last reset.
+ */
+ public int getSQLCount() {
+ return sql.size();
+ }
+
+ /**
+ * Resets SQL count.
+ * @return number of SQL counted since last reset.
+ */
+ public int resetSQL() {
+ int tmp = sql.size();
+ sql.clear();
+ return tmp;
+ }
public class Listener
extends AbstractJDBCListener {
@Override
public void beforeExecuteStatement(JDBCEvent event) {
- if (event.getSQL() != null && sql != null)
+ if (event.getSQL() != null && sql != null) {
sql.add(event.getSQL());
+ }
}
}
+
+ public void assertSQLOrder(String... expected) {
+ int hits = 0;
+
+ for (String executedSQL : sql) {
+ if (executedSQL.matches(expected[hits])) {
+ hits++;
+ }
+ }
+
+ if (hits != expected.length) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Did not find SQL in expected order : ").append(_nl);
+ for (String s : expected) {
+ sb.append(s).append(_nl);
+ }
+
+ sb.append("SQL Statements issued : ");
+ for (String s : sql) {
+ sb.append(s).append(_nl);
+ }
+ fail(sb.toString());
+ }
+ }
+
+ /**
+ * Confirm the list of expected SQL expressions have been executed in the
+ * exact number and order specified.
+ *
+ * @param expected
+ * SQL expressions. E.g., ("SELECT FOO .*", "UPDATE .*")
+ */
+ public void assertAllExactSQLInOrder(String... expected) {
+ assertSQLInOrder(true, expected);
+ }
+
+ private void assertSQLInOrder(boolean exact, String... expected) {
+ boolean match = false;
+ int sqlSize = sql.size();
+ if (expected.length <= sqlSize) {
+ int hits = 0;
+ for (String executedSQL : sql) {
+ if (executedSQL.matches(expected[hits])) {
+ if (++hits == expected.length)
+ break;
+ }
+ }
+ match = hits == (exact ? sqlSize : expected.length);
+ }
+
+ if (!match) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Did not find SQL in expected order : ").append(_nl);
+ for (String s : expected) {
+ sb.append(s).append(_nl);
+ }
+
+ sb.append("SQL Statements issued : ");
+ for (String s : sql) {
+ sb.append(s).append(_nl);
+ }
+ fail(sb.toString());
+ }
+ }
}
Modified:
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java?rev=1339899&r1=1339898&r2=1339899&view=diff
==============================================================================
---
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java
(original)
+++
openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java
Thu May 17 22:31:10 2012
@@ -20,6 +20,7 @@ package org.apache.openjpa.persistence.t
import org.apache.openjpa.jdbc.meta.ClassMapping;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.lib.log.Log;
public abstract class SingleEMFTestCase
extends PersistenceTestCase {
@@ -73,4 +74,8 @@ public abstract class SingleEMFTestCase
.getMetaDataRepositoryInstance().getMetaData(name,
getClass().getClassLoader(), true);
}
+
+ protected Log getLog() {
+ return emf.getConfiguration().getLog("Tests");
+ }
}
Modified:
openjpa/branches/1.0.x/openjpa-project/src/doc/manual/jpa_overview_mapping.xml
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-project/src/doc/manual/jpa_overview_mapping.xml?rev=1339899&r1=1339898&r2=1339899&view=diff
==============================================================================
---
openjpa/branches/1.0.x/openjpa-project/src/doc/manual/jpa_overview_mapping.xml
(original)
+++
openjpa/branches/1.0.x/openjpa-project/src/doc/manual/jpa_overview_mapping.xml
Thu May 17 22:31:10 2012
@@ -960,16 +960,17 @@ default.
allocationSize property
</secondary>
</indexterm>
-<literal>int allocationSize</literal>: Some databases can pre-allocate groups
-of sequence values. This allows the database to service sequence requests from
-cache, rather than physically incrementing the sequence with every request.
This
-allocation size defaults to 50.
+<literal>int allocationSize</literal>: The number of values to allocate in
+memory for each trip to the database. Allocating values in memory allows the
JPA
+runtime to avoid accessing the database for every sequence request.
+This number also specifies the amount that the sequence value is incremented
+each time the sequence is accessed. Defaults to 50.
</para>
</listitem>
</itemizedlist>
<note>
<para>
-OpenJPA allows you to use describe one of OpenJPA's built-in generator
+OpenJPA allows you to use one of OpenJPA's built-in generator
implementations in the <literal>sequenceName</literal> property. You can also
set the <literal>sequenceName</literal> to <literal>system</literal> to use the
system sequence defined by the <link linkend="openjpa.Sequence"><literal>
Modified:
openjpa/branches/1.0.x/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml?rev=1339899&r1=1339898&r2=1339899&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml
(original)
+++ openjpa/branches/1.0.x/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml
Thu May 17 22:31:10 2012
@@ -2449,7 +2449,9 @@ automatically in the dictionary, and sho
</indexterm>
<literal>NextSequenceQuery</literal>: A SQL string for obtaining a native
sequence value. May use a placeholder of <literal>{0}</literal> for the
variable
-sequence name. Defaults to a database-appropriate value.
+sequence name and <literal>{1}</literal> for sequence increment.
+Defaults to a database-appropriate value. For example,
+<literal>"SELECT {0}.NEXTVAL FROM DUAL"</literal> for Oracle database.
</para>
</listitem>
</itemizedlist>
Modified:
openjpa/branches/1.0.x/openjpa-project/src/doc/manual/ref_guide_optimization.xml
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-project/src/doc/manual/ref_guide_optimization.xml?rev=1339899&r1=1339898&r2=1339899&view=diff
==============================================================================
---
openjpa/branches/1.0.x/openjpa-project/src/doc/manual/ref_guide_optimization.xml
(original)
+++
openjpa/branches/1.0.x/openjpa-project/src/doc/manual/ref_guide_optimization.xml
Thu May 17 22:31:10 2012
@@ -295,8 +295,7 @@ it can become a factor.
</entry>
<entry colname="desc">
For applications that perform large bulk inserts, the retrieval of sequence
-numbers can be a bottleneck. Increasing sequence increments and using
-table-based rather than native database sequences can reduce or eliminate
+numbers can be a bottleneck. Increasing sequence allocation sizes can reduce
or eliminate
this bottleneck. In some cases, implementing your own sequence factory can
further optimize sequence number retrieval.
</entry>
Modified:
openjpa/branches/1.0.x/openjpa-project/src/doc/manual/ref_guide_runtime.xml
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-project/src/doc/manual/ref_guide_runtime.xml?rev=1339899&r1=1339898&r2=1339899&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-project/src/doc/manual/ref_guide_runtime.xml
(original)
+++ openjpa/branches/1.0.x/openjpa-project/src/doc/manual/ref_guide_runtime.xml
Thu May 17 22:31:10 2012
@@ -1602,8 +1602,11 @@ properties:
</listitem>
<listitem>
<para>
-<literal>Allocate</literal>: Some database can allocate values in-memory to
-service subsequent sequence requests faster.
+<literal>Allocate</literal>: The number of values to allocate on each database
+trip. Defaults to 50, meaning the class will set aside the next 50 numbers each
+time it accesses the sequence, which in turn means it only has to make a
+database trip to get new sequence numbers once every 50 sequence number
+requests.
</para>
</listitem>
</itemizedlist>