| java.lang.Object com.mckoi.database.SimpleTransaction com.mckoi.database.Transaction
Transaction | public class Transaction extends SimpleTransaction (Code) | | An open transaction that manages all data access to the
TableDataConglomerate. A transaction sees a view of the data as it was when
the transaction was created. It also sees any modifications that were made
within the context of this transaction. It does not see modifications made
by other open transactions.
A transaction ends when it is committed or rollbacked. All operations
on this transaction object only occur within the context of this transaction
and are not permanent changes to the database structure. Only when the
transaction is committed are changes reflected in the master data.
author: Tobias Downer |
Inner Class :public static class ColumnGroup | |
Inner Class :public static class CheckExpression | |
Inner Class :public static class ColumnGroupReference | |
Method Summary | |
public void | addCheckConstraint(TableName table_name, Expression expression, short deferred, String constraint_name) Adds a check expression that becomes perminent when the transaction
is committed. | public void | addForeignKeyConstraint(TableName table, String[] cols, TableName ref_table, String[] ref_cols, String delete_rule, String update_rule, short deferred, String constraint_name) Adds a foreign key constraint to the database which becomes perminent
when the transaction is committed. | void | addInternalTableInfo(InternalTableInfo info) Adds an internal table container (InternalTableInfo) used to
resolve internal tables. | public void | addPrimaryKeyConstraint(TableName table_name, String[] cols, short deferred, String constraint_name) Adds a primary key constraint that becomes perminent when the transaction
is committed. | public void | addSelectedFromTable(TableName table_name) Called by the query evaluation layer when information is selected
from this table as part of this transaction. | public void | addUniqueConstraint(TableName table_name, String[] cols, short deferred, String constraint_name) Adds a unique constraint to the database which becomes perminant when
the transaction is committed. | public void | alterCreateTable(DataTableDef table_def, int data_sector_size, int index_sector_size) Given a DataTableDef, if the table exists then it is updated otherwise
if it doesn't exist then it is created.
This should only be used as very fine grain optimization for creating/
altering tables. | public void | alterTable(TableName table_name, DataTableDef table_def, int data_sector_size, int index_sector_size) Alter the table with the given name to the new definition and give the
copied table a new data sector size. | public void | alterTable(TableName table_name, DataTableDef table_def) Alters the table with the given name within this transaction to the
specified table definition. | public void | checkAllConstraints(TableName table_name) Checks all the rows in the table for immediate constraint violations
and when the transaction is next committed check for all deferred
constraint violations. | public void | closeAndCommit() Closes and marks a transaction as committed. | public void | closeAndRollback() Closes and rolls back a transaction as if the commands the transaction ran
never happened. | public void | compactTable(TableName table_name) Compacts the table with the given name within this transaction. | public void | copyTable(MasterTableDataSource src_master_table, IndexSet index_set) Generates an exact copy of the table within this transaction. | public MutableTableDataSource | createMutableTableDataSourceAtCommit(MasterTableDataSource master) Overwritten from SimpleTransaction.
Returns a new MutableTableDataSource for the view of the
MasterTableDataSource at the start of this transaction. | public void | createSchema(String name, String type) Create a new schema in this transaction. | public void | createSequenceGenerator(TableName 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 TableName and
initializes it with the given details. | public void | createTable(DataTableDef table_def, int data_sector_size, int index_sector_size) Creates a new table within this transaction with the given sector size. | public void | createTable(DataTableDef table_def) Creates a new table within this transaction. | void | databaseObjectCreated(TableName table_name) Notifies this transaction that a database object with the given name has
successfully been created. | void | databaseObjectDropped(TableName table_name) Notifies this transaction that a database object with the given name has
successfully been dropped. | void | dispose() Disposes this transaction without rolling back or committing the changes. | public void | dropAllConstraintsForTable(TableName table_name) Drops all the constraints defined for the given table. | public boolean | dropCheckConstraintForTable(TableName table, String constraint_name) Drops a single named check constraint from the given table. | public boolean | dropForeignKeyReferenceConstraintForTable(TableName table, String constraint_name) Drops a single named foreign key reference from the given table. | public int | dropNamedConstraint(TableName table_name, String constraint_name) Drops the named constraint from the transaction. | public boolean | dropPrimaryKeyConstraintForTable(TableName table_name, String constraint_name) Drops the primary key constraint for the given table. | public void | dropSchema(String name) Drops a schema from this transaction. | public void | dropSequenceGenerator(TableName name) Drops an existing sequence generator with the given name. | public void | dropTable(TableName table_name) Drops a table within this transaction. | public boolean | dropUniqueConstraintForTable(TableName table, String constraint_name) Drops a single named unique constraint from the given table. | public void | finalize() Finalize, we should close the transaction. | ArrayList | getAllNamesCreated() Returns the normalized list of database object names created in this
transaction. | ArrayList | getAllNamesDropped() Returns the normalized list of database object names dropped in this
transaction. | long | getCommitID() Returns the 'commit_id' which is the last commit that occured before
this transaction was created.
NOTE: Don't make this synchronized over anything. | final TableDataConglomerate | getConglomerate() Returns the TableDataConglomerate of this transaction. | protected DataTableDef | getDynamicDataTableDef(TableName table_name) Returns the DataTableDef for the given internal table. | protected MutableTableDataSource | getDynamicTable(TableName table_name) Returns an instance of MutableDataTableSource that represents the
contents of the internal table with the given name. | protected TableName[] | getDynamicTableList() Returns a list of all dynamic table names. | public String | getDynamicTableType(TableName table_name) Returns a string type describing the type of the dynamic table. | public String | getPersistantVar(String variable) Returns the value of the persistent variable with the given name or null
if it doesn't exist. | public SchemaDef[] | getSchemaList() Returns an array of SchemaDef objects for each schema currently setup in
the database. | protected boolean | isDynamicTable(TableName table_name) Returns true if the given table name represents a dynamically generated
system table. | void | liveCopyAllDataTo(TableDataConglomerate dest_conglomerate) Copies all the tables within this transaction view to the destination
conglomerate object. | public static CheckExpression[] | queryTableCheckExpressions(SimpleTransaction transaction, TableName table_name) Returns a set of check expressions that are constrained over all new
columns added to the given table in this transaction. | public static ColumnGroupReference[] | queryTableForeignKeyReferences(SimpleTransaction transaction, TableName table_name) Returns an array of column references in the given table that represent
foreign key references. | public static ColumnGroupReference[] | queryTableImportedForeignKeyReferences(SimpleTransaction transaction, TableName ref_table_name) Returns an array of column references in the given table that represent
foreign key references that reference columns in the given table. | public static ColumnGroup | queryTablePrimaryKeyGroup(SimpleTransaction transaction, TableName table_name) Returns a set of primary key groups that are constrained to be unique
for the given table in this transaction (there can be only 1 primary
key defined for a table). | public static ColumnGroup[] | queryTableUniqueGroups(SimpleTransaction transaction, TableName table_name) Returns a set of unique groups that are constrained to be unique for
the given table in this transaction. | public static TableName[] | queryTablesRelationallyLinkedTo(SimpleTransaction transaction, TableName table) Returns the list of tables (as a TableName array) that are dependant
on the data in the given table to maintain referential consistancy. | public SchemaDef | resolveSchemaCase(String name, boolean ignore_case) Resolves the case of the given schema name if the database is performing
case insensitive identifier matching. | public boolean | schemaExists(String name) Returns true if the schema exists within this transaction. | void | setErrorOnDirtySelect(boolean status) Sets the transaction error on dirty select for this transaction. | public void | setPersistentVar(String variable, String value) Sets a persistent variable of the database that becomes a committed
change once this transaction is committed. | boolean | transactionErrorOnDirtySelect() Returns true if the conglomerate commit procedure should check for
dirty selects and produce a transaction error. |
INITIALLY_DEFERRED | final public static short INITIALLY_DEFERRED(Code) | | The type of deferrance.
|
INITIALLY_IMMEDIATE | final public static short INITIALLY_IMMEDIATE(Code) | | |
NOT_DEFERRABLE | final public static short NOT_DEFERRABLE(Code) | | |
NO_ACTION | final public static String NO_ACTION(Code) | | Foreign key referential trigger actions.
|
addCheckConstraint | public void addCheckConstraint(TableName table_name, Expression expression, short deferred, String constraint_name)(Code) | | Adds a check expression that becomes perminent when the transaction
is committed. A check expression is an expression that must evaluate
to true for all records added/updated in the database.
NOTE: Security checks for adding constraints must be checked for at a
higher layer.
NOTE: We must guarentee that the transaction be in exclusive mode before
this method is called.
|
addForeignKeyConstraint | public void addForeignKeyConstraint(TableName table, String[] cols, TableName ref_table, String[] ref_cols, String delete_rule, String update_rule, short deferred, String constraint_name)(Code) | | Adds a foreign key constraint to the database which becomes perminent
when the transaction is committed. A foreign key represents a referential
link from one table to another (may be the same table). The 'table_name',
'cols' args represents the object to link from. The 'ref_table',
'ref_cols' args represents the object to link to. The update rules are
for specifying cascading delete/update rules. The deferred arg is for
IMMEDIATE/DEFERRED checking.
NOTE: Security checks for adding constraints must be checked for at a
higher layer.
NOTE: We must guarentee that the transaction be in exclusive mode before
this method is called.
|
addInternalTableInfo | void addInternalTableInfo(InternalTableInfo info)(Code) | | Adds an internal table container (InternalTableInfo) used to
resolve internal tables. This is intended as a way for the
DatabaseConnection layer to plug in 'virtual' tables, such as those
showing connection statistics, etc. It also allows modelling database
objects as tables, such as sequences, triggers, procedures, etc.
|
addPrimaryKeyConstraint | public void addPrimaryKeyConstraint(TableName table_name, String[] cols, short deferred, String constraint_name)(Code) | | Adds a primary key constraint that becomes perminent when the transaction
is committed. A primary key represents a set of columns in a table
that are constrained to be unique and can not be null. If the
constraint name parameter is 'null' a primary key constraint is created
with a unique constraint name.
NOTE: Security checks for adding constraints must be checked for at a
higher layer.
NOTE: We must guarentee that the transaction be in exclusive mode before
this method is called.
|
addSelectedFromTable | public void addSelectedFromTable(TableName table_name)(Code) | | Called by the query evaluation layer when information is selected
from this table as part of this transaction. When there is a select
query on a table, when the transaction is committed we should look for
any concurrently committed changes to the table. If there are any, then
any selects on the table should be considered incorrect and cause a
commit failure.
|
addUniqueConstraint | public void addUniqueConstraint(TableName table_name, String[] cols, short deferred, String constraint_name)(Code) | | Adds a unique constraint to the database which becomes perminant when
the transaction is committed. Columns in a table that are defined as
unique are prevented from being duplicated by the engine.
NOTE: Security checks for adding constraints must be checked for at a
higher layer.
NOTE: We must guarentee that the transaction be in exclusive mode before
this method is called.
|
alterCreateTable | public void alterCreateTable(DataTableDef table_def, int data_sector_size, int index_sector_size)(Code) | | Given a DataTableDef, if the table exists then it is updated otherwise
if it doesn't exist then it is created.
This should only be used as very fine grain optimization for creating/
altering tables. If in the future the underlying table model is changed
so that the given 'sector_size' value is unapplicable, then the value
will be ignored.
|
alterTable | public void alterTable(TableName table_name, DataTableDef table_def, int data_sector_size, int index_sector_size)(Code) | | Alter the table with the given name to the new definition and give the
copied table a new data sector size. If the table does not exist then
an exception is thrown.
This copies all columns that were in the original table to the new
altered table if the name is the same. Any names that don't exist are
set to the default value.
This should only be called under an exclusive lock on the connection.
|
alterTable | public void alterTable(TableName table_name, DataTableDef table_def)(Code) | | Alters the table with the given name within this transaction to the
specified table definition. If the table does not exist then an exception
is thrown.
This should only be called under an exclusive lock on the connection.
|
checkAllConstraints | public void checkAllConstraints(TableName table_name)(Code) | | Checks all the rows in the table for immediate constraint violations
and when the transaction is next committed check for all deferred
constraint violations. This method is used when the constraints on a
table changes and we need to determine if any constraint violations
occurred. To the constraint checking system, this is like adding all
the rows to the given table.
|
closeAndCommit | public void closeAndCommit() throws TransactionException(Code) | | Closes and marks a transaction as committed. Any changes made by this
transaction are seen by all transactions created after this method
returns.
This method will fail under the following circumstances:
- There are any rows deleted in this transaction that were deleted
by another successfully committed transaction.
- There were rows added in another committed transaction that would
change the result of the search clauses committed by this transaction.
The first check is not too difficult to check for. The second is very
difficult however we need it to ensure TRANSACTION_SERIALIZABLE isolation
is enforced. We may have to simplify this by throwing a transaction
exception if the table has had any changes made to it during this
transaction.
This should only be called under an exclusive lock on the connection.
|
closeAndRollback | public void closeAndRollback()(Code) | | Closes and rolls back a transaction as if the commands the transaction ran
never happened. This will not throw a transaction exception.
This should only be called under an exclusive lock on the connection.
|
compactTable | public void compactTable(TableName table_name)(Code) | | Compacts the table with the given name within this transaction. If the
table doesn't exist then an exception is thrown.
|
copyTable | public void copyTable(MasterTableDataSource src_master_table, IndexSet index_set)(Code) | | Generates an exact copy of the table within this transaction. It is
recommended that the table is dropped before the copy is made. The
purpose of this method is to generate a temporary table that can be
modified without fear of another transaction changing the contents in
another transaction. This also provides a convenient way to compact
a table because any spare space is removed when the table is copied. It
also allows us to make a copy of MasterTableDataSource into a foreign
conglomerate which allows us to implement a backup procedure.
This method does NOT assume the given MasterTableDataSource is contained,
or has once been contained within this conglomerate.
|
createMutableTableDataSourceAtCommit | public MutableTableDataSource createMutableTableDataSourceAtCommit(MasterTableDataSource master)(Code) | | Overwritten from SimpleTransaction.
Returns a new MutableTableDataSource for the view of the
MasterTableDataSource at the start of this transaction. Note that this is
only ever called once per table accessed in this transaction.
|
createSchema | public void createSchema(String name, String type)(Code) | | Create a new schema in this transaction. When the transaction is
committed the schema will become globally accessable. Note that any
security checks must be performed before this method is called.
NOTE: We must guarentee that the transaction be in exclusive mode before
this method is called.
|
createSequenceGenerator | public void createSequenceGenerator(TableName name, long start_value, long increment_by, long min_value, long max_value, long cache, boolean cycle)(Code) | | Creates a new sequence generator with the given TableName and
initializes it with the given details. This does NOT check if the
given name clashes with an existing database object.
|
createTable | public void createTable(DataTableDef table_def, int data_sector_size, int index_sector_size)(Code) | | Creates a new table within this transaction with the given sector size.
If the table already exists then an exception is thrown.
This should only be called under an exclusive lock on the connection.
|
createTable | public void createTable(DataTableDef table_def)(Code) | | Creates a new table within this transaction. If the table already
exists then an exception is thrown.
This should only be called under an exclusive lock on the connection.
|
databaseObjectCreated | void databaseObjectCreated(TableName table_name)(Code) | | Notifies this transaction that a database object with the given name has
successfully been created.
|
databaseObjectDropped | void databaseObjectDropped(TableName table_name)(Code) | | Notifies this transaction that a database object with the given name has
successfully been dropped.
|
dispose | void dispose()(Code) | | Disposes this transaction without rolling back or committing the changes.
Care should be taken when using this - it must only be used for simple
transactions that are short lived and have not modified the database.
|
dropAllConstraintsForTable | public void dropAllConstraintsForTable(TableName table_name)(Code) | | Drops all the constraints defined for the given table. This is a useful
function when dropping a table from the database.
NOTE: Security checks that the user can drop constraints must be checke at
a higher layer.
NOTE: We must guarentee that the transaction be in exclusive mode before
this method is called.
|
dropCheckConstraintForTable | public boolean dropCheckConstraintForTable(TableName table, String constraint_name)(Code) | | Drops a single named check constraint from the given table. Returns true
if the check constraint was dropped (the constraint existed).
NOTE: Security checks that the user can drop constraints must be checke at
a higher layer.
NOTE: We must guarentee that the transaction be in exclusive mode before
this method is called.
|
dropForeignKeyReferenceConstraintForTable | public boolean dropForeignKeyReferenceConstraintForTable(TableName table, String constraint_name)(Code) | | Drops a single named foreign key reference from the given table. Returns
true if the foreign key reference constraint was dropped (the constraint
existed).
NOTE: Security checks that the user can drop constraints must be checke at
a higher layer.
NOTE: We must guarentee that the transaction be in exclusive mode before
this method is called.
|
dropNamedConstraint | public int dropNamedConstraint(TableName table_name, String constraint_name)(Code) | | Drops the named constraint from the transaction. Used when altering
table schema. Returns the number of constraints that were removed from
the system. If this method returns 0 then it indicates there is no
constraint with the given name in the table.
NOTE: Security checks that the user can drop constraints must be checke at
a higher layer.
NOTE: We must guarentee that the transaction be in exclusive mode before
this method is called.
|
dropPrimaryKeyConstraintForTable | public boolean dropPrimaryKeyConstraintForTable(TableName table_name, String constraint_name)(Code) | | Drops the primary key constraint for the given table. Used when altering
table schema. If 'constraint_name' is null this method will search for
the primary key of the table name. Returns true if the primary key
constraint was dropped (the constraint existed).
NOTE: Security checks that the user can drop constraints must be checke at
a higher layer.
NOTE: We must guarentee that the transaction be in exclusive mode before
this method is called.
|
dropSchema | public void dropSchema(String name)(Code) | | Drops a schema from this transaction. When the transaction is committed
the schema will be dropped perminently. Note that any security checks
must be performed before this method is called.
NOTE: We must guarentee that the transaction be in exclusive mode before
this method is called.
|
dropSequenceGenerator | public void dropSequenceGenerator(TableName name)(Code) | | Drops an existing sequence generator with the given name.
|
dropTable | public void dropTable(TableName table_name)(Code) | | Drops a table within this transaction. If the table does not exist then
an exception is thrown.
This should only be called under an exclusive lock on the connection.
|
dropUniqueConstraintForTable | public boolean dropUniqueConstraintForTable(TableName table, String constraint_name)(Code) | | Drops a single named unique constraint from the given table. Returns
true if the unique constraint was dropped (the constraint existed).
NOTE: Security checks that the user can drop constraints must be checke at
a higher layer.
NOTE: We must guarentee that the transaction be in exclusive mode before
this method is called.
|
finalize | public void finalize() throws Throwable(Code) | | Finalize, we should close the transaction.
|
getAllNamesCreated | ArrayList getAllNamesCreated()(Code) | | Returns the normalized list of database object names created in this
transaction.
|
getAllNamesDropped | ArrayList getAllNamesDropped()(Code) | | Returns the normalized list of database object names dropped in this
transaction.
|
getCommitID | long getCommitID()(Code) | | Returns the 'commit_id' which is the last commit that occured before
this transaction was created.
NOTE: Don't make this synchronized over anything. This is accessed
by OpenTransactionList.
|
getDynamicDataTableDef | protected DataTableDef getDynamicDataTableDef(TableName table_name)(Code) | | Returns the DataTableDef for the given internal table.
|
getDynamicTable | protected MutableTableDataSource getDynamicTable(TableName table_name)(Code) | | Returns an instance of MutableDataTableSource that represents the
contents of the internal table with the given name.
|
getDynamicTableList | protected TableName[] getDynamicTableList()(Code) | | Returns a list of all dynamic table names. This method returns a
reference to a static, make sure you don't change the contents of the
array!
|
getDynamicTableType | public String getDynamicTableType(TableName table_name)(Code) | | Returns a string type describing the type of the dynamic table.
|
getPersistantVar | public String getPersistantVar(String variable)(Code) | | Returns the value of the persistent variable with the given name or null
if it doesn't exist.
|
getSchemaList | public SchemaDef[] getSchemaList()(Code) | | Returns an array of SchemaDef objects for each schema currently setup in
the database.
|
isDynamicTable | protected boolean isDynamicTable(TableName table_name)(Code) | | Returns true if the given table name represents a dynamically generated
system table.
|
liveCopyAllDataTo | void liveCopyAllDataTo(TableDataConglomerate dest_conglomerate)(Code) | | Copies all the tables within this transaction view to the destination
conglomerate object. Some care should be taken with security when using
this method. This is useful for generating a backup of the current
view of the database that can work without interfering with the general
operation of the database.
|
queryTableCheckExpressions | public static CheckExpression[] queryTableCheckExpressions(SimpleTransaction transaction, TableName table_name)(Code) | | Returns a set of check expressions that are constrained over all new
columns added to the given table in this transaction. For example,
we may want a column called 'serial_number' to be constrained as
CHECK serial_number LIKE '___-________-___'.
|
queryTableForeignKeyReferences | public static ColumnGroupReference[] queryTableForeignKeyReferences(SimpleTransaction transaction, TableName table_name)(Code) | | Returns an array of column references in the given table that represent
foreign key references. For example, say a foreign reference has been
set up in the given table as follows;
FOREIGN KEY (customer_id) REFERENCES Customer (id)
This method will return the column group reference
Order(customer_id) -> Customer(id).
This method is used to check that a foreign key reference actually points
to a valid record in the referenced table as expected.
|
queryTableImportedForeignKeyReferences | public static ColumnGroupReference[] queryTableImportedForeignKeyReferences(SimpleTransaction transaction, TableName ref_table_name)(Code) | | Returns an array of column references in the given table that represent
foreign key references that reference columns in the given table. This
is a reverse mapping of the 'queryTableForeignKeyReferences' method. For
example, say a foreign reference has been set up in any table as follows;
[ In table Order ]
FOREIGN KEY (customer_id) REFERENCE Customer (id)
And the table name we are querying is 'Customer' then this method will
return the column group reference
Order(customer_id) -> Customer(id).
This method is used to check that a reference isn't broken when we remove
a record (for example, removing a Customer that has references to it will
break integrity).
|
queryTablePrimaryKeyGroup | public static ColumnGroup queryTablePrimaryKeyGroup(SimpleTransaction transaction, TableName table_name)(Code) | | Returns a set of primary key groups that are constrained to be unique
for the given table in this transaction (there can be only 1 primary
key defined for a table). Returns null if there is no primary key
defined for the table.
|
queryTableUniqueGroups | public static ColumnGroup[] queryTableUniqueGroups(SimpleTransaction transaction, TableName table_name)(Code) | | Returns a set of unique groups that are constrained to be unique for
the given table in this transaction. For example, if columns ('name')
and ('number', 'document_rev') are defined as unique, this will return
an array of two groups that represent unique columns in the given
table.
|
queryTablesRelationallyLinkedTo | public static TableName[] queryTablesRelationallyLinkedTo(SimpleTransaction transaction, TableName table)(Code) | | Returns the list of tables (as a TableName array) that are dependant
on the data in the given table to maintain referential consistancy. The
list includes the tables referenced as foreign keys, and the tables
that reference the table as a foreign key.
This is a useful query for determining ahead of time the tables that
require a read lock when inserting/updating a table. A table will require
a read lock if the operation needs to query it for potential referential
integrity violations.
|
resolveSchemaCase | public SchemaDef resolveSchemaCase(String name, boolean ignore_case)(Code) | | Resolves the case of the given schema name if the database is performing
case insensitive identifier matching. Returns a SchemaDef object that
identifiers the schema. Returns null if the schema name could not be
resolved.
|
schemaExists | public boolean schemaExists(String name)(Code) | | Returns true if the schema exists within this transaction.
|
setErrorOnDirtySelect | void setErrorOnDirtySelect(boolean status)(Code) | | Sets the transaction error on dirty select for this transaction.
|
setPersistentVar | public void setPersistentVar(String variable, String value)(Code) | | Sets a persistent variable of the database that becomes a committed
change once this transaction is committed. The variable can later be
retrieved with a call to the 'getPersistantVar' method. A persistant
var is created if it doesn't exist in the DatabaseVars table otherwise
it is overwritten.
|
transactionErrorOnDirtySelect | boolean transactionErrorOnDirtySelect()(Code) | | Returns true if the conglomerate commit procedure should check for
dirty selects and produce a transaction error. A dirty select is when
a query reads information from a table that is effected by another table
during a transaction. This in itself will not cause data
consistancy problems but for strict conformance to SERIALIZABLE
isolation level this should return true.
NOTE; We MUST NOT make this method serialized because it is back called
from within a commit lock in TableDataConglomerate.
|
|
|