String hintName = "openjpa.jdbc.TransactionIsolation";
EntityManager em = emf.createEntityManager();
OpenJPAEntityManager oem = (OpenJPAEntityManager) em.getDelegate();
JDBCFetchPlan fPlan = (JDBCFetchPlan) oem.getFetchPlan();
JDBCFetchConfigurationImpl fConfig = (JDBCFetchConfigurationImpl)
((EntityManagerImpl) oem).getBroker().getFetchConfiguration();
isolationHintTest(oem, fPlan, fConfig, hintName, "-1",
IsolationLevel.DEFAULT, -1);
isolationHintTest(oem, fPlan, fConfig, hintName, -1,
IsolationLevel.DEFAULT, -1);
boolean supportIsolationForUpdate = ((JDBCConfiguration) fConfig
.getContext().getConfiguration()).getDBDictionaryInstance()
.supportsIsolationForUpdate();
if (supportIsolationForUpdate) {
isolationHintTest(oem, fPlan, fConfig, hintName, String
.valueOf(Connection.TRANSACTION_NONE), IsolationLevel.NONE,
Connection.TRANSACTION_NONE);
isolationHintTest(oem, fPlan, fConfig, hintName,
Connection.TRANSACTION_NONE, IsolationLevel.NONE,
Connection.TRANSACTION_NONE);
isolationHintTest(oem, fPlan, fConfig, hintName, String
.valueOf(Connection.TRANSACTION_READ_UNCOMMITTED),
IsolationLevel.READ_UNCOMMITTED,
Connection.TRANSACTION_READ_UNCOMMITTED);
isolationHintTest(oem, fPlan, fConfig, hintName,
Connection.TRANSACTION_READ_UNCOMMITTED,
IsolationLevel.READ_UNCOMMITTED,
Connection.TRANSACTION_READ_UNCOMMITTED);
isolationHintTest(oem, fPlan, fConfig, hintName, String
.valueOf(Connection.TRANSACTION_READ_COMMITTED),
IsolationLevel.READ_COMMITTED,
Connection.TRANSACTION_READ_COMMITTED);
isolationHintTest(oem, fPlan, fConfig, hintName,
Connection.TRANSACTION_READ_COMMITTED,
IsolationLevel.READ_COMMITTED,
Connection.TRANSACTION_READ_COMMITTED);
isolationHintTest(oem, fPlan, fConfig, hintName, String
.valueOf(Connection.TRANSACTION_REPEATABLE_READ),
IsolationLevel.REPEATABLE_READ,
Connection.TRANSACTION_REPEATABLE_READ);
isolationHintTest(oem, fPlan, fConfig, hintName,
Connection.TRANSACTION_REPEATABLE_READ,
IsolationLevel.REPEATABLE_READ,
Connection.TRANSACTION_REPEATABLE_READ);
isolationHintTest(oem, fPlan, fConfig, hintName, String
.valueOf(Connection.TRANSACTION_SERIALIZABLE),
IsolationLevel.SERIALIZABLE,
Connection.TRANSACTION_SERIALIZABLE);
isolationHintTest(oem, fPlan, fConfig, hintName,
Connection.TRANSACTION_SERIALIZABLE,
IsolationLevel.SERIALIZABLE,
Connection.TRANSACTION_SERIALIZABLE);
}
try {
fPlan.setHint(hintName, "xxxxx", false);
fPlan.setHint(hintName, "yyyyy", true);
fail("Expecting a IllegalArgumentException.");
} catch (Exception e) {
assertTrue("Caught expected exception",
IllegalArgumentException.class.isAssignableFrom(e.getClass()));
}
try {
fPlan.setHint(hintName, "12345", false);
fPlan.setHint(hintName, "67890", true);
fail("Expecting a a IllegalArgumentException.");
} catch (Exception e) {
assertTrue("Caught expected exception",
IllegalArgumentException.class.isAssignableFrom(e.getClass()));
}
try {
fPlan.setHint(hintName, -2, false);
fPlan.setHint(hintName, -3, true);
fail("Expecting a a IllegalArgumentException.");
} catch (Exception e) {
assertTrue("Caught expected exception",
IllegalArgumentException.class.isAssignableFrom(e.getClass()));
}
try {
fPlan.setHint(hintName, FetchConfiguration.DEFAULT, true);
assertEquals(IsolationLevel.DEFAULT, fPlan.getIsolation());
assertEquals(-1, fConfig.getIsolation());
} catch (Exception e) {
fail("Unexpected " + e.getClass().getName());
}
em.close();
}