From 8cf5f35488427d07778f54a1b7181e024d94f756 Mon Sep 17 00:00:00 2001 From: Albert Lee Date: Thu, 9 Dec 2010 15:33:06 +0000 Subject: [PATCH] OPENJPA-1904 Propagate refresh operation for eagerly fetched relationship fields. git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.1.x@1044005 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/openjpa/kernel/BrokerImpl.java | 4 ++-- .../org/apache/openjpa/kernel/LockManager.java | 4 ++-- .../apache/openjpa/kernel/NoneLockManager.java | 4 ++-- .../apache/openjpa/kernel/VersionLockManager.java | 15 +++++++++++++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java index 1cc668a30..ba4de640f 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java @@ -3011,7 +3011,7 @@ public class BrokerImpl } int level = _fc.getReadLockLevel(); int timeout = _fc.getLockTimeout(); - _lm.lock(sm, level, timeout, null, false); + _lm.refreshLock(sm, level, timeout, null); sm.readLocked(level, level); } else if (assertPersistenceCapable(obj).pcIsDetached() == Boolean.TRUE) @@ -3083,7 +3083,7 @@ public class BrokerImpl } int level = _fc.getReadLockLevel(); int timeout = _fc.getLockTimeout(); - _lm.lock(sm, level, timeout, null, false); + _lm.refreshLock(sm, level, timeout, null); sm.readLocked(level, level); fireLifecycleEvent(sm.getManagedInstance(), null, sm.getMetaData(), LifecycleEvent.AFTER_REFRESH); diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/LockManager.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/LockManager.java index 062b2c48e..9f5d4b62f 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/LockManager.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/LockManager.java @@ -74,8 +74,8 @@ public interface LockManager * Perform the same function as previous lock method and has the option * to perform a version check after the lock function has completed. */ - public void lock(OpenJPAStateManager sm, int level, int timeout, - Object sdata, boolean postLockVersionCheck); + public void refreshLock(OpenJPAStateManager sm, int level, int timeout, + Object sdata); /** * Obtain locks on the specified objects. diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/NoneLockManager.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/NoneLockManager.java index 3a70b019a..56bbb8bd5 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/NoneLockManager.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/NoneLockManager.java @@ -33,8 +33,8 @@ public class NoneLockManager sm.setLock(Boolean.TRUE); } - public void lock(OpenJPAStateManager sm, int level, int timeout, - Object context, boolean postLockVersionCheck) { + public void refreshLock(OpenJPAStateManager sm, int level, int timeout, + Object context) { sm.setLock(Boolean.TRUE); } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionLockManager.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionLockManager.java index becb970a5..93bcf1205 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionLockManager.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionLockManager.java @@ -31,6 +31,7 @@ public class VersionLockManager private boolean _versionCheckOnReadLock = true; private boolean _versionUpdateOnWriteLock = true; + private boolean _refreshing = false; /** * Returns the given instance's lock level, assuming that the state's @@ -67,10 +68,20 @@ public class VersionLockManager */ public void lock(OpenJPAStateManager sm, int level, int timeout, Object sdata) { - lock(sm, level, timeout, sdata, true); + commonLock(sm, level, timeout, sdata, !_refreshing); } - public void lock(OpenJPAStateManager sm, int level, int timeout, + public void refreshLock(OpenJPAStateManager sm, int level, int timeout, + Object sdata) { + try { + _refreshing = true; + commonLock(sm, level, timeout, sdata, false); + } finally { + _refreshing = false; + } + } + + private void commonLock(OpenJPAStateManager sm, int level, int timeout, Object sdata, boolean postLockVersionCheck) { if (level == LOCK_NONE) return;