You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by jg...@apache.org on 2014/02/03 22:07:50 UTC
svn commit: r1564058 - in /openjpa/branches/2.3.x:
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/
openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/
openjpa-project/src/do...
Author: jgrassel
Date: Mon Feb 3 21:07:50 2014
New Revision: 1564058
URL: http://svn.apache.org/r1564058
Log:
OPENJPA-2450: Option to disable execution of ALTER SEQUENCE...INCREMENT BY statement for sequences.
Modified:
openjpa/branches/2.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java
openjpa/branches/2.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
openjpa/branches/2.3.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties
openjpa/branches/2.3.x/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml
Modified: openjpa/branches/2.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java?rev=1564058&r1=1564057&r2=1564058&view=diff
==============================================================================
--- openjpa/branches/2.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java (original)
+++ openjpa/branches/2.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java Mon Feb 3 21:07:50 2014
@@ -83,6 +83,7 @@ public class NativeJDBCSeq
private boolean alterIncrementBy = false;
private boolean alreadyLoggedAlterSeqFailure = false;
+ private boolean alreadyLoggedAlterSeqDisabled = false;
/**
* The sequence name. Defaults to <code>OPENJPA_SEQUENCE</code>.
@@ -219,17 +220,29 @@ public class NativeJDBCSeq
try {
if (!alterIncrementBy) {
DBDictionary dict = _conf.getDBDictionaryInstance();
- // If this fails, we will warn the user at most one time and set _allocated and _increment to 1 so
- // as to not potentially insert records ahead of what the database thinks is the next sequence value.
- if (updateSql(conn, dict.getAlterSequenceSQL(_seq)) == -1) {
- if (!alreadyLoggedAlterSeqFailure) {
+ if (!dict.disableAlterSeqenceIncrementBy) {
+ // If this fails, we will warn the user at most one time and set _allocated and _increment to 1 so
+ // as to not potentially insert records ahead of what the database thinks is the next sequence
+ // value.
+ if (updateSql(conn, dict.getAlterSequenceSQL(_seq)) == -1) {
+ if (!alreadyLoggedAlterSeqFailure) {
+ Log log = _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
+ if (log.isWarnEnabled()) {
+ log.warn(_loc.get("fallback-no-seq-cache", _seqName));
+ }
+ }
+ alreadyLoggedAlterSeqFailure = true;
+ _allocate = 1;
+ }
+ } else {
+ if (!alreadyLoggedAlterSeqDisabled) {
Log log = _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
if (log.isWarnEnabled()) {
- log.warn(_loc.get("fallback-no-seq-cache", _seqName));
+ log.warn(_loc.get("alter-seq-disabled", _seqName));
}
}
- alreadyLoggedAlterSeqFailure = true;
- _allocate = 1;
+
+ alreadyLoggedAlterSeqDisabled = true;
}
}
_nextValue = getSequence(conn);
Modified: openjpa/branches/2.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=1564058&r1=1564057&r2=1564058&view=diff
==============================================================================
--- openjpa/branches/2.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java (original)
+++ openjpa/branches/2.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java Mon Feb 3 21:07:50 2014
@@ -219,6 +219,7 @@ public class DBDictionary
public boolean setStringRightTruncationOn = true;
// sql
+ public boolean disableAlterSeqenceIncrementBy=false;
public String validationSQL = null;
public String closePoolSQL = null;
public String initializationSQL = null;
Modified: openjpa/branches/2.3.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/branches/2.3.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties?rev=1564058&r1=1564057&r2=1564058&view=diff
==============================================================================
--- openjpa/branches/2.3.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties (original)
+++ openjpa/branches/2.3.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties Mon Feb 3 21:07:50 2014
@@ -175,4 +175,13 @@ exclude-pagination: Query "{0}" is not c
fallback-no-seq-cache: Unable to cache sequence values for sequence "{0}". \
Your application does not have permission to run an ALTER SEQUENCE \
command. Ensure that it has the appropriate permission to run an \
- ALTER SEQUENCE command.
\ No newline at end of file
+ ALTER SEQUENCE command.
+alter-seq-disabled: The property "openjpa.jdbc.DBDictionary=disableAlterSeqenceIncrementBy" \
+ is set to true. This means that the ''ALTER SEQUENCE...INCREMENT BY'' SQL statement \
+ will not be executed for sequence "{0}". OpenJPA executes this command to ensure that \
+ the sequence''s INCREMENT BY value defined in the database matches the allocationSize \
+ which is defined in the entity''s sequence. With this SQL statement disabled, it is the \
+ responsibility of the user to ensure that the entity''s sequence definition matches the \
+ sequence defined in the database.
+
+
\ No newline at end of file
Modified: openjpa/branches/2.3.x/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml
URL: http://svn.apache.org/viewvc/openjpa/branches/2.3.x/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml?rev=1564058&r1=1564057&r2=1564058&view=diff
==============================================================================
--- openjpa/branches/2.3.x/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml (original)
+++ openjpa/branches/2.3.x/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml Mon Feb 3 21:07:50 2014
@@ -1453,6 +1453,30 @@ generated by the <literal>mappingtool</l
about identifiers that have been delimited. It defaults to preserving the
case of the originally specified name. Available values are:
<literal>upper, lower, preserve.</literal>
+ </para>
+ </listitem>
+ <listitem id="DBDictionary.DisableAlterSeqenceIncrementBy">
+ <para>
+ <indexterm>
+ <primary>
+ SQL
+ </primary>
+ <secondary>
+ DisableAlterSeqenceIncrementBy
+ </secondary>
+ </indexterm>
+<literal>DisableAlterSeqenceIncrementBy</literal>: OpenJPA attempts to execute
+an ALTER SEQUENCE....INCREMENT BY SQL statement for a user defined sequence. This
+is done to ensure that the 'allocationSize' value defined by the entity's sequence,
+or default value, matches the sequence defined in the database. For example, with
+an allocationSize of 1000 for a sequence named 'SEQ_JPASAMPLE', the following SQL
+will be generated (the SQL might vary slightly depending on the databases):
+<literal>ALTER SEQUENCE SEQ_JPASAMPLE INCREMENT BY 1000</literal>. If the user
+executing this command doesn't have permissions to execute the command, it will
+fail and in turn OpenJPA will disable sequence caching. If a user wants to disable
+this SQL command, this property can be set to true. However, the user must ensure
+that the entities defined sequence is kept in synch with the sequence defined in the
+database. Defaults to false.
</para>
</listitem>
<listitem id="DBDictionary.DistinctCountColumnSeparator">