Package org.h2.command
Class Command
- java.lang.Object
-
- org.h2.command.Command
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,CommandInterface
- Direct Known Subclasses:
CommandContainer
,CommandList
public abstract class Command extends java.lang.Object implements CommandInterface
Represents a SQL statement. This object is only used on the server side.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
cancel
If this query was canceled.private boolean
canReuse
protected SessionLocal
session
The session.private java.lang.String
sql
protected long
startTimeNanos
The last start time.private Trace
trace
The trace module.-
Fields inherited from interface org.h2.command.CommandInterface
ALTER_DOMAIN_ADD_CONSTRAINT, ALTER_DOMAIN_DEFAULT, ALTER_DOMAIN_DROP_CONSTRAINT, ALTER_DOMAIN_ON_UPDATE, ALTER_DOMAIN_RENAME, ALTER_DOMAIN_RENAME_CONSTRAINT, ALTER_INDEX_RENAME, ALTER_SCHEMA_RENAME, ALTER_SEQUENCE, ALTER_TABLE_ADD_COLUMN, ALTER_TABLE_ADD_CONSTRAINT_CHECK, ALTER_TABLE_ADD_CONSTRAINT_PRIMARY_KEY, ALTER_TABLE_ADD_CONSTRAINT_REFERENTIAL, ALTER_TABLE_ADD_CONSTRAINT_UNIQUE, ALTER_TABLE_ALTER_COLUMN_CHANGE_TYPE, ALTER_TABLE_ALTER_COLUMN_DEFAULT, ALTER_TABLE_ALTER_COLUMN_DEFAULT_ON_NULL, ALTER_TABLE_ALTER_COLUMN_DROP_EXPRESSION, ALTER_TABLE_ALTER_COLUMN_DROP_IDENTITY, ALTER_TABLE_ALTER_COLUMN_DROP_NOT_NULL, ALTER_TABLE_ALTER_COLUMN_NOT_NULL, ALTER_TABLE_ALTER_COLUMN_ON_UPDATE, ALTER_TABLE_ALTER_COLUMN_RENAME, ALTER_TABLE_ALTER_COLUMN_SELECTIVITY, ALTER_TABLE_ALTER_COLUMN_VISIBILITY, ALTER_TABLE_DROP_COLUMN, ALTER_TABLE_DROP_CONSTRAINT, ALTER_TABLE_RENAME, ALTER_TABLE_RENAME_CONSTRAINT, ALTER_TABLE_SET_REFERENTIAL_INTEGRITY, ALTER_USER_ADMIN, ALTER_USER_RENAME, ALTER_USER_SET_PASSWORD, ALTER_VIEW, ANALYZE, BACKUP, BEGIN, CALL, CHECKPOINT, CHECKPOINT_SYNC, COMMENT, COMMIT, COMMIT_TRANSACTION, CREATE_AGGREGATE, CREATE_ALIAS, CREATE_CONSTANT, CREATE_DOMAIN, CREATE_INDEX, CREATE_LINKED_TABLE, CREATE_ROLE, CREATE_SCHEMA, CREATE_SEQUENCE, CREATE_SYNONYM, CREATE_TABLE, CREATE_TRIGGER, CREATE_USER, CREATE_VIEW, DEALLOCATE, DELETE, DROP_AGGREGATE, DROP_ALIAS, DROP_ALL_OBJECTS, DROP_CONSTANT, DROP_DOMAIN, DROP_INDEX, DROP_ROLE, DROP_SCHEMA, DROP_SEQUENCE, DROP_SYNONYM, DROP_TABLE, DROP_TRIGGER, DROP_USER, DROP_VIEW, EXECUTE, EXECUTE_IMMEDIATELY, EXPLAIN, EXPLAIN_ANALYZE, GRANT, HELP, INSERT, MERGE, NO_OPERATION, PREPARE, PREPARE_COMMIT, REPLACE, REVOKE, ROLLBACK, ROLLBACK_TO_SAVEPOINT, ROLLBACK_TRANSACTION, RUNSCRIPT, SAVEPOINT, SCRIPT, SELECT, SET, SET_AUTOCOMMIT_FALSE, SET_AUTOCOMMIT_TRUE, SHUTDOWN, SHUTDOWN_COMPACT, SHUTDOWN_DEFRAG, SHUTDOWN_IMMEDIATELY, TRUNCATE_TABLE, UNKNOWN, UPDATE
-
-
Constructor Summary
Constructors Constructor Description Command(SessionLocal session, java.lang.String sql)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
cancel()
Cancel the statement if it is still processing.boolean
canReuse()
Whether the command is already closed (in which case it can be re-used).protected void
checkCanceled()
Check if this command has been canceled, and throw an exception if yes.void
close()
Close the statement.private void
commitIfNonTransactional()
ResultInterface
executeQuery(long maxrows, boolean scrollable)
Execute a query and return the result.ResultWithGeneratedKeys
executeUpdate(java.lang.Object generatedKeysRequest)
Execute the statementprivate long
filterConcurrentUpdate(DbException e, long start)
abstract java.util.Set<DbObject>
getDependencies()
ResultInterface
getMetaData()
Get an empty result set containing the meta data of the result.abstract java.util.ArrayList<? extends ParameterInterface>
getParameters()
Get the list of parameters.boolean
isCacheable()
protected abstract boolean
isCurrentCommandADefineCommand()
Is the command we just tried to execute a DefineCommand (i.e.abstract boolean
isQuery()
Check if this command is a query.abstract boolean
isReadOnly()
Check if this command is read only.abstract boolean
isTransactional()
Check if this command is transactional.abstract ResultInterface
query(long maxrows)
Execute a query statement, if this is possible.abstract ResultInterface
queryMeta()
Get an empty result set containing the meta data.void
reuse()
The command is now re-used, therefore reset the canReuse flag, and the parameter values.void
setCanReuse(boolean canReuse)
(package private) void
setProgress(int state)
(package private) void
start()
Start the stopwatch.void
stop()
Stop the command execution, release all locks and resourcesjava.lang.String
toString()
abstract ResultWithGeneratedKeys
update(java.lang.Object generatedKeysRequest)
Execute an updating statement (for example insert, delete, or update), if this is possible.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.h2.command.CommandInterface
getCommandType
-
-
-
-
Field Detail
-
session
protected final SessionLocal session
The session.
-
startTimeNanos
protected long startTimeNanos
The last start time.
-
trace
private final Trace trace
The trace module.
-
cancel
private volatile boolean cancel
If this query was canceled.
-
sql
private final java.lang.String sql
-
canReuse
private boolean canReuse
-
-
Constructor Detail
-
Command
Command(SessionLocal session, java.lang.String sql)
-
-
Method Detail
-
isTransactional
public abstract boolean isTransactional()
Check if this command is transactional. If it is not, then it forces the current transaction to commit.- Returns:
- true if it is
-
isQuery
public abstract boolean isQuery()
Check if this command is a query.- Specified by:
isQuery
in interfaceCommandInterface
- Returns:
- true if it is
-
getParameters
public abstract java.util.ArrayList<? extends ParameterInterface> getParameters()
Get the list of parameters.- Specified by:
getParameters
in interfaceCommandInterface
- Returns:
- the list of parameters
-
isReadOnly
public abstract boolean isReadOnly()
Check if this command is read only.- Returns:
- true if it is
-
queryMeta
public abstract ResultInterface queryMeta()
Get an empty result set containing the meta data.- Returns:
- an empty result set
-
update
public abstract ResultWithGeneratedKeys update(java.lang.Object generatedKeysRequest)
Execute an updating statement (for example insert, delete, or update), if this is possible.- Parameters:
generatedKeysRequest
-false
if generated keys are not needed,true
if generated keys should be configured automatically,int[]
to specify column indices to return generated keys from, orString[]
to specify column names to return generated keys from- Returns:
- the update count and generated keys, if any
- Throws:
DbException
- if the command is not an updating statement
-
query
public abstract ResultInterface query(long maxrows)
Execute a query statement, if this is possible.- Parameters:
maxrows
- the maximum number of rows returned- Returns:
- the local result set
- Throws:
DbException
- if the command is not a query
-
getMetaData
public final ResultInterface getMetaData()
Description copied from interface:CommandInterface
Get an empty result set containing the meta data of the result.- Specified by:
getMetaData
in interfaceCommandInterface
- Returns:
- the empty result
-
start
void start()
Start the stopwatch.
-
setProgress
void setProgress(int state)
-
checkCanceled
protected void checkCanceled()
Check if this command has been canceled, and throw an exception if yes.- Throws:
DbException
- if the statement has been canceled
-
stop
public void stop()
Description copied from interface:CommandInterface
Stop the command execution, release all locks and resources- Specified by:
stop
in interfaceCommandInterface
-
executeQuery
public ResultInterface executeQuery(long maxrows, boolean scrollable)
Execute a query and return the result. This method prepares everything and callsquery(long)
finally.- Specified by:
executeQuery
in interfaceCommandInterface
- Parameters:
maxrows
- the maximum number of rows to returnscrollable
- if the result set must be scrollable (ignored)- Returns:
- the result set
-
executeUpdate
public ResultWithGeneratedKeys executeUpdate(java.lang.Object generatedKeysRequest)
Description copied from interface:CommandInterface
Execute the statement- Specified by:
executeUpdate
in interfaceCommandInterface
- Parameters:
generatedKeysRequest
-null
orfalse
if generated keys are not needed,true
if generated keys should be configured automatically,int[]
to specify column indices to return generated keys from, orString[]
to specify column names to return generated keys from- Returns:
- the update count and generated keys, if any
-
commitIfNonTransactional
private void commitIfNonTransactional()
-
filterConcurrentUpdate
private long filterConcurrentUpdate(DbException e, long start)
-
close
public void close()
Description copied from interface:CommandInterface
Close the statement.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceCommandInterface
-
cancel
public void cancel()
Description copied from interface:CommandInterface
Cancel the statement if it is still processing.- Specified by:
cancel
in interfaceCommandInterface
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
isCacheable
public boolean isCacheable()
-
canReuse
public boolean canReuse()
Whether the command is already closed (in which case it can be re-used).- Returns:
- true if it can be re-used
-
reuse
public void reuse()
The command is now re-used, therefore reset the canReuse flag, and the parameter values.
-
setCanReuse
public void setCanReuse(boolean canReuse)
-
getDependencies
public abstract java.util.Set<DbObject> getDependencies()
-
isCurrentCommandADefineCommand
protected abstract boolean isCurrentCommandADefineCommand()
Is the command we just tried to execute a DefineCommand (i.e. DDL).- Returns:
- true if yes
-
-