Package com.mckoi.database
Class DatabaseSystem
- java.lang.Object
-
- com.mckoi.database.TransactionSystem
-
- com.mckoi.database.DatabaseSystem
-
public final class DatabaseSystem extends TransactionSystem
This class provides information about shared resources available for the entire database system running in this VM. Shared information includes configuration details, DataCellCache, plug-ins, user management, etc.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
DatabaseSystem.ShutdownThread
The shut down thread.
-
Field Summary
Fields Modifier and Type Field Description private java.util.ArrayList
database_list
The list of Database objects that this system is being managed by this VM.private boolean
query_logging
True if all queries on the database should be logged in the 'commands.log' file in the log directory.private java.util.ArrayList
shut_down_delegates
private boolean
shutdown
Set to true when the database is shut down.private DatabaseSystem.ShutdownThread
shutdown_thread
The thread to run to shut down the database system.private StatementCache
statement_cache
The StatementCache that maintains a cache of parsed queries.private UserManager
user_manager
The UserManager object that handles users connected to the database engine.private WorkerPool
worker_pool
The WorkerPool object that manages access to the database(s) in the system.
-
Constructor Summary
Constructors Constructor Description DatabaseSystem()
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
dispose()
Disposes all the resources associated with this DatabaseSystem and invalidates this object.(package private) void
execute(User user, DatabaseConnection database, java.lang.Runnable runner)
Executes database functions from the 'run' method of the given runnable instance on the first available worker thread.StatementCache
getStatementCache()
Returns the StatementCache that is used to cache StatementTree objects that are being queried by the database.(package private) UserManager
getUserManager()
Returns the UserManager object that handles users that are connected to the database.(package private) boolean
hasShutDown()
Returns true if 'shutDown' method has been called.void
init(DBConfig config)
Inits the DatabaseSystem with the configuration properties of the system.boolean
logQueries()
If query logging is enabled (all queries are output to 'commands.log' in the log directory), this returns true.Transaction.CheckExpression
prepareTransactionCheckConstraint(DataTableDef table_def, Transaction.CheckExpression check)
Given a Transaction.CheckExpression, this will prepare the expression and return a new prepared CheckExpression.(package private) void
registerShutDownDelegate(java.lang.Runnable delegate)
Registers the delegate that is executed when the shutdown thread is activated.(package private) void
setIsExecutingCommands(boolean status)
Controls whether the database system is allowed to execute commands or not.(package private) void
startShutDownThread()
This starts the ShutDown thread that is used to shut down the database server.(package private) void
waitUntilAllWorkersQuiet()
Waits until all executing commands have stopped.(package private) void
waitUntilShutdown()
Wait until the shutdown thread has completed.-
Methods inherited from class com.mckoi.database.TransactionSystem
addFunctionFactory, alwaysReindexDirtyTables, createEvent, Debug, dontSynchFileSystem, flushCachedFunctionLookup, getBufferManager, getConfigBoolean, getConfigInt, getConfigString, getDatabasePath, getDataCellCache, getFunctionLookup, getLogDirectory, getRegexLibrary, ignoreIdentifierCase, lookupComparisonListEnabled, postEvent, readOnlyAccess, setDebugLevel, setDebugOutput, setLogDirectory, setupRowCache, softIndexStorage, stats, storeSystem, tableLockingEnabled, transactionErrorOnDirtySelect
-
-
-
-
Field Detail
-
statement_cache
private StatementCache statement_cache
The StatementCache that maintains a cache of parsed queries.
-
query_logging
private boolean query_logging
True if all queries on the database should be logged in the 'commands.log' file in the log directory.
-
worker_pool
private WorkerPool worker_pool
The WorkerPool object that manages access to the database(s) in the system.
-
database_list
private java.util.ArrayList database_list
The list of Database objects that this system is being managed by this VM.
-
shutdown
private boolean shutdown
Set to true when the database is shut down.
-
user_manager
private UserManager user_manager
The UserManager object that handles users connected to the database engine.
-
shutdown_thread
private DatabaseSystem.ShutdownThread shutdown_thread
The thread to run to shut down the database system.
-
shut_down_delegates
private final java.util.ArrayList shut_down_delegates
-
-
Method Detail
-
init
public void init(DBConfig config)
Inits the DatabaseSystem with the configuration properties of the system. This can only be called once, and should be called at database boot time.- Overrides:
init
in classTransactionSystem
-
logQueries
public boolean logQueries()
If query logging is enabled (all queries are output to 'commands.log' in the log directory), this returns true. Otherwise it returns false.
-
dispose
public void dispose()
Disposes all the resources associated with this DatabaseSystem and invalidates this object.- Overrides:
dispose
in classTransactionSystem
-
getStatementCache
public StatementCache getStatementCache()
Returns the StatementCache that is used to cache StatementTree objects that are being queried by the database. This is used to reduce the SQL command parsing overhead.If this method returns 'null' then statement caching is disabled.
-
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.A DatabaseSystem resolves the variables (ignoring case if necessary) and the functions of the expression.
- Overrides:
prepareTransactionCheckConstraint
in classTransactionSystem
-
getUserManager
UserManager getUserManager()
Returns the UserManager object that handles users that are connected to the database. The aim of this class is to unify the way users are handled by the engine. It allows us to perform queries to see who's connected, and any inter-user communication (triggers).
-
waitUntilAllWorkersQuiet
void waitUntilAllWorkersQuiet()
Waits until all executing commands have stopped. This is best called right after a call to 'setIsExecutingCommands(false)'. If these two commands are run, the database is in a known state where no commands can be executed.NOTE: This can't be called from the WorkerThread. Deadlock will result if we were allowed to do this.
-
setIsExecutingCommands
void setIsExecutingCommands(boolean status)
Controls whether the database system is allowed to execute commands or not. If this is set to true, then calls to 'execute' will be executed as soon as there is a free worker thread available. Otherwise no commands are executed until this is enabled.
-
execute
void execute(User user, DatabaseConnection database, java.lang.Runnable runner)
Executes database functions from the 'run' method of the given runnable instance on the first available worker thread. All database functions must go through a worker thread. If we ensure this, we can easily stop all database functions from executing if need be. Also, we only need to have a certain number of threads active at any one time rather than a unique thread for each connection.
-
registerShutDownDelegate
void registerShutDownDelegate(java.lang.Runnable delegate)
Registers the delegate that is executed when the shutdown thread is activated. Only one delegate may be registered with the database system. This is only called once and shuts down the relevant database services.
-
startShutDownThread
void startShutDownThread()
This starts the ShutDown thread that is used to shut down the database server. Since the actual shutdown method is dependent on the type of database we are running (server or stand-alone) we delegate the shutdown method to the registered shutdown delegate.
-
hasShutDown
boolean hasShutDown()
Returns true if 'shutDown' method has been called.
-
waitUntilShutdown
void waitUntilShutdown()
Wait until the shutdown thread has completed. (Shutdown process has finished).
-
-