IEntityLock[] locks = retrieveLocks(entityType, entityKey, null);
if ( lockType == WRITE_LOCK )
{
if ( locks.length > 0 )
{ throw new LockingException("Could not create lock: entity already locked."); }
getLockStore().add(newLock);
locks = retrieveLocks(entityType, entityKey, null);
if ( locks.length > 1 ) // another lock snuck in
{
release(newLock);
throw new LockingException("Could not create lock: entity already locked.");
}
}
else // ( lockType == READ_LOCK )
{
for ( int i = 0; i<locks.length; i++ )
{
if ( locks[i].getLockType() == WRITE_LOCK )
{ throw new LockingException("Could not create lock: entity already write locked."); }
else
{
if ( locks[i].equals(newLock) )
{
// another read lock from the same owner; bump the expiration time.