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,DropBackup,DropUser,Execute,Exit,Export,Flush,Get,Grant,Help,Info,InfoDB,InfoIndex,InfoStorage,Inspect,JobsList,JobsResult,JobsStop,Kill,List,Open,Password,RepoDelete,RepoInstall,RepoList,Restore,Set,ShowBackups,ShowSessions,ShowUsers,Test
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-21, BSD License, Christian Gruen
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal String[]Command arguments.protected ContextDatabase context.protected ExceptionException, resulting from command execution.protected InputSourceOptional input source.protected intMaximum number of results (ignored if negative).final booleanIndicates if the command requires an opened database.protected MainOptionsConvenience access to database options.protected PrintOutputOutput stream.protected StaticOptionsConvenience access to static options.protected StringBase URI. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final booleanAdds the name of the database that has been addressed by the argument index.baseURI()Returns the base URI.Sets a base URI.protected voidbuild(CmdBuilder cb) Builds a string representation from the command.protected static booleanCloses the specified database if it is currently opened and only pinned once.protected final booleanAdds the error message to the message bufferinfo.final ExceptionReturns the cause of an error.final StringExecutes the command and returns the result as string.final voidexecute(Context ctx, OutputStream os) Executes the command and prints the result to the specified output stream.protected final <E extends Enum<E>>
EReturns the specified command option.protected static <E extends Enum<E>>
EReturns the specified command option.final Stringinfo()Returns command information.protected final booleanAdds information on command execution.final voidinit(Context ctx, OutputStream os) Initializes the command execution.final voidmaxResults(int max) Enforces a maximum number of query results.booleanCloses an open data reference and returnstrueif this command will change theContext.data()reference.result()Returns a cached result set generated byAQuery.protected abstract booleanrun()Executes the command and serializes the result (internal call).final booleanRuns the command without permission, data and concurrency checks.final booleanrun(Context ctx, OutputStream os) Runs the command without permission, data and concurrency checks.final voidsetInput(InputStream input) Attaches an input stream.final voidsetInput(InputSource input) Attaches an input source.booleanReturns true if this command can be stopped.booleanReturns true if this command returns a progress value.final StringtoString()final StringtoString(boolean conf) Returns a string representation of the command.booleanChecks if the command has updated any data.booleanChecks if the command performs updates/write operations.
-
Field Details
-
args
Command arguments. -
openDB
public final boolean openDBIndicates if the command requires an opened database. -
context
Database context. -
options
Convenience access to database options. -
soptions
Convenience access to static options. -
out
Output stream. -
in
Optional input source. -
uri
Base URI. -
exception
Exception, resulting from command execution. -
maxResults
protected int maxResultsMaximum number of results (ignored if negative).
-
-
Constructor Details
-
Command
Constructor for commands requiring no opened database.- Parameters:
perm- required permissionargs- arguments
-
Command
Constructor.- Parameters:
perm- required permissionopenDB- requires an opened databaseargs- arguments
-
-
Method Details
-
execute
Executes the command and prints the result to the specified output stream. If an exception occurs, aBaseXExceptionis thrown.- Parameters:
ctx- database contextos- output stream reference- Throws:
BaseXException- command exception
-
execute
Executes the command and returns the result as string. If an exception occurs, aBaseXExceptionis thrown.- Parameters:
ctx- database context- Returns:
- string result
- Throws:
BaseXException- command exception
-
setInput
Attaches an input stream.- Parameters:
input- input stream
-
setInput
Attaches an input source.- Parameters:
input- input source
-
run
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
Returns command information.- Returns:
- info string
-
exception
Returns the cause of an error.- Returns:
- error
-
result
Returns a cached result set generated byAQuery. Can only be called once.- Returns:
- result set or
null
-
updating
Checks if the command performs updates/write operations.- Parameters:
ctx- database context- Returns:
- result of check
-
updated
Checks if the command has updated any data.- Parameters:
ctx- database context- Returns:
- result of check
-
newData
Closes an open data reference and returnstrueif this command will change theContext.data()reference. This method is only required by the GUI.- Parameters:
ctx- database context- Returns:
- result of check
-
maxResults
public final void maxResults(int max) Enforces a maximum number of query results. This method is only required by the GUI.- Parameters:
max- maximum number of results (ignored if negative)
-
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
Initializes the command execution.- Parameters:
ctx- database contextos- output stream
-
run
Runs the command without permission, data and concurrency checks.- Parameters:
ctx- database contextos- output stream- Returns:
- result of check
-
toString
Returns a string representation of the command.- Parameters:
conf- hide confidential information- Returns:
- result of check
-
baseURI
Sets a base URI.- Parameters:
base- base URI- Returns:
- self reference
-
baseURI
Returns the base URI.- Returns:
- base URI
-
toString
-
run
Executes the command and serializes the result (internal call).- Returns:
- success of operation
- Throws:
IOException- I/O exception
-
build
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
Adds the error message to the message bufferinfo.- Parameters:
msg- error messageext- error extension- Returns:
false
-
info
Adds information on command execution.- Parameters:
str- information to be addedext- extended info- Returns:
true
-
getOption
Returns the specified command option.- Type Parameters:
E- token type- Parameters:
typ- options enumeration- Returns:
- option
-
addLocks
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- Returns:
falseif database cannot be determined due to glob syntax
-
getOption
Returns the specified command option.- Type Parameters:
E- token type- Parameters:
string- string to be foundtype- options enumeration- Returns:
- option, or
nullif the option is not found
-
close
Closes the specified database if it is currently opened and only pinned once.- Parameters:
ctx- database contextdb- database to be closed- Returns:
trueif opened database was closed
-