From e541936463b4b6be3ab05ded5b2ed224b4692d6b Mon Sep 17 00:00:00 2001 From: Srinivasa Segu Date: Thu, 5 Apr 2007 20:06:24 +0000 Subject: [PATCH] OPENJPA-203. git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@525950 13f79535-47bb-0310-9956-ffa450edef68 --- .../jdbc/kernel/PessimisticLockManager.java | 6 +++--- .../apache/openjpa/kernel/VersionLockManager.java | 14 +++++++------- 2 files changed, 10 insertions(+), 10 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 44e664bcf..f81c93af5 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 @@ -86,7 +86,7 @@ public class PessimisticLockManager setLockLevel(sm, LOCK_DATASTORE_ONLY); } - protected void lockInternal(OpenJPAStateManager sm, int level, int timeout, + protected void lockInternal(OpenJPAStateManager sm, int level, long timeout, Object sdata) { // we can skip any already-locked instance regardless of level because // we treat all locks the same (though super doesn't) @@ -103,7 +103,7 @@ public class PessimisticLockManager * Lock the specified instance row by issuing a "SELECT ... FOR UPDATE" * statement. */ - private void lockRow(OpenJPAStateManager sm, int timeout) { + private void lockRow(OpenJPAStateManager sm, long timeout) { // assert that the dictionary supports the "SELECT ... FOR UPDATE" // construct; if not, and we the assertion does not throw an // exception, then just return without locking @@ -136,7 +136,7 @@ public class PessimisticLockManager if (log.isWarnEnabled()) log.warn(_loc.get("millis-query-timeout")); } - stmnt.setQueryTimeout(timeout / 1000); + stmnt.setQueryTimeout((int) (timeout / 1000)); } rs = stmnt.executeQuery(); if (!rs.next()) 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 22dfd561d..ee39e982e 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 @@ -69,17 +69,15 @@ public class VersionLockManager return; while (sm.getOwner() != null) sm = sm.getOwner(); - int oldlevel = getLockLevel(sm); - if (!sm.isPersistent() || sm.isNew() || level <= oldlevel) + int oldLevel = getLockLevel(sm); + if (!sm.isPersistent() || sm.isNew() || level <= oldLevel) return; - // set the lock level first to avoid infinite recursion - setLockLevel(sm, level); try { lockInternal(sm, level, timeout, sdata); } catch (RuntimeException re) { // revert lock - setLockLevel(sm, oldlevel); + setLockLevel(sm, oldLevel); throw re; } } @@ -94,6 +92,9 @@ public class VersionLockManager */ protected void lockInternal(OpenJPAStateManager sm, int level, long timeout, Object sdata) { + // Set lock level first to prevent infinite recursion with + // transactional(..) call + setLockLevel(sm, level); if (level >= LockLevels.LOCK_WRITE && _versionUpdateOnWriteLock) getContext().transactional(sm.getManagedInstance(), true, null); else if (level >= LockLevels.LOCK_READ && _versionCheckOnReadLock) @@ -132,6 +133,5 @@ public class VersionLockManager */ public boolean getVersionUpdateOnWriteLock() { return _versionUpdateOnWriteLock; - } + } } -