Package org.basex.core
Class Command
- java.lang.Object
-
- org.basex.core.jobs.Job
-
- org.basex.core.Command
-
- Direct Known Subclasses:
ACreate
,AlterBackup
,AlterPassword
,AlterUser
,AQuery
,Check
,Close
,Copy
,CreateBackup
,CreateUser
,Dir
,DropBackup
,DropUser
,Execute
,Exit
,Export
,Flush
,Grant
,Help
,Info
,InfoDB
,InfoIndex
,InfoStorage
,Inspect
,Kill
,List
,Open
,Password
,RepoDelete
,RepoInstall
,RepoList
,Restore
,Set
,ShowBackups
,ShowOptions
,ShowSessions
,ShowUsers
,Test
public abstract class Command extends Job
This class provides the architecture for all internal command implementations. It evaluates queries that are sent by the GUI, the client or the standalone version.- Author:
- BaseX Team 2005-24, BSD License, Christian Gruen
-
-
Field Summary
Fields Modifier and Type Field Description String[]
args
Command arguments.protected Context
context
Database context.Exception
exception
Exception during command execution.protected InputSource
in
Optional input source.boolean
openDB
Indicates if the command requires an opened database.protected MainOptions
options
Convenience access to database options.protected PrintOutput
out
Output stream.Value
result
Cached result of a command execution.protected StaticOptions
soptions
Convenience access to static options.protected String
uri
Base URI.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addLocks(LockList list, int index)
Adds the name of the database that has been addressed by the argument index.String
baseURI()
Returns the base URI.Command
baseURI(String base)
Sets a base URI.protected void
build(CmdBuilder cb)
Builds a string representation from the command.protected static boolean
close(Context ctx, String db)
Closes the specified database if it is currently opened and only pinned once.protected boolean
error(String msg, Object... ext)
Adds the error message to the message bufferinfo
.String
execute(Context ctx)
Executes the command and returns the result as string.void
execute(Context ctx, OutputStream os)
Executes the command and prints the result to the specified output stream.protected <E extends Enum<E>>
EgetOption(Class<E> typ)
Returns the specified command option.protected static <E extends Enum<E>>
EgetOption(String string, Class<E> type)
Returns the specified command option.String
info()
Returns command information.protected boolean
info(String str, Object... ext)
Adds information on command execution.void
init(Context ctx, OutputStream os)
Initializes the command execution.boolean
newData(Context ctx)
Closes an open data reference and returnstrue
if this command will change theContext.data()
reference.protected abstract boolean
run()
Executes the command and serializes the result (internal call).boolean
run(Context ctx)
Runs the command without permission, data and concurrency checks.boolean
run(Context ctx, OutputStream os)
Runs the command without permission, data and concurrency checks.void
setInput(InputStream input)
Attaches an input stream.void
setInput(InputSource input)
Attaches an input source.boolean
stoppable()
Returns true if this command can be stopped.boolean
supportsProg()
Returns true if this command returns a progress value.String
toString()
String
toString(boolean password)
Returns a string representation of the command.boolean
updated(Context ctx)
Checks if the command has updated any data.boolean
updating(Context ctx)
Checks if the command performs updates/write operations.
-
-
-
Field Detail
-
args
public final String[] args
Command arguments.
-
openDB
public final boolean openDB
Indicates if the command requires an opened database.
-
exception
public Exception exception
Exception during command execution.
-
result
public Value result
Cached result of a command execution.
-
context
protected Context context
Database context.
-
options
protected MainOptions options
Convenience access to database options.
-
soptions
protected StaticOptions soptions
Convenience access to static options.
-
out
protected PrintOutput out
Output stream.
-
in
protected InputSource in
Optional input source.
-
uri
protected String uri
Base URI.
-
-
Method Detail
-
execute
public final void execute(Context ctx, OutputStream os) throws BaseXException
Executes the command and prints the result to the specified output stream. If an exception occurs, aBaseXException
is thrown.- Parameters:
ctx
- database contextos
- output stream reference- Throws:
BaseXException
- command exception
-
execute
public final String execute(Context ctx) throws BaseXException
Executes the command and returns the result as string. If an exception occurs, aBaseXException
is thrown.- Parameters:
ctx
- database context- Returns:
- string result
- Throws:
BaseXException
- command exception
-
setInput
public final void setInput(InputStream input)
Attaches an input stream.- Parameters:
input
- input stream
-
setInput
public final void setInput(InputSource input)
Attaches an input source.- Parameters:
input
- input source
-
run
public final boolean run(Context ctx)
Runs the command without permission, data and concurrency checks. Should only be called by other database commands.- Parameters:
ctx
- database context- Returns:
- result of check
-
info
public final String info()
Returns command information.- Returns:
- info string
-
updating
public boolean updating(Context ctx)
Checks if the command performs updates/write operations.- Parameters:
ctx
- database context- Returns:
- result of check
-
updated
public boolean updated(Context ctx)
Checks if the command has updated any data.- Parameters:
ctx
- database context- Returns:
- result of check
-
newData
public boolean newData(Context ctx)
Closes an open data reference and returnstrue
if this command will change theContext.data()
reference. This method is only required by the GUI.- Parameters:
ctx
- database context- Returns:
- result of check
-
supportsProg
public boolean supportsProg()
Returns true if this command returns a progress value. This method is only required by the GUI.- Returns:
- result of check
-
stoppable
public boolean stoppable()
Returns true if this command can be stopped. This method is only required by the GUI.- Returns:
- result of check
-
init
public final void init(Context ctx, OutputStream os)
Initializes the command execution.- Parameters:
ctx
- database contextos
- output stream
-
run
public final boolean run(Context ctx, OutputStream os)
Runs the command without permission, data and concurrency checks.- Parameters:
ctx
- database contextos
- output stream- Returns:
- result of check
-
toString
public final String toString(boolean password)
Returns a string representation of the command.- Parameters:
password
- password flag- Returns:
- result of check
-
baseURI
public Command baseURI(String base)
Sets a base URI.- Parameters:
base
- base URI- Returns:
- self reference
-
baseURI
public String baseURI()
Returns the base URI.- Returns:
- base URI
-
run
protected abstract boolean run() throws IOException
Executes the command and serializes the result (internal call).- Returns:
- success of operation
- Throws:
IOException
- I/O exception
-
build
protected void build(CmdBuilder cb)
Builds a string representation from the command. This string must be correctly built, as commands are sent to the server as strings.- Parameters:
cb
- command builder
-
error
protected final boolean error(String msg, Object... ext)
Adds the error message to the message bufferinfo
.- Parameters:
msg
- error messageext
- error extension- Returns:
false
-
info
protected final boolean info(String str, Object... ext)
Adds information on command execution.- Parameters:
str
- information to be addedext
- extended info- Returns:
true
-
getOption
protected final <E extends Enum<E>> E getOption(Class<E> typ)
Returns the specified command option.- Type Parameters:
E
- token type- Parameters:
typ
- options enumeration- Returns:
- option
-
addLocks
protected final void addLocks(LockList list, int index)
Adds the name of the database that has been addressed by the argument index. No databases will be added if the argument uses glob syntax.- Parameters:
list
- lock listindex
- argument index
-
getOption
protected static <E extends Enum<E>> E getOption(String string, Class<E> type)
Returns the specified command option.- Type Parameters:
E
- token type- Parameters:
string
- string to be foundtype
- options enumeration- Returns:
- option, or
null
if the option is not found
-
-