public class Transaction extends SimpleTransaction
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.
Modifier and Type | Class and Description |
---|---|
static class |
Transaction.CheckExpression
Represents a constraint expression to check.
|
static class |
Transaction.ColumnGroup
A group of columns as used by the constraint system.
|
static class |
Transaction.ColumnGroupReference
Represents a reference from a group of columns in one table to a group of
columns in another table.
|
Modifier and Type | Field and Description |
---|---|
static String |
CASCADE |
static short |
INITIALLY_DEFERRED
The type of deferrance.
|
static short |
INITIALLY_IMMEDIATE |
static String |
NO_ACTION
Foreign key referential trigger actions.
|
static short |
NOT_DEFERRABLE |
static String |
SET_DEFAULT |
static String |
SET_NULL |
Modifier and Type | Method and Description |
---|---|
void |
addCheckConstraint(TableName table_name,
Expression expression,
short deferred,
String constraint_name)
Adds a check expression that becomes perminent when the transaction
is committed.
|
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 |
addPrimaryKeyConstraint(TableName table_name,
String[] cols,
short deferred,
String constraint_name)
Adds a primary key constraint that becomes perminent when the transaction
is committed.
|
void |
addSelectedFromTable(TableName table_name)
Called by the query evaluation layer when information is selected
from this table as part of this transaction.
|
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.
|
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.
|
void |
alterTable(TableName table_name,
DataTableDef table_def)
Alters the table with the given name within this transaction to the
specified table definition.
|
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.
|
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.
|
void |
closeAndCommit()
Closes and marks a transaction as committed.
|
void |
closeAndRollback()
Closes and rolls back a transaction as if the commands the transaction ran
never happened.
|
void |
compactTable(TableName table_name)
Compacts the table with the given name within this transaction.
|
void |
copyTable(com.mckoi.database.MasterTableDataSource src_master_table,
IndexSet index_set)
Generates an exact copy of the table within this transaction.
|
MutableTableDataSource |
createMutableTableDataSourceAtCommit(com.mckoi.database.MasterTableDataSource master)
Overwritten from SimpleTransaction.
|
void |
createSchema(String name,
String type)
Create a new schema in this transaction.
|
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.
|
void |
createTable(DataTableDef table_def)
Creates a new table within this transaction.
|
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.
|
void |
dropAllConstraintsForTable(TableName table_name)
Drops all the constraints defined for the given table.
|
boolean |
dropCheckConstraintForTable(TableName table,
String constraint_name)
Drops a single named check constraint from the given table.
|
boolean |
dropForeignKeyReferenceConstraintForTable(TableName table,
String constraint_name)
Drops a single named foreign key reference from the given table.
|
int |
dropNamedConstraint(TableName table_name,
String constraint_name)
Drops the named constraint from the transaction.
|
boolean |
dropPrimaryKeyConstraintForTable(TableName table_name,
String constraint_name)
Drops the primary key constraint for the given table.
|
void |
dropSchema(String name)
Drops a schema from this transaction.
|
void |
dropSequenceGenerator(TableName name)
Drops an existing sequence generator with the given name.
|
void |
dropTable(TableName table_name)
Drops a table within this transaction.
|
boolean |
dropUniqueConstraintForTable(TableName table,
String constraint_name)
Drops a single named unique constraint from the given table.
|
void |
finalize()
Finalize, we should close the 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.
|
String |
getDynamicTableType(TableName table_name)
Returns a string type describing the type of the dynamic table.
|
String |
getPersistantVar(String variable)
Returns the value of the persistent variable with the given name or null
if it doesn't exist.
|
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.
|
static Transaction.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.
|
static Transaction.ColumnGroupReference[] |
queryTableForeignKeyReferences(SimpleTransaction transaction,
TableName table_name)
Returns an array of column references in the given table that represent
foreign key references.
|
static Transaction.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.
|
static Transaction.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).
|
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.
|
static Transaction.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.
|
SchemaDef |
resolveSchemaCase(String name,
boolean ignore_case)
Resolves the case of the given schema name if the database is performing
case insensitive identifier matching.
|
boolean |
schemaExists(String name)
Returns true if the schema exists within this transaction.
|
void |
setPersistentVar(String variable,
String value)
Sets a persistent variable of the database that becomes a committed
change once this transaction is committed.
|
currentUniqueID, Debug, disposeAllIndices, findVisibleTable, flushTableCache, getDataTableDef, getSystem, getTable, getTableDataSource, getTableList, getTableType, getVisibleTable, getVisibleTableCount, getVisibleTables, isReadOnly, lastSequenceValue, nextSequenceValue, nextUniqueID, resolveToTableName, setIndexSetForTable, setReadOnly, setSequenceValue, setUniqueID, tableExists, tryResolveCase
public static final short INITIALLY_DEFERRED
public static final short INITIALLY_IMMEDIATE
public static final short NOT_DEFERRABLE
public static final String NO_ACTION
public static final String CASCADE
public static final String SET_NULL
public static final String SET_DEFAULT
public MutableTableDataSource createMutableTableDataSourceAtCommit(com.mckoi.database.MasterTableDataSource master)
public void addSelectedFromTable(TableName table_name)
protected boolean isDynamicTable(TableName table_name)
isDynamicTable
in class SimpleTransaction
protected TableName[] getDynamicTableList()
getDynamicTableList
in class SimpleTransaction
protected DataTableDef getDynamicDataTableDef(TableName table_name)
getDynamicDataTableDef
in class SimpleTransaction
protected MutableTableDataSource getDynamicTable(TableName table_name)
getDynamicTable
in class SimpleTransaction
public String getDynamicTableType(TableName table_name)
getDynamicTableType
in class SimpleTransaction
public void createTable(DataTableDef table_def, int data_sector_size, int index_sector_size)
This should only be called under an exclusive lock on the connection.
public void createTable(DataTableDef table_def)
This should only be called under an exclusive lock on the connection.
public void alterCreateTable(DataTableDef table_def, int data_sector_size, int index_sector_size)
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.
public void dropTable(TableName table_name)
This should only be called under an exclusive lock on the connection.
public void copyTable(com.mckoi.database.MasterTableDataSource src_master_table, IndexSet index_set)
This method does NOT assume the given MasterTableDataSource is contained, or has once been contained within this conglomerate.
public void alterTable(TableName table_name, DataTableDef table_def, int data_sector_size, int index_sector_size)
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.
public void alterTable(TableName table_name, DataTableDef table_def)
This should only be called under an exclusive lock on the connection.
public void checkAllConstraints(TableName table_name)
public void compactTable(TableName table_name)
public void createSchema(String name, String type)
NOTE: We must guarentee that the transaction be in exclusive mode before this method is called.
public void dropSchema(String name)
NOTE: We must guarentee that the transaction be in exclusive mode before this method is called.
public boolean schemaExists(String name)
public SchemaDef resolveSchemaCase(String name, boolean ignore_case)
public SchemaDef[] getSchemaList()
public void setPersistentVar(String variable, String value)
public String getPersistantVar(String variable)
public void createSequenceGenerator(TableName name, long start_value, long increment_by, long min_value, long max_value, long cache, boolean cycle)
public void dropSequenceGenerator(TableName name)
public void addUniqueConstraint(TableName table_name, String[] cols, short deferred, String 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.
public void addForeignKeyConstraint(TableName table, String[] cols, TableName ref_table, String[] ref_cols, String delete_rule, String update_rule, short deferred, String 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.
public void addPrimaryKeyConstraint(TableName table_name, String[] cols, short deferred, String 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.
public void addCheckConstraint(TableName table_name, Expression expression, short deferred, String 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.
public void dropAllConstraintsForTable(TableName table_name)
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.
public int dropNamedConstraint(TableName table_name, String constraint_name)
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.
public boolean dropPrimaryKeyConstraintForTable(TableName table_name, String constraint_name)
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.
public boolean dropUniqueConstraintForTable(TableName table, String constraint_name)
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.
public boolean dropCheckConstraintForTable(TableName table, String constraint_name)
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.
public boolean dropForeignKeyReferenceConstraintForTable(TableName table, String constraint_name)
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.
public static TableName[] queryTablesRelationallyLinkedTo(SimpleTransaction transaction, TableName table)
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.
public static Transaction.ColumnGroup[] queryTableUniqueGroups(SimpleTransaction transaction, TableName table_name)
public static Transaction.ColumnGroup queryTablePrimaryKeyGroup(SimpleTransaction transaction, TableName table_name)
public static Transaction.CheckExpression[] queryTableCheckExpressions(SimpleTransaction transaction, TableName table_name)
public static Transaction.ColumnGroupReference[] queryTableForeignKeyReferences(SimpleTransaction transaction, TableName table_name)
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.
public static Transaction.ColumnGroupReference[] queryTableImportedForeignKeyReferences(SimpleTransaction transaction, TableName ref_table_name)
[ 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).
public void closeAndCommit() throws TransactionException
This method will fail under the following circumstances:
This should only be called under an exclusive lock on the connection.
TransactionException
public void closeAndRollback()
This should only be called under an exclusive lock on the connection.
Copyright © 2015. All rights reserved.