You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by fa...@apache.org on 2010/04/07 19:39:27 UTC
svn commit: r931628 -
/openjpa/trunk/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestPessimisticLocks.java
Author: faywang
Date: Wed Apr 7 17:39:26 2010
New Revision: 931628
URL: http://svn.apache.org/viewvc?rev=931628&view=rev
Log:
OPENJPA-1602: check in test case
Modified:
openjpa/trunk/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestPessimisticLocks.java
Modified: openjpa/trunk/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestPessimisticLocks.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestPessimisticLocks.java?rev=931628&r1=931627&r2=931628&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestPessimisticLocks.java (original)
+++ openjpa/trunk/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestPessimisticLocks.java Wed Apr 7 17:39:26 2010
@@ -334,6 +334,31 @@ public class TestPessimisticLocks extend
em2.close();
}
+ /*
+ * Test multiple execution of the same query with pessimistic lock.
+ */
+ public void testRepeatedQueryWithPessimisticLocks() {
+ EntityManager em = emf.createEntityManager();
+ resetSQL();
+ em.getTransaction().begin();
+ String jpql = "select e.firstName from Employee e where e.id = 1";
+ Query q1 = em.createQuery(jpql);
+ q1.setLockMode(LockModeType.PESSIMISTIC_WRITE);
+ String firstName1 = (String) q1.getSingleResult();
+ //Expected sql for Derby is:
+ //SELECT t0.firstName FROM Employee t0 WHERE (t0.id = CAST(? AS BIGINT)) FOR UPDATE WITH RR
+ String SQL1 = toString(sql);
+
+ // run the second time
+ resetSQL();
+ Query q2 = em.createQuery(jpql);
+ q2.setLockMode(LockModeType.PESSIMISTIC_WRITE);
+ String firstName2 = (String) q2.getSingleResult();
+ String SQL2 = toString(sql);
+ assertEquals(SQL1, SQL2);
+ em.getTransaction().commit();
+ }
+
/**
* Assert that an exception of proper type has been thrown. Also checks that
* that the exception has populated the failed object.