Module org.jooq
Package org.jooq

Interface CloseableQuery

All Superinterfaces:
Attachable, AttachableQueryPart, AutoCloseable, Query, QueryPart, Serializable, Statement
All Known Subinterfaces:
CloseableResultQuery<R>

public interface CloseableQuery extends Query, AutoCloseable
A Query that holds a reference to the underlying PreparedStatement without closing it, for reuse.

It was created via Query.keepStatement(boolean) and must be treated as a resource, e.g. in a try-with-resources statement.

Author:
Lukas Eder
  • Method Details

    • bind

      @NotNull @NotNull CloseableQuery bind(String param, Object value) throws IllegalArgumentException, DataTypeException
      Description copied from interface: Query
      Bind a new value to a named parameter.

      [#1886] If the bind value with name param is inlined ( Param.isInline()) or if this query was created with StatementType.STATIC_STATEMENT and there is an underlying PreparedStatement kept open because of Query.keepStatement(boolean), the underlying PreparedStatement will be closed automatically in order for new bind values to have an effect.

      Performance consideration

      Historically, the bind value is inserted into the mutable Query, which means that the Query needs to be traversed in order to find the bind value and change it.

      As such, it is usually better to supply bind values directly with the input of an expression, e.g.:

      Specified by:
      bind in interface Query
      Parameters:
      param - The named parameter name. If this is a number, then this is the same as calling Query.bind(int, Object)
      value - The new bind value.
      Throws:
      IllegalArgumentException - if there is no parameter by the given parameter name or index.
      DataTypeException - if value cannot be converted into the parameter's data type
    • bind

      @NotNull @NotNull CloseableQuery bind(int index, Object value) throws IllegalArgumentException, DataTypeException
      Description copied from interface: Query
      Bind a new value to an indexed parameter.

      Bind index order

      The 1-based parameter index describes a parameter in rendering order, not in input order. For example, if a query contains a DSL.log(Field, Field) call, where the first argument is the value and the second argument is the base, this may produce different dialect specific renderings:
      • Db2: ln(value) / ln(base)
      • Oracle: log(base, value)
      • SQL Server: log(value, base)

      Some bind values may even be repeated by a dialect specific emulation, leading to duplication and index-shifting.

      Performance consideration

      Historically, the bind value is inserted into the mutable Query, which means that the Query needs to be traversed in order to find the bind value and change it.

      As such, it is usually better to supply bind values directly with the input of an expression, e.g.:

      Inlined values

      [#1886] If the bind value at index is inlined ( Param.isInline()) or if this query was created with StatementType.STATIC_STATEMENT and there is an underlying PreparedStatement kept open because of Query.keepStatement(boolean), the underlying PreparedStatement will be closed automatically in order for new bind values to have an effect.

      Specified by:
      bind in interface Query
      Parameters:
      index - The parameter index in rendering order, starting with 1
      value - The new bind value.
      Throws:
      IllegalArgumentException - if there is no parameter by the given parameter index.
      DataTypeException - if value cannot be converted into the parameter's data type
    • poolable

      @NotNull @NotNull CloseableQuery poolable(boolean poolable)
      Description copied from interface: Query
      Specify whether any JDBC Statement created by this query should be Statement.setPoolable(boolean).

      If this method is not called on jOOQ types, then jOOQ will not specify the flag on JDBC either, resulting in JDBC's default behaviour.

      Specified by:
      poolable in interface Query
      See Also:
    • queryTimeout

      @NotNull @NotNull CloseableQuery queryTimeout(int seconds)
      Description copied from interface: Query
      Specify the query timeout in number of seconds for the underlying JDBC Statement.
      Specified by:
      queryTimeout in interface Query
      See Also:
    • keepStatement

      @NotNull @NotNull CloseableQuery keepStatement(boolean keepStatement)
      Description copied from interface: Query
      Keep the query's underlying statement open after execution.

      This indicates to jOOQ that the query's underlying Statement or PreparedStatement should be kept open after execution. If it is kept open, client code is responsible for properly closing it using close(), e.g. via a try-with-resources statement.

      Specified by:
      keepStatement in interface Query
      Parameters:
      keepStatement - Whether to keep the underlying statement open
    • close

      void close() throws DataAccessException
      Close the underlying statement.

      This closes the query's underlying Statement or PreparedStatement if a previous call to keepStatement(boolean) indicated that jOOQ should keep statements open after query execution. If there is no underlying open statement, this call is simply ignored.

      Specified by:
      close in interface AutoCloseable
      Throws:
      DataAccessException - If something went wrong closing the statement
      See Also: