Package com.mckoi.database

## Class SimpleTransaction

- java.lang.Object
- - com.mckoi.database.SimpleTransaction

Direct Known Subclasses:
  `Transaction`

    public abstract class SimpleTransaction
    extends java.lang.Object

An 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.

Author:
  Tobias Downer

### Method Summary

All Methods Instance Methods Concrete Methods
`long` `currentUniqueID​(TableName table_name)` Returns the current unique id for the given table name.
`DebugLogger` `Debug()` Returns a DebugLogger object that we use to log debug messages to.
`protected void` `disposeAllIndices()` Disposes of all IndexSet objects currently accessed by this Transaction.
`protected com.mckoi.database.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.
`protected void` `flushTableCache​(TableName table_name)` Flushes the table cache and purges the cache of the entry for the given table name.
`DataTableDef` `getDataTableDef​(TableName table_name)` Returns the DataTableDef for the table with the given name that is visible within this transaction.
`protected DataTableDef` `getDynamicDataTableDef​(TableName table_name)` Returns the DataTableDef for a dynamic table defined in this transaction.
`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.
`protected TableName[]` `getDynamicTableList()` Returns a list of all dynamic table names.
`protected java.lang.String` `getDynamicTableType​(TableName table_name)` Returns a string type describing the type of the dynamic table.
`TransactionSystem` `getSystem()` Returns the TransactionSystem that this Transaction is part of.
`MutableTableDataSource` `getTable​(TableName table_name)` Returns a MutableTableDataSource object that represents the table with the given name within this transaction.
`TableDataSource` `getTableDataSource​(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.String` `getTableType​(TableName table_name)` Returns the type of the table object with the given name.
`protected com.mckoi.database.MasterTableDataSource` `getVisibleTable​(int n)` Returns a MasterTableDataSource object representing table 'n' in the set of tables visible in this transaction.
`protected int` `getVisibleTableCount()` Returns the number of visible tables being managed by this transaction.
`protected java.util.ArrayList` `getVisibleTables()` Returns a list of all visible tables.
`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.
`boolean` `isReadOnly()` Returns true if the transaction is read-only, otherwise returns false.
`long` `lastSequenceValue​(TableName name)` Returns the sequence value for the given sequence generator that was last returned by a call to 'nextSequenceValue'.
`long` `nextSequenceValue​(TableName name)` Requests of the sequence generator the next value from the sequence.
`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.
`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.
`protected void` `setIndexSetForTable​(com.mckoi.database.MasterTableDataSource table, IndexSet index_set)` Sets the IndexSet for the given MasterTableDataSource object in this transaction.
`void` `setReadOnly()` Sets this transaction as read only.
`void` `setSequenceValue​(TableName name, long value)` Sets the sequence value for the given sequence generator.
`void` `setUniqueID​(TableName table_name, long unique_id)` Sets the unique id for the given table name.
`boolean` `tableExists​(TableName table_name)` Returns true if the database table object with the given name exists within this transaction.
`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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### 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 com.mckoi.database.MasterTableDataSource getVisibleTable​(int n)

Returns a MasterTableDataSource object representing table 'n' in the set of tables visible in this transaction.

#### findVisibleTable

    protected com.mckoi.database.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.

#### setIndexSetForTable

    protected final void setIndexSetForTable​(com.mckoi.database.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)

#### flushTableCache

    protected void flushTableCache​(TableName table_name)

Flushes the table cache and purges the cache of the entry for the given table name.

#### 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.

#### 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.

#### 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.