getLog().trace("testNoProperties() - no properties in persistence.xml");
OpenJPAEntityManagerFactory emf1 = null, emf2 = null;
OpenJPAEntityManager em1 = null, em2 = null;
try {
OpenJPAQuery q;
Map<String, Object> hints;
Integer timeout;
Integer lTime = new Integer(0);
Integer qTime = new Integer(0);
// create our PU without properties
emf1 = OpenJPAPersistence.createEntityManagerFactory(
"qtimeout-no-properties", "persistence3.xml");
assertNotNull(emf1);
emf2 = OpenJPAPersistence.createEntityManagerFactory(
"qtimeout-no-properties", "persistence3.xml", props);
assertNotNull(emf2);
//=============
// Test for 1a)
//=============
// verify no config properties from persistence.xml
OpenJPAConfiguration conf1 = emf1.getConfiguration();
assertNotNull(conf1);
assertEquals("Expected no default lock timeout", lTime.intValue(),
conf1.getLockTimeout());
assertEquals("Expected no default query timeout", qTime.intValue(),
conf1.getQueryTimeout());
// verify Query receives no properties
em1 = emf1.createEntityManager();
assertNotNull(em1);
q = em1.createNamedQuery("NoHintList");
// verify no Query hints
hints = q.getHints();
assertFalse(hints.containsKey("javax.persistence.lock.timeout"));
assertFalse(hints.containsKey("javax.persistence.query.timeout"));
// verify default config values of no timeouts
timeout = q.getFetchPlan().getLockTimeout();
assertEquals("Expected no default lock timeout", lTime.intValue(),
timeout.intValue());
timeout = q.getFetchPlan().getQueryTimeout();
assertEquals("Expected no default query timeout", qTime.intValue(),
timeout.intValue());
//=============
// Test for 2a)
//=============
// verify properties in Map override persistence.xml
OpenJPAConfiguration conf2 = emf2.getConfiguration();
assertNotNull(conf2);
lTime = 12000;
qTime = 7000;
assertEquals("Expected Map updated lock timeout", lTime.intValue(),
conf2.getLockTimeout());
assertEquals("Expected Map updated query timeout", qTime.intValue(),
conf2.getQueryTimeout());
// Verify Query receives the properties
em2 = emf2.createEntityManager();
assertNotNull(em2);
q = em2.createNamedQuery("NoHintList");
// Cannot verify properties are passed through as Query hints
/*
* Following test would fail, as the code currently does not pass
* the properties down as hints, but only as config settings.
*
* The spec says that PU or Map provided properties to the EMF
* will be used as defaults and that Query.setHint() can be used
* to override, but there is no requirement for getHints() to
* return these default values.
*
hints = q.getHints();
assertTrue(hints.containsKey("javax.persistence.lock.timeout"));
assertTrue(hints.containsKey("javax.persistence.query.timeout"));
timeout = new Integer((String) hints.get(
"javax.persistence.lock.timeout"));
assertEquals("Expected Map updated lockTimeout",
lTime.intValue(), timeout.intValue());
timeout = new Integer((String) hints.get(
"javax.persistence.query.timeout"));
assertEquals("Expected Map updated queryTimeout",
qTime.intValue(), timeout.intValue());
*/
// verify internal config values were updated
timeout = q.getFetchPlan().getLockTimeout();
assertEquals("Expected Map updated lock timeout", lTime.intValue(),
timeout.intValue());
timeout = q.getFetchPlan().getQueryTimeout();
assertEquals("Expected Map updated query timeout", qTime.intValue(),
timeout.intValue());
//=============
// Test for 4a)
//=============
// verify setHint overrides Map provided properties
lTime = 15000;
qTime = 10000;
q.setHint("javax.persistence.lock.timeout", lTime);
q.setHint("javax.persistence.query.timeout", qTime);
hints = q.getHints();
// verify getHints values were updated
timeout = (Integer) hints.get("javax.persistence.lock.timeout");
assertEquals(
"Expected setHint updated javax.persistence.lock.timeout",
lTime.intValue(), timeout.intValue());
timeout = (Integer) hints.get("javax.persistence.query.timeout");
assertEquals(
"Expected setHint updated javax.persistence.query.timeout",
qTime.intValue(), timeout.intValue());
// verify internal config values were updated
timeout = q.getFetchPlan().getLockTimeout();
assertEquals("Expected setHint updated lockTimeout",
lTime.intValue(), timeout.intValue());
timeout = q.getFetchPlan().getQueryTimeout();
assertEquals("Expected setHint updated queryTimeout",
qTime.intValue(), timeout.intValue());
} finally {
// cleanup
closeEMF(emf1);