Package com.mckoi.database

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

Author:
  Tobias Downer

### Field Summary

Fields
`static TableName` `CHECK_INFO_TABLE`
`static TableName` `FOREIGN_COLS_TABLE`
`static TableName` `FOREIGN_INFO_TABLE`
`static TableName` `PERSISTENT_VAR_TABLE`
`static TableName` `PRIMARY_COLS_TABLE`
`static TableName` `PRIMARY_INFO_TABLE`
`static TableName` `SCHEMA_INFO_TABLE` The schema info table.
`static java.lang.String` `STATE_POST` The postfix on the name of the state file for the database store name.
`static TableName` `SYS_SEQUENCE`
`static TableName` `SYS_SEQUENCE_INFO`
`static java.lang.String` `SYSTEM_SCHEMA` The name of the system schema where persistant conglomerate state is stored.
`static TableName` `UNIQUE_COLS_TABLE`
`static TableName` `UNIQUE_INFO_TABLE`

### Constructor Summary

Constructors
`TableDataConglomerate​(TransactionSystem system, com.mckoi.database.StoreSystem store_system)` Constructs the conglomerate.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addTransactionModificationListener​(TableName table_name, TransactionModificationListener listener)` Adds a listener for transactional modification events that occur on the given table in this conglomerate.
`void` `checkVisibleTables​(UserTerminal terminal)` Checks the list of committed tables in this conglomerate.
`void` `close()` Closes this conglomerate.
`void` `create​(java.lang.String name)` Creates a new conglomerate at the given path in the file system.
`Transaction` `createTransaction()` Starts a new transaction.
`DebugLogger` `Debug()` Returns the DebugLogger object that we use to log debug messages to.
`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()`
`void` `fix​(java.lang.String name, UserTerminal terminal)` Checks the conglomerate state file.
`java.lang.String[]` `getAllTableFileNames()` Returns the list of file names for all tables in 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.
`TransactionSystem` `getSystem()` Returns the TransactionSystem that this conglomerate is part of.
`boolean` `isClosed()` Returns true if the conglomerate is closed.
`void` `liveCopyTo​(TableDataConglomerate dest_conglomerate)` Makes a complete copy of this database to the position represented by the given TableDataConglomerate object.
`void` `open​(java.lang.String name)` Opens a 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.
`com.mckoi.database.StoreSystem` `storeSystem()` Returns the StoreSystem used by this conglomerate to manage the persistent state of the database.

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

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

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

### Constructor Detail

#### TableDataConglomerate

    public TableDataConglomerate​(TransactionSystem system,
                                 com.mckoi.database.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 com.mckoi.database.StoreSystem storeSystem()

Returns the StoreSystem used by this conglomerate to manage the persistent state of the database.

#### Debug

    public final DebugLogger Debug()

Returns the DebugLogger object that we use to log debug messages to.

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

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

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

#### finalize

    public void finalize()

Overrides:
  `finalize` in class `java.lang.Object`