Class SimpleTransaction
- java.lang.Object
-
- com.mckoi.database.SimpleTransaction
-
- Direct Known Subclasses:
Transaction
public abstract class SimpleTransaction extends java.lang.ObjectAn simple implementation of Transaction that provides various facilities for implementing a Transaction object on a number of MasterTableDataSource tables. The Transaction object is designed such that concurrent modification can happen to the database via other transactions without this view of the database being changed.This object does not implement any transaction control mechanisms such as 'commit' or 'rollback'. This object is most useful for setting up a short-term minimal transaction for modifying or querying some data in the database given on some view.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.ArrayListcleanup_queueA queue of MasterTableDataSource and IndexSet objects that are pending to be cleaned up when this transaction is disposed.private booleanread_onlyIf true, this is a read-only transaction and does not permit any type of modification to this vew of the database.private SequenceManagersequence_managerThe SequenceManager for this abstract transaction.private java.util.HashMapsequence_value_cacheA local cache for sequence values.private TransactionSystemsystemThe TransactionSystem context.private java.util.HashMaptable_cacheA cache of tables that have been accessed via this transaction.private java.util.ArrayListtable_indicesAn IndexSet for each visible table from the above list.private java.util.ArrayListvisible_tablesThe list of tables that represent this transaction's view of the database.
-
Constructor Summary
Constructors Constructor Description SimpleTransaction(TransactionSystem system, SequenceManager sequence_manager)Constructs the AbstractTransaction.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) voidaddVisibleTable(MasterTableDataSource table, IndexSet index_set)Adds a MasterTableDataSource and IndexSet to this transaction view.(package private) abstract MutableTableDataSourcecreateMutableTableDataSourceAtCommit(MasterTableDataSource master)Returns a new MutableTableDataSource for the view of the MasterTableDataSource at the start of this transaction.longcurrentUniqueID(TableName table_name)Returns the current unique id for the given table name.DebugLoggerDebug()Returns a DebugLogger object that we use to log debug messages to.protected voiddisposeAllIndices()Disposes of all IndexSet objects currently accessed by this Transaction.protected MasterTableDataSourcefindVisibleTable(TableName table_name, boolean ignore_case)Searches through the list of tables visible within this transaction and returns the MasterTableDataSource object with the given name.(package private) voidflushSequenceManager(TableName name)Flushes the sequence cache.protected voidflushTableCache(TableName table_name)Flushes the table cache and purges the cache of the entry for the given table name.DataTableDefgetDataTableDef(TableName table_name)Returns the DataTableDef for the table with the given name that is visible within this transaction.protected DataTableDefgetDynamicDataTableDef(TableName table_name)Returns the DataTableDef for a dynamic table defined in this transaction.protected MutableTableDataSourcegetDynamicTable(TableName table_name)If this transaction implementation defines dynamic tables (tables whose content is determined by some function), this should return the table here as a MutableTableDataSource object.protected TableName[]getDynamicTableList()Returns a list of all dynamic table names.protected java.lang.StringgetDynamicTableType(TableName table_name)Returns a string type describing the type of the dynamic table.(package private) IndexSetgetIndexSetForTable(MasterTableDataSource table)Returns the IndexSet for the given MasterTableDataSource object that is visible in this transaction.TransactionSystemgetSystem()Returns the TransactionSystem that this Transaction is part of.MutableTableDataSourcegetTable(TableName table_name)Returns a MutableTableDataSource object that represents the table with the given name within this transaction.TableDataSourcegetTableDataSource(TableName table_name)Returns a TableDataSource object that represents the table with the given name within this transaction.TableName[]getTableList()Returns a list of table names that are visible within this transaction.java.lang.StringgetTableType(TableName table_name)Returns the type of the table object with the given name.protected MasterTableDataSourcegetVisibleTable(int n)Returns a MasterTableDataSource object representing table 'n' in the set of tables visible in this transaction.protected intgetVisibleTableCount()Returns the number of visible tables being managed by this transaction.protected java.util.ArrayListgetVisibleTables()Returns a list of all visible tables.protected booleanisDynamicTable(TableName table_name)Returns true if the given table name is a dynamically generated table and is not a table that is found in the table list defined in this transaction object.booleanisReadOnly()Returns true if the transaction is read-only, otherwise returns false.longlastSequenceValue(TableName name)Returns the sequence value for the given sequence generator that was last returned by a call to 'nextSequenceValue'.longnextSequenceValue(TableName name)Requests of the sequence generator the next value from the sequence.longnextUniqueID(TableName table_name)Atomically returns a unique id that can be used as a seed for a set of unique identifiers for a table.(package private) booleanrealTableExists(TableName table_name)Returns true if the table with the given name exists within this transaction.(package private) voidremoveVisibleTable(MasterTableDataSource table)Removes a MasterTableDataSource (and its IndexSet) from this view and puts the information on the cleanup queue.TableNameresolveToTableName(java.lang.String current_schema, java.lang.String name, boolean case_insensitive)Resolves the given string to a table name, throwing an exception if the reference is ambiguous.protected voidsetIndexSetForTable(MasterTableDataSource table, IndexSet index_set)Sets the IndexSet for the given MasterTableDataSource object in this transaction.voidsetReadOnly()Sets this transaction as read only.voidsetSequenceValue(TableName name, long value)Sets the sequence value for the given sequence generator.voidsetUniqueID(TableName table_name, long unique_id)Sets the unique id for the given table name.booleantableExists(TableName table_name)Returns true if the database table object with the given name exists within this transaction.TableNametryResolveCase(TableName table_name)Attempts to resolve the given table name to its correct case assuming the table name represents a case insensitive version of the name.(package private) voidupdateVisibleTable(MasterTableDataSource table, IndexSet index_set)Updates a MastertableDataSource (and its IndexSet) for this view.
-
-
-
Field Detail
-
system
private TransactionSystem system
The TransactionSystem context.
-
visible_tables
private java.util.ArrayList visible_tables
The list of tables that represent this transaction's view of the database. (MasterTableDataSource).
-
table_indices
private java.util.ArrayList table_indices
An IndexSet for each visible table from the above list. These objects are used to represent index information for all tables. (IndexSet)
-
cleanup_queue
private java.util.ArrayList cleanup_queue
A queue of MasterTableDataSource and IndexSet objects that are pending to be cleaned up when this transaction is disposed.
-
table_cache
private java.util.HashMap table_cache
A cache of tables that have been accessed via this transaction. This is a map of table_name -> MutableTableDataSource.
-
sequence_value_cache
private java.util.HashMap sequence_value_cache
A local cache for sequence values.
-
sequence_manager
private SequenceManager sequence_manager
The SequenceManager for this abstract transaction.
-
read_only
private boolean read_only
If true, this is a read-only transaction and does not permit any type of modification to this vew of the database.
-
-
Constructor Detail
-
SimpleTransaction
SimpleTransaction(TransactionSystem system, SequenceManager sequence_manager)
Constructs the AbstractTransaction. SequenceManager may be null in which case sequence generator operations are not permitted.
-
-
Method Detail
-
setReadOnly
public void setReadOnly()
Sets this transaction as read only. A read only transaction does not allow for the view to be modified in any way.
-
isReadOnly
public boolean isReadOnly()
Returns true if the transaction is read-only, otherwise returns false.
-
getSystem
public final TransactionSystem getSystem()
Returns the TransactionSystem that this Transaction is part of.
-
getVisibleTables
protected final java.util.ArrayList getVisibleTables()
Returns a list of all visible tables.
-
Debug
public final DebugLogger Debug()
Returns a DebugLogger object that we use to log debug messages to.
-
getVisibleTableCount
protected int getVisibleTableCount()
Returns the number of visible tables being managed by this transaction.
-
getVisibleTable
protected MasterTableDataSource getVisibleTable(int n)
Returns a MasterTableDataSource object representing table 'n' in the set of tables visible in this transaction.
-
findVisibleTable
protected MasterTableDataSource findVisibleTable(TableName table_name, boolean ignore_case)
Searches through the list of tables visible within this transaction and returns the MasterTableDataSource object with the given name. Returns null if no visible table with the given name could be found.
-
getIndexSetForTable
final IndexSet getIndexSetForTable(MasterTableDataSource table)
Returns the IndexSet for the given MasterTableDataSource object that is visible in this transaction.
-
setIndexSetForTable
protected final void setIndexSetForTable(MasterTableDataSource table, IndexSet index_set)
Sets the IndexSet for the given MasterTableDataSource object in this transaction.
-
isDynamicTable
protected boolean isDynamicTable(TableName table_name)
Returns true if the given table name is a dynamically generated table and is not a table that is found in the table list defined in this transaction object.It is intended this is implemented by derived classes to handle dynamically generated tables (tables based on some function or from an external data source)
-
getDynamicTable
protected MutableTableDataSource getDynamicTable(TableName table_name)
If this transaction implementation defines dynamic tables (tables whose content is determined by some function), this should return the table here as a MutableTableDataSource object. If the table is not defined an exception is generated.It is intended this is implemented by derived classes to handle dynamically generated tables (tables based on some function or from an external data source)
-
getDynamicDataTableDef
protected DataTableDef getDynamicDataTableDef(TableName table_name)
Returns the DataTableDef for a dynamic table defined in this transaction.It is intended this is implemented by derived classes to handle dynamically generated tables (tables based on some function or from an external data source)
-
getDynamicTableType
protected java.lang.String getDynamicTableType(TableName table_name)
Returns a string type describing the type of the dynamic table.It is intended this is implemented by derived classes to handle dynamically generated tables (tables based on some function or from an external data source)
-
getDynamicTableList
protected TableName[] getDynamicTableList()
Returns a list of all dynamic table names. We can assume that the object returned here is static so the content of this list should not be changed.It is intended this is implemented by derived classes to handle dynamically generated tables (tables based on some function or from an external data source)
-
createMutableTableDataSourceAtCommit
abstract MutableTableDataSource createMutableTableDataSourceAtCommit(MasterTableDataSource master)
Returns a new MutableTableDataSource for the view of the MasterTableDataSource at the start of this transaction. Note that this is called only once per table accessed in this transaction.
-
flushTableCache
protected void flushTableCache(TableName table_name)
Flushes the table cache and purges the cache of the entry for the given table name.
-
addVisibleTable
void addVisibleTable(MasterTableDataSource table, IndexSet index_set)
Adds a MasterTableDataSource and IndexSet to this transaction view.
-
removeVisibleTable
void removeVisibleTable(MasterTableDataSource table)
Removes a MasterTableDataSource (and its IndexSet) from this view and puts the information on the cleanup queue.
-
updateVisibleTable
void updateVisibleTable(MasterTableDataSource table, IndexSet index_set)
Updates a MastertableDataSource (and its IndexSet) for this view. The existing IndexSet/MasterTableDataSource for this is put on the clean up queue.
-
disposeAllIndices
protected void disposeAllIndices()
Disposes of all IndexSet objects currently accessed by this Transaction. This includes IndexSet objects on tables that have been dropped by operations on this transaction and are in the 'cleanup_queue' object. Disposing of the IndexSet is a common cleanup practice and would typically be used at the end of a transaction.
-
getTableDataSource
public TableDataSource getTableDataSource(TableName table_name)
Returns a TableDataSource object that represents the table with the given name within this transaction. This table is represented by an immutable interface.
-
getTable
public MutableTableDataSource getTable(TableName table_name)
Returns a MutableTableDataSource object that represents the table with the given name within this transaction. Any changes made to this table are only made within the context of this transaction. This means if a row is added or removed, it is not made perminant until the transaction is committed.If the table does not exist then an exception is thrown.
-
getDataTableDef
public DataTableDef getDataTableDef(TableName table_name)
Returns the DataTableDef for the table with the given name that is visible within this transaction.Returns null if table name doesn't refer to a table that exists.
-
getTableList
public TableName[] getTableList()
Returns a list of table names that are visible within this transaction.
-
tableExists
public boolean tableExists(TableName table_name)
Returns true if the database table object with the given name exists within this transaction.
-
realTableExists
final boolean realTableExists(TableName table_name)
Returns true if the table with the given name exists within this transaction. This is different from 'tableExists' because it does not try to resolve against dynamic tables, and is therefore useful for quickly checking if a system table exists or not.
-
tryResolveCase
public TableName tryResolveCase(TableName table_name)
Attempts to resolve the given table name to its correct case assuming the table name represents a case insensitive version of the name. For example, "aPP.CuSTOMer" may resolve to "APP.Customer". If the table name can not resolve to a valid identifier it returns the input table name, therefore the actual presence of the table should always be checked by calling 'tableExists' after this method returns.
-
getTableType
public java.lang.String getTableType(TableName table_name)
Returns the type of the table object with the given name. If the table is a base table, this method returns "TABLE". If it is a virtual table, it returns the type assigned to by the InternalTableInfo interface.
-
resolveToTableName
public TableName resolveToTableName(java.lang.String current_schema, java.lang.String name, boolean case_insensitive)
Resolves the given string to a table name, throwing an exception if the reference is ambiguous. This also generates an exception if the table object is not found.
-
flushSequenceManager
void flushSequenceManager(TableName name)
Flushes the sequence cache. This should be used whenever a sequence is changed.
-
nextSequenceValue
public long nextSequenceValue(TableName name)
Requests of the sequence generator the next value from the sequence.NOTE: This does NOT check that the user owning this connection has the correct privs to perform this operation.
-
lastSequenceValue
public long lastSequenceValue(TableName name)
Returns the sequence value for the given sequence generator that was last returned by a call to 'nextSequenceValue'. If a value was not last returned by a call to 'nextSequenceValue' then a statement exception is generated.NOTE: This does NOT check that the user owning this connection has the correct privs to perform this operation.
-
setSequenceValue
public void setSequenceValue(TableName name, long value)
Sets the sequence value for the given sequence generator. If the generator does not exist or it is not possible to set the value for the generator then an exception is generated.NOTE: This does NOT check that the user owning this connection has the correct privs to perform this operation.
-
currentUniqueID
public long currentUniqueID(TableName table_name)
Returns the current unique id for the given table name. Note that this is NOT a view of the ID, it is the actual ID value at this time regardless of transaction.
-
nextUniqueID
public long nextUniqueID(TableName table_name)
Atomically returns a unique id that can be used as a seed for a set of unique identifiers for a table. Values returned by this method are guarenteed unique within this table. This is true even across transactions.NOTE: This change can not be rolled back.
-
setUniqueID
public void setUniqueID(TableName table_name, long unique_id)
Sets the unique id for the given table name. This must only be called under very controlled situations, such as when altering a table or when we need to fix sequence corruption.
-
-