Top Description Fields Methods
org.apache.derby.iapi.store.raw

public Interface LockingPolicy

Known Direct Implementers
org.apache.derby.impl.store.raw.xact.NoLocking
Imports
org.apache.derby.shared.common.error.StandardException

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, org.apache.derby.iapi.services.locks.LockFactory, org.apache.derby.iapi.services.locks.Lockable

Field Summary

Modifier and TypeField and Description
public static final int
MODE_CONTAINER

ContainerHandle level locking.

public static final int
MODE_NONE

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

public static final int
MODE_RECORD

Record level locking.

Method Summary

Modifier and TypeMethod and Description
public int
getMode()

Get the mode of this policy

public boolean

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.
lockContainer
(Transaction
Transaction to associate lock with.
t
,
ContainerHandle
Container to lock.
container
,
boolean
Should lock request wait until granted?
waitForLock
,
boolean
Should container be locked for update, or read?
forUpdate
)

Called when a container is opened.

public boolean
lockRecordForRead(Transaction
Transaction to associate lock with.
t
,
ContainerHandle
Open Container used to get record. Will be used to row locks by the container they belong to.
container
,
RecordHandle
Record to lock.
record
,
boolean
Should lock request wait until granted?
waitForLock
,
boolean
Should container be locked for update, or read?
forUpdate
)

Called before a record is fetched.

public boolean

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.
lockRecordForWrite
(Transaction
Transaction to associate lock with.
t
,
RecordHandle
Record to lock.
record
,
boolean
Lock is for an insert.
lockForInsert
,
boolean
Should lock request wait until granted?
waitForLock
)

Called before a record is inserted, updated or deleted.

public void
unlockContainer(Transaction t, ContainerHandle container)

Called when a container is closed.

public void
unlockRecordAfterRead(Transaction t, ContainerHandle container, RecordHandle record, boolean forUpdate, boolean row_qualified)

Called after a record has been fetched.

public boolean

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.
zeroDurationLockRecordForWrite
(Transaction
Transaction to associate lock with.
t
,
RecordHandle
Record to lock.
record
,
boolean
Lock is for a previous key of a insert.
lockForPreviousKey
,
boolean
Should lock request wait until granted?
waitForLock
)

Request a write lock which will be released immediately upon grant.

Field Detail

MODE_CONTAINERback to summary
public static final int MODE_CONTAINER

ContainerHandle level locking.

MODE_NONEback to summary
public static final int MODE_NONE

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

See Also
RawStoreFactory
MODE_RECORDback to summary
public static final int MODE_RECORD

Record level locking.

Method Detail

getModeback to summary
public int getMode()

Get the mode of this policy

lockContainerback to summary
public boolean lockContainer(Transaction t, ContainerHandle container, boolean waitForLock, boolean forUpdate) throws StandardException

Called when a container is opened.

Parameters
t:Transaction

Transaction to associate lock with.

container:ContainerHandle

Container to lock.

waitForLock:boolean

Should lock request wait until granted?

forUpdate:boolean

Should container be locked for update, or read?

Returns:boolean

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.

Exceptions
StandardException:
Standard Derby error policy
See Also
ContainerHandle
lockRecordForReadback to summary
public boolean lockRecordForRead(Transaction t, ContainerHandle container, RecordHandle record, boolean waitForLock, boolean forUpdate) throws StandardException

Called before a record is fetched.

Parameters
t:Transaction

Transaction to associate lock with.

container:ContainerHandle

Open Container used to get record. Will be used to row locks by the container they belong to.

record:RecordHandle

Record to lock.

waitForLock:boolean

Should lock request wait until granted?

forUpdate:boolean

Should container be locked for update, or read?

Exceptions
StandardException:
Standard Derby error policy
See Also
Page
lockRecordForWriteback to summary
public 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

Transaction to associate lock with.

record:RecordHandle

Record to lock.

lockForInsert:boolean

Lock is for an insert.

waitForLock:boolean

Should lock request wait until granted?

Returns:boolean

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.

Exceptions
StandardException:
Standard Derby error policy
See Also
Page
unlockContainerback to summary
public void unlockContainer(Transaction t, ContainerHandle container)

Called when a container is closed.

See Also
ContainerHandle, ContainerHandle#close
unlockRecordAfterReadback to summary
public void unlockRecordAfterRead(Transaction t, ContainerHandle container, RecordHandle record, boolean forUpdate, boolean row_qualified) throws StandardException

Called after a record has been fetched.

Exceptions
StandardException:
Standard Derby error policy
See Also
Page
zeroDurationLockRecordForWriteback to summary
public 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

Transaction to associate lock with.

record:RecordHandle

Record to lock.

lockForPreviousKey:boolean

Lock is for a previous key of a insert.

waitForLock:boolean

Should lock request wait until granted?

Returns:boolean

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.

Exceptions
StandardException:
Standard Derby error policy
See Also
Page