|
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.Sequencer
Class with methods to handle unique numbers tables 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 "sequencertable". In MySQL, that table would have to be created like this:
create table sequencertable( name char(40) not null default "", value int not null default 0, accessors int not null default 0, unique(name) );The class itself implements all element functions that should be implemented to operate with the unique number generator.
Note that this class cannot be instantiated.
Field Summary | |
private static java.util.Random |
rndgen
|
static java.lang.String |
TABLENAME
|
Constructor Summary | |
private |
Sequencer()
|
Method Summary | |
static int |
checkIntegrity(java.sql.Statement stmt)
Checks and restores the integrity of the unique number generators' table. |
static boolean |
create(java.sql.Statement stmt,
java.lang.String name)
Create a new unique number generator with the given name. |
static void |
drop(java.sql.Statement stmt,
java.lang.String name)
Drops the unique number generator with the given name. |
static boolean |
exists(java.sql.Statement stmt,
java.lang.String name)
Checks whether there is a unique number generator with the given name. |
static int |
getNext(java.sql.Statement stmt,
java.lang.String name)
Returns next unique number of the given generator. |
static int |
getNext(java.sql.Statement stmt,
java.lang.String name,
java.lang.String tablename,
java.lang.String column,
java.lang.String addwhere)
Returns the next unique number from generator and guarantees that it does not already exist in tablenames column. |
static int |
getThis(java.sql.Statement stmt,
java.lang.String name)
Returns the last returned number of the generator. |
private static void |
lock(java.sql.Statement stmt,
java.lang.String name)
Locking method. |
static void |
store(java.sql.Statement stmt,
java.lang.String name,
int value)
Stores a new value in the unique number generator. |
static boolean |
storeIfGreater(java.sql.Statement stmt,
java.lang.String name,
int value)
Stores a new value in the generator, but only if it is greater than the currently stored number. |
private static void |
unlock(java.sql.Statement stmt,
java.lang.String name)
Releases monitor for generator. |
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 Sequencer()
Method Detail |
public static final boolean create(java.sql.Statement stmt, java.lang.String name) throws java.sql.SQLException
java.sql.SQLException
public static final boolean exists(java.sql.Statement stmt, java.lang.String name) throws java.sql.SQLException
java.sql.SQLException
public static final void drop(java.sql.Statement stmt, java.lang.String name) throws java.sql.SQLException
java.sql.SQLException
public static final int checkIntegrity(java.sql.Statement stmt) throws java.sql.SQLException
java.sql.SQLException
public static final int getNext(java.sql.Statement stmt, java.lang.String name) throws java.sql.SQLException
java.sql.SQLException
public static final int getNext(java.sql.Statement stmt, java.lang.String name, java.lang.String tablename, java.lang.String column, java.lang.String addwhere) throws java.sql.SQLException
The method is also completely threadsafe when it comes to the generator. To close all loopholes for other threads which add the number on their own, there should also be an additional locking of the table in question for insertions in general. Otherwise, the external insertion thread could insert an entry with a number which just has been identified as "free" by this method - before it sets the number itself. This method does itself not impose any locks on the other table.
The method's efficiency decreases if there are huge blocks of contiguous numbers which have been assigned from outside the generator.
stmt
- The database statementname
- Name of the sequencer to take the unique number fromtablename
- Table in which the number is insertedcolumn
- Row in which the number can be found lateraddwhere
- Additional constraints for the uniqueness test. Null if not applicable.
java.sql.SQLException
public static final int getThis(java.sql.Statement stmt, java.lang.String name) throws java.sql.SQLException
java.sql.SQLException
public static final void store(java.sql.Statement stmt, java.lang.String name, int value) throws java.sql.SQLException
java.sql.SQLException
public static final boolean storeIfGreater(java.sql.Statement stmt, java.lang.String name, int value) throws java.sql.SQLException
java.sql.SQLException
private static final void lock(java.sql.Statement stmt, java.lang.String name) throws java.sql.SQLException
java.sql.SQLException
private static final void unlock(java.sql.Statement stmt, java.lang.String name) 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 |