private static class RecordLockContext.Perm extends RecordLockContext
RecordLockContext
which enables
intra-session record lock sharing across record buffers for permanent
database tables.Modifier and Type | Class and Description |
---|---|
private class |
RecordLockContext.Perm.LockState
The lock state of a particular record, which includes its current
lock type, its unique identifier, and the set of buffers which share
access to the backing lock.
|
Modifier and Type | Field and Description |
---|---|
private BufferManager |
bufferManager
Buffer manager which tracks buffer scopes
|
private java.util.Map<RecordBuffer,java.util.Set<RecordIdentifier>> |
locksByBuffer
Mapping of buffers to lock state sets
|
private java.util.Map<RecordIdentifier,RecordLockContext.Perm.LockState> |
lockStates
Mapping of record identifiers to lock states
|
private Persistence |
persistence
Persistence service object through which lock manager is accessed
|
Modifier | Constructor and Description |
---|---|
private |
Perm(Persistence persistence,
BufferManager bufferManager)
Constructor accessible only from within this class.
|
Modifier and Type | Method and Description |
---|---|
void |
forceRelease(RecordIdentifier ident,
RecordBuffer buffer)
Force the unconditional release of a lock.
|
private RecordLockContext.Perm.LockState |
getLockState(RecordIdentifier ident,
boolean create)
Get the
LockState object associated with the given
record identifier, optionally creating it if it does not yet exist. |
LockType |
lock(RecordIdentifier ident,
LockType requestedType,
long timeout,
RecordBuffer buffer)
Request that the communal lock on a record be acquired or otherwise
modified to match the requested type.
|
void |
registerBuffer(RecordIdentifier ident,
RecordBuffer buffer)
Register a record buffer to a particular record lock, which must
have been created previously.
|
java.util.Set<java.io.Serializable> |
relinquishBufferLocks(RecordBuffer buffer)
Attempt to release all locks associated with the given buffer.
|
java.util.Set<java.io.Serializable> |
transactionEnded()
Process any pending lock changes which have been deferred during the most recent
application level transaction.
|
get, lock
private final Persistence persistence
private final BufferManager bufferManager
private final java.util.Map<RecordIdentifier,RecordLockContext.Perm.LockState> lockStates
private final java.util.Map<RecordBuffer,java.util.Set<RecordIdentifier>> locksByBuffer
private Perm(Persistence persistence, BufferManager bufferManager)
persistence
- Persistence service object which will be used for access to
the global lock manager.bufferManager
- Buffer manager which tracks buffer scopes.public void registerBuffer(RecordIdentifier ident, RecordBuffer buffer)
Explicit deregistration of this association is unnecessary. It occurs implicitly when the lock is released and/or the buffer goes out of scope.
registerBuffer
in class RecordLockContext
ident
- Unique identifier for a particular database record.buffer
- Record buffer to be associated with the specified record
lock.public LockType lock(RecordIdentifier ident, LockType requestedType, long timeout, RecordBuffer buffer) throws LockUnavailableException, LockTimeoutException
The communal lock may or may not be modified immediately, according to the rules described in this class' description. Generally, a request to upgrade or acquire the lock for the first time is honored immediately. However, a request to downgrade or release the lock may be deferred.
lock
in class RecordLockContext
ident
- Unique identifier for a particular database record.requestedType
- The lock type being requested.timeout
- Positive number of milliseconds to wait to acquire lock before
raising an exception; specify 0 to wait indefinitely. Ignored if
a no-wait lock variant is requested.buffer
- Record buffer on whose behalf the request is being made.
May be null
in cases where the association
will be made later or if the lock is being managed for
framework housekeeping purposes.LockUnavailableException
- if a no-wait lock variant is requested, and another session
currently holds the lock. This will never be thrown in
cases where a downgrade or release is being requested.java.lang.IllegalStateException
- if an exclusive lock is requested outside an active
transaction.LockTimeoutException
- never.public java.util.Set<java.io.Serializable> relinquishBufferLocks(RecordBuffer buffer)
This method only should be invoked outside of a transaction.
relinquishBufferLocks
in class RecordLockContext
buffer
- Record buffer whose locks are being relinquished.null
if no locks were released. Does not
include locks which were downgraded to SHARE locks.public void forceRelease(RecordIdentifier ident, RecordBuffer buffer)
forceRelease
in class RecordLockContext
ident
- Record identifier.buffer
- Optional buffer whose pinned state should be updated in accordance with the
lock release.public java.util.Set<java.io.Serializable> transactionEnded()
transactionEnded
in class RecordLockContext
null
if no locks were released. Does not
include locks which were downgraded to SHARE locks.private RecordLockContext.Perm.LockState getLockState(RecordIdentifier ident, boolean create)
LockState
object associated with the given
record identifier, optionally creating it if it does not yet exist.ident
- Unique identifier for a particular database record.create
- If true
, create the lock state object if not
found; if false
, do not create it.LockState
for given identifier.