mirror of https://github.com/apache/openjpa.git
Get lock clause from DBDictionary in locking tests
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@983762 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7c0f066234
commit
0f0c6de652
|
@ -201,5 +201,16 @@ public abstract class SingleEMFTestCase
|
|||
protected Log getLog() {
|
||||
return emf.getConfiguration().getLog("Tests");
|
||||
}
|
||||
|
||||
protected String getForUpdateClause() {
|
||||
DBDictionary dict = ((JDBCConfiguration) emf.getConfiguration()).getDBDictionaryInstance();
|
||||
if (dict.forUpdateClause != null) {
|
||||
return dict.forUpdateClause;
|
||||
}
|
||||
if (dict.tableForUpdateClause != null) {
|
||||
return dict.tableForUpdateClause;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,8 +36,7 @@ import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
|
|||
public class TestEmLockMode extends SequencedActionsTest {
|
||||
private static String NON_SUPPORTED_OPTIMISTIC_SQL =
|
||||
"SELECT .* FROM LockEmployee .*";
|
||||
private static String NON_SUPPORTED_FOR_UPDATE_SQL =
|
||||
"SELECT .* FROM LockEmployee .* FOR UPDATE.*";
|
||||
private static String NON_SUPPORTED_FOR_UPDATE_SQL = "" ; // append lock clause from dict
|
||||
private static String VERSION_UPDATE_SQL =
|
||||
"UPDATE LockEmployee SET version .* WHERE .*";
|
||||
private static String DB2_OPTIMISTIC_SQL =
|
||||
|
@ -50,6 +49,15 @@ public class TestEmLockMode extends SequencedActionsTest {
|
|||
public void setUp() {
|
||||
setUp(LockEmployee.class, "openjpa.LockManager", "mixed");
|
||||
commonSetUp();
|
||||
NON_SUPPORTED_FOR_UPDATE_SQL = NON_SUPPORTED_OPTIMISTIC_SQL + " " + escapeRegex(getForUpdateClause()) + ".*";
|
||||
}
|
||||
|
||||
private String escapeRegex(String clause) {
|
||||
// escape an update clause for use in a regex.
|
||||
// only handling ( ) for now
|
||||
String rval = clause.replace("(", "\\(");
|
||||
rval = rval.replace(")", "\\)");
|
||||
return rval;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -37,23 +37,26 @@ import org.apache.openjpa.persistence.test.SQLListenerTestCase;
|
|||
*
|
||||
*/
|
||||
public class TestNamedQueryLockMode extends SQLListenerTestCase {
|
||||
String lockClause = "FOR UPDATE";
|
||||
|
||||
public void setUp() {
|
||||
super.setUp(CLEAR_TABLES, LockEmployee.class,
|
||||
"openjpa.LockManager", "pessimistic",
|
||||
"openjpa.Optimistic", "false"
|
||||
);
|
||||
lockClause = getForUpdateClause();
|
||||
}
|
||||
|
||||
public void testForUpdateClausePresentInNamedQueryWithLockMode() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
assertClausePresentInSQL("FOR UPDATE", em.createNamedQuery("findEmployeeByIdWithLock").setParameter("id", 0));
|
||||
assertClausePresentInSQL(lockClause, em.createNamedQuery("findEmployeeByIdWithLock").setParameter("id", 0));
|
||||
em.getTransaction().rollback();
|
||||
em.getTransaction().begin();
|
||||
assertClausePresentInSQL("FOR UPDATE", em.createNamedQuery("findEmployeeByIdWithLock").setParameter("id", 0));
|
||||
assertClausePresentInSQL(lockClause, em.createNamedQuery("findEmployeeByIdWithLock").setParameter("id", 0));
|
||||
em.getTransaction().rollback();
|
||||
em.getTransaction().begin();
|
||||
assertClausePresentInSQL("FOR UPDATE", em.createNamedQuery("findEmployeeByIdWithLock").setParameter("id", 0));
|
||||
assertClausePresentInSQL(lockClause, em.createNamedQuery("findEmployeeByIdWithLock").setParameter("id", 0));
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
|
||||
|
@ -72,8 +75,8 @@ public class TestNamedQueryLockMode extends SQLListenerTestCase {
|
|||
public void testForUpdateClausePresentInQueryWithDefault() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
assertClausePresentInSQL("FOR UPDATE", em.createNamedQuery("findEmployeeById").setParameter("id", 0));
|
||||
assertClausePresentInSQL("FOR UPDATE", em.createNamedQuery("findEmployeeById").setParameter("id", 0));
|
||||
assertClausePresentInSQL(lockClause, em.createNamedQuery("findEmployeeById").setParameter("id", 0));
|
||||
assertClausePresentInSQL(lockClause, em.createNamedQuery("findEmployeeById").setParameter("id", 0));
|
||||
|
||||
OpenJPAEntityManager oem = (OpenJPAEntityManager)em;
|
||||
OpenJPAQuery<?> q = oem.createNamedQuery("findEmployeeById").setParameter("id", 0);
|
||||
|
@ -90,12 +93,12 @@ public class TestNamedQueryLockMode extends SQLListenerTestCase {
|
|||
OpenJPAQuery<?> q = em.createNamedQuery("findEmployeeById").setParameter("id", 0);
|
||||
FetchPlan fp = q.getFetchPlan();
|
||||
fp.setReadLockMode(LockModeType.NONE);
|
||||
assertClauseAbsentInSQL("FOR UPDATE", q);
|
||||
assertClauseAbsentInSQL(lockClause, q);
|
||||
|
||||
q = em.createNamedQuery("findEmployeeByIdWithNoLock").setParameter("id", 0);
|
||||
fp = q.getFetchPlan();
|
||||
fp.setReadLockMode(LockModeType.NONE);
|
||||
assertClauseAbsentInSQL("FOR UPDATE", q);
|
||||
assertClauseAbsentInSQL(lockClause, q);
|
||||
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
|
@ -104,8 +107,8 @@ public class TestNamedQueryLockMode extends SQLListenerTestCase {
|
|||
public void testForUpdateClauseAbsentInQueryWithExplictNoLock() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
assertClauseAbsentInSQL("FOR UPDATE", em.createNamedQuery("findEmployeeByIdWithNoLock").setParameter("id", 0));
|
||||
assertClauseAbsentInSQL("FOR UPDATE", em.createNamedQuery("findEmployeeByIdWithNoLock").setParameter("id", 0));
|
||||
assertClauseAbsentInSQL(lockClause, em.createNamedQuery("findEmployeeByIdWithNoLock").setParameter("id", 0));
|
||||
assertClauseAbsentInSQL(lockClause, em.createNamedQuery("findEmployeeByIdWithNoLock").setParameter("id", 0));
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
|
||||
|
|
|
@ -22,12 +22,12 @@ import javax.persistence.EntityManager;
|
|||
import javax.persistence.LockModeType;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
|
||||
import org.apache.openjpa.jdbc.sql.DBDictionary;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -35,10 +35,13 @@ import org.apache.openjpa.persistence.test.SQLListenerTestCase;
|
|||
* query when Optimistic=true (default), with pessimistic lock manager.
|
||||
*/
|
||||
public class TestOptimisticNamedQueryLockMode extends SQLListenerTestCase {
|
||||
String lockClause = "FOR UPDATE";
|
||||
|
||||
public void setUp() {
|
||||
super.setUp(CLEAR_TABLES, LockEmployee.class,
|
||||
"openjpa.LockManager", "pessimistic"
|
||||
);
|
||||
lockClause = getForUpdateClause();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -47,13 +50,13 @@ public class TestOptimisticNamedQueryLockMode extends SQLListenerTestCase {
|
|||
public void testForUpdateClausePresentInNamedQueryWithLockMode() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
assertClausePresentInSQL("FOR UPDATE", em.createNamedQuery("findEmployeeByIdWithLock").setParameter("id", 0));
|
||||
assertClausePresentInSQL(lockClause, em.createNamedQuery("findEmployeeByIdWithLock").setParameter("id", 0));
|
||||
em.getTransaction().rollback();
|
||||
em.getTransaction().begin();
|
||||
assertClausePresentInSQL("FOR UPDATE", em.createNamedQuery("findEmployeeByIdWithLock").setParameter("id", 0));
|
||||
assertClausePresentInSQL(lockClause, em.createNamedQuery("findEmployeeByIdWithLock").setParameter("id", 0));
|
||||
em.getTransaction().rollback();
|
||||
em.getTransaction().begin();
|
||||
assertClausePresentInSQL("FOR UPDATE", em.createNamedQuery("findEmployeeByIdWithLock").setParameter("id", 0));
|
||||
assertClausePresentInSQL(lockClause, em.createNamedQuery("findEmployeeByIdWithLock").setParameter("id", 0));
|
||||
em.getTransaction().rollback();
|
||||
em.close();
|
||||
}
|
||||
|
@ -64,8 +67,8 @@ public class TestOptimisticNamedQueryLockMode extends SQLListenerTestCase {
|
|||
public void testForUpdateClausePresentInQueryWithDefault() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
assertClauseAbsentInSQL("FOR UPDATE", em.createNamedQuery("findEmployeeById").setParameter("id", 0));
|
||||
assertClauseAbsentInSQL("FOR UPDATE", em.createNamedQuery("findEmployeeById").setParameter("id", 0));
|
||||
assertClauseAbsentInSQL(lockClause, em.createNamedQuery("findEmployeeById").setParameter("id", 0));
|
||||
assertClauseAbsentInSQL(lockClause, em.createNamedQuery("findEmployeeById").setParameter("id", 0));
|
||||
|
||||
OpenJPAEntityManager oem = (OpenJPAEntityManager)em;
|
||||
OpenJPAQuery<?> q = oem.createNamedQuery("findEmployeeById").setParameter("id", 0);
|
||||
|
@ -86,12 +89,12 @@ public class TestOptimisticNamedQueryLockMode extends SQLListenerTestCase {
|
|||
OpenJPAQuery<?> q = em.createNamedQuery("findEmployeeById").setParameter("id", 0);
|
||||
FetchPlan fp = q.getFetchPlan();
|
||||
fp.setReadLockMode(LockModeType.NONE);
|
||||
assertClauseAbsentInSQL("FOR UPDATE", q);
|
||||
assertClauseAbsentInSQL(lockClause, q);
|
||||
|
||||
q = em.createNamedQuery("findEmployeeByIdWithNoLock").setParameter("id", 0);
|
||||
fp = q.getFetchPlan();
|
||||
fp.setReadLockMode(LockModeType.NONE);
|
||||
assertClauseAbsentInSQL("FOR UPDATE", q);
|
||||
assertClauseAbsentInSQL(lockClause, q);
|
||||
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
|
@ -103,8 +106,8 @@ public class TestOptimisticNamedQueryLockMode extends SQLListenerTestCase {
|
|||
public void testForUpdateClauseAbsentInQueryWithExplictNoLock() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
assertClauseAbsentInSQL("FOR UPDATE", em.createNamedQuery("findEmployeeByIdWithNoLock").setParameter("id", 0));
|
||||
assertClauseAbsentInSQL("FOR UPDATE", em.createNamedQuery("findEmployeeByIdWithNoLock").setParameter("id", 0));
|
||||
assertClauseAbsentInSQL(lockClause, em.createNamedQuery("findEmployeeByIdWithNoLock").setParameter("id", 0));
|
||||
assertClauseAbsentInSQL(lockClause, em.createNamedQuery("findEmployeeByIdWithNoLock").setParameter("id", 0));
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue