public class CliSession extends ParseSession
| Modifier and Type | Class and Description |
|---|---|
static interface |
CliSession.Action
Callback interface used by
CliSession.performCliSessionAction()
and CliSession.performCliSessionActionWithCurrentTransaction(). |
static interface |
CliSession.TransactionalAction
Deprecated.
Implement
Session.TransactionalAction instead of this interface |
Session.HasTransactionOptions, Session.RetryableAction| Modifier and Type | Field and Description |
|---|---|
static String |
CLI_COMMANDS_DESCRIPTOR_RESOURCE
Classpath XML file resource describing available
Commands: "META-INF/jsimpledb/cli-command-implementations.xml". |
PARSE_FUNCTIONS_DESCRIPTOR_RESOURCEDEFAULT_INITIAL_RETRY_DELAY, DEFAULT_MAX_RETRIES, DEFAULT_MAXIMUM_RETRY_DELAY, log| Constructor and Description |
|---|
CliSession(Database db,
PrintWriter writer,
Console console)
Constructor for
SessionMode.CORE_API mode. |
CliSession(JSimpleDB jdb,
PrintWriter writer,
Console console)
Constructor for
SessionMode.JSIMPLEDB mode. |
CliSession(KVDatabase kvdb,
PrintWriter writer,
Console console)
Constructor for
SessionMode.KEY_VALUE mode. |
| Modifier and Type | Method and Description |
|---|---|
SortedMap<String,Command> |
getCommands()
Get the
Commands registered with this instance. |
Console |
getConsole()
Get the associated
Console, if any. |
String |
getErrorMessagePrefix()
Get prefix for error messages.
|
int |
getLineLimit() |
PrintWriter |
getWriter()
Get the output
PrintWriter for this CLI session. |
boolean |
isDone() |
boolean |
isVerbose() |
void |
loadCommandsFromClasspath()
Scan the classpath for
Commands and register them. |
boolean |
performCliSessionAction(CliSession.Action action)
Perform the given action in the context of this session.
|
boolean |
performCliSessionActionWithCurrentTransaction(CliSession.Action action)
Associate the current
JTransaction with this instance, if not already associated,
while performing the given action. |
void |
registerCommand(Command command)
Register the given
Command. |
protected void |
reportException(Exception e) |
void |
setDone(boolean done) |
void |
setErrorMessagePrefix(String prefix)
Set prefix for error messages.
|
void |
setLineLimit(int lineLimit) |
void |
setVerbose(boolean verbose) |
protected boolean |
showStackTrace(Exception e) |
getFunctions, getIdentifierParser, getImports, getVars, loadFunctionsFromClasspath, performParseSessionAction, performParseSessionActionWithCurrentTransaction, registerFunction, relativizeClassName, resolveClass, setIdentifierParsergetDatabase, getDatabaseDescription, getInitialRetryDelay, getJSimpleDB, getJTransaction, getKVDatabase, getKVTransaction, getMaximumRetryDelay, getMaxRetries, getMode, getNameIndex, getSchemaModel, getSchemaVersion, getTransaction, getValidationMode, isAllowNewSchema, isReadOnly, isTransactionOpen, performSessionAction, performSessionActionWithCurrentTransaction, setAllowNewSchema, setDatabaseDescription, setInitialRetryDelay, setMaximumRetryDelay, setMaxRetries, setMode, setReadOnly, setRollbackOnly, setSchemaModel, setSchemaVersion, setValidationModepublic static final String CLI_COMMANDS_DESCRIPTOR_RESOURCE
Commands: "META-INF/jsimpledb/cli-command-implementations.xml".
Example:
<cli-command-implementations>
<cli-command-implementation class="com.example.MyCliCommand"/>
</cli-command-implementations>
Instances must have a public constructor taking either zero parameters or one CliSession parameter.
public CliSession(KVDatabase kvdb, PrintWriter writer, Console console)
SessionMode.KEY_VALUE mode.kvdb - key/value databasewriter - CLI outputconsole - associated console if any, otherwise nullIllegalArgumentException - if kvdb or writer is nullpublic CliSession(Database db, PrintWriter writer, Console console)
SessionMode.CORE_API mode.db - core databasewriter - CLI outputconsole - associated console if any, otherwise nullIllegalArgumentException - if db or writer is nullpublic CliSession(JSimpleDB jdb, PrintWriter writer, Console console)
SessionMode.JSIMPLEDB mode.jdb - databasewriter - CLI outputconsole - associated console if any, otherwise nullIllegalArgumentException - if jdb or writer is nullpublic Console getConsole()
Console, if any.Console, or null if there is no console associated with this instancepublic PrintWriter getWriter()
PrintWriter for this CLI session.public SortedMap<String,Command> getCommands()
Commands registered with this instance.public int getLineLimit()
public void setLineLimit(int lineLimit)
public boolean isVerbose()
public void setVerbose(boolean verbose)
public boolean isDone()
public void setDone(boolean done)
public void loadCommandsFromClasspath()
Commands and register them.CLI_COMMANDS_DESCRIPTOR_RESOURCEpublic void registerCommand(Command command)
command - new commandIllegalArgumentException - if command is nullprotected void reportException(Exception e)
reportException in class Sessionprotected boolean showStackTrace(Exception e)
public String getErrorMessagePrefix()
Default prefix is "Error: ".
public void setErrorMessagePrefix(String prefix)
prefix - error message prefixpublic boolean performCliSessionAction(CliSession.Action action)
This is a CliSession-specific overload of
Session.performSessionAction(); see that method for details.
action - action to perform, possibly within a transactionaction completed successfully, false if a transaction could not be created
or action threw an exceptionIllegalArgumentException - if action is nullpublic boolean performCliSessionActionWithCurrentTransaction(CliSession.Action action)
JTransaction with this instance, if not already associated,
while performing the given action.
This is a CliSession-specific overload of
Session.performSessionActionWithCurrentTransaction();
see that method for details.
action - action to performaction completed successfully, false if action threw an exceptionIllegalStateException - if there is a different open transaction already associated with this instanceIllegalStateException - if this instance is not in mode SessionMode.JSIMPLEDBIllegalArgumentException - if action is nullCopyright © 2016. All rights reserved.