Package groovy.sql

# Class Sql.AbstractQueryCommand

java.lang.Object
groovy.sql.Sql.AbstractQueryCommand

Enclosing class:
  Sql

protected abstract class Sql.AbstractQueryCommand extends Object
Base command object for query operations that manage statement and connection lifecycle.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final String`
  `sql`
  The SQL text executed by this command.
  `protected Statement`
  `statement`
  The statement created while running the command.

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `AbstractQueryCommand(String sql)`
  Creates a query command for the supplied SQL text.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected final void`
  `closeResources()`
  After performing the execute operation and making use of its return, it's necessary to free the resources allocated for the statement.
  `protected final void`
  `closeResources(ResultSet rs)`
  After performing the execute operation and making use of its return, it's necessary to free the resources allocated for the statement.
  `protected final ResultSet`
  `execute()`
  Execute the command that's defined by the subclass following the Command pattern.
  `protected int`
  `getMaxRows()`
  Get the maximum number of rows to return in the ResultSet
  `protected abstract ResultSet`
  `runQuery(Connection connection)`
  Perform the query.
  `protected void`
  `setMaxRows(int maxRows)`
  Set the maximum number of rows to return in the ResultSet

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### sql

    protected final String sql
    The SQL text executed by this command.

  - ### statement

    protected Statement statement
    The statement created while running the command.

- ## Constructor Details

  - ### AbstractQueryCommand

    protected AbstractQueryCommand(String sql)
    Creates a query command for the supplied SQL text.
    Parameters:
      `sql` - the SQL statement to execute

- ## Method Details

  - ### execute

    protected final ResultSet execute() throws SQLException
    Execute the command that's defined by the subclass following the Command pattern. Specialized parameters are held in the command instances.
    Returns:
      ResultSet from executing a query
    Throws:
      `SQLException` - if a database error occurs

  - ### closeResources

    protected final void closeResources()
    After performing the execute operation and making use of its return, it's necessary to free the resources allocated for the statement.

  - ### closeResources

    protected final void closeResources(ResultSet rs)
    After performing the execute operation and making use of its return, it's necessary to free the resources allocated for the statement.
    Parameters:
      `rs` - allows the caller to conveniently close its resource as well

  - ### runQuery

    protected abstract ResultSet runQuery(Connection connection) throws SQLException
    Perform the query. Must set statement field so that the main (`execute()`) method can clean up. This is the method that encloses the variant part of the code.
    Parameters:
      `connection` - the connection to use
    Returns:
      ResultSet from an executeQuery method.
    Throws:
      `SQLException` - if a database error occurs

  - ### setMaxRows

    protected void setMaxRows(int maxRows)
    Set the maximum number of rows to return in the ResultSet
    Parameters:
      `maxRows` - the maximum number of rows

  - ### getMaxRows

    protected int getMaxRows()
    Get the maximum number of rows to return in the ResultSet
    Returns:
      the maximum number of rows