From 0836fba1588af1a9c4f1544bd123a3333fcd4a6d Mon Sep 17 00:00:00 2001 From: Fay Wang Date: Mon, 8 Nov 2010 20:10:45 +0000 Subject: [PATCH] OPENJPA-1762: lock join table when pessimistic scope is set to EXTENDED git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1032686 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/jdbc/kernel/PessimisticLockManager.java | 4 +++- .../apache/openjpa/persistence/EntityManagerImpl.java | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PessimisticLockManager.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PessimisticLockManager.java index 1d6b30a69..51e250321 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PessimisticLockManager.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PessimisticLockManager.java @@ -34,6 +34,7 @@ import org.apache.openjpa.jdbc.sql.DBDictionary; import org.apache.openjpa.jdbc.sql.SQLBuffer; import org.apache.openjpa.jdbc.sql.SQLFactory; import org.apache.openjpa.jdbc.sql.Select; +import org.apache.openjpa.kernel.LockScopes; import org.apache.openjpa.kernel.MixedLockLevels; import org.apache.openjpa.kernel.OpenJPAStateManager; import org.apache.openjpa.kernel.StoreContext; @@ -128,7 +129,8 @@ public class PessimisticLockManager ClassMapping mapping = (ClassMapping) sm.getMetaData(); List sqls = getLockRows(dict, id, mapping, fetch, _store.getSQLFactory()); - lockJoinTables(sqls, dict, id, mapping, fetch, _store.getSQLFactory()); + if (ctx.getFetchConfiguration().getLockScope() == LockScopes.LOCKSCOPE_EXTENDED) + lockJoinTables(sqls, dict, id, mapping, fetch, _store.getSQLFactory()); ensureStoreManagerTransaction(); Connection conn = _store.getConnection(); diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java index b47303507..83d28ae35 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java @@ -43,6 +43,7 @@ import javax.persistence.CacheStoreMode; import javax.persistence.EntityManager; import javax.persistence.FlushModeType; import javax.persistence.LockModeType; +import javax.persistence.PessimisticLockScope; import javax.persistence.Query; import javax.persistence.TypedQuery; import javax.persistence.criteria.CriteriaQuery; @@ -1682,8 +1683,14 @@ public class EntityManagerImpl LockModeType lock, boolean requiresTxn) { // handle properties in map first if (properties != null) { - for (Map.Entry entry : properties.entrySet()) - fetch.setHint(entry.getKey(), entry.getValue()); + for (Map.Entry entry : properties.entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); + if (key.equals("javax.persistence.lock.scope")) { + fetch.setLockScope((PessimisticLockScope)value); + } else + fetch.setHint(key, value); + } } // override with the specific lockMode, if needed. if (lock != null && lock != LockModeType.NONE) {