Package org.h2.command
Class Command
java.lang.Object
org.h2.command.Command
- All Implemented Interfaces:
AutoCloseable,CommandInterface
- Direct Known Subclasses:
CommandContainer
Represents a SQL statement. This object is only used on the server side.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final SessionLocalThe session.protected longThe last start time.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_TYPE, 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_MATERIALIZED_VIEW, 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_MATERIALIZED_VIEW, 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, REFRESH_MATERIALIZED_VIEW, 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 -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Cancel the statement if it is still processing.booleancanReuse()Whether the command is already closed (in which case it can be re-used).protected voidCheck if this command has been canceled, and throw an exception if yes.voidclose()Close the statement.executeBatchUpdate(ArrayList<Value[]> batchParameters, Object generatedKeysRequest) Executes the statement with multiple sets of parameters.executeQuery(long maxrows, int fetchSize, boolean scrollable) Execute a query and return the result.executeUpdate(Object generatedKeysRequest) Execute the statementprotected final DatabaseCollect all database objects, this command depends onfinal ResultInterfaceGet an empty result set containing the meta data of the result.abstract ArrayList<? extends ParameterInterface> Get the list of parameters.abstract voidinvalidateCachedResult(Table reason) Clear cached results of all prepared statements, which depends on a given tablebooleanabstract booleanisQuery()Check if this command is a query.abstract booleanCheck if this command is read only.protected abstract booleanChecks if this command can be repeated on locking failure.abstract booleanCheck if this command is transactional.abstract ResultInterfacequery(long maxrows) Execute a query statement, if this is possible.abstract ResultInterfaceGet an empty result set containing the metadata.voidreuse()The command is now re-used, therefore reset the canReuse flag, and the parameter values.voidstop(boolean commitIfAutoCommit) Stop the command execution, release all locks and resources.toString()abstract ResultWithGeneratedKeysExecute 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, waitMethods inherited from interface org.h2.command.CommandInterface
getCommandType
-
Field Details
-
session
The session. -
startTimeNanos
protected long startTimeNanosThe last start time.
-
-
Method Details
-
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:
isQueryin interfaceCommandInterface- Returns:
- true if it is
-
getParameters
Get the list of parameters.- Specified by:
getParametersin interfaceCommandInterface- Returns:
- the list of parameters
-
isReadOnly
public abstract boolean isReadOnly()Check if this command is read only.- Returns:
- true if it is
-
queryMeta
Get an empty result set containing the metadata.- Returns:
- an empty result set
-
update
Execute an updating statement (for example insert, delete, or update), if this is possible.- Parameters:
generatedKeysRequest-falseif generated keys are not needed,trueif 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
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
Description copied from interface:CommandInterfaceGet an empty result set containing the meta data of the result.- Specified by:
getMetaDatain interfaceCommandInterface- Returns:
- the empty result
-
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(boolean commitIfAutoCommit) Description copied from interface:CommandInterfaceStop the command execution, release all locks and resources.- Specified by:
stopin interfaceCommandInterface- Parameters:
commitIfAutoCommit- commit the session if auto-commit is enabled
-
executeQuery
Execute a query and return the result. This method prepares everything and callsquery(long)finally.- Specified by:
executeQueryin interfaceCommandInterface- Parameters:
maxrows- the maximum number of rows to returnfetchSize- ignored by local commandsscrollable- if the result set must be scrollable (ignored)- Returns:
- the result set
-
executeUpdate
Description copied from interface:CommandInterfaceExecute the statement- Specified by:
executeUpdatein interfaceCommandInterface- Parameters:
generatedKeysRequest-nullorfalseif generated keys are not needed,trueif 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
-
executeBatchUpdate
public BatchResult executeBatchUpdate(ArrayList<Value[]> batchParameters, Object generatedKeysRequest) Description copied from interface:CommandInterfaceExecutes the statement with multiple sets of parameters.- Specified by:
executeBatchUpdatein interfaceCommandInterface- Parameters:
batchParameters- batch parametersgeneratedKeysRequest-nullorfalseif generated keys are not needed,trueif 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:
- result of batch execution
-
close
public void close()Description copied from interface:CommandInterfaceClose the statement.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCommandInterface
-
cancel
public void cancel()Description copied from interface:CommandInterfaceCancel the statement if it is still processing.- Specified by:
cancelin interfaceCommandInterface
-
toString
-
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. -
getDependencies
Collect all database objects, this command depends on- Returns:
- Set of dependencies
-
invalidateCachedResult
Clear cached results of all prepared statements, which depends on a given table- Parameters:
reason- table causing invalidation
-
isRetryable
protected abstract boolean isRetryable()Checks if this command can be repeated on locking failure.- Returns:
- true if this command can be repeated on locking failure
-
getDatabase
-