org.apache.derby.iapi.store.raw
Interface LockingPolicy

All Known Implementing Classes:
ContainerLocking2, ContainerLocking3, NoLocking, RowLocking1, RowLocking2, RowLocking2nohold, RowLocking3, RowLocking3Escalate, RowLockingRR

public interface LockingPolicy

Any object that implements this interface can be used as a locking policy for accessing a container.

The locking policy must use the defined lock qualifiers (ContainerLock.CIS, RowLock.RS, etc.) and the standard lock manager. (A locking policy that just performs no locking wouldn't need to use these :-)

A locking policy must use the object that is an instance of Transaction (originally obtained via startTransaction() in RawStoreFactory) as the compatibilitySpace for the LockFactory calls.
A locking policy must use the passed in transaction as the compatability space and the lock group. This chain (group) of locks has the following defined behaviour


MT - Thread Safe

See Also:
ContainerHandle, RecordHandle, LockFactory, Lockable

Field Summary
static int MODE_CONTAINER
          ContainerHandle level locking.
static int MODE_NONE
          No locking what so ever, isolation parameter will be ignored by getLockingPolicy().
static int MODE_RECORD
          Record level locking.
 
Method Summary
 int getMode()
          Get the mode of this policy
 boolean lockContainer(Transaction t, ContainerHandle container, boolean waitForLock, boolean forUpdate)
          Called when a container is opened.
 boolean lockRecordForRead(Transaction t, ContainerHandle container, RecordHandle record, boolean waitForLock, boolean forUpdate)
          Called before a record is fetched.
 boolean lockRecordForWrite(Transaction t, RecordHandle record, boolean lockForInsert, boolean waitForLock)
          Called before a record is inserted, updated or deleted.
 void unlockContainer(Transaction t, ContainerHandle container)
          Called when a container is closed.
 void unlockRecordAfterRead(Transaction t, ContainerHandle container, RecordHandle record, boolean forUpdate, boolean row_qualified)
          Called after a record has been fetched.
 boolean zeroDurationLockRecordForWrite(Transaction t, RecordHandle record, boolean lockForPreviousKey, boolean waitForLock)
          Request a write lock which will be released immediately upon grant.
 

Field Detail

MODE_NONE

static final int MODE_NONE
No locking what so ever, isolation parameter will be ignored by getLockingPolicy().

See Also:
RawStoreFactory, Constant Field Values

MODE_RECORD

static final int MODE_RECORD
Record level locking.

See Also:
Constant Field Values

MODE_CONTAINER

static final int MODE_CONTAINER
ContainerHandle level locking.

See Also:
Constant Field Values
Method Detail

lockContainer

boolean lockContainer(Transaction t,
                      ContainerHandle container,
                      boolean waitForLock,
                      boolean forUpdate)
                      throws StandardException
Called when a container is opened.

Parameters:
t - Transaction to associate lock with.
container - Container to lock.
waitForLock - Should lock request wait until granted?
forUpdate - Should container be locked for update, or read?
Returns:
true if the lock was obtained, false if it wasn't. False should only be returned if the waitForLock policy was set to "false," and the lock was unavailable.
Throws:
StandardException - Standard Derby error policy
See Also:
ContainerHandle

unlockContainer

void unlockContainer(Transaction t,
                     ContainerHandle container)
Called when a container is closed.

See Also:
ContainerHandle, ContainerHandle.close()

lockRecordForRead

boolean lockRecordForRead(Transaction t,
                          ContainerHandle container,
                          RecordHandle record,
                          boolean waitForLock,
                          boolean forUpdate)
                          throws StandardException
Called before a record is fetched.

Parameters:
t - Transaction to associate lock with.
container - Open Container used to get record. Will be used to row locks by the container they belong to.
record - Record to lock.
waitForLock - Should lock request wait until granted?
forUpdate - Should container be locked for update, or read?
Throws:
StandardException - Standard Derby error policy
See Also:
Page

zeroDurationLockRecordForWrite

boolean zeroDurationLockRecordForWrite(Transaction t,
                                       RecordHandle record,
                                       boolean lockForPreviousKey,
                                       boolean waitForLock)
                                       throws StandardException
Request a write lock which will be released immediately upon grant.

Parameters:
t - Transaction to associate lock with.
record - Record to lock.
lockForPreviousKey - Lock is for a previous key of a insert.
waitForLock - Should lock request wait until granted?
Returns:
true if the lock was obtained, false if it wasn't. False should only be returned if the waitForLock argument was set to "false," and the lock was unavailable.
Throws:
StandardException - Standard Derby error policy
See Also:
Page

lockRecordForWrite

boolean lockRecordForWrite(Transaction t,
                           RecordHandle record,
                           boolean lockForInsert,
                           boolean waitForLock)
                           throws StandardException
Called before a record is inserted, updated or deleted. If zeroDuration is true then lock is released immediately after it has been granted.

Parameters:
t - Transaction to associate lock with.
record - Record to lock.
lockForInsert - Lock is for an insert.
waitForLock - Should lock request wait until granted?
Returns:
true if the lock was obtained, false if it wasn't. False should only be returned if the waitForLock argument was set to "false," and the lock was unavailable.
Throws:
StandardException - Standard Derby error policy
See Also:
Page

unlockRecordAfterRead

void unlockRecordAfterRead(Transaction t,
                           ContainerHandle container,
                           RecordHandle record,
                           boolean forUpdate,
                           boolean row_qualified)
                           throws StandardException
Called after a record has been fetched.

Throws:
StandardException - Standard Derby error policy
See Also:
Page

getMode

int getMode()
Get the mode of this policy


Built on Thu 2012-03-29 21:53:33+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.