Class TransactionSystem

  • Direct Known Subclasses:
    DatabaseSystem

    public class TransactionSystem
    extends java.lang.Object
    A class that provides information and global functions for the transaction layer in the engine. Shared information includes configuration details, logging, etc.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  TransactionSystem.DSFunctionLookup
      A FunctionLookup implementation that will look up a function from a list of FunctionFactory objects provided with.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean always_reindex_dirty_tables
      If this is set to true, during boot up the engine will reindex all the tables that weren't closed.
      private LoggingBufferManager buffer_manager
      A LoggingBufferManager object used to manage pages of ScatteringFileStore objects in the file system.
      private DBConfig config
      The ResourceBundle that contains properties of the entire database system.
      private DataCellCache data_cell_cache
      The DataCellCache that is a shared resource between on database's.
      private java.io.File db_path
      The path in the file system for the database files.
      private DatabaseDispatcher dispatcher
      The dispatcher.
      private boolean dont_synch_filesystem
      Set to true if the file handles should NOT be synchronized with the system file IO when the indices are written.
      private java.util.ArrayList function_factory_list
      The list of FunctionFactory objects that handle different functions from SQL.
      private TransactionSystem.DSFunctionLookup function_lookup
      The FunctionLookup object that can resolve a FunctionDef object to a Function object.
      private boolean ignore_case_for_identifiers
      Set to true if the parser should ignore case when searching for a schema, table or column using an identifier.
      private java.io.File log_directory
      The log directory.
      private DefaultDebugLogger logger
      A logger to output any debugging messages.
      private boolean lookup_comparison_list_enabled
      Set to true if lookup comparison lists are enabled.
      private boolean read_only_access
      Set to true if the database is in read only mode.
      private RegexLibrary regex_library
      The regular expression library bridge for the library we are configured to use.
      private boolean soft_index_storage
      Set to false if there is conservative index memory storage.
      private Stats stats
      The stats object that keeps track of database statistics.
      private StoreSystem store_system
      The underlying StoreSystem implementation that encapsulates the behaviour for storing data persistantly.
      private java.util.ArrayList table_listeners
      A list of table names and listeners that are notified of add and remove events in a table.
      private boolean table_lock_check
      Set to true if locking checks should be performed each time a table is accessed.
      private boolean transaction_error_on_dirty_select
      Transaction option, if this is true then a transaction error is generated during commit if a transaction selects data from a table that has committed changes to it during commit time.
    • Constructor Summary

      Constructors 
      Constructor Description
      TransactionSystem()
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addFunctionFactory​(FunctionFactory factory)
      Registers a new FunctionFactory with the database system.
      boolean alwaysReindexDirtyTables()
      Returns the status of the 'always_reindex_dirty_tables' property.
      (package private) java.lang.Object createEvent​(java.lang.Runnable runnable)
      Creates an event object that is passed into 'postEvent' method to run the given Runnable method after the time has passed.
      DebugLogger Debug()
      Returns the DebugLogger object that is used to log debug message.
      void dispose()
      Disposes this object.
      boolean dontSynchFileSystem()
      Returns true if we shouldn't synchronize with the file system when important indexing information is flushed to the disk.
      void flushCachedFunctionLookup()
      Flushes the 'FunctionLookup' object returned by the getFunctionLookup method.
      LoggingBufferManager getBufferManager()
      Returns the LoggingBufferManager object enabling us to create no file stores in the file system.
      boolean getConfigBoolean​(java.lang.String property, boolean default_val)
      Returns a configuration value, or the default if it's not found.
      int getConfigInt​(java.lang.String property, int default_val)
      Returns a configuration value, or the default if it's not found.
      java.lang.String getConfigString​(java.lang.String property, java.lang.String default_val)
      Returns a configuration value, or the default if it's not found.
      java.io.File getDatabasePath()
      Returns the path of the database in the local file system if the database exists within the local file system.
      (package private) DataCellCache getDataCellCache()
      Returns a DataCellCache object that is a shared resource between all database's running on this VM.
      private DatabaseDispatcher getDispatcher()
      Returns the DatabaseDispatcher object.
      FunctionLookup getFunctionLookup()
      Returns a FunctionLookup object that will search through the function factories in this database system and find and resolve a function.
      java.io.File getLogDirectory()
      Returns the current log directory or null if no logging should occur.
      RegexLibrary getRegexLibrary()
      Returns the regular expression library from the configuration file.
      boolean ignoreIdentifierCase()
      Returns true if the parser should ignore case when searching for schema/table/column identifiers.
      void init​(DBConfig config)
      Inits the TransactionSystem with the configuration properties of the system.
      boolean lookupComparisonListEnabled()
      Returns true if we should generate lookup caches in InsertSearch otherwise returns false.
      private static java.io.File parseFileString​(java.io.File root_path, java.lang.String root_info, java.lang.String path_string)
      Parses a file string to an absolute position in the file system.
      (package private) void postEvent​(int time_to_wait, java.lang.Object event)
      Adds a new event to be dispatched on the queue after 'time_to_wait' milliseconds has passed.
      Transaction.CheckExpression prepareTransactionCheckConstraint​(DataTableDef table_def, Transaction.CheckExpression check)
      Given a Transaction.CheckExpression, this will prepare the expression and return a new prepared CheckExpression.
      boolean readOnlyAccess()
      Returns true if the database is in read only mode.
      private static java.lang.String regexStringToClass​(java.lang.String lib)
      Given a regular expression string representing a particular library, this will return the name of the class to use as a bridge between the library and Mckoi.
      void setDebugLevel​(int level)
      Sets the debug minimum level that is output to the logger.
      void setDebugOutput​(java.io.Writer writer)
      Sets the Writer output for the debug logger.
      void setLogDirectory​(java.io.File log_path)
      Sets the log directory.
      private void setupLog​(DBConfig config)
      Sets up the log file from the config information.
      void setupRowCache​(int max_cache_size, int max_cache_entry_size)
      Hack - set up the DataCellCache in DatabaseSystem so we can use the MasterTableDataSource object without having to boot a new DatabaseSystem.
      boolean softIndexStorage()
      Returns true if all table indices are kept behind a soft reference that can be garbage collected.
      Stats stats()
      Returns a com.mckoi.util.Stats object that can be used to keep track of database statistics for this VM.
      StoreSystem storeSystem()
      Returns the StoreSystem encapsulation being used in this database.
      boolean tableLockingEnabled()
      Returns true if the database should perform checking of table locks.
      boolean transactionErrorOnDirtySelect()
      Returns true if during commit the engine should look for any selects on a modified table and fail if they are detected.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • stats

        private final Stats stats
        The stats object that keeps track of database statistics.
      • logger

        private final DefaultDebugLogger logger
        A logger to output any debugging messages. NOTE: This MUST be final, because other objects may retain a reference to the object. If it is not final, then different objects will be logging to different places if this reference is changed.
      • config

        private DBConfig config
        The ResourceBundle that contains properties of the entire database system.
      • db_path

        private java.io.File db_path
        The path in the file system for the database files. Note that this will be null if the database does not exist in a local file system. For this reason it's best not to write code that relies on the use of this value.
      • lookup_comparison_list_enabled

        private boolean lookup_comparison_list_enabled
        Set to true if lookup comparison lists are enabled.
      • read_only_access

        private boolean read_only_access
        Set to true if the database is in read only mode. This is set from the configuration file.
      • table_lock_check

        private boolean table_lock_check
        Set to true if locking checks should be performed each time a table is accessed.
      • soft_index_storage

        private boolean soft_index_storage
        Set to false if there is conservative index memory storage. If true, all root selectable schemes are stored behind a soft reference that will be garbage collected.
      • always_reindex_dirty_tables

        private boolean always_reindex_dirty_tables
        If this is set to true, during boot up the engine will reindex all the tables that weren't closed. If false, the engine will only reindex the tables that have unchecked in modifications.
      • dont_synch_filesystem

        private boolean dont_synch_filesystem
        Set to true if the file handles should NOT be synchronized with the system file IO when the indices are written. If this is true, then the database is not as fail safe, however File IO performance is improved.
      • ignore_case_for_identifiers

        private boolean ignore_case_for_identifiers
        Set to true if the parser should ignore case when searching for a schema, table or column using an identifier.
      • transaction_error_on_dirty_select

        private boolean transaction_error_on_dirty_select
        Transaction option, if this is true then a transaction error is generated during commit if a transaction selects data from a table that has committed changes to it during commit time.

        True by default.

      • data_cell_cache

        private DataCellCache data_cell_cache
        The DataCellCache that is a shared resource between on database's.
      • function_factory_list

        private java.util.ArrayList function_factory_list
        The list of FunctionFactory objects that handle different functions from SQL.
      • regex_library

        private RegexLibrary regex_library
        The regular expression library bridge for the library we are configured to use.
      • log_directory

        private java.io.File log_directory
        The log directory.
      • buffer_manager

        private LoggingBufferManager buffer_manager
        A LoggingBufferManager object used to manage pages of ScatteringFileStore objects in the file system. We can configure the maximum pages and page size via this object, so we have control over how much memory from the heap is used for buffering.
      • store_system

        private StoreSystem store_system
        The underlying StoreSystem implementation that encapsulates the behaviour for storing data persistantly.
      • table_listeners

        private java.util.ArrayList table_listeners
        A list of table names and listeners that are notified of add and remove events in a table.
    • Constructor Detail

      • TransactionSystem

        public TransactionSystem()
        Constructor.
    • Method Detail

      • parseFileString

        private static java.io.File parseFileString​(java.io.File root_path,
                                                    java.lang.String root_info,
                                                    java.lang.String path_string)
        Parses a file string to an absolute position in the file system. We must provide the path to the root directory (eg. the directory where the config bundle is located).
      • setupLog

        private void setupLog​(DBConfig config)
        Sets up the log file from the config information.
      • getConfigString

        public final java.lang.String getConfigString​(java.lang.String property,
                                                      java.lang.String default_val)
        Returns a configuration value, or the default if it's not found.
      • getConfigInt

        public final int getConfigInt​(java.lang.String property,
                                      int default_val)
        Returns a configuration value, or the default if it's not found.
      • getConfigBoolean

        public final boolean getConfigBoolean​(java.lang.String property,
                                              boolean default_val)
        Returns a configuration value, or the default if it's not found.
      • regexStringToClass

        private static java.lang.String regexStringToClass​(java.lang.String lib)
        Given a regular expression string representing a particular library, this will return the name of the class to use as a bridge between the library and Mckoi. Returns null if the library name is invalid.
      • init

        public void init​(DBConfig config)
        Inits the TransactionSystem with the configuration properties of the system. This can only be called once, and should be called at database boot time.
      • setupRowCache

        public void setupRowCache​(int max_cache_size,
                                  int max_cache_entry_size)
        Hack - set up the DataCellCache in DatabaseSystem so we can use the MasterTableDataSource object without having to boot a new DatabaseSystem.
      • readOnlyAccess

        public boolean readOnlyAccess()
        Returns true if the database is in read only mode. In read only mode, any 'write' operations are not permitted.
      • getDatabasePath

        public java.io.File getDatabasePath()
        Returns the path of the database in the local file system if the database exists within the local file system. If the database is not within the local file system then null is returned. It is recommended this method is not used unless for legacy or compatability purposes.
      • tableLockingEnabled

        public boolean tableLockingEnabled()
        Returns true if the database should perform checking of table locks.
      • lookupComparisonListEnabled

        public boolean lookupComparisonListEnabled()
        Returns true if we should generate lookup caches in InsertSearch otherwise returns false.
      • softIndexStorage

        public boolean softIndexStorage()
        Returns true if all table indices are kept behind a soft reference that can be garbage collected.
      • alwaysReindexDirtyTables

        public boolean alwaysReindexDirtyTables()
        Returns the status of the 'always_reindex_dirty_tables' property.
      • dontSynchFileSystem

        public boolean dontSynchFileSystem()
        Returns true if we shouldn't synchronize with the file system when important indexing information is flushed to the disk.
      • transactionErrorOnDirtySelect

        public boolean transactionErrorOnDirtySelect()
        Returns true if during commit the engine should look for any selects on a modified table and fail if they are detected.
      • ignoreIdentifierCase

        public boolean ignoreIdentifierCase()
        Returns true if the parser should ignore case when searching for schema/table/column identifiers.
      • getBufferManager

        public LoggingBufferManager getBufferManager()
        Returns the LoggingBufferManager object enabling us to create no file stores in the file system. This provides access to the buffer scheme that has been configured.
      • getRegexLibrary

        public RegexLibrary getRegexLibrary()
        Returns the regular expression library from the configuration file.
      • storeSystem

        public final StoreSystem storeSystem()
        Returns the StoreSystem encapsulation being used in this database.
      • setDebugOutput

        public final void setDebugOutput​(java.io.Writer writer)
        Sets the Writer output for the debug logger.
      • setDebugLevel

        public final void setDebugLevel​(int level)
        Sets the debug minimum level that is output to the logger.
      • Debug

        public final DebugLogger Debug()
        Returns the DebugLogger object that is used to log debug message. This method must always return a debug logger that we can log to.
      • addFunctionFactory

        public void addFunctionFactory​(FunctionFactory factory)
        Registers a new FunctionFactory with the database system. The function factories are used to resolve a function name into a Function object. Function factories are checked in the order they are added to the database system.
      • flushCachedFunctionLookup

        public void flushCachedFunctionLookup()
        Flushes the 'FunctionLookup' object returned by the getFunctionLookup method. This should be called if the function factory list has been modified in some way.
      • getFunctionLookup

        public FunctionLookup getFunctionLookup()
        Returns a FunctionLookup object that will search through the function factories in this database system and find and resolve a function. The returned object may throw an exception from the 'generateFunction' method if the FunctionDef is invalid. For example, if the number of parameters is incorrect or the name can not be found.
      • prepareTransactionCheckConstraint

        public Transaction.CheckExpression prepareTransactionCheckConstraint​(DataTableDef table_def,
                                                                             Transaction.CheckExpression check)
        Given a Transaction.CheckExpression, this will prepare the expression and return a new prepared CheckExpression. The default implementation of this is to do nothing. However, a sub-class of the system choose to prepare the expression, such as resolving the functions via the function lookup, and resolving the sub-queries, etc.
      • stats

        public final Stats stats()
        Returns a com.mckoi.util.Stats object that can be used to keep track of database statistics for this VM.
      • setLogDirectory

        public final void setLogDirectory​(java.io.File log_path)
        Sets the log directory. This should preferably be called during initialization. If the log directory is not set or is set to 'null' then no logging to files occurs.
      • getLogDirectory

        public final java.io.File getLogDirectory()
        Returns the current log directory or null if no logging should occur.
      • getDataCellCache

        DataCellCache getDataCellCache()
        Returns a DataCellCache object that is a shared resource between all database's running on this VM. If this returns 'null' then the internal cache is disabled.
      • getDispatcher

        private DatabaseDispatcher getDispatcher()
        Returns the DatabaseDispatcher object.
      • createEvent

        java.lang.Object createEvent​(java.lang.Runnable runnable)
        Creates an event object that is passed into 'postEvent' method to run the given Runnable method after the time has passed.

        The event created here can be safely posted on the event queue as many times as you like. It's useful to create an event as a persistant object to service some event. Just post it on the dispatcher when you want it run!

      • postEvent

        void postEvent​(int time_to_wait,
                       java.lang.Object event)
        Adds a new event to be dispatched on the queue after 'time_to_wait' milliseconds has passed.

        'event' must be an event object returned via 'createEvent'.

      • dispose

        public void dispose()
        Disposes this object.