mirror of https://github.com/apache/openjpa.git
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:
parent
ad8f4be2e0
commit
5eed1ecc90
|
@ -83,6 +83,7 @@ public class NativeJDBCSeq
|
||||||
|
|
||||||
private boolean alterIncrementBy = false;
|
private boolean alterIncrementBy = false;
|
||||||
private boolean alreadyLoggedAlterSeqFailure = false;
|
private boolean alreadyLoggedAlterSeqFailure = false;
|
||||||
|
private boolean alreadyLoggedAlterSeqDisabled = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The sequence name. Defaults to <code>OPENJPA_SEQUENCE</code>.
|
* The sequence name. Defaults to <code>OPENJPA_SEQUENCE</code>.
|
||||||
|
@ -219,8 +220,10 @@ public class NativeJDBCSeq
|
||||||
try {
|
try {
|
||||||
if (!alterIncrementBy) {
|
if (!alterIncrementBy) {
|
||||||
DBDictionary dict = _conf.getDBDictionaryInstance();
|
DBDictionary dict = _conf.getDBDictionaryInstance();
|
||||||
|
if (!dict.disableAlterSeqenceIncrementBy) {
|
||||||
// If this fails, we will warn the user at most one time and set _allocated and _increment to 1 so
|
// 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.
|
// 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 (updateSql(conn, dict.getAlterSequenceSQL(_seq)) == -1) {
|
||||||
if (!alreadyLoggedAlterSeqFailure) {
|
if (!alreadyLoggedAlterSeqFailure) {
|
||||||
Log log = _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
|
Log log = _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
|
||||||
|
@ -231,6 +234,16 @@ public class NativeJDBCSeq
|
||||||
alreadyLoggedAlterSeqFailure = true;
|
alreadyLoggedAlterSeqFailure = true;
|
||||||
_allocate = 1;
|
_allocate = 1;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (!alreadyLoggedAlterSeqDisabled) {
|
||||||
|
Log log = _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
|
||||||
|
if (log.isWarnEnabled()) {
|
||||||
|
log.warn(_loc.get("alter-seq-disabled", _seqName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
alreadyLoggedAlterSeqDisabled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_nextValue = getSequence(conn);
|
_nextValue = getSequence(conn);
|
||||||
_maxValue = _nextValue + _allocate * _increment;
|
_maxValue = _nextValue + _allocate * _increment;
|
||||||
|
|
|
@ -219,6 +219,7 @@ public class DBDictionary
|
||||||
public boolean setStringRightTruncationOn = true;
|
public boolean setStringRightTruncationOn = true;
|
||||||
|
|
||||||
// sql
|
// sql
|
||||||
|
public boolean disableAlterSeqenceIncrementBy=false;
|
||||||
public String validationSQL = null;
|
public String validationSQL = null;
|
||||||
public String closePoolSQL = null;
|
public String closePoolSQL = null;
|
||||||
public String initializationSQL = null;
|
public String initializationSQL = null;
|
||||||
|
|
|
@ -176,3 +176,12 @@ fallback-no-seq-cache: Unable to cache sequence values for sequence "{0}". \
|
||||||
Your application does not have permission to run an ALTER SEQUENCE \
|
Your application does not have permission to run an ALTER SEQUENCE \
|
||||||
command. Ensure that it has the appropriate permission to run an \
|
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.
|
||||||
|
|
||||||
|
|
|
@ -1455,6 +1455,30 @@ case of the originally specified name. Available values are:
|
||||||
<literal>upper, lower, preserve.</literal>
|
<literal>upper, lower, preserve.</literal>
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</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">
|
<listitem id="DBDictionary.DistinctCountColumnSeparator">
|
||||||
<para>
|
<para>
|
||||||
<indexterm>
|
<indexterm>
|
||||||
|
|
Loading…
Reference in New Issue