String hintName = "openjpa.ReadLockLevel";
EntityManager em = emf.createEntityManager();
OpenJPAEntityManager oem = (OpenJPAEntityManager)em.getDelegate();
JDBCFetchPlan fPlan = (JDBCFetchPlan) oem.getFetchPlan();
JDBCFetchConfigurationImpl fConfig = (JDBCFetchConfigurationImpl)
((EntityManagerImpl) oem).getBroker().getFetchConfiguration();
em.getTransaction().begin();
readLockLevelHintTest(fPlan, fConfig, hintName, String
.valueOf(MixedLockLevels.LOCK_NONE), LockModeType.NONE,
MixedLockLevels.LOCK_NONE);
readLockLevelHintTest(fPlan, fConfig, hintName,
MixedLockLevels.LOCK_NONE, LockModeType.NONE,
MixedLockLevels.LOCK_NONE);
readLockLevelHintTest(fPlan, fConfig, hintName, String
.valueOf(MixedLockLevels.LOCK_READ), LockModeType.READ,
MixedLockLevels.LOCK_READ);
readLockLevelHintTest(fPlan, fConfig, hintName,
MixedLockLevels.LOCK_READ, LockModeType.READ,
MixedLockLevels.LOCK_READ);
readLockLevelHintTest(fPlan, fConfig, hintName, String
.valueOf(MixedLockLevels.LOCK_WRITE), LockModeType.WRITE,
MixedLockLevels.LOCK_WRITE);
readLockLevelHintTest(fPlan, fConfig, hintName,
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,
MixedLockLevels.LOCK_OPTIMISTIC, LockModeType.OPTIMISTIC,
MixedLockLevels.LOCK_OPTIMISTIC);
readLockLevelHintTest(fPlan, fConfig, hintName, String
.valueOf(MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT),
LockModeType.OPTIMISTIC_FORCE_INCREMENT,
MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT);
readLockLevelHintTest(fPlan, fConfig, hintName,
MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT,
LockModeType.OPTIMISTIC_FORCE_INCREMENT,
MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT);
readLockLevelHintTest(fPlan, fConfig, hintName,
String.valueOf(MixedLockLevels.LOCK_PESSIMISTIC_READ),
LockModeType.PESSIMISTIC_READ,
MixedLockLevels.LOCK_PESSIMISTIC_READ);
readLockLevelHintTest(fPlan, fConfig, hintName,
MixedLockLevels.LOCK_PESSIMISTIC_READ,
LockModeType.PESSIMISTIC_READ,
MixedLockLevels.LOCK_PESSIMISTIC_READ);
readLockLevelHintTest(fPlan, fConfig, hintName,
String.valueOf(MixedLockLevels.LOCK_PESSIMISTIC_WRITE),
LockModeType.PESSIMISTIC_WRITE,
MixedLockLevels.LOCK_PESSIMISTIC_WRITE);
readLockLevelHintTest(fPlan, fConfig, hintName,
MixedLockLevels.LOCK_PESSIMISTIC_WRITE,
LockModeType.PESSIMISTIC_WRITE,
MixedLockLevels.LOCK_PESSIMISTIC_WRITE);
readLockLevelHintTest(fPlan, fConfig, hintName, String
.valueOf(MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT),
LockModeType.PESSIMISTIC_FORCE_INCREMENT,
MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT);
readLockLevelHintTest(fPlan, fConfig, hintName,
MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT,
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()));
}
try {
fPlan.setHint(hintName, FetchConfiguration.DEFAULT);
assertEquals(MixedLockLevels.LOCK_READ, fConfig.getReadLockLevel());
} catch (Exception e) {
fail("Unexpected " + e.getClass().getName());
}
em.getTransaction().rollback();
em.close();