|
QJCC homepage | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object biz.chitec.quarterback.util.RowLock
Class to lock unique rows of tables against concurrent access using a database that doesn't support this on its own. This class consists only of static methods that operate on a JDBC-Statement to access a table "rowlocktable". In MySQL, that table would have to be created like this:
create table rowlocktable( tablename char(40) not null, rownr int not null, unique(tablename,rownr) );The class itself implements all element functions that should be implemented to operate with locks.
Note that this class cannot be instantiated.
Field Summary | |
private static java.util.Random |
rndgen
|
static java.lang.String |
TABLENAME
|
Constructor Summary | |
private |
RowLock()
|
Method Summary | |
static int |
checkIntegrity(java.sql.Statement stmt)
Checks and restores the integrity of the locks table. |
static void |
lock(java.sql.Statement stmt,
java.lang.String table)
Obtain monitor for complete table and always wait for semaphore. |
static void |
lock(java.sql.Statement stmt,
java.lang.String table,
boolean waitforsemaphore)
Obtain monitor for complete table and wait for semaphore if said so. |
static void |
lock(java.sql.Statement stmt,
java.lang.String table,
int row)
Aquires semaphore and waits for it. |
static void |
lock(java.sql.Statement stmt,
java.lang.String table,
int row,
boolean waitforsemaphore)
Main implementation of semaphone aquisition. |
static void |
lock(java.sql.Statement stmt,
java.lang.String table,
int row,
long waitmillis)
Main implementation of semaphone aquisition. |
static void |
lock(java.sql.Statement stmt,
java.lang.String table,
long waitmillis)
Obtain monitor for complete table and wait for semaphore if said so. |
static void |
unlock(java.sql.Statement stmt,
java.lang.String table)
Releases table-wide monitor. |
static void |
unlock(java.sql.Statement stmt,
java.lang.String table,
int row)
Releases monitor for row in table. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String TABLENAME
private static final java.util.Random rndgen
Constructor Detail |
private RowLock()
Method Detail |
public static final int checkIntegrity(java.sql.Statement stmt) throws java.sql.SQLException
java.sql.SQLException
public static final void lock(java.sql.Statement stmt, java.lang.String table, int row, long waitmillis) throws java.sql.SQLException
Long.MAX_VALUE
, the method will wait indefinitely which could lead to a deadlock.
stmt
- Statement to work on the database withtable
- Name of table to aquire lock for. Just a general key.row
- Row in the table to obtain lock for. Can be -1 for general locks.waitmillis
- Maximum time to wait in milliseconds to catch the semaphore. Actual waiting can be up to 300 milliseconds more.
java.util.ConcurrentModificationException
- If semaphore could not be aquired
java.sql.SQLException
public static final void lock(java.sql.Statement stmt, java.lang.String table, int row, boolean waitforsemaphore) throws java.sql.SQLException
stmt
- Statement to work on the database withtable
- Name of table to aquire lock for. Just a general key.row
- Row in the table to obtain lock for. Can be -1 for general locks.waitforsemaphore
- Flag whether method should wait for semaphore of throw an exception if aquisition fails
java.util.ConcurrentModificationException
- If semaphore could not be aquired
java.sql.SQLException
public static final void lock(java.sql.Statement stmt, java.lang.String table, int row) throws java.sql.SQLException
stmt
- Statement to work on the database withtable
- Name of table to aquire lock for. Just a general key.row
- Row in the table to obtain lock for. Can be -1 for general locks.
java.sql.SQLException
public static final void unlock(java.sql.Statement stmt, java.lang.String table, int row) throws java.sql.SQLException
java.sql.SQLException
public static final void lock(java.sql.Statement stmt, java.lang.String table, boolean waitforsemaphore) throws java.sql.SQLException
java.sql.SQLException
public static final void lock(java.sql.Statement stmt, java.lang.String table, long waitmillis) throws java.sql.SQLException
java.sql.SQLException
public static final void lock(java.sql.Statement stmt, java.lang.String table) throws java.sql.SQLException
java.sql.SQLException
public static final void unlock(java.sql.Statement stmt, java.lang.String table) throws java.sql.SQLException
java.sql.SQLException
|
QJCC homepage | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |