Package com.mckoi.database
Class LockHandle
- java.lang.Object
-
- com.mckoi.database.LockHandle
-
public final class LockHandle extends java.lang.Object
This represents a handle for a series of locks that a query has over the tables in a database. It is returned by the 'LockingMechanism' object after the 'lockTables' method is used.
-
-
Field Summary
Fields Modifier and Type Field Description private DebugLogger
debug
The DebugLogger object that we log debug messages to.private int
lock_index
A temporary index used during initialisation of object to add locks.private Lock[]
lock_list
The array of Lock objects that are being used in this locking process.private boolean
unlocked
Set when the 'unlockAll' method is called for the first time.
-
Constructor Summary
Constructors Constructor Description LockHandle(int lock_count, DebugLogger logger)
The Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
addLock(Lock lock)
Adds a new lock to the locks for this handle.void
checkAccess(DataTable table, int access_type)
Blocks until access to the given DataTable object is safe.void
finalize()
On garbage collection, this will call 'unlockAll' just in case the program did not use the 'LockingMechanism.unlockTables' method in error.java.lang.String
toString()
(package private) void
unlockAll()
Unlocks all the locks in this handle.
-
-
-
Field Detail
-
lock_list
private Lock[] lock_list
The array of Lock objects that are being used in this locking process.
-
lock_index
private int lock_index
A temporary index used during initialisation of object to add locks.
-
unlocked
private boolean unlocked
Set when the 'unlockAll' method is called for the first time.
-
debug
private final DebugLogger debug
The DebugLogger object that we log debug messages to.
-
-
Constructor Detail
-
LockHandle
LockHandle(int lock_count, DebugLogger logger)
The Constructor. Takes the number of locks that will be put into this handle.
-
-
Method Detail
-
addLock
void addLock(Lock lock)
Adds a new lock to the locks for this handle. NOTE: This method does not need to be synchronized because synchronization is handled by the 'LockingMechanism.lockTables' method.
-
unlockAll
void unlockAll()
Unlocks all the locks in this handle. This removes the locks from its table queue. NOTE: This method does not need to be synchronized because synchronization is handled by the 'LockingMechanism.unlockTables' method.
-
checkAccess
public void checkAccess(DataTable table, int access_type)
Blocks until access to the given DataTable object is safe. It blocks using either the read or read/write privs that it has been given. Note that this method is public and is a method that is intended to be used outside the locking mechanism. We also provide an 'access_type' field which is set to the type of access that is happening for this check. This is either Lock.READ or Lock.WRITE. NOTE: Any call to this method after the first call should be instantanious.
-
finalize
public void finalize()
On garbage collection, this will call 'unlockAll' just in case the program did not use the 'LockingMechanism.unlockTables' method in error. This should ensure the database does not deadlock. This method is a 'just in case' clause.- Overrides:
finalize
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-