Author: jgrassel Date: Thu Dec 5 19:01:27 2013 New Revision: 1548240 URL: http://svn.apache.org/r1548240 Log: OPENJPA-2450: Option to disable execution of ALTER SEQUENCE...INCREMENT BY statement for sequences.
Modified: openjpa/branches/2.2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java openjpa/branches/2.2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java openjpa/branches/2.2.1.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties openjpa/branches/2.2.1.x/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml Modified: openjpa/branches/2.2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java?rev=1548240&r1=1548239&r2=1548240&view=diff ============================================================================== --- openjpa/branches/2.2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java (original) +++ openjpa/branches/2.2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java Thu Dec 5 19:01:27 2013 @@ -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.2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=1548240&r1=1548239&r2=1548240&view=diff ============================================================================== --- openjpa/branches/2.2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java (original) +++ openjpa/branches/2.2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java Thu Dec 5 19:01:27 2013 @@ -218,6 +218,7 @@ public class DBDictionary public boolean fullResultCollectionInOrderByRelation = false; // sql + public boolean disableAlterSeqenceIncrementBy=false; public String validationSQL = null; public String closePoolSQL = null; public String initializationSQL = null; Modified: openjpa/branches/2.2.1.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.1.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties?rev=1548240&r1=1548239&r2=1548240&view=diff ============================================================================== --- openjpa/branches/2.2.1.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties (original) +++ openjpa/branches/2.2.1.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties Thu Dec 5 19:01:27 2013 @@ -175,4 +175,11 @@ 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.2.1.x/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.1.x/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml?rev=1548240&r1=1548239&r2=1548240&view=diff ============================================================================== --- openjpa/branches/2.2.1.x/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml (original) +++ openjpa/branches/2.2.1.x/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml Thu Dec 5 19:01:27 2013 @@ -1428,6 +1428,30 @@ case of the originally specified name. A <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"> <para> <indexterm>