private void fetchPlanWriteLockModeHint(boolean inTransaction) {
String hintName = "openjpa.FetchPlan.WriteLockMode";
EntityManager em = emf.createEntityManager();
OpenJPAEntityManager oem = (OpenJPAEntityManager)em.getDelegate();
JDBCFetchPlan fPlan = (JDBCFetchPlan) oem.getFetchPlan();
JDBCFetchConfigurationImpl fConfig = (JDBCFetchConfigurationImpl)
((EntityManagerImpl) oem).getBroker().getFetchConfiguration();
if(inTransaction)
em.getTransaction().begin();
writeLockModeHintTest(fPlan, fConfig, hintName, "none",
LockModeType.NONE, MixedLockLevels.LOCK_NONE);
writeLockModeHintTest(fPlan, fConfig, hintName, LockModeType.NONE,
LockModeType.NONE, MixedLockLevels.LOCK_NONE);
writeLockModeHintTest(fPlan, fConfig, hintName, LockModeType.NONE
.name(), LockModeType.NONE, MixedLockLevels.LOCK_NONE);
writeLockModeHintTest(fPlan, fConfig, hintName, "read",
LockModeType.READ, MixedLockLevels.LOCK_READ);
writeLockModeHintTest(fPlan, fConfig, hintName, LockModeType.READ,
LockModeType.READ, MixedLockLevels.LOCK_READ);
writeLockModeHintTest(fPlan, fConfig, hintName, LockModeType.READ
.name(), LockModeType.READ, MixedLockLevels.LOCK_READ);
writeLockModeHintTest(fPlan, fConfig, hintName, "write",
LockModeType.WRITE, MixedLockLevels.LOCK_WRITE);
writeLockModeHintTest(fPlan, fConfig, hintName, LockModeType.WRITE,
LockModeType.WRITE, MixedLockLevels.LOCK_WRITE);
writeLockModeHintTest(fPlan, fConfig, hintName, LockModeType.WRITE
.name(), LockModeType.WRITE, MixedLockLevels.LOCK_WRITE);
writeLockModeHintTest(fPlan, fConfig, hintName,
"optimistic", LockModeType.OPTIMISTIC,
MixedLockLevels.LOCK_OPTIMISTIC);
writeLockModeHintTest(fPlan, fConfig, hintName,
LockModeType.OPTIMISTIC, LockModeType.OPTIMISTIC,
MixedLockLevels.LOCK_OPTIMISTIC);
writeLockModeHintTest(fPlan, fConfig, hintName, LockModeType.OPTIMISTIC
.name(), LockModeType.OPTIMISTIC, MixedLockLevels.LOCK_OPTIMISTIC);
writeLockModeHintTest(fPlan, fConfig, hintName,
"optimistic-force-increment",
LockModeType.OPTIMISTIC_FORCE_INCREMENT,
MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT);
writeLockModeHintTest(fPlan, fConfig, hintName,
LockModeType.OPTIMISTIC_FORCE_INCREMENT,
LockModeType.OPTIMISTIC_FORCE_INCREMENT,
MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT);
writeLockModeHintTest(fPlan, fConfig, hintName,
LockModeType.OPTIMISTIC_FORCE_INCREMENT.name(),
LockModeType.OPTIMISTIC_FORCE_INCREMENT,
MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT);
writeLockModeHintTest(fPlan, fConfig, hintName,
"pessimistic-read", LockModeType.PESSIMISTIC_READ,
MixedLockLevels.LOCK_PESSIMISTIC_READ);
writeLockModeHintTest(fPlan, fConfig, hintName,
LockModeType.PESSIMISTIC_READ, LockModeType.PESSIMISTIC_READ,
MixedLockLevels.LOCK_PESSIMISTIC_READ);
writeLockModeHintTest(fPlan, fConfig, hintName,
LockModeType.PESSIMISTIC_READ.name(),
LockModeType.PESSIMISTIC_READ,
MixedLockLevels.LOCK_PESSIMISTIC_READ);
writeLockModeHintTest(fPlan, fConfig, hintName,
"pessimistic-write", LockModeType.PESSIMISTIC_WRITE,
MixedLockLevels.LOCK_PESSIMISTIC_WRITE);
writeLockModeHintTest(fPlan, fConfig, hintName,
LockModeType.PESSIMISTIC_WRITE, LockModeType.PESSIMISTIC_WRITE,
MixedLockLevels.LOCK_PESSIMISTIC_WRITE);
writeLockModeHintTest(fPlan, fConfig, hintName,
LockModeType.PESSIMISTIC_WRITE.name(),
LockModeType.PESSIMISTIC_WRITE,
MixedLockLevels.LOCK_PESSIMISTIC_WRITE);
writeLockModeHintTest(fPlan, fConfig, hintName,
"pessimistic-force-increment",
LockModeType.PESSIMISTIC_FORCE_INCREMENT,
MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT);
writeLockModeHintTest(fPlan, fConfig, hintName,
LockModeType.PESSIMISTIC_FORCE_INCREMENT,
LockModeType.PESSIMISTIC_FORCE_INCREMENT,
MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT);
writeLockModeHintTest(fPlan, fConfig, hintName,
LockModeType.PESSIMISTIC_FORCE_INCREMENT.name(),
LockModeType.PESSIMISTIC_FORCE_INCREMENT,
MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT);
try {
fPlan.setHint(hintName, "xxxxx");
fPlan.setHint(hintName, "yyyyy");
fail("Expecting a a IllegalArgumentException.");
} catch (Exception e) {
assertTrue("Caught expected exception",
IllegalArgumentException.class.isAssignableFrom(e.getClass()));
}
try {
fPlan.setHint(hintName, "12345");
fPlan.setHint(hintName, "67890");
fail("Expecting a a IllegalArgumentException.");
} catch (Exception e) {
assertTrue("Caught expected exception",
IllegalArgumentException.class.isAssignableFrom(e.getClass()));
}
try {
fPlan.setHint(hintName, -1);
fPlan.setHint(hintName, -2);
fail("Expecting a a IllegalArgumentException.");
} catch (Exception e) {
assertTrue("Caught expected exception",
IllegalArgumentException.class.isAssignableFrom(e.getClass()));
}