LockManager lm = LockManagerFactory.getLockManager();
if (lockMode == Transaction.READ)
{
if (!lm.readLock(this, obj))
{
throw new LockNotGrantedException("Can not lock for READ: " + obj);
}
}
else if (lockMode == Transaction.WRITE)
{
if (!lm.writeLock(this, obj))
{
throw new LockNotGrantedException("Can not lock for WRITE: " + obj);
}
}
else if (lockMode == Transaction.UPGRADE)
{
if (!lm.upgradeLock(this, obj))
{
throw new LockNotGrantedException("Can not lock for UPGRADE: " + obj);
}
}
try
{
if (log.isDebugEnabled()) log.debug("registering lock on object at " + System.currentTimeMillis());
register(obj, lockMode);
}
catch (Throwable t)
{
log.error("Locking obj " + obj + " with lock mode " + lockMode + " failed", t);
lm.releaseLock(this, obj);
throw new LockNotGrantedException(t.getMessage());
}
}