// Following fails to cause a SQLException, but takes 2+ secs
// Query q = em.createNativeQuery("INSERT INTO QTimeout (id, " +
// "stringField) VALUES (?,?)");
// q.setParameter(1, 99);
// q.setParameter(2, new String("inserted"));
OpenJPAQuery q = em.createNativeQuery(nativeUpdateStr);
q.setParameter(1, new String("updated"));
// verify no default javax.persistence.query.timeout is supplied
Map<String, Object> hints = q.getHints();
assertFalse(hints.containsKey("javax.persistence.query.timeout"));
// update the query timeout value and verify it was set
setTime = 1000;
getLog().trace("testQueryTimeout33c() - Setting hint " +
"javax.persistence.query.timeout=" + setTime);
q.setHint("javax.persistence.query.timeout", setTime);
hints = q.getHints();
assertTrue(hints.containsKey("javax.persistence.query.timeout"));
Integer timeout = (Integer) hints.get(
"javax.persistence.query.timeout");
assertEquals(timeout, setTime);
// verify internal config values were updated
assertEquals("PU provided query timeout", setTime.intValue(),
q.getFetchPlan().getQueryTimeout());
em.getTransaction().begin();
for (int i=0; i<=1 && bRetry; i++)
{
try {
long startTime = System.currentTimeMillis();
@SuppressWarnings("unused")
int count = q.executeUpdate();
em.getTransaction().commit();
long endTime = System.currentTimeMillis();
long runTime = endTime - startTime;
getLog().trace("testQueryTimeout33c() - executeUpdate " +
"runTime msecs=" + runTime);