OPENJPA-2450: Option to disable execution of ALTER SEQUENCE...INCREMENT BY statement for sequences.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.3.x@1564058 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jody Grassel 2014-02-03 21:07:50 +00:00
parent ad8f4be2e0
commit 5eed1ecc90
4 changed files with 55 additions and 8 deletions

View File

@ -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);

View File

@ -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;

View File

@ -175,4 +175,13 @@ exclude-pagination: Query "{0}" is not cached because it uses pagination.
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.
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.

View File

@ -1453,6 +1453,30 @@ generated by the <literal>mappingtool</literal>.
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">