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:
Albert Lee 2009-04-06 16:30:24 +00:00
parent 983775de06
commit bdce39ae28
9 changed files with 499 additions and 502 deletions

View File

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

View File

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

View File

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

View File

@ -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}.

View File

@ -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;
@ -327,381 +326,381 @@ public abstract class SequencedActionsTest extends SQLListenerTestCase {
curAction = (Act) args[0];
log.trace("** Act=" + Arrays.toString(args));
try {
switch (curAction) {
case CreateEm:
em = emf.createEntityManager();
break;
case CloseEm:
if (em != null && em.isOpen()) {
em.close();
em = null;
switch (curAction) {
case CreateEm:
em = emf.createEntityManager();
break;
case CloseEm:
if (em != null && em.isOpen()) {
em.close();
em = null;
}
break;
case Clear:
em.clear();
break;
case Flush:
em.flush();
break;
case Find:
id = 1;
if (args.length > 1) {
id = (Integer)args[1];
}
employee = em.find(LockEmployee.class, id);
log.trace("Employee=" + employee);
if( employee != null ) {
employees.put(id, employee);
} else {
employees.remove(id);
}
break;
case FindWithLock:
id = 1;
if (args[1] != null) {
id = (Integer)args[1];
}
lockMode = LockModeType.NONE;
if (args[2] != null) {
lockMode = (LockModeType)args[2];
}
Map<String, Object> findProps = buildPropsMap(args, 3);
if (findProps != null) {
employee = em.find(LockEmployee.class, id,
lockMode, findProps);
} else {
employee = em
.find(LockEmployee.class, id, lockMode);
}
log.trace("Employee=" + employee);
if( employee != null ) {
employees.put(id, employee);
} else {
employees.remove(id);
}
break;
case FindObject:
em.find((Class<?>)args[1], args[2],
(LockModeType) args[3]);
// log.trace("Employee=" + employee);
break;
case Persist:
id = 1;
if (args[1] != null) {
id = (Integer)args[1];
}
String firstName = (String)args[2];
employee = new LockEmployee();
employee.setId(id);
employee.setFirstName(firstName);
log.trace("Employee=" + employee);
em.persist(employee);
break;
case Remove:
id = 1;
if (args.length > 1) {
id = (Integer)args[1];
}
employee = employees.get(id);
log.trace("Employee=" + employee);
em.remove(employee);
break;
case Refresh:
id = 1;
if (args.length > 1) {
id = (Integer)args[1];
}
employee = employees.get(id);
log.trace("Employee(before)=" + employee);
em.refresh(employee);
log.trace("Employee(after) =" + employee);
break;
case RefreshWithLock:
id = 1;
if (args[1] != null) {
id = (Integer)args[1];
}
lockMode = LockModeType.NONE;
if (args[2] != null) {
lockMode = (LockModeType)args[2];
}
employee = employees.get(id);
log.trace("Employee(before)=" + employee);
Map<String, Object> refreshProps = buildPropsMap(args,
3);
if (refreshProps != null) {
em.refresh(employee, lockMode, refreshProps);
} else {
em.refresh(employee, lockMode);
}
log.trace("Employee(after) =" + employee);
break;
case RefreshObject:
em.refresh(args[1], (LockModeType) args[2]);
break;
case Lock:
id = 1;
if (args[1] != null) {
id = (Integer)args[1];
}
lockMode = LockModeType.NONE;
if (args[2] != null) {
lockMode = (LockModeType)args[2];
}
employee = employees.get(id);
log.trace("Employee=" + employee);
Map<String, Object> lockProps = buildPropsMap(args, 3);
if (lockProps != null) {
em.lock(employee, lockMode, lockProps);
} else {
em.lock(employee, lockMode);
}
break;
case LockObject:
em.lock(args[1], (LockModeType) args[2]);
break;
case UpdateEmployee:
id = 1;
if (args.length > 1) {
id = (Integer) args[1];
}
employee = employees.get(id);
log.trace("Employee (before):" + employee);
String newFirstName = "Unknown";
if (args.length > 2) {
newFirstName = (String) args[2];
} else {
newFirstName = (new Date()).toString();
}
employee.setFirstName(newFirstName);
log.trace("Employee (after) :" + employee);
break;
case Detach:
id = 1;
if (args[1] != null) {
id = (Integer)args[1];
}
employee = employees.get(id);
log.trace("Employee (before) :" + employee);
LockEmployee detEmployee = ((OpenJPAEntityManager) em
.getDelegate()).detachCopy(employee);
employees.put((Integer)args[2], detEmployee);
log.trace("Employee (after) :" + detEmployee);
break;
case StartTx:
em.getTransaction().begin();
break;
case CommitTx:
em.getTransaction().commit();
break;
case RollbackTx:
em.getTransaction().rollback();
break;
case NewThread:
int childToRun = (Integer) args[1];
TestThread t1 = new TestThread(childToRun, actions);
threads.add(t1);
break;
case StartThread:
threads.get((Integer) args[1]).start();
break;
case Notify:
int notifyThreadid = 0;
if (args.length > 1 && args[1] != null) {
notifyThreadid = (Integer) args[1];
}
if (args.length > 2) {
Thread.sleep((Integer) args[2]);
}
if( notifyThreadid == 0) {
notifyParent();
} else {
threads.get(notifyThreadid).notifyThread();
}
break;
case Wait:
int waitThreadid = threadToRun;
if (args.length > 1 && args[1] != null) {
waitThreadid = (Integer) args[1];
}
int waitTime = 5000; //15000;
if (args.length > 2 && args[2] != null) {
waitTime = (Integer) args[2];
}
if( waitThreadid != 0) {
thisThread.wait(waitTime);
} else {
synchronized (this) {
wait(waitTime);
}
break;
case Clear:
em.clear();
break;
case Flush:
em.flush();
break;
case Find:
id = 1;
if (args.length > 1) {
id = (Integer)args[1];
}
break;
case EmployeeNotNull:
id = 1;
if (args[1] != null) {
id = (Integer)args[1];
}
employee = employees.get(id);
assertNotNull(employee);
break;
case TestEmployee:
id = 1;
if (args[1] != null) {
id = (Integer)args[1];
}
employee = employees.get(id);
switch (args.length) {
case 4:
if (args[3] != null) {
assertEquals("", saveVersion
+ (Integer) args[3], employee.getVersion());
}
employee = em.find(LockEmployee.class, id);
log.trace("Employee=" + employee);
if( employee != null ) {
employees.put(id, employee);
} else {
employees.remove(id);
}
break;
case FindWithLock:
id = 1;
if (args[1] != null) {
id = (Integer)args[1];
}
lockMode = LockModeType.NONE;
case 3:
if (args[2] != null) {
lockMode = (LockModeType)args[2];
assertEquals("", (String) args[2], employee
.getFirstName());
}
Map<String, Object> findProps = buildPropsMap(args, 3);
if (findProps != null) {
employee = em.find(LockEmployee.class, id,
lockMode, findProps);
} else {
employee = em
.find(LockEmployee.class, id, lockMode);
}
log.trace("Employee=" + employee);
if( employee != null ) {
employees.put(id, employee);
} else {
employees.remove(id);
}
break;
case FindObject:
em.find((Class<?>)args[1], args[2],
(LockModeType) args[3]);
// log.trace("Employee=" + employee);
break;
case Persist:
id = 1;
case 2:
if (args[1] != null) {
id = (Integer)args[1];
}
String firstName = (String)args[2];
employee = new LockEmployee();
employee.setId(id);
employee.setFirstName(firstName);
log.trace("Employee=" + employee);
em.persist(employee);
break;
case Remove:
id = 1;
if (args.length > 1) {
id = (Integer)args[1];
}
employee = employees.get(id);
log.trace("Employee=" + employee);
em.remove(employee);
break;
case Refresh:
id = 1;
if (args.length > 1) {
id = (Integer)args[1];
}
employee = employees.get(id);
log.trace("Employee(before)=" + employee);
em.refresh(employee);
log.trace("Employee(after) =" + employee);
break;
case RefreshWithLock:
id = 1;
if (args[1] != null) {
id = (Integer)args[1];
}
lockMode = LockModeType.NONE;
if (args[2] != null) {
lockMode = (LockModeType)args[2];
}
employee = employees.get(id);
log.trace("Employee(before)=" + employee);
Map<String, Object> refreshProps = buildPropsMap(args,
3);
if (refreshProps != null) {
em.refresh(employee, lockMode, refreshProps);
} else {
em.refresh(employee, lockMode);
}
log.trace("Employee(after) =" + employee);
break;
case RefreshObject:
em.refresh(args[1], (LockModeType) args[2]);
break;
case Lock:
id = 1;
if (args[1] != null) {
id = (Integer)args[1];
}
lockMode = LockModeType.NONE;
if (args[2] != null) {
lockMode = (LockModeType)args[2];
}
employee = employees.get(id);
log.trace("Employee=" + employee);
Map<String, Object> lockProps = buildPropsMap(args, 3);
if (lockProps != null) {
em.lock(employee, lockMode, lockProps);
} else {
em.lock(employee, lockMode);
assertEquals("", id.intValue(),
employee.getId());
}
break;
case LockObject:
em.lock(args[1], (LockModeType) args[2]);
break;
case UpdateEmployee:
id = 1;
if (args.length > 1) {
id = (Integer) args[1];
}
employee = employees.get(id);
log.trace("Employee (before):" + employee);
String newFirstName = "Unknown";
if (args.length > 2) {
newFirstName = (String) args[2];
} else {
newFirstName = (new Date()).toString();
}
employee.setFirstName(newFirstName);
log.trace("Employee (after) :" + employee);
break;
case 1:
assertNull(employee);
}
break;
case SaveVersion:
id = 1;
if (args.length > 1) {
id = (Integer) args[1];
}
employee = employees.get(id);
saveVersion = employee.getVersion();
log.trace("save version= " + saveVersion);
break;
case TestVersion:
id = 1;
if (args[1] != null) {
id = (Integer) args[1];
}
int increment = (Integer)args[2];
employee = employees.get(id);
log.trace("test version: expected="
+ (saveVersion + increment) + ", testing="
+ employee.getVersion());
case Detach:
id = 1;
if (args[1] != null) {
id = (Integer)args[1];
}
employee = employees.get(id);
log.trace("Employee (before) :" + employee);
LockEmployee detEmployee = ((OpenJPAEntityManager) em
.getDelegate()).detachCopy(employee);
employees.put((Integer)args[2], detEmployee);
log.trace("Employee (after) :" + detEmployee);
break;
assertEquals("", saveVersion + increment, employee
.getVersion());
break;
case TestLockMode:
id = 1;
if (args[1] != null) {
id = (Integer) args[1];
}
employee = employees.get(id);
LockModeType expectedlockMode = (LockModeType)args[2];
LockModeType testinglockMode = em.getLockMode(employee);
log.trace("test version: expected=" + expectedlockMode
+ ", testing=" + testinglockMode);
case StartTx:
em.getTransaction().begin();
break;
case CommitTx:
em.getTransaction().commit();
break;
case RollbackTx:
em.getTransaction().rollback();
break;
case NewThread:
int childToRun = (Integer) args[1];
TestThread t1 = new TestThread(childToRun, actions);
threads.add(t1);
break;
case StartThread:
threads.get((Integer) args[1]).start();
break;
case Notify:
int notifyThreadid = 0;
if (args.length > 1 && args[1] != null) {
notifyThreadid = (Integer) args[1];
}
if (args.length > 2) {
Thread.sleep((Integer) args[2]);
}
if( notifyThreadid == 0) {
notifyParent();
} else {
threads.get(notifyThreadid).notifyThread();
}
break;
case Wait:
int waitThreadid = threadToRun;
if (args.length > 1 && args[1] != null) {
waitThreadid = (Integer) args[1];
}
int waitTime = 5000; //15000;
if (args.length > 2 && args[2] != null) {
waitTime = (Integer) args[2];
}
if( waitThreadid != 0) {
thisThread.wait(waitTime);
} else {
synchronized (this) {
wait(waitTime);
}
}
break;
case EmployeeNotNull:
id = 1;
if (args[1] != null) {
id = (Integer)args[1];
}
employee = employees.get(id);
assertNotNull(employee);
break;
case TestEmployee:
id = 1;
if (args[1] != null) {
id = (Integer)args[1];
}
employee = employees.get(id);
switch (args.length) {
case 4:
if (args[3] != null) {
assertEquals("", saveVersion
+ (Integer) args[3], employee.getVersion());
}
case 3:
if (args[2] != null) {
assertEquals("", (String) args[2], employee
.getFirstName());
}
case 2:
if (args[1] != null) {
assertEquals("", id.intValue(),
employee.getId());
}
break;
case 1:
assertNull(employee);
}
break;
case SaveVersion:
id = 1;
if (args.length > 1) {
id = (Integer) args[1];
}
employee = employees.get(id);
saveVersion = employee.getVersion();
log.trace("save version= " + saveVersion);
break;
case TestVersion:
id = 1;
if (args[1] != null) {
id = (Integer) args[1];
}
int increment = (Integer)args[2];
employee = employees.get(id);
log.trace("test version: expected="
+ (saveVersion + increment) + ", testing="
+ employee.getVersion());
assertEquals("", saveVersion + increment, employee
.getVersion());
break;
case TestLockMode:
id = 1;
if (args[1] != null) {
id = (Integer) args[1];
}
employee = employees.get(id);
LockModeType expectedlockMode = (LockModeType)args[2];
LockModeType testinglockMode = em.getLockMode(employee);
log.trace("test version: expected=" + expectedlockMode
+ ", testing=" + testinglockMode);
assertEquals("", getCanonical(expectedlockMode),
getCanonical(testinglockMode));
break;
case ResetException:
thisThread.throwable = null;
break;
case TestException:
List<Class<?>> expectedExceptions = null;
if (args.length > 2) {
expectedExceptions = new ArrayList<Class<?>>();
for (int i = 2; i < args.length; ++i) {
if (args[i] instanceof Object[]) {
for (Object o : (Object[]) args[i]) {
if (o != null && o instanceof Class) {
expectedExceptions
.add((Class<?>) o);
}
}
} else {
if (args[i] != null
&& args[i] instanceof Class) {
assertEquals("", getCanonical(expectedlockMode),
getCanonical(testinglockMode));
break;
case ResetException:
thisThread.throwable = null;
break;
case TestException:
List<Class<?>> expectedExceptions = null;
if (args.length > 2) {
expectedExceptions = new ArrayList<Class<?>>();
for (int i = 2; i < args.length; ++i) {
if (args[i] instanceof Object[]) {
for (Object o : (Object[]) args[i]) {
if (o != null && o instanceof Class) {
expectedExceptions
.add((Class<?>) args[i]);
.add((Class<?>) o);
}
}
}
}
String testExClass = null;
Throwable curThrowable = null;
int threadId = threadToRun;
if (args.length > 1) {
threadId = (Integer) args[1];
}
TestThread exThread = threads.get(threadId);
curThrowable = exThread.throwable;
testExClass = processException(curAction, curThrowable);
boolean exMatched = false;
if (expectedExceptions != null
&& expectedExceptions.size() > 0) {
for (Class<?> expectedException :
expectedExceptions) {
if (matchExpectedException(expectedException,
curThrowable)) {
exMatched = true;
break;
} else {
if (args[i] != null
&& args[i] instanceof Class) {
expectedExceptions
.add((Class<?>) args[i]);
}
}
} else {
if (curThrowable == null) {
}
}
String testExClass = null;
Throwable curThrowable = null;
int threadId = threadToRun;
if (args.length > 1) {
threadId = (Integer) args[1];
}
TestThread exThread = threads.get(threadId);
curThrowable = exThread.throwable;
testExClass = processException(curAction, curThrowable);
boolean exMatched = false;
if (expectedExceptions != null
&& expectedExceptions.size() > 0) {
for (Class<?> expectedException :
expectedExceptions) {
if (matchExpectedException(expectedException,
curThrowable)) {
exMatched = true;
break;
}
}
if (!exMatched) {
log.trace(testExClass);
if (curThrowable != null) {
logStack(curThrowable);
}
} else {
if (curThrowable == null) {
exMatched = true;
}
assertTrue("Expecting=" + expectedExceptions
+ ", Testing=" + testExClass, exMatched);
exThread.throwable = null;
break;
}
if (!exMatched) {
log.trace(testExClass);
if (curThrowable != null) {
logStack(curThrowable);
}
}
assertTrue("Expecting=" + expectedExceptions
+ ", Testing=" + testExClass, exMatched);
exThread.throwable = null;
break;
case WaitAllChildren:
// wait for threads to die or timeout
log.trace("checking if thread is alive for " +
(endTime-System.currentTimeMillis()) + "ms.");
int deadThreads = 0;
List<TestThread> proceedThread =
new ArrayList<TestThread>(threads);
while (proceedThread.size() > 0
&& System.currentTimeMillis() < endTime) {
for (Thread thread : proceedThread) {
if (thread.isAlive()) {
log.trace(thread + " is still alive, wait" +
" for 500ms and try again.");
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
}
log.trace("waiting children thread ("
+ (endTime - System.currentTimeMillis())
+ " ms left)");
continue;
} else {
deadThreads++;
proceedThread.remove(thread);
break;
case WaitAllChildren:
// wait for threads to die or timeout
log.trace("checking if thread is alive for " +
(endTime-System.currentTimeMillis()) + "ms.");
int deadThreads = 0;
List<TestThread> proceedThread =
new ArrayList<TestThread>(threads);
while (proceedThread.size() > 0
&& System.currentTimeMillis() < endTime) {
for (Thread thread : proceedThread) {
if (thread.isAlive()) {
log.trace(thread + " is still alive, wait" +
" for 500ms and try again.");
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
}
log.trace("waiting children thread ("
+ (endTime - System.currentTimeMillis())
+ " ms left)");
continue;
} else {
deadThreads++;
proceedThread.remove(thread);
break;
}
}
if (proceedThread.size() > 0) {
}
if (proceedThread.size() > 0) {
log.trace(proceedThread.size()
+ " threads still alive.");
for (TestThread thread : proceedThread) {
@ -710,116 +709,109 @@ public abstract class SequencedActionsTest extends SQLListenerTestCase {
thread.interrupt();
}
}
break;
case JoinParent:
for (Thread thread : threads) {
boolean alive = thread.isAlive();
if (alive) {
log.trace(thread.getName() + " is still alive");
try {
thread.interrupt();
thread.join();
} catch (Exception e) {
logStack(e);
}
break;
case JoinParent:
for (Thread thread : threads) {
boolean alive = thread.isAlive();
if (alive) {
log.trace(thread.getName() + " is still alive");
try {
thread.interrupt();
thread.join();
} catch (Exception e) {
logStack(e);
}
}
break;
case YieldThread:
Thread.yield();
break;
case Sleep:
Thread.sleep((Integer) args[1]);
break;
case DetachSerialize:
id = 1;
if (args[1] != null) {
id = (Integer) args[1];
}
employee = employees.get(id);
log.trace("Employee (before)=" + employee);
ByteArrayOutputStream baos =
new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
employee.writeExternal(oos);
oos.flush(); baos.flush();
ByteArrayInputStream bais = new ByteArrayInputStream(
baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
LockEmployee transformedEmployee = new LockEmployee();
transformedEmployee.readExternal(ois);
log.trace("Employee (after) =" + transformedEmployee);
employees.put((Integer)args[2],transformedEmployee);
break;
case Info:
log.info(args[1]);
break;
case Warn:
log.warn(args[1]);
break;
case Error:
log.error(args[1]);
break;
case Trace:
log.trace(args[1]);
break;
case Test:
em.lock("xxx", LockModeType.WRITE);
break;
default:
}
} catch (Exception ex) {
// only remember the first exception caught
if (thisThread.throwable == null) {
thisThread.throwable = ex;
break;
case YieldThread:
Thread.yield();
break;
case Sleep:
Thread.sleep((Integer) args[1]);
break;
case DetachSerialize:
id = 1;
if (args[1] != null) {
id = (Integer) args[1];
}
log.trace("Caught exception and continue: " + ex);
logStack(ex);
} catch (Error err) {
// only remember the first exception caught
if (thisThread.throwable == null) {
thisThread.throwable = err;
}
log.trace("Caught exception and continue: " + err);
logStack(err);
employee = employees.get(id);
log.trace("Employee (before)=" + employee);
ByteArrayOutputStream baos =
new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
employee.writeExternal(oos);
oos.flush(); baos.flush();
ByteArrayInputStream bais = new ByteArrayInputStream(
baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
LockEmployee transformedEmployee = new LockEmployee();
transformedEmployee.readExternal(ois);
log.trace("Employee (after) =" + transformedEmployee);
employees.put((Integer)args[2],transformedEmployee);
break;
case Info:
log.info(args[1]);
break;
case Warn:
log.warn(args[1]);
break;
case Error:
log.error(args[1]);
break;
case Trace:
log.trace(args[1]);
break;
case Test:
em.lock("xxx", LockModeType.WRITE);
break;
default:
}
} catch (Exception ex) {
// only remember the first exception caught
if (thisThread.throwable == null) {
thisThread.throwable = ex;
}
log.trace("Caught exception and continue: " + ex);
logStack(ex);
} catch (Error err) {
// only remember the first exception caught
if (thisThread.throwable == null) {
thisThread.throwable = err;
}
log.trace("Caught exception and continue: " + err);
logStack(err);
}
}
if (em != null && em.isOpen()) {
if (em.getTransaction().isActive()) {
if (thisThread != null) {
thisThread.systemRolledback = em.getTransaction()
.getRollbackOnly();
}
try {
if (em.getTransaction().getRollbackOnly()) {
log.trace("finally: rolledback");
em.getTransaction().rollback();
log.trace("finally: rolledback completed");
} else {
log.trace("finally: commit");
em.getTransaction().commit();
log.trace("finally: commit completed");
}
} catch(Exception finalEx) {
String failStr = processException(curAction, finalEx);
log.trace("Fincally:" + failStr);
}
}
if (em != null && em.isOpen()) {
if (em.getTransaction().isActive()) {
if (thisThread != null) {
thisThread.systemRolledback = em.getTransaction()
.getRollbackOnly();
}
try {
if (em.getTransaction().getRollbackOnly()) {
log.trace("finally: rolledback");
em.getTransaction().rollback();
log.trace("finally: rolledback completed");
} else {
log.trace("finally: commit");
em.getTransaction().commit();
log.trace("finally: commit completed");
}
} catch(Exception finalEx) {
String failStr = processException(curAction, finalEx);
log.trace("Fincally:" + failStr);
}
}
em.close();
Throwable firstThrowable = thisThread.throwable;
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);

View File

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

View File

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

View File

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

View File

@ -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}.