Class Command

  • All Implemented Interfaces:
    java.lang.AutoCloseable, CommandInterface
    Direct Known Subclasses:
    CommandContainer

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

      • session

        protected final SessionLocal session
        The session.
      • startTimeNanos

        protected long startTimeNanos
        The last start time.
    • 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 interface CommandInterface
        Returns:
        true if it is
      • 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 metadata.
        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, 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
      • 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: CommandInterface
        Stop the command execution, release all locks and resources.
        Specified by:
        stop in interface CommandInterface
        Parameters:
        commitIfAutoCommit - commit the session if auto-commit is enabled
      • executeQuery

        public ResultInterface executeQuery​(long maxrows,
                                            int fetchSize,
                                            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
        fetchSize - ignored by local commands
        scrollable - 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 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
      • executeBatchUpdate

        public BatchResult executeBatchUpdate​(java.util.ArrayList<Value[]> batchParameters,
                                              java.lang.Object generatedKeysRequest)
        Description copied from interface: CommandInterface
        Executes the statement with multiple sets of parameters.
        Specified by:
        executeBatchUpdate in interface CommandInterface
        Parameters:
        batchParameters - batch 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:
        result of batch execution
      • close

        public void close()
        Description copied from interface: CommandInterface
        Close the statement.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface CommandInterface
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.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.
      • getDependencies

        public abstract java.util.Set<DbObject> getDependencies()
        Collect all database objects, this command depends on
        Returns:
        Set of dependencies
      • invalidateCachedResult

        public abstract void invalidateCachedResult​(Table reason)
        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

        protected final Database getDatabase()