Class TableDataConglomerate
- java.lang.Object
-
- com.mckoi.database.TableDataConglomerate
-
public class TableDataConglomerate extends java.lang.Object
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
TableDataConglomerate.CommitTableInfo
A static container class for information collected about a table during the commit cycle.private static class
TableDataConglomerate.NameSpaceJournal
A journal for handling namespace clashes between transactions.private static class
TableDataConglomerate.TableRowVariableResolver
A variable resolver for a single row of a table source.
-
Field Summary
Fields Modifier and Type Field Description private Store
act_blob_store
The actual Store implementation that maintains the BlobStore information for this conglomerate (if there is one).private Store
act_state_store
The actual store that backs the state store.private BlobStore
blob_store
The BlobStore object for this conglomerate.static TableName
CHECK_INFO_TABLE
private long
commit_id
The current commit id for committed transactions.(package private) java.lang.Object
commit_lock
This lock is obtained when we go to commit a change to the table.static TableName
FOREIGN_COLS_TABLE
static TableName
FOREIGN_INFO_TABLE
private java.util.HashMap
modification_listeners
All listeners for modification events on tables in this conglomerate.private java.lang.String
name
The name given to this conglomerate.private java.util.ArrayList
namespace_journal_list
The list of all name space journals for the history of committed transactions.private OpenTransactionList
open_transactions
The list of transactions that are currently open over this conglomerate.static TableName
PERSISTENT_VAR_TABLE
static TableName
PRIMARY_COLS_TABLE
static TableName
PRIMARY_INFO_TABLE
static TableName
SCHEMA_INFO_TABLE
The schema info table.private SequenceManager
sequence_manager
The SequenceManager object for this conglomerate.static java.lang.String
STATE_POST
The postfix on the name of the state file for the database store name.private StateStore
state_store
A store for the conglomerate state container.private StoreSystem
store_system
The StoreSystem object used by this conglomerate to store the underlying representation.static TableName
SYS_SEQUENCE
static TableName
SYS_SEQUENCE_INFO
private TransactionSystem
system
The TransactionSystem that this Conglomerate is a child of.static java.lang.String
SYSTEM_SCHEMA
The name of the system schema where persistant conglomerate state is stored.private java.util.ArrayList
table_list
The list of all tables that are currently open in this conglomerate.static TableName
UNIQUE_COLS_TABLE
static TableName
UNIQUE_INFO_TABLE
-
Constructor Summary
Constructors Constructor Description TableDataConglomerate(TransactionSystem system, StoreSystem store_system)
Constructs the conglomerate.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTransactionModificationListener(TableName table_name, TransactionModificationListener listener)
Adds a listener for transactional modification events that occur on the given table in this conglomerate.(package private) 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.(package private) 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.(package private) static void
checkAllAddConstraintViolations(SimpleTransaction transaction, TableDataSource table, short deferred)
Performs constraint violation checks on all the rows in the given table.(package private) 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.(package private) 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.(package private) 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.void
checkVisibleTables(UserTerminal terminal)
Checks the list of committed tables in this conglomerate.private void
cleanUpConglomerate()
Cleans up the conglomerate by deleting all tables marked as deleted.void
close()
Closes this conglomerate.private boolean
closeAndDropTable(java.lang.String table_file_name)
Closes and drops the MasterTableDataSource.private void
closeTable(java.lang.String table_file_name, boolean pending_drop)
Closes the MasterTableDataSource with the given source ident.private void
closeTransaction(Transaction transaction)
This is called to notify the conglomerate that the transaction has closed.private static boolean
commitTableListContains(java.util.List list, MasterTableDataSource master)
Returns true if the given List of 'CommitTableInfo' objects contains an entry for the given master table.private void
commitToTables(IntegerVector created_tables, IntegerVector dropped_tables)
Sets the given List of MasterTableDataSource objects to the currently committed list of tables in this conglomerate.(package private) 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.void
create(java.lang.String name)
Creates a new conglomerate at the given path in the file system.private static java.lang.String
createEncodedTableFile(MasterTableDataSource table)
Returns a string that is an encoded table file name.(package private) 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.(package private) Ref
createNewLargeObject(byte type, long size)
Creates and allocates storage for a new large object in the blob store.Transaction
createTransaction()
Starts a new transaction.DebugLogger
Debug()
Returns the DebugLogger object that we use to log debug messages to.(package private) static java.lang.String
deferredString(short deferred)
Convenience, returns either 'Immediate' or 'Deferred' dependant on the deferred short.void
delete()
Deletes and closes the conglomerate.boolean
exists(java.lang.String name)
Returns true if the conglomerate exists in the file system and can be opened.void
finalize()
(package private) static int[]
findColumnIndices(DataTableDef table_def, java.lang.String[] cols)
Returns a list of column indices into the given DataTableDef for the given column names.(package private) static IntegerVector
findKeys(TableDataSource t2, int[] col2_indexes, TObject[] key_value)
Returns the key indices found in the given table.void
fix(java.lang.String name, UserTerminal terminal)
Checks the conglomerate state file.(package private) void
flushBlobStore()
Called when one or more blobs has been completed.java.lang.String[]
getAllTableFileNames()
Returns the list of file names for all tables in this conglomerate.(package private) BlobStore
getBlobStore()
Returns the BlobStore for this conglomerate.RawDiagnosticTable
getDiagnosticTable(java.lang.String table_file_name)
Returns a RawDiagnosticTable object that is used for diagnostics of the table with the given file name.(package private) MasterTableDataSource
getMasterTable(int table_id)
Returns the MasterTableDataSource in this conglomerate with the given table id.(package private) java.lang.String
getName()
Returns the name given to this conglomerate.private java.io.File
getPath()
Returns the path of the database.(package private) SequenceManager
getSequenceManager()
Returns the SequenceManager object for this conglomerate.TransactionSystem
getSystem()
Returns the TransactionSystem that this conglomerate is part of.private void
initializeBlobStore()
Initializes the BlobStore.private void
initializeSystemTableSchema()
Populates the system table schema with initial data for an empty conglomerate.boolean
isClosed()
Returns true if the conglomerate is closed.private boolean
isReadOnly()
Returns true if the system is in read only mode.private static boolean
isUniqueColumns(TableDataSource table, int rindex, java.lang.String[] cols, boolean nulls_are_allowed)
Checks the uniqueness of the columns in the row of the table.void
liveCopyTo(TableDataConglomerate dest_conglomerate)
Makes a complete copy of this database to the position represented by the given TableDataConglomerate object.private MasterTableDataSource
loadMasterTable(int table_id, java.lang.String table_str, int table_type)
Loads the master table given the table_id and the name of the table resource in the database path.private void
markAsCommittedDropped(int table_id)
Marks the given table id as committed dropped.(package private) void
minimalCreate(java.lang.String name)
Minimally creates a new conglomerate but does NOT initialize any of the system tables.private int
nextUniqueTableID()
Returns the next unique table_id value for a new table and updates the conglomerate state information as appropriate.void
open(java.lang.String name)
Opens a conglomerate.(package private) void
processCommit(Transaction transaction, java.util.ArrayList visible_tables, java.util.ArrayList selected_from_tables, java.util.ArrayList touched_tables, TransactionJournal journal)
Tries to commit a transaction to the conglomerate.(package private) void
processRollback(Transaction transaction, java.util.ArrayList touched_tables, TransactionJournal journal)
Rollbacks a transaction and invalidates any changes that the transaction made to the database.private void
readDroppedTables()
Reads in the list of committed dropped tables on this conglomerate.private void
readVisibleTables()
Reads in the list of committed tables in this conglomerate.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.(package private) void
resetAllSystemTableID()
Resets the table sequence id for all the system tables managed by the conglomerate.(package private) 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.private static int
rowCountOfReferenceTable(SimpleTransaction transaction, int row_index, TableName table1, java.lang.String[] cols1, TableName table2, java.lang.String[] cols2, boolean check_source_table_key)
Finds the number of rows that are referenced between the given row of table1 and that match table2.private void
setupInternal()
Sets up the internal state of this object.StoreSystem
storeSystem()
Returns the StoreSystem used by this conglomerate to manage the persistent state of the database.(package private) static java.lang.String
stringColumnList(java.lang.String[] list)
Convenience, converts a String[] array to a comma deliminated string list.(package private) void
updateSystemTableSchema()
Create the system tables that must be present in a conglomerates.
-
-
-
Field Detail
-
STATE_POST
public static final java.lang.String STATE_POST
The postfix on the name of the state file for the database store name.- See Also:
- Constant Field Values
-
SYSTEM_SCHEMA
public static final java.lang.String SYSTEM_SCHEMA
The name of the system schema where persistant conglomerate state is stored.- See Also:
- Constant Field Values
-
SCHEMA_INFO_TABLE
public static final TableName SCHEMA_INFO_TABLE
The schema info table.
-
PERSISTENT_VAR_TABLE
public static final TableName PERSISTENT_VAR_TABLE
-
FOREIGN_COLS_TABLE
public static final TableName FOREIGN_COLS_TABLE
-
UNIQUE_COLS_TABLE
public static final TableName UNIQUE_COLS_TABLE
-
PRIMARY_COLS_TABLE
public static final TableName PRIMARY_COLS_TABLE
-
CHECK_INFO_TABLE
public static final TableName CHECK_INFO_TABLE
-
UNIQUE_INFO_TABLE
public static final TableName UNIQUE_INFO_TABLE
-
FOREIGN_INFO_TABLE
public static final TableName FOREIGN_INFO_TABLE
-
PRIMARY_INFO_TABLE
public static final TableName PRIMARY_INFO_TABLE
-
SYS_SEQUENCE_INFO
public static final TableName SYS_SEQUENCE_INFO
-
SYS_SEQUENCE
public static final TableName SYS_SEQUENCE
-
system
private final TransactionSystem system
The TransactionSystem that this Conglomerate is a child of.
-
store_system
private final StoreSystem store_system
The StoreSystem object used by this conglomerate to store the underlying representation.
-
name
private java.lang.String name
The name given to this conglomerate.
-
act_state_store
private Store act_state_store
The actual store that backs the state store.
-
state_store
private StateStore state_store
A store for the conglomerate state container. This file stores information persistantly about the state of this object.
-
commit_id
private long commit_id
The current commit id for committed transactions. Whenever transactional changes are committed to the conglomerate, this id is incremented.
-
table_list
private java.util.ArrayList table_list
The list of all tables that are currently open in this conglomerate. This includes tables that are not committed.
-
act_blob_store
private Store act_blob_store
The actual Store implementation that maintains the BlobStore information for this conglomerate (if there is one).
-
blob_store
private BlobStore blob_store
The BlobStore object for this conglomerate.
-
sequence_manager
private SequenceManager sequence_manager
The SequenceManager object for this conglomerate.
-
open_transactions
private OpenTransactionList open_transactions
The list of transactions that are currently open over this conglomerate. This list is ordered from lowest commit_id to highest. This object is shared with all the children MasterTableDataSource objects.
-
namespace_journal_list
private java.util.ArrayList namespace_journal_list
The list of all name space journals for the history of committed transactions.
-
modification_listeners
private final java.util.HashMap modification_listeners
All listeners for modification events on tables in this conglomerate. This is a mapping from TableName -> ArrayList of listeners.
-
commit_lock
final java.lang.Object commit_lock
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.
-
-
Constructor Detail
-
TableDataConglomerate
public TableDataConglomerate(TransactionSystem system, StoreSystem store_system)
Constructs the conglomerate.
-
-
Method Detail
-
getSystem
public final TransactionSystem getSystem()
Returns the TransactionSystem that this conglomerate is part of.
-
storeSystem
public final StoreSystem storeSystem()
Returns the StoreSystem used by this conglomerate to manage the persistent state of the database.
-
getSequenceManager
final SequenceManager getSequenceManager()
Returns the SequenceManager object for this conglomerate.
-
getBlobStore
final BlobStore getBlobStore()
Returns the BlobStore for this conglomerate.
-
Debug
public final DebugLogger Debug()
Returns the DebugLogger object that we use to log debug messages to.
-
getName
java.lang.String getName()
Returns the name given to this conglomerate.
-
markAsCommittedDropped
private void markAsCommittedDropped(int table_id)
Marks the given table id as committed dropped.
-
loadMasterTable
private MasterTableDataSource loadMasterTable(int table_id, java.lang.String table_str, int table_type) throws java.io.IOException
Loads the master table given the table_id and the name of the table resource in the database path. The table_string is a specially formatted string that we parse to determine the file structure of the table.- Throws:
java.io.IOException
-
createEncodedTableFile
private static java.lang.String createEncodedTableFile(MasterTableDataSource table)
Returns a string that is an encoded table file name. An encoded table file name includes information about the table type with the name of the table. For example, ":1ThisTable" represents a V1MasterTableDataSource table with file name "ThisTable".
-
readVisibleTables
private void readVisibleTables() throws java.io.IOException
Reads in the list of committed tables in this conglomerate. This should only be called during an 'open' like method. This method fills the 'committed_tables' and 'table_list' lists with the tables in this conglomerate.- Throws:
java.io.IOException
-
checkVisibleTables
public void checkVisibleTables(UserTerminal terminal) throws java.io.IOException
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.- Throws:
java.io.IOException
-
readDroppedTables
private void readDroppedTables() throws java.io.IOException
Reads in the list of committed dropped tables on this conglomerate. This should only be called during an 'open' like method. This method fills the 'committed_dropped' and 'table_list' lists with the tables in this conglomerate.- Parameters:
terminal
- the terminal to ask questions if problems are found. If null then an exception is thrown if there are problems.- Throws:
java.io.IOException
-
updateSystemTableSchema
void updateSystemTableSchema()
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 ) );
-
resetTableID
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.
-
resetAllSystemTableID
void resetAllSystemTableID()
Resets the table sequence id for all the system tables managed by the conglomerate.
-
initializeSystemTableSchema
private void initializeSystemTableSchema()
Populates the system table schema with initial data for an empty conglomerate. This sets up the standard variables and table constraint data.
-
initializeBlobStore
private void initializeBlobStore() throws java.io.IOException
Initializes the BlobStore. If the BlobStore doesn't exist it will be created, and if it does exist it will be initialized.- Throws:
java.io.IOException
-
isReadOnly
private boolean isReadOnly()
Returns true if the system is in read only mode.
-
getPath
private java.io.File getPath()
Returns the path of the database.
-
nextUniqueTableID
private int nextUniqueTableID() throws java.io.IOException
Returns the next unique table_id value for a new table and updates the conglomerate state information as appropriate.- Throws:
java.io.IOException
-
setupInternal
private void setupInternal()
Sets up the internal state of this object.
-
minimalCreate
void minimalCreate(java.lang.String name) throws java.io.IOException
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.- Throws:
java.io.IOException
-
create
public void create(java.lang.String name) throws java.io.IOException
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.- Throws:
java.io.IOException
-
open
public void open(java.lang.String name) throws java.io.IOException
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.- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
Closes this conglomerate. The conglomerate must be open for it to be closed. When closed, any use of this object is undefined.- Throws:
java.io.IOException
-
delete
public void delete() throws java.io.IOException
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.
- Throws:
java.io.IOException
-
isClosed
public boolean isClosed()
Returns true if the conglomerate is closed.
-
exists
public boolean exists(java.lang.String name) throws java.io.IOException
Returns true if the conglomerate exists in the file system and can be opened.- Throws:
java.io.IOException
-
liveCopyTo
public void liveCopyTo(TableDataConglomerate dest_conglomerate) throws java.io.IOException
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.
- Throws:
java.io.IOException
-
getDiagnosticTable
public RawDiagnosticTable getDiagnosticTable(java.lang.String table_file_name)
Returns a RawDiagnosticTable object that is used for diagnostics of the table with the given file name.
-
getAllTableFileNames
public java.lang.String[] getAllTableFileNames()
Returns the list of file names for all tables in this conglomerate.
-
addTransactionModificationListener
public void addTransactionModificationListener(TableName table_name, TransactionModificationListener listener)
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 for events from.listener
- the listener to be notified of events.
-
removeTransactionModificationListener
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.- Parameters:
table_name
- the name of the table in the conglomerate to remove from the listener list.listener
- the listener to be removed.
-
createTransaction
public Transaction createTransaction()
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.
-
closeTransaction
private void closeTransaction(Transaction transaction)
This is called to notify the conglomerate that the transaction has closed. This is always called from either the rollback or commit method of the transaction object.NOTE: This increments 'commit_id' and requires that the conglomerate is commit locked.
-
closeAndDropTable
private boolean closeAndDropTable(java.lang.String table_file_name) throws java.io.IOException
Closes and drops the MasterTableDataSource. This should only be called from the clean up method (cleanUpConglomerate()).Returns true if the drop succeeded. A drop may fail if, for example, the roots of the table are locked.
Note that the table_file_name will be encoded with the table type. For example, ":2mighty.koi"
- Throws:
java.io.IOException
-
closeTable
private void closeTable(java.lang.String table_file_name, boolean pending_drop) throws java.io.IOException
Closes the MasterTableDataSource with the given source ident. This should only be called from the clean up method (cleanUpConglomerate()).Note that the table_file_name will be encoded with the table type. For example, ":2mighty.koi"
- Throws:
java.io.IOException
-
cleanUpConglomerate
private void cleanUpConglomerate() throws java.io.IOException
Cleans up the conglomerate by deleting all tables marked as deleted. This should be called when the conglomerate is opened, shutdown and when there are no transactions open.- Throws:
java.io.IOException
-
stringColumnList
static java.lang.String stringColumnList(java.lang.String[] list)
Convenience, converts a String[] array to a comma deliminated string list.
-
deferredString
static java.lang.String deferredString(short deferred)
Convenience, returns either 'Immediate' or 'Deferred' dependant on the deferred short.
-
findColumnIndices
static int[] findColumnIndices(DataTableDef table_def, java.lang.String[] cols)
Returns a list of column indices into the given DataTableDef for the given column names.
-
isUniqueColumns
private static boolean isUniqueColumns(TableDataSource table, int rindex, java.lang.String[] cols, boolean nulls_are_allowed)
Checks the uniqueness of the columns in the row of the table. If the given column information in the row data is not unique then it returns false. We also check for a NULL values - a PRIMARY KEY constraint does not allow NULL values, whereas a UNIQUE constraint does.
-
findKeys
static IntegerVector findKeys(TableDataSource t2, int[] col2_indexes, TObject[] key_value)
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.
-
rowCountOfReferenceTable
private static int rowCountOfReferenceTable(SimpleTransaction transaction, int row_index, TableName table1, java.lang.String[] cols1, TableName table2, java.lang.String[] cols2, boolean check_source_table_key)
Finds the number of rows that are referenced between the given row of table1 and that match table2. This method is used to determine if there are referential links.If this method returns -1 it means the value being searched for is NULL therefore we can't determine if there are any referenced links.
HACK: If 'check_source_table_key' is set then the key is checked for in the source table and if it exists returns 0. Otherwise it looks for references to the key in table2.
-
checkFieldConstraintViolations
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. Should be used as part of the insert procedure.
-
checkAddConstraintViolations
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. 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 table constraints.table
- the table to testrow_indices
- the list of rows that were added to the table.deferred
- '1' indicates Transaction.IMMEDIATE, '2' indicates Transaction.DEFERRED.
-
checkAddConstraintViolations
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. 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 table constraints.table
- the table to testrow_index
- the row that was added to the table.deferred
- '1' indicates Transaction.IMMEDIATE, '2' indicates Transaction.DEFERRED.
-
checkRemoveConstraintViolations
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. 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 table constraints.table
- the table to testrow_indices
- the set of rows that were removed from the table.deferred
- '1' indicates Transaction.IMMEDIATE, '2' indicates Transaction.DEFERRED.
-
checkRemoveConstraintViolations
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. 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 table constraints.table
- the table to testrow_index
- the row that was removed from the table.deferred
- '1' indicates Transaction.IMMEDIATE, '2' indicates Transaction.DEFERRED.
-
checkAllAddConstraintViolations
static void checkAllAddConstraintViolations(SimpleTransaction transaction, TableDataSource table, short deferred)
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.
-
createNewLargeObject
Ref createNewLargeObject(byte type, long size)
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.
-
flushBlobStore
void flushBlobStore()
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.
-
fix
public void fix(java.lang.String name, UserTerminal terminal)
Checks the conglomerate state file. The returned ErrorState object contains information about any error generated.
-
commitTableListContains
private static boolean commitTableListContains(java.util.List list, MasterTableDataSource master)
Returns true if the given List of 'CommitTableInfo' objects contains an entry for the given master table.
-
processCommit
void processCommit(Transaction transaction, java.util.ArrayList visible_tables, java.util.ArrayList selected_from_tables, java.util.ArrayList touched_tables, TransactionJournal journal) throws TransactionException
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.visible_tables
- the list of visible tables at the end of the commit (MasterTableDataSource)selected_from_tables
- ths list of tables that this transaction performed 'select' like queries on (MasterTableDataSource)touched_tables
- the list of tables touched by the transaction (MutableTableDataSource)journal
- the journal that describes all the changes within the transaction.- Throws:
TransactionException
-
processRollback
void processRollback(Transaction transaction, java.util.ArrayList touched_tables, TransactionJournal journal)
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.
-
commitToTables
private void commitToTables(IntegerVector created_tables, IntegerVector dropped_tables)
Sets the given List of MasterTableDataSource objects to the currently committed list of tables in this conglomerate. This will make the change permanent by updating the state file also.This should be called as part of a transaction commit.
-
getMasterTable
MasterTableDataSource getMasterTable(int table_id)
Returns the MasterTableDataSource in this conglomerate with the given table id.
-
createMasterTable
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. 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.data_sector_size
- the size of the data sectors (affects performance and size of the file).index_sector_size
- the size of the index sectors.
-
copyMasterTable
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. 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.index_set
- the view of the table index to copy.- Returns:
- the MasterTableDataSource with the copied information.
-
finalize
public void finalize()
- Overrides:
finalize
in classjava.lang.Object
-
-