mirror of https://github.com/apache/openjpa.git
OPENJPA-1022 - Ensure LockMode READ/OPTIMISTIC & WRITE/OPTIMISTIC_FORCE_INCREMENT are distinct in type but semantics equivalent.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@762409 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
983775de06
commit
bdce39ae28
|
@ -66,7 +66,7 @@ public class MixedLockManager extends PessimisticLockManager {
|
|||
setVersionCheckOnReadLock(true);
|
||||
setVersionUpdateOnWriteLock(false);
|
||||
super.lockInternal(sm, level, timeout, sdata, postLockVersionCheck);
|
||||
} else if (level >= MixedLockLevels.LOCK_OPTIMISTIC) {
|
||||
} else if (level >= MixedLockLevels.LOCK_READ) {
|
||||
setVersionCheckOnReadLock(true);
|
||||
setVersionUpdateOnWriteLock(true);
|
||||
optimisticLockInternal(sm, level, timeout, sdata,
|
||||
|
|
|
@ -483,7 +483,9 @@ public class FetchConfigurationImpl
|
|||
|
||||
if (level != DEFAULT
|
||||
&& level != MixedLockLevels.LOCK_NONE
|
||||
&& level != MixedLockLevels.LOCK_READ
|
||||
&& level != MixedLockLevels.LOCK_OPTIMISTIC
|
||||
&& level != MixedLockLevels.LOCK_WRITE
|
||||
&& level != MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT
|
||||
&& level != MixedLockLevels.LOCK_PESSIMISTIC_READ
|
||||
&& level != MixedLockLevels.LOCK_PESSIMISTIC_WRITE
|
||||
|
@ -525,7 +527,9 @@ public class FetchConfigurationImpl
|
|||
|
||||
if (level != DEFAULT
|
||||
&& level != MixedLockLevels.LOCK_NONE
|
||||
&& level != MixedLockLevels.LOCK_READ
|
||||
&& level != MixedLockLevels.LOCK_OPTIMISTIC
|
||||
&& level != MixedLockLevels.LOCK_WRITE
|
||||
&& level != MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT
|
||||
&& level != MixedLockLevels.LOCK_PESSIMISTIC_READ
|
||||
&& level != MixedLockLevels.LOCK_PESSIMISTIC_WRITE
|
||||
|
|
|
@ -27,16 +27,16 @@ package org.apache.openjpa.kernel;
|
|||
public interface MixedLockLevels extends LockLevels {
|
||||
|
||||
/**
|
||||
* Generic optimistic read lock level. Value of 10.
|
||||
* Generic optimistic read lock level. Value of 15.
|
||||
*
|
||||
*/
|
||||
public static final int LOCK_OPTIMISTIC = LOCK_READ;
|
||||
public static final int LOCK_OPTIMISTIC = LOCK_READ + 5;
|
||||
|
||||
/**
|
||||
* Generic optimistic write lock level. Value of 20.
|
||||
* Generic optimistic write lock level. Value of 25.
|
||||
*/
|
||||
public static final int LOCK_OPTIMISTIC_FORCE_INCREMENT =
|
||||
LockLevels.LOCK_WRITE;
|
||||
LockLevels.LOCK_WRITE + 5;
|
||||
|
||||
/**
|
||||
* Generic pessimistic read lock level. Value of 30.
|
||||
|
|
|
@ -413,7 +413,7 @@ bad-hint-value: "{1}" is not a valid value for hint "{0}" caused by: {2}.
|
|||
bad-flush-before-queries: Invalid flush before queries type. Valid values are \
|
||||
"true"(0), "false"(1) or "with-connection"(2). Specified value: {0}.
|
||||
bad-lock-level: Invalid lock mode/level. Valid values are \
|
||||
"none"(0), "read"(10), "write"(20), "optimistic"(10), \
|
||||
"optimistic-force-increment"(20), "pessimistic-read"(30), \
|
||||
"none"(0), "read"(10), "optimistic"(15), "write"(20), \
|
||||
"optimistic-force-increment"(25), "pessimistic-read"(30), \
|
||||
"pessimistic-write"(40) or "pessimistic-force-increment"(50). \
|
||||
Specified value: {0}.
|
||||
|
|
|
@ -22,7 +22,6 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
|
@ -811,15 +810,8 @@ public abstract class SequencedActionsTest extends SQLListenerTestCase {
|
|||
em.close();
|
||||
Throwable firstThrowable = thisThread.throwable;
|
||||
if (firstThrowable != null) {
|
||||
if( firstThrowable instanceof Error ) {
|
||||
if( firstThrowable instanceof Error )
|
||||
throw (Error)firstThrowable;
|
||||
} else {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
PrintStream ps = new PrintStream(baos);
|
||||
firstThrowable.printStackTrace(ps);
|
||||
ps.flush();
|
||||
fail(baos.toString());
|
||||
}
|
||||
}
|
||||
log.trace("<<<< Sequenced Test: Threads=" + threadToRun + '/'
|
||||
+ numThreads);
|
||||
|
|
|
@ -1764,26 +1764,25 @@ public class TestFetchHints extends SequencedActionsTest {
|
|||
MixedLockLevels.LOCK_NONE);
|
||||
|
||||
readLockLevelHintTest(fPlan, fConfig, hintName, String
|
||||
.valueOf(MixedLockLevels.LOCK_READ), LockModeType.OPTIMISTIC,
|
||||
.valueOf(MixedLockLevels.LOCK_READ), LockModeType.READ,
|
||||
MixedLockLevels.LOCK_READ);
|
||||
readLockLevelHintTest(fPlan, fConfig, hintName,
|
||||
MixedLockLevels.LOCK_READ, LockModeType.OPTIMISTIC,
|
||||
MixedLockLevels.LOCK_READ, LockModeType.READ,
|
||||
MixedLockLevels.LOCK_READ);
|
||||
|
||||
readLockLevelHintTest(fPlan, fConfig, hintName, String
|
||||
.valueOf(MixedLockLevels.LOCK_WRITE),
|
||||
LockModeType.OPTIMISTIC_FORCE_INCREMENT,
|
||||
.valueOf(MixedLockLevels.LOCK_WRITE), LockModeType.WRITE,
|
||||
MixedLockLevels.LOCK_WRITE);
|
||||
readLockLevelHintTest(fPlan, fConfig, hintName,
|
||||
MixedLockLevels.LOCK_WRITE,
|
||||
LockModeType.OPTIMISTIC_FORCE_INCREMENT,
|
||||
MixedLockLevels.LOCK_WRITE, LockModeType.WRITE,
|
||||
MixedLockLevels.LOCK_WRITE);
|
||||
|
||||
readLockLevelHintTest(fPlan, fConfig, hintName, String
|
||||
.valueOf(MixedLockLevels.LOCK_OPTIMISTIC), LockModeType.OPTIMISTIC,
|
||||
MixedLockLevels.LOCK_OPTIMISTIC);
|
||||
readLockLevelHintTest(fPlan, fConfig, hintName, 10,
|
||||
LockModeType.OPTIMISTIC, MixedLockLevels.LOCK_OPTIMISTIC);
|
||||
readLockLevelHintTest(fPlan, fConfig, hintName,
|
||||
MixedLockLevels.LOCK_OPTIMISTIC, LockModeType.OPTIMISTIC,
|
||||
MixedLockLevels.LOCK_OPTIMISTIC);
|
||||
|
||||
readLockLevelHintTest(fPlan, fConfig, hintName, String
|
||||
.valueOf(MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT),
|
||||
|
@ -1887,19 +1886,17 @@ public class TestFetchHints extends SequencedActionsTest {
|
|||
MixedLockLevels.LOCK_NONE);
|
||||
|
||||
writeLockLevelHintTest(fPlan, fConfig, hintName, String
|
||||
.valueOf(MixedLockLevels.LOCK_READ), LockModeType.OPTIMISTIC,
|
||||
.valueOf(MixedLockLevels.LOCK_READ), LockModeType.READ,
|
||||
MixedLockLevels.LOCK_READ);
|
||||
writeLockLevelHintTest(fPlan, fConfig, hintName,
|
||||
MixedLockLevels.LOCK_READ, LockModeType.OPTIMISTIC,
|
||||
MixedLockLevels.LOCK_READ, LockModeType.READ,
|
||||
MixedLockLevels.LOCK_READ);
|
||||
|
||||
writeLockLevelHintTest(fPlan, fConfig, hintName, String
|
||||
.valueOf(MixedLockLevels.LOCK_WRITE),
|
||||
LockModeType.OPTIMISTIC_FORCE_INCREMENT,
|
||||
.valueOf(MixedLockLevels.LOCK_WRITE), LockModeType.WRITE,
|
||||
MixedLockLevels.LOCK_WRITE);
|
||||
writeLockLevelHintTest(fPlan, fConfig, hintName,
|
||||
MixedLockLevels.LOCK_WRITE,
|
||||
LockModeType.OPTIMISTIC_FORCE_INCREMENT,
|
||||
MixedLockLevels.LOCK_WRITE, LockModeType.WRITE,
|
||||
MixedLockLevels.LOCK_WRITE);
|
||||
|
||||
writeLockLevelHintTest(fPlan, fConfig, hintName, String
|
||||
|
@ -2022,22 +2019,19 @@ public class TestFetchHints extends SequencedActionsTest {
|
|||
MixedLockLevels.LOCK_NONE);
|
||||
|
||||
readLockModeHintTest(fPlan, fConfig, hintName, "read",
|
||||
LockModeType.OPTIMISTIC, MixedLockLevels.LOCK_OPTIMISTIC);
|
||||
LockModeType.READ, MixedLockLevels.LOCK_READ);
|
||||
readLockModeHintTest(fPlan, fConfig, hintName, LockModeType.READ,
|
||||
LockModeType.OPTIMISTIC, MixedLockLevels.LOCK_OPTIMISTIC);
|
||||
LockModeType.READ, MixedLockLevels.LOCK_READ);
|
||||
readLockModeHintTest(fPlan, fConfig, hintName,
|
||||
LockModeType.READ.name(), LockModeType.OPTIMISTIC,
|
||||
MixedLockLevels.LOCK_OPTIMISTIC);
|
||||
LockModeType.READ.name(), LockModeType.READ,
|
||||
MixedLockLevels.LOCK_READ);
|
||||
|
||||
readLockModeHintTest(fPlan, fConfig, hintName, "write",
|
||||
LockModeType.OPTIMISTIC_FORCE_INCREMENT,
|
||||
MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT);
|
||||
LockModeType.WRITE, MixedLockLevels.LOCK_WRITE);
|
||||
readLockModeHintTest(fPlan, fConfig, hintName, LockModeType.WRITE,
|
||||
LockModeType.OPTIMISTIC_FORCE_INCREMENT,
|
||||
MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT);
|
||||
LockModeType.WRITE, MixedLockLevels.LOCK_WRITE);
|
||||
readLockModeHintTest(fPlan, fConfig, hintName, LockModeType.WRITE
|
||||
.name(), LockModeType.OPTIMISTIC_FORCE_INCREMENT,
|
||||
MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT);
|
||||
.name(), LockModeType.WRITE, MixedLockLevels.LOCK_WRITE);
|
||||
|
||||
readLockModeHintTest(fPlan, fConfig, hintName, "optimistic",
|
||||
LockModeType.OPTIMISTIC, MixedLockLevels.LOCK_OPTIMISTIC);
|
||||
|
@ -2164,21 +2158,18 @@ public class TestFetchHints extends SequencedActionsTest {
|
|||
.name(), LockModeType.NONE, MixedLockLevels.LOCK_NONE);
|
||||
|
||||
writeLockModeHintTest(fPlan, fConfig, hintName, "read",
|
||||
LockModeType.OPTIMISTIC, MixedLockLevels.LOCK_READ);
|
||||
LockModeType.READ, MixedLockLevels.LOCK_READ);
|
||||
writeLockModeHintTest(fPlan, fConfig, hintName, LockModeType.READ,
|
||||
LockModeType.OPTIMISTIC, MixedLockLevels.LOCK_READ);
|
||||
LockModeType.READ, MixedLockLevels.LOCK_READ);
|
||||
writeLockModeHintTest(fPlan, fConfig, hintName, LockModeType.READ
|
||||
.name(), LockModeType.OPTIMISTIC, MixedLockLevels.LOCK_READ);
|
||||
.name(), LockModeType.READ, MixedLockLevels.LOCK_READ);
|
||||
|
||||
writeLockModeHintTest(fPlan, fConfig, hintName, "write",
|
||||
LockModeType.OPTIMISTIC_FORCE_INCREMENT,
|
||||
MixedLockLevels.LOCK_WRITE);
|
||||
LockModeType.WRITE, MixedLockLevels.LOCK_WRITE);
|
||||
writeLockModeHintTest(fPlan, fConfig, hintName, LockModeType.WRITE,
|
||||
LockModeType.OPTIMISTIC_FORCE_INCREMENT,
|
||||
MixedLockLevels.LOCK_WRITE);
|
||||
LockModeType.WRITE, MixedLockLevels.LOCK_WRITE);
|
||||
writeLockModeHintTest(fPlan, fConfig, hintName, LockModeType.WRITE
|
||||
.name(), LockModeType.OPTIMISTIC_FORCE_INCREMENT,
|
||||
MixedLockLevels.LOCK_WRITE);
|
||||
.name(), LockModeType.WRITE, MixedLockLevels.LOCK_WRITE);
|
||||
|
||||
writeLockModeHintTest(fPlan, fConfig, hintName,
|
||||
"optimistic", LockModeType.OPTIMISTIC,
|
||||
|
|
|
@ -201,7 +201,9 @@ public class FetchPlanHintHandler extends AbstractHintHandler {
|
|||
intValue = (Integer) value;
|
||||
if (intValue == null
|
||||
|| (intValue != MixedLockLevels.LOCK_NONE
|
||||
&& intValue != MixedLockLevels.LOCK_READ
|
||||
&& intValue != MixedLockLevels.LOCK_OPTIMISTIC
|
||||
&& intValue != MixedLockLevels.LOCK_WRITE
|
||||
&& intValue != MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT
|
||||
&& intValue != MixedLockLevels.LOCK_PESSIMISTIC_READ
|
||||
&& intValue != MixedLockLevels.LOCK_PESSIMISTIC_WRITE
|
||||
|
|
|
@ -36,10 +36,13 @@ public class MixedLockLevelsHelper {
|
|||
public static int toLockLevel(LockModeType mode) {
|
||||
if (mode == null || mode == LockModeType.NONE)
|
||||
return MixedLockLevels.LOCK_NONE;
|
||||
if (mode == LockModeType.READ || mode == LockModeType.OPTIMISTIC)
|
||||
if (mode == LockModeType.READ)
|
||||
return MixedLockLevels.LOCK_READ;
|
||||
if (mode == LockModeType.OPTIMISTIC)
|
||||
return MixedLockLevels.LOCK_OPTIMISTIC;
|
||||
if (mode == LockModeType.WRITE
|
||||
|| mode == LockModeType.OPTIMISTIC_FORCE_INCREMENT)
|
||||
if (mode == LockModeType.WRITE)
|
||||
return MixedLockLevels.LOCK_WRITE;
|
||||
if (mode == LockModeType.OPTIMISTIC_FORCE_INCREMENT)
|
||||
return MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT;
|
||||
if (mode == LockModeType.PESSIMISTIC_READ)
|
||||
return MixedLockLevels.LOCK_PESSIMISTIC_READ;
|
||||
|
@ -52,10 +55,14 @@ public class MixedLockLevelsHelper {
|
|||
* Translates internal lock level to javax.persistence LockModeType.
|
||||
*/
|
||||
public static LockModeType fromLockLevel(int level) {
|
||||
if (level < MixedLockLevels.LOCK_OPTIMISTIC)
|
||||
if (level < MixedLockLevels.LOCK_READ)
|
||||
return LockModeType.NONE;
|
||||
if (level < MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT)
|
||||
if (level < MixedLockLevels.LOCK_OPTIMISTIC)
|
||||
return LockModeType.READ;
|
||||
if (level < MixedLockLevels.LOCK_WRITE)
|
||||
return LockModeType.OPTIMISTIC;
|
||||
if (level < MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT)
|
||||
return LockModeType.WRITE;
|
||||
if (level < MixedLockLevels.LOCK_PESSIMISTIC_READ)
|
||||
return LockModeType.OPTIMISTIC_FORCE_INCREMENT;
|
||||
if (level < MixedLockLevels.LOCK_PESSIMISTIC_WRITE)
|
||||
|
|
|
@ -170,6 +170,7 @@ unwrap-query-invalid: Query can not be unwrapped to an instance of "{0}".
|
|||
invalid_entity_argument: Object being locked must be an valid and not detached \
|
||||
entity.
|
||||
bad-lock-level: Invalid lock mode/level. Valid values are \
|
||||
"none"(0), "optimistic"(10), "optimistic-force-increment"(20), \
|
||||
"none"(0), "read"(10), "optimistic"(15), "write"(20), \
|
||||
"optimistic-force-increment"(25), \
|
||||
"pessimistic-read"(30), "pessimistic-write"(40) or \
|
||||
"pessimistic-force-increment"(50). Specified value: {0}.
|
||||
|
|
Loading…
Reference in New Issue