From 0cfb656770842c5291bb906dcd5e1703ecd4d1bc Mon Sep 17 00:00:00 2001 From: "Richard G. Curtis" Date: Wed, 21 Apr 2010 19:05:41 +0000 Subject: [PATCH] OPENJPA-1638: Add new testcase. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@936445 13f79535-47bb-0310-9956-ffa450edef68 --- .../lockmgr/TestNamedQueryLockMode.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestNamedQueryLockMode.java b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestNamedQueryLockMode.java index c108abacc..8b49ee47e 100644 --- a/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestNamedQueryLockMode.java +++ b/openjpa-persistence-locking/src/test/java/org/apache/openjpa/persistence/lockmgr/TestNamedQueryLockMode.java @@ -19,8 +19,13 @@ package org.apache.openjpa.persistence.lockmgr; import javax.persistence.EntityManager; +import javax.persistence.LockModeType; import javax.persistence.Query; +import org.apache.openjpa.persistence.FetchPlan; +import org.apache.openjpa.persistence.OpenJPAEntityManager; +import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI; +import org.apache.openjpa.persistence.OpenJPAQuery; import org.apache.openjpa.persistence.TransactionRequiredException; import org.apache.openjpa.persistence.test.AllowFailure; import org.apache.openjpa.persistence.test.SQLListenerTestCase; @@ -57,8 +62,7 @@ public class TestNamedQueryLockMode extends SQLListenerTestCase { EntityManager em = emf.createEntityManager(); // execute without a transaction try { - em.createNamedQuery("findEmployeeByIdWithLock").setParameter("id", - 0).getResultList(); + em.createNamedQuery("findEmployeeByIdWithLock").setParameter("id", 0).getResultList(); fail("Expected " + TransactionRequiredException.class.getName()); } catch (TransactionRequiredException e) { // Expected @@ -70,6 +74,29 @@ public class TestNamedQueryLockMode extends SQLListenerTestCase { em.getTransaction().begin(); assertClausePresentInSQL("FOR UPDATE", em.createNamedQuery("findEmployeeById").setParameter("id", 0)); assertClausePresentInSQL("FOR UPDATE", em.createNamedQuery("findEmployeeById").setParameter("id", 0)); + + OpenJPAEntityManager oem = (OpenJPAEntityManager)em; + OpenJPAQuery q = oem.createNamedQuery("findEmployeeById").setParameter("id", 0); + FetchPlan fp = q.getFetchPlan(); + fp.setReadLockMode(LockModeType.NONE); + + em.getTransaction().commit(); + } + + public void testForUpdateClauseAbsentInQueryWithFetchPlanNoneLockMode() { + OpenJPAEntityManagerSPI em = emf.createEntityManager(); + em.getTransaction().begin(); + + OpenJPAQuery q = em.createNamedQuery("findEmployeeById").setParameter("id", 0); + FetchPlan fp = q.getFetchPlan(); + fp.setReadLockMode(LockModeType.NONE); + assertClauseAbsentInSQL("FOR UPDATE", q); + + q = em.createNamedQuery("findEmployeeByIdWithNoLock").setParameter("id", 0); + fp = q.getFetchPlan(); + fp.setReadLockMode(LockModeType.NONE); + assertClauseAbsentInSQL("FOR UPDATE", q); + em.getTransaction().commit(); }