Package edu.caltech.nanodb.server
Class NanoDBServer
- java.lang.Object
-
- edu.caltech.nanodb.server.NanoDBServer
-
- All Implemented Interfaces:
ServerProperties
public class NanoDBServer extends java.lang.Object implements ServerProperties
This class provides the entry-point operations for managing the database server, and executing commands against it. While it is certainly possible to implement these operations separately, these implementations are strongly recommended since they include all necessary supporting steps, such as firing before- and after-command events, acquiring and releasing locks, and other critical resource-management tasks.
This class also includes operations to parse strings into command objects, so that code can construct SQL statements as strings and then issue them against the database. Sometimes it is easier to create a SQL string than it is to construct the corresponding command objects.
-
-
Field Summary
Fields Modifier and Type Field Description private EventDispatcher
eventDispatcher
The event dispatcher for this database server.private FunctionDirectory
functionDirectory
The function directory for this database server.private static org.apache.logging.log4j.Logger
logger
A logging object for reporting anything interesting that happens.private PropertyRegistry
propertyRegistry
The property registry for this database server.private java.util.concurrent.locks.ReentrantReadWriteLock
schemaLock
A read-write lock to force DDL operations to occur serially, and without any overlap from DML operations.private StorageManager
storageManager
The storage manager for this database server.-
Fields inherited from interface edu.caltech.nanodb.server.properties.ServerProperties
DEFAULT_BASE_DIRECTORY, DEFAULT_PAGE_SIZE, DEFAULT_PAGECACHE_POLICY, DEFAULT_PAGECACHE_SIZE, DEFAULT_PLANNER_CLASS, MAX_PAGECACHE_SIZE, MIN_PAGECACHE_SIZE, PAGECACHE_POLICY_VALUES, PROP_BASE_DIRECTORY, PROP_CREATE_INDEXES_ON_KEYS, PROP_ENABLE_INDEXES, PROP_ENABLE_TRANSACTIONS, PROP_ENFORCE_KEY_CONSTRAINTS, PROP_FLUSH_AFTER_CMD, PROP_PAGE_SIZE, PROP_PAGECACHE_POLICY, PROP_PAGECACHE_SIZE, PROP_PLANNER_CLASS
-
-
Constructor Summary
Constructors Constructor Description NanoDBServer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CommandResult
doCommand(Command command, boolean includeTuples)
Executes a single database command, generating aCommandResult
holding details about the operation, and optionally any tuples generated by the operation.CommandResult
doCommand(java.lang.String command, boolean includeTuples)
Parse and execute a single command, returning aCommandResult
object describing the results.java.util.List<CommandResult>
doCommands(java.lang.String commands, boolean includeTuples)
Parse and execute one or more commands, returning a list ofCommandResult
object describing the results.EventDispatcher
getEventDispatcher()
Returns the event-dispatcher for this database server.FunctionDirectory
getFunctionDirectory()
Returns the function directory for this database server.PropertyRegistry
getPropertyRegistry()
Returns the property registry for this database server.Planner
getQueryPlanner()
Returns a query-planner object of the type specified in the current server properties.StorageManager
getStorageManager()
Returns the storage manager for this database server.Command
parseCommand(java.lang.String command)
boolean
shutdown()
This method encapsulates all of the operations necessary for cleanly shutting down the NanoDB server.void
startup()
This static method encapsulates all of the operations necessary for cleanly starting the NanoDB server.void
startup(java.util.Properties initialProperties)
This static method encapsulates all of the operations necessary for cleanly starting the NanoDB server.
-
-
-
Field Detail
-
logger
private static org.apache.logging.log4j.Logger logger
A logging object for reporting anything interesting that happens.
-
propertyRegistry
private PropertyRegistry propertyRegistry
The property registry for this database server.
-
functionDirectory
private FunctionDirectory functionDirectory
The function directory for this database server.
-
eventDispatcher
private EventDispatcher eventDispatcher
The event dispatcher for this database server.
-
storageManager
private StorageManager storageManager
The storage manager for this database server.
-
schemaLock
private java.util.concurrent.locks.ReentrantReadWriteLock schemaLock
A read-write lock to force DDL operations to occur serially, and without any overlap from DML operations.
-
-
Method Detail
-
startup
public void startup()
This static method encapsulates all of the operations necessary for cleanly starting the NanoDB server. Database server properties are initialized from the JVM system properties, and/or defaults are used.
-
startup
public void startup(java.util.Properties initialProperties)
This static method encapsulates all of the operations necessary for cleanly starting the NanoDB server. Database server properties are initialized from the JVM system properties, and/or defaults are used, but these values may optionally be overridden by the initial properties specified as an argument.- Parameters:
initialProperties
- an optional set of database configuration properties which will override system properties and default values, ornull
if no initial properties should be provided.
-
getEventDispatcher
public EventDispatcher getEventDispatcher()
Returns the event-dispatcher for this database server.- Returns:
- the event-dispatcher for this database server.
-
getPropertyRegistry
public PropertyRegistry getPropertyRegistry()
Returns the property registry for this database server.- Returns:
- the property registry for this database server.
-
getFunctionDirectory
public FunctionDirectory getFunctionDirectory()
Returns the function directory for this database server.- Returns:
- the function directory for this database server.
-
getStorageManager
public StorageManager getStorageManager()
Returns the storage manager for this database server.- Returns:
- the storage manager for this database server.
-
parseCommand
public Command parseCommand(java.lang.String command)
-
getQueryPlanner
public Planner getQueryPlanner()
Returns a query-planner object of the type specified in the current server properties. If the planner cannot be instantiated for some reason, aRuntimeException
will be thrown.- Returns:
- a query-planner object of the type specified in the current server properties.
- Throws:
java.lang.RuntimeException
- if the specified planner class cannot be instantiated for some reason.
-
doCommand
public CommandResult doCommand(java.lang.String command, boolean includeTuples)
Parse and execute a single command, returning aCommandResult
object describing the results. The tuples produced by the command may optionally be included in the results as well.- Parameters:
command
- the SQL operation to performincludeTuples
- iftrue
, the results will include all tuples produced by the command- Returns:
- an object describing the outcome of the command execution
-
doCommands
public java.util.List<CommandResult> doCommands(java.lang.String commands, boolean includeTuples)
Parse and execute one or more commands, returning a list ofCommandResult
object describing the results. The tuples produced by the commands may optionally be included in the results as well.- Parameters:
commands
- one or more SQL operations to performincludeTuples
- iftrue
, the results will include all tuples produced by the commands- Returns:
- a list of objects describing the outcome of the command execution
-
doCommand
public CommandResult doCommand(Command command, boolean includeTuples)
Executes a single database command, generating aCommandResult
holding details about the operation, and optionally any tuples generated by the operation. This method also takes care of other command-related details, such as firing "before-command" and "after-command" events, and acquiring and releasing appropriate locks.- Parameters:
command
- the command to executeincludeTuples
- a value oftrue
causes the command's tuples to be stored into the command-result;false
causes any tuples to be discarded.- Returns:
- a command-result describing the results of the operation
-
shutdown
public boolean shutdown()
This method encapsulates all of the operations necessary for cleanly shutting down the NanoDB server.- Returns:
true
if the database server was shutdown cleanly, orfalse
if an error occurred during shutdown.
-
-