Package com.mckoi.database
Class SequenceManager
- java.lang.Object
-
- com.mckoi.database.SequenceManager
-
final class SequenceManager extends java.lang.Object
An object that manages the creation and removal of sequence keys, and that offers access to the sequence values (possibly cached). When the sequence table is changed, this opens an optimized transaction on the database and manipulates the SequenceInfo table.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
SequenceManager.SequenceGenerator
An object that encapsulates information about the sequence key.private static class
SequenceManager.SequenceInternalTableInfo
An object that models the list of sequences as table objects in a transaction.
-
Field Summary
Fields Modifier and Type Field Description private TableDataConglomerate
conglomerate
The TableDataConglomerate object.private static TObject
ONE_VAL
A static TObject that represents numeric 1.private java.util.HashMap
sequence_key_map
A hashmap that maps from the TableName of the sequence key to the object that manages this sequence (SequenceGenerator).private static TObject
TRUE_VAL
A static TObject that represents boolean true.
-
Constructor Summary
Constructors Constructor Description SequenceManager(TableDataConglomerate conglomerate)
Constructs the object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static void
addNativeTableGenerator(Transaction transaction, TableName table_name)
Static convenience - adds an entry to the Sequence table for a native table in the database.(package private) static InternalTableInfo
createInternalTableInfo(Transaction transaction)
Returns an InternalTableInfo object used to model the list of sequence generators that are accessible within the given Transaction object.(package private) static void
createSequenceGenerator(Transaction transaction, TableName table_name, long start_value, long increment_by, long min_value, long max_value, long cache, boolean cycle)
Creates a new sequence generator with the given name and details.(package private) long
curValue(SimpleTransaction transaction, TableName name)
Returns the current value from the sequence generator.(package private) static void
dropSequenceGenerator(Transaction transaction, TableName table_name)
(package private) void
flushGenerator(TableName name)
Flushes a sequence generator from the cache.private SequenceManager.SequenceGenerator
getGenerator(TableName name)
Returns a SequenceGenerator object representing the sequence generator with the given name.private Transaction
getTransaction()
Returns a new Transaction object for manipulating and querying the system state.(package private) long
nextValue(SimpleTransaction transaction, TableName name)
Returns the next value from the sequence generator.(package private) static void
removeNativeTableGenerator(Transaction transaction, TableName table_name)
Static convenience - removes an entry in the Sequence table for a native table in the database.(package private) void
setValue(SimpleTransaction transaction, TableName name, long value)
Sets the current value of the sequence generator.private void
updateGeneratorState(SequenceManager.SequenceGenerator generator)
Updates the state of the sequence key in the sequence tables in the database.
-
-
-
Field Detail
-
conglomerate
private TableDataConglomerate conglomerate
The TableDataConglomerate object.
-
sequence_key_map
private java.util.HashMap sequence_key_map
A hashmap that maps from the TableName of the sequence key to the object that manages this sequence (SequenceGenerator). (TableName) -> (SequenceGenerator)
-
ONE_VAL
private static final TObject ONE_VAL
A static TObject that represents numeric 1.
-
TRUE_VAL
private static final TObject TRUE_VAL
A static TObject that represents boolean true.
-
-
Constructor Detail
-
SequenceManager
SequenceManager(TableDataConglomerate conglomerate)
Constructs the object.
-
-
Method Detail
-
getTransaction
private Transaction getTransaction()
Returns a new Transaction object for manipulating and querying the system state.
-
getGenerator
private SequenceManager.SequenceGenerator getGenerator(TableName name)
Returns a SequenceGenerator object representing the sequence generator with the given name.
-
updateGeneratorState
private void updateGeneratorState(SequenceManager.SequenceGenerator generator)
Updates the state of the sequence key in the sequence tables in the database. The update occurs on an independant transaction.
-
flushGenerator
void flushGenerator(TableName name)
Flushes a sequence generator from the cache. This should be used when a sequence generator is altered or dropped from the database.
-
addNativeTableGenerator
static void addNativeTableGenerator(Transaction transaction, TableName table_name)
Static convenience - adds an entry to the Sequence table for a native table in the database. This acts as a gateway between the native sequence table function and the custom sequence generator. Note that some of the system tables and all of the VIEW tables will not have native sequence generators and thus not have an entry in the sequence table.
-
removeNativeTableGenerator
static void removeNativeTableGenerator(Transaction transaction, TableName table_name)
Static convenience - removes an entry in the Sequence table for a native table in the database.
-
createSequenceGenerator
static void createSequenceGenerator(Transaction transaction, TableName table_name, long start_value, long increment_by, long min_value, long max_value, long cache, boolean cycle)
Creates a new sequence generator with the given name and details. Note that this method does not check if the generator name clashes with an existing database object.
-
dropSequenceGenerator
static void dropSequenceGenerator(Transaction transaction, TableName table_name)
-
nextValue
long nextValue(SimpleTransaction transaction, TableName name)
Returns the next value from the sequence generator. This will atomically increment the sequence counter.
-
curValue
long curValue(SimpleTransaction transaction, TableName name)
Returns the current value from the sequence generator.
-
setValue
void setValue(SimpleTransaction transaction, TableName name, long value)
Sets the current value of the sequence generator.
-
createInternalTableInfo
static InternalTableInfo createInternalTableInfo(Transaction transaction)
Returns an InternalTableInfo object used to model the list of sequence generators that are accessible within the given Transaction object. This is used to model all sequence generators that have been defined as tables.
-
-