| java.lang.Object com.mckoi.database.TableDataConglomerate
TableDataConglomerate | public class TableDataConglomerate (Code) | | A conglomerate of data that represents the contents of all tables in a
complete database. This object handles all data persistance management
(storage, retrieval, removal) issues. It is a transactional manager for
both data and indices in the database.
author: Tobias Downer |
Method Summary | |
final public DebugLogger | Debug() Returns the DebugLogger object that we use to log debug messages to. | public void | addTransactionModificationListener(TableName table_name, TransactionModificationListener listener) Adds a listener for transactional modification events that occur on the
given table in this conglomerate. | static void | checkAddConstraintViolations(SimpleTransaction transaction, TableDataSource table, int[] row_indices, short deferred) Performs constraint violation checks on an addition of the given set of
row indices into the TableDataSource in the given transaction. | static void | checkAddConstraintViolations(SimpleTransaction transaction, TableDataSource table, int row_index, short deferred) Performs constraint violation checks on an addition of the given
row index into the TableDataSource in the given transaction. | static void | checkAllAddConstraintViolations(SimpleTransaction transaction, TableDataSource table, short deferred) Performs constraint violation checks on all the rows in the given
table. | static void | checkFieldConstraintViolations(SimpleTransaction transaction, TableDataSource table, int[] row_indices) Checks that the nullibility and class of the fields in the given
rows are valid. | static void | checkRemoveConstraintViolations(SimpleTransaction transaction, TableDataSource table, int[] row_indices, short deferred) Performs constraint violation checks on a removal of the given set of
row indexes from the TableDataSource in the given transaction. | static void | checkRemoveConstraintViolations(SimpleTransaction transaction, TableDataSource table, int row_index, short deferred) Performs constraint violation checks on a removal of the given
row index from the TableDataSource in the given transaction. | public void | checkVisibleTables(UserTerminal terminal) Checks the list of committed tables in this conglomerate. | public void | close() Closes this conglomerate. | MasterTableDataSource | copyMasterTable(MasterTableDataSource src_master_table, IndexSet index_set) Creates a table store in this conglomerate that is an exact copy of the
given MasterTableDataSource. | public void | create(String name) Creates a new conglomerate at the given path in the file system. | MasterTableDataSource | createMasterTable(DataTableDef table_def, int data_sector_size, int index_sector_size) Creates a table store in this conglomerate with the given name and returns
a reference to the table. | Ref | createNewLargeObject(byte type, long size) Creates and allocates storage for a new large object in the blob store. | public Transaction | createTransaction() Starts a new transaction. | static String | deferredString(short deferred) Convenience, returns either 'Immediate' or 'Deferred' dependant on the
deferred short. | public void | delete() Deletes and closes the conglomerate. | public boolean | exists(String name) Returns true if the conglomerate exists in the file system and can
be opened. | public void | finalize() | static int[] | findColumnIndices(DataTableDef table_def, String[] cols) Returns a list of column indices into the given DataTableDef for the
given column names. | static IntegerVector | findKeys(TableDataSource t2, int[] col2_indexes, TObject[] key_value) Returns the key indices found in the given table. | public void | fix(String name, UserTerminal terminal) Checks the conglomerate state file. | void | flushBlobStore() Called when one or more blobs has been completed. | public String[] | getAllTableFileNames() Returns the list of file names for all tables in this conglomerate. | final BlobStore | getBlobStore() Returns the BlobStore for this conglomerate. | public RawDiagnosticTable | getDiagnosticTable(String table_file_name) Returns a RawDiagnosticTable object that is used for diagnostics of the
table with the given file name. | MasterTableDataSource | getMasterTable(int table_id) Returns the MasterTableDataSource in this conglomerate with the given
table id. | String | getName() Returns the name given to this conglomerate. | final SequenceManager | getSequenceManager() Returns the SequenceManager object for this conglomerate. | final public TransactionSystem | getSystem() Returns the TransactionSystem that this conglomerate is part of. | public boolean | isClosed() Returns true if the conglomerate is closed. | public void | liveCopyTo(TableDataConglomerate dest_conglomerate) Makes a complete copy of this database to the position represented by the
given TableDataConglomerate object. | void | minimalCreate(String name) Minimally creates a new conglomerate but does NOT initialize any of the
system tables. | public void | open(String name) Opens a conglomerate. | void | processCommit(Transaction transaction, ArrayList visible_tables, ArrayList selected_from_tables, ArrayList touched_tables, TransactionJournal journal) Tries to commit a transaction to the conglomerate. | void | processRollback(Transaction transaction, ArrayList touched_tables, TransactionJournal journal) Rollbacks a transaction and invalidates any changes that the transaction
made to the database. | public void | removeTransactionModificationListener(TableName table_name, TransactionModificationListener listener) Removes a listener for transaction modification events on the given table
in this conglomerate as previously set by the
'addTransactionModificationListener' method. | void | resetAllSystemTableID() Resets the table sequence id for all the system tables managed by the
conglomerate. | void | resetTableID(TableName tname) Given a table with a 'id' field, this will check that the sequence
value for the table is at least greater than the maximum id in the column. | final public StoreSystem | storeSystem() Returns the StoreSystem used by this conglomerate to manage the
persistent state of the database. | static String | stringColumnList(String[] list) Convenience, converts a String[] array to a comma deliminated string
list. | void | updateSystemTableSchema() Create the system tables that must be present in a conglomerates. |
PERSISTENT_VAR_TABLE | final public static TableName PERSISTENT_VAR_TABLE(Code) | | |
SCHEMA_INFO_TABLE | final public static TableName SCHEMA_INFO_TABLE(Code) | | The schema info table.
|
STATE_POST | final public static String STATE_POST(Code) | | The postfix on the name of the state file for the database store name.
|
SYSTEM_SCHEMA | final public static String SYSTEM_SCHEMA(Code) | | The name of the system schema where persistant conglomerate state is
stored.
|
commit_lock | final Object commit_lock(Code) | | This lock is obtained when we go to commit a change to the table.
Grabbing this lock ensures that no other commits can occur at the same
time on this conglomerate.
|
Debug | final public DebugLogger Debug()(Code) | | Returns the DebugLogger object that we use to log debug messages to.
|
addTransactionModificationListener | public void addTransactionModificationListener(TableName table_name, TransactionModificationListener listener)(Code) | | Adds a listener for transactional modification events that occur on the
given table in this conglomerate. A transactional modification event is
an event fired immediately upon the modification of a table by a
transaction, either immediately before the modification or immediately
after. Also an event is fired when a modification to a table is
successfully committed.
The BEFORE_* type triggers are given the opportunity to modify the
contents of the RowData before the update or insert occurs. All triggers
may generate an exception which will cause the transaction to rollback.
The event carries with it the event type, the transaction that the event
occurred in, and any information regarding the modification itself.
This event/listener mechanism is intended to be used to implement higher
layer database triggering systems. Note that care must be taken with
the commit level events because they occur inside a commit lock on this
conglomerate and so synchronization and deadlock issues need to be
carefully considered.
NOTE: A listener on the given table will be notified of ALL table
modification events by all transactions at the time they happen.
Parameters: table_name - the name of the table in the conglomerate to listen forevents from. Parameters: listener - the listener to be notified of events. |
checkAddConstraintViolations | static void checkAddConstraintViolations(SimpleTransaction transaction, TableDataSource table, int[] row_indices, short deferred)(Code) | | Performs constraint violation checks on an addition of the given set of
row indices into the TableDataSource in the given transaction. If a
violation is detected a DatabaseConstraintViolationException is thrown.
If deferred = IMMEDIATE only immediate constraints are tested. If
deferred = DEFERRED all constraints are tested.
Parameters: transaction - the Transaction instance used to determine tableconstraints. Parameters: table - the table to test Parameters: row_indices - the list of rows that were added to the table. Parameters: deferred - '1' indicates Transaction.IMMEDIATE,'2' indicates Transaction.DEFERRED. |
checkAddConstraintViolations | static void checkAddConstraintViolations(SimpleTransaction transaction, TableDataSource table, int row_index, short deferred)(Code) | | Performs constraint violation checks on an addition of the given
row index into the TableDataSource in the given transaction. If a
violation is detected a DatabaseConstraintViolationException is thrown.
If deferred = IMMEDIATE only immediate constraints are tested. If
deferred = DEFERRED all constraints are tested.
Parameters: transaction - the Transaction instance used to determine tableconstraints. Parameters: table - the table to test Parameters: row_index - the row that was added to the table. Parameters: deferred - '1' indicates Transaction.IMMEDIATE,'2' indicates Transaction.DEFERRED. |
checkAllAddConstraintViolations | static void checkAllAddConstraintViolations(SimpleTransaction transaction, TableDataSource table, short deferred)(Code) | | Performs constraint violation checks on all the rows in the given
table. If a violation is detected a DatabaseConstraintViolationException
is thrown.
This method is useful when the constraint schema of a table changes and
we need to check existing data in a table is conformant with the new
constraint changes.
If deferred = IMMEDIATE only immediate constraints are tested. If
deferred = DEFERRED all constraint are tested.
|
checkFieldConstraintViolations | static void checkFieldConstraintViolations(SimpleTransaction transaction, TableDataSource table, int[] row_indices)(Code) | | Checks that the nullibility and class of the fields in the given
rows are valid. Should be used as part of the insert procedure.
|
checkRemoveConstraintViolations | static void checkRemoveConstraintViolations(SimpleTransaction transaction, TableDataSource table, int[] row_indices, short deferred)(Code) | | Performs constraint violation checks on a removal of the given set of
row indexes from the TableDataSource in the given transaction. If a
violation is detected a DatabaseConstraintViolationException is thrown.
If deferred = IMMEDIATE only immediate constraints are tested. If
deferred = DEFERRED all constraints are tested.
Parameters: transaction - the Transaction instance used to determine tableconstraints. Parameters: table - the table to test Parameters: row_indices - the set of rows that were removed from the table. Parameters: deferred - '1' indicates Transaction.IMMEDIATE,'2' indicates Transaction.DEFERRED. |
checkRemoveConstraintViolations | static void checkRemoveConstraintViolations(SimpleTransaction transaction, TableDataSource table, int row_index, short deferred)(Code) | | Performs constraint violation checks on a removal of the given
row index from the TableDataSource in the given transaction. If a
violation is detected a DatabaseConstraintViolationException is thrown.
If deferred = IMMEDIATE only immediate constraints are tested. If
deferred = DEFERRED all constraints are tested.
Parameters: transaction - the Transaction instance used to determine tableconstraints. Parameters: table - the table to test Parameters: row_index - the row that was removed from the table. Parameters: deferred - '1' indicates Transaction.IMMEDIATE,'2' indicates Transaction.DEFERRED. |
checkVisibleTables | public void checkVisibleTables(UserTerminal terminal) throws IOException(Code) | | Checks the list of committed tables in this conglomerate. This should
only be called during an 'check' like method. This method fills the
'committed_tables' and 'table_list' lists with the tables in this
conglomerate.
|
close | public void close() throws IOException(Code) | | Closes this conglomerate. The conglomerate must be open for it to be
closed. When closed, any use of this object is undefined.
|
copyMasterTable | MasterTableDataSource copyMasterTable(MasterTableDataSource src_master_table, IndexSet index_set)(Code) | | Creates a table store in this conglomerate that is an exact copy of the
given MasterTableDataSource. Note that this table is not a commited change
to the system. It is a free standing blank table store. The table
returned here is uncommitted and will be deleted unless it is committed.
Note that two tables may exist within a conglomerate with the same name,
however each committed table must have a unique name.
Parameters: src_master_table - the source master table to copy. Parameters: index_set - the view of the table index to copy. the MasterTableDataSource with the copied information. |
create | public void create(String name) throws IOException(Code) | | Creates a new conglomerate at the given path in the file system. This
must be an empty directory where files can be stored. This will create
the conglomerate and exit in an open (read/write) state.
|
createMasterTable | MasterTableDataSource createMasterTable(DataTableDef table_def, int data_sector_size, int index_sector_size)(Code) | | Creates a table store in this conglomerate with the given name and returns
a reference to the table. Note that this table is not a commited change
to the system. It is a free standing blank table store. The table
returned here is uncommitted and will be deleted unless it is committed.
Note that two tables may exist within a conglomerate with the same name,
however each committed table must have a unique name.
Parameters: table_def - the table definition. Parameters: data_sector_size - the size of the data sectors (affects performanceand size of the file). Parameters: index_sector_size - the size of the index sectors. |
createNewLargeObject | Ref createNewLargeObject(byte type, long size)(Code) | | Creates and allocates storage for a new large object in the blob store.
This is called to create a new large object before filling it with data
sent from the client.
|
createTransaction | public Transaction createTransaction()(Code) | | Starts a new transaction. The Transaction object returned by this
method is used to read the contents of the database at the time
the transaction was started. It is also used if any modifications are
required to be made.
|
deferredString | static String deferredString(short deferred)(Code) | | Convenience, returns either 'Immediate' or 'Deferred' dependant on the
deferred short.
|
delete | public void delete() throws IOException(Code) | | Deletes and closes the conglomerate. This will delete all the files in
the file system associated with this conglomerate, so this method should
be used with care.
WARNING: Will result in total loss of all data stored in the conglomerate.
|
exists | public boolean exists(String name) throws IOException(Code) | | Returns true if the conglomerate exists in the file system and can
be opened.
|
finalize | public void finalize()(Code) | | |
findColumnIndices | static int[] findColumnIndices(DataTableDef table_def, String[] cols)(Code) | | Returns a list of column indices into the given DataTableDef for the
given column names.
|
findKeys | static IntegerVector findKeys(TableDataSource t2, int[] col2_indexes, TObject[] key_value)(Code) | | Returns the key indices found in the given table. The keys are
in the given column indices, and the key is in the 'key' array. This can
be used to count the number of keys found in a table for constraint
violation checking.
|
fix | public void fix(String name, UserTerminal terminal)(Code) | | Checks the conglomerate state file. The returned ErrorState object
contains information about any error generated.
|
flushBlobStore | void flushBlobStore()(Code) | | Called when one or more blobs has been completed. This flushes the blob
to the blob store and completes the blob write procedure. It's important
this is called otherwise the BlobStore may not be correctly flushed to
disk with the changes and the data will not be recoverable if a crash
occurs.
|
getAllTableFileNames | public String[] getAllTableFileNames()(Code) | | Returns the list of file names for all tables in this conglomerate.
|
getBlobStore | final BlobStore getBlobStore()(Code) | | Returns the BlobStore for this conglomerate.
|
getDiagnosticTable | public RawDiagnosticTable getDiagnosticTable(String table_file_name)(Code) | | Returns a RawDiagnosticTable object that is used for diagnostics of the
table with the given file name.
|
getMasterTable | MasterTableDataSource getMasterTable(int table_id)(Code) | | Returns the MasterTableDataSource in this conglomerate with the given
table id.
|
getName | String getName()(Code) | | Returns the name given to this conglomerate.
|
getSequenceManager | final SequenceManager getSequenceManager()(Code) | | Returns the SequenceManager object for this conglomerate.
|
getSystem | final public TransactionSystem getSystem()(Code) | | Returns the TransactionSystem that this conglomerate is part of.
|
isClosed | public boolean isClosed()(Code) | | Returns true if the conglomerate is closed.
|
liveCopyTo | public void liveCopyTo(TableDataConglomerate dest_conglomerate) throws IOException(Code) | | Makes a complete copy of this database to the position represented by the
given TableDataConglomerate object. The given TableDataConglomerate
object must NOT be being used by another database running in the JVM.
This may take a while to complete. The backup operation occurs within its
own transaction and the copy transaction is read-only meaning there is no
way for the copy process to interfere with other transactions running
concurrently.
The conglomerate must be open before this method is called.
|
minimalCreate | void minimalCreate(String name) throws IOException(Code) | | Minimally creates a new conglomerate but does NOT initialize any of the
system tables. This is a useful feature for a copy function that requires
a TableDataConglomerate object to copy data into but does not require any
initial system tables (because this information is copied from the source
conglomerate.
|
open | public void open(String name) throws IOException(Code) | | Opens a conglomerate. If the conglomerate does not exist then an
IOException is generated. Once a conglomerate is open, we may start
opening transactions and altering the data within it.
|
processCommit | void processCommit(Transaction transaction, ArrayList visible_tables, ArrayList selected_from_tables, ArrayList touched_tables, TransactionJournal journal) throws TransactionException(Code) | | Tries to commit a transaction to the conglomerate. This is called
by the 'closeAndCommit' method in Transaction. An overview of how this
works follows:
- Determine if any transactions have been committed since this
transaction was created.
- If no transactions committed then commit this transaction and exit.
- Otherwise, determine the tables that have been changed by the
committed transactions since this was created.
- If no tables changed in the tables changed by this transaction then
commit this transaction and exit.
- Determine if there are any rows that have been deleted that this
transaction read/deleted.
- If there are then rollback this transaction and throw an error.
- Determine if any rows have been added to the tables this transaction
read/changed.
- If there are then rollback this transaction and throw an error.
- Otherwise commit the transaction.
Parameters: transaction - the transaction to commit from. Parameters: visible_tables - the list of visible tables at the end of the commit(MasterTableDataSource) Parameters: selected_from_tables - ths list of tables that this transactionperformed 'select' like queries on (MasterTableDataSource) Parameters: touched_tables - the list of tables touched by the transaction(MutableTableDataSource) Parameters: journal - the journal that describes all the changes within thetransaction. |
processRollback | void processRollback(Transaction transaction, ArrayList touched_tables, TransactionJournal journal)(Code) | | Rollbacks a transaction and invalidates any changes that the transaction
made to the database. The rows that this transaction changed are given
up as freely available rows. This is called by the 'closeAndRollback'
method in Transaction.
|
removeTransactionModificationListener | public void removeTransactionModificationListener(TableName table_name, TransactionModificationListener listener)(Code) | | Removes a listener for transaction modification events on the given table
in this conglomerate as previously set by the
'addTransactionModificationListener' method.
Parameters: table_name - the name of the table in the conglomerate to remove fromthe listener list. Parameters: listener - the listener to be removed. |
resetAllSystemTableID | void resetAllSystemTableID()(Code) | | Resets the table sequence id for all the system tables managed by the
conglomerate.
|
resetTableID | void resetTableID(TableName tname)(Code) | | Given a table with a 'id' field, this will check that the sequence
value for the table is at least greater than the maximum id in the column.
|
storeSystem | final public StoreSystem storeSystem()(Code) | | Returns the StoreSystem used by this conglomerate to manage the
persistent state of the database.
|
stringColumnList | static String stringColumnList(String[] list)(Code) | | Convenience, converts a String[] array to a comma deliminated string
list.
|
updateSystemTableSchema | void updateSystemTableSchema()(Code) | | Create the system tables that must be present in a conglomerates. These
tables consist of contraint and table management data.
sUSRPKeyInfo - Primary key constraint information.
sUSRFKeyInfo - Foreign key constraint information.
sUSRUniqueInfo - Unique set constraint information.
sUSRCheckInfo - Check constraint information.
sUSRPrimaryColumns - Primary columns information (refers to PKeyInfo)
sUSRUniqueColumns - Unique columns information (refers to UniqueInfo)
sUSRForeignColumns1 - Foreign column information (refers to FKeyInfo)
sUSRForeignColumns2 - Secondary Foreign column information (refers to
FKeyInfo).
These tables handle data for referential integrity. There are also some
additional tables containing general table information.
sUSRTableColumnInfo - All table and column information.
The design is fairly elegant in that we are using the database to store
information to maintain referential integrity.
The schema layout for these tables;
CREATE TABLE sUSRPKeyInfo (
id NUMERIC NOT NULL,
name TEXT NOT NULL, // The name of the primary key constraint
schema TEXT NOT NULL, // The name of the schema
table TEXT NOT NULL, // The name of the table
deferred BIT NOT NULL, // Whether deferred or immediate
PRIMARY KEY (id),
UNIQUE (schema, table)
);
CREATE TABLE sUSRFKeyInfo (
id NUMERIC NOT NULL,
name TEXT NOT NULL, // The name of the foreign key constraint
schema TEXT NOT NULL, // The name of the schema
table TEXT NOT NULL, // The name of the table
ref_schema TEXT NOT NULL, // The name of the schema referenced
ref_table TEXT NOT NULL, // The name of the table referenced
update_rule TEXT NOT NULL, // The rule for updating to table
delete_rule TEXT NOT NULL, // The rule for deleting from table
deferred BIT NOT NULL, // Whether deferred or immediate
PRIMARY KEY (id)
);
CREATE TABLE sUSRUniqueInfo (
id NUMERIC NOT NULL,
name TEXT NOT NULL, // The name of the unique constraint
schema TEXT NOT NULL, // The name of the schema
table TEXT NOT NULL, // The name of the table
deferred BIT NOT NULL, // Whether deferred or immediate
PRIMARY KEY (id)
);
CREATE TABLE sUSRCheckInfo (
id NUMERIC NOT NULL,
name TEXT NOT NULL, // The name of the check constraint
schema TEXT NOT NULL, // The name of the schema
table TEXT NOT NULL, // The name of the table
expression TEXT NOT NULL, // The check expression
deferred BIT NOT NULL, // Whether deferred or immediate
PRIMARY KEY (id)
);
CREATE TABLE sUSRPrimaryColumns (
pk_id NUMERIC NOT NULL, // The primary key constraint id
column TEXT NOT NULL, // The name of the primary
seq_no INTEGER NOT NULL, // The sequence number of this constraint
FOREIGN KEY pk_id REFERENCES sUSRPKeyInfo
);
CREATE TABLE sUSRUniqueColumns (
un_id NUMERIC NOT NULL, // The unique constraint id
column TEXT NOT NULL, // The column that is unique
seq_no INTEGER NOT NULL, // The sequence number of this constraint
FOREIGN KEY un_id REFERENCES sUSRUniqueInfo
);
CREATE TABLE sUSRForeignColumns (
fk_id NUMERIC NOT NULL, // The foreign key constraint id
fcolumn TEXT NOT NULL, // The column in the foreign key
pcolumn TEXT NOT NULL, // The column in the primary key
// (referenced)
seq_no INTEGER NOT NULL, // The sequence number of this constraint
FOREIGN KEY fk_id REFERENCES sUSRFKeyInfo
);
CREATE TABLE sUSRSchemaInfo (
id NUMERIC NOT NULL,
name TEXT NOT NULL,
type TEXT, // Schema type (system, etc)
other TEXT,
UNIQUE ( name )
);
CREATE TABLE sUSRTableInfo (
id NUMERIC NOT NULL,
name TEXT NOT NULL, // The name of the table
schema TEXT NOT NULL, // The name of the schema of this table
type TEXT, // Table type (temporary, system, etc)
other TEXT, // Notes, etc
UNIQUE ( name )
);
CREATE TABLE sUSRColumnColumns (
t_id NUMERIC NOT NULL, // Foreign key to sUSRTableInfo
column TEXT NOT NULL, // The column name
seq_no INTEGER NOT NULL, // The sequence in the table
type TEXT NOT NULL, // The SQL type of this column
size NUMERIC, // The size of the column if applicable
scale NUMERIC, // The scale of the column if applicable
default TEXT NOT NULL, // The default expression
constraints TEXT NOT NULL, // The constraints of this column
other TEXT, // Notes, etc
FOREIGN KEY t_id REFERENCES sUSRTableInfo,
UNIQUE ( t_id, column )
);
|
|
|