Class Command

java.lang.Object
org.h2.command.Command
All Implemented Interfaces:
AutoCloseable, CommandInterface
Direct Known Subclasses:
CommandContainer, CommandList

public abstract class Command extends Object implements CommandInterface
Represents a SQL statement. This object is only used on the server side.
  • Field Details

    • 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 String sql
    • canReuse

      private boolean canReuse
  • Constructor Details

  • 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:
      isQuery in interface CommandInterface
      Returns:
      true if it is
    • getParameters

      public abstract ArrayList<? extends ParameterInterface> getParameters()
      Get the list of parameters.
      Specified by:
      getParameters in interface CommandInterface
      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(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, or String[] 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 interface CommandInterface
      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 interface CommandInterface
    • executeQuery

      public ResultInterface executeQuery(long maxrows, boolean scrollable)
      Execute a query and return the result. This method prepares everything and calls query(long) finally.
      Specified by:
      executeQuery in interface CommandInterface
      Parameters:
      maxrows - the maximum number of rows to return
      scrollable - if the result set must be scrollable (ignored)
      Returns:
      the result set
    • executeUpdate

      public ResultWithGeneratedKeys executeUpdate(Object generatedKeysRequest)
      Description copied from interface: CommandInterface
      Execute the statement
      Specified by:
      executeUpdate in interface CommandInterface
      Parameters:
      generatedKeysRequest - null or 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, or String[] 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 interface AutoCloseable
      Specified by:
      close in interface CommandInterface
    • cancel

      public void cancel()
      Description copied from interface: CommandInterface
      Cancel the statement if it is still processing.
      Specified by:
      cancel in interface CommandInterface
    • toString

      public String toString()
      Overrides:
      toString in class 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 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