OPENJPA-2449: refresh(PESSIMISTIC_WRITE) generates seperate SQL for the lock - applied to 2.1.x Albert Lee's patch.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.1.x@1539188 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Heath Thomann 2013-11-05 23:19:16 +00:00
parent 8437f735f4
commit f0fc8e3808
2 changed files with 11 additions and 10 deletions

View File

@ -101,13 +101,12 @@ public class PessimisticLockManager
protected void lockInternal(OpenJPAStateManager sm, int level, int timeout,
Object sdata, boolean postVersionCheck) {
// we can skip any already-locked instance regardless of level because
// we treat all locks the same (though super doesn't)
if (getLockLevel(sm) == LOCK_NONE) {
// only need to lock if not loaded from locking result
ConnectionInfo info = (ConnectionInfo) sdata;
if (info == null || info.result == null || !info.result.isLocking())
lockRow(sm, timeout, level);
}
// we treat all locks the same (though super doesn't).
// only need to lock if not loaded from locking result
ConnectionInfo info = (ConnectionInfo) sdata;
if (info == null || info.result == null || !info.result.isLocking())
lockRow(sm, timeout, level);
optimisticLockInternal(sm, level, timeout, sdata, postVersionCheck);
}
@ -128,7 +127,9 @@ public class PessimisticLockManager
Object id = sm.getObjectId();
ClassMapping mapping = (ClassMapping) sm.getMetaData();
List<SQLBuffer> sqls = getLockRows(dict, id, mapping, fetch, _store.getSQLFactory());
List<SQLBuffer> sqls = sm.getLock() == null
? getLockRows(dict, id, mapping, fetch, _store.getSQLFactory())
: new ArrayList<SQLBuffer>();
if (ctx.getFetchConfiguration().getLockScope() == LockScopes.LOCKSCOPE_EXTENDED)
lockJoinTables(sqls, dict, id, mapping, fetch, _store.getSQLFactory());

View File

@ -1391,9 +1391,9 @@ public class StateManagerImpl
if (fetch == null)
fetch = _broker.getFetchConfiguration();
if (_readLockLevel == -1)
if (_readLockLevel == -1 || _readLockLevel < fetch.getReadLockLevel())
_readLockLevel = fetch.getReadLockLevel();
if (_writeLockLevel == -1)
if (_writeLockLevel == -1 || _writeLockLevel < fetch.getWriteLockLevel())
_writeLockLevel = fetch.getWriteLockLevel();
return (forWrite) ? _writeLockLevel : _readLockLevel;
}