Package org.jooq

Interface Query

    • Method Summary

      All Methods Instance Methods Abstract Methods Deprecated Methods 
      Modifier and Type Method Description
      Query bind​(int index, java.lang.Object value)
      Bind a new value to an indexed parameter.
      Query bind​(java.lang.String param, java.lang.Object value)
      Bind a new value to a named parameter.
      void cancel()
      Cancel the underlying statement.
      void close()
      Close the underlying statement.
      int execute()
      Execute the query, if it has been created with a proper configuration.
      java.util.concurrent.CompletionStage<java.lang.Integer> executeAsync()
      Execute the query in a new CompletionStage.
      java.util.concurrent.CompletionStage<java.lang.Integer> executeAsync​(java.util.concurrent.Executor executor)
      Execute the query in a new CompletionStage that is asynchronously completed by a task running in the given executor.
      java.util.List<java.lang.Object> getBindValues()
      Retrieve the bind values that will be bound by this Query.
      Param<?> getParam​(java.lang.String name)
      Get a named parameter from the Query, provided its name.
      java.util.Map<java.lang.String,​Param<?>> getParams()
      Get a Map of named parameters.
      java.lang.String getSQL()
      Retrieve the SQL code rendered by this Query.
      java.lang.String getSQL​(boolean inline)
      Deprecated.
      - [#2414] - 3.1.0 - Use getSQL(ParamType) instead
      java.lang.String getSQL​(ParamType paramType)
      Retrieve the SQL code rendered by this Query.
      boolean isExecutable()
      Whether this query is executable in its current state.
      Query keepStatement​(boolean keepStatement)
      Keep the query's underlying statement open after execution.
      Query poolable​(boolean poolable)
      Specify whether any JDBC Statement created by this query should be Statement.setPoolable(boolean).
      Query queryTimeout​(int seconds)
      Specify the query timeout in number of seconds for the underlying JDBC Statement.
    • Method Detail

      • execute

        int execute()
             throws DataAccessException
        Execute the query, if it has been created with a proper configuration.
        Returns:
        A result value, depending on the concrete implementation of Query:
        • Delete : the number of deleted records
        • Insert : the number of inserted records
        • Merge : the result may have no meaning
        • Select : the number of resulting records
        • Truncate : the result may have no meaning
        • Update : the number of updated records
        Throws:
        DataAccessException - If anything goes wrong in the database
      • executeAsync

        java.util.concurrent.CompletionStage<java.lang.Integer> executeAsync()
        Execute the query in a new CompletionStage.

        The result is asynchronously completed by a task running in an Executor provided by the underlying Configuration.executorProvider().

        Returns:
        A result value, depending on the concrete implementation of Query:
        • Delete : the number of deleted records
        • Insert : the number of inserted records
        • Merge : the result may have no meaning
        • Select : the number of resulting records
        • Truncate : the result may have no meaning
        • Update : the number of updated records
      • executeAsync

        java.util.concurrent.CompletionStage<java.lang.Integer> executeAsync​(java.util.concurrent.Executor executor)
        Execute the query in a new CompletionStage that is asynchronously completed by a task running in the given executor.
        Returns:
        A result value, depending on the concrete implementation of Query:
        • Delete : the number of deleted records
        • Insert : the number of inserted records
        • Merge : the result may have no meaning
        • Select : the number of resulting records
        • Truncate : the result may have no meaning
        • Update : the number of updated records
      • isExecutable

        boolean isExecutable()
        Whether this query is executable in its current state.

        DML queries may be incomplete in structure and thus not executable. Calling execute() on such queries has no effect, but beware that getSQL() may not render valid SQL!

      • getSQL

        java.lang.String getSQL()
        Retrieve the SQL code rendered by this Query.

        Use this method, when you want to use jOOQ for object oriented query creation, but execute the query with some other technology, such as

        • JDBC
        • Spring Templates
        • JPA native queries
        • etc...

        Note, this is the same as calling getSQL(boolean). The boolean parameter will depend on your DSLContext's Settings:

        StatementType boolean parameter effect
        StatementType.PREPARED_STATEMENT false (default) This will render bind variables to be used with a JDBC PreparedStatement. You can extract bind values from this Query using getBindValues()
        StatementType.STATIC_STATEMENT true This will inline all bind variables in a statement to be used with a JDBC Statement

        [#1520] Note that the query actually being executed might not contain any bind variables, in case the number of bind variables exceeds your SQL dialect's maximum number of supported bind variables. This is not reflected by this method, which will only use the Settings to decide whether to render bind values.

        See Also:
        getSQL(boolean)
      • getSQL

        @Deprecated
        java.lang.String getSQL​(boolean inline)
        Deprecated.
        - [#2414] - 3.1.0 - Use getSQL(ParamType) instead
        Retrieve the SQL code rendered by this Query.

        [#1520] Note that the query actually being executed might not contain any bind variables, in case the number of bind variables exceeds your SQL dialect's maximum number of supported bind variables. This is not reflected by this method, which will only use inline argument to decide whether to render bind values.

        See getSQL() for more details.

        Parameters:
        inline - Whether to inline bind variables. This overrides values in Settings.getStatementType()
        Returns:
        The generated SQL
      • getSQL

        java.lang.String getSQL​(ParamType paramType)
        Retrieve the SQL code rendered by this Query.

        [#1520] Note that the query actually being executed might not contain any bind variables, in case the number of bind variables exceeds your SQL dialect's maximum number of supported bind variables. This is not reflected by this method, which will only use paramType argument to decide whether to render bind values.

        See getSQL() for more details.

        Parameters:
        paramType - How to render parameters. This overrides values in Settings.getStatementType()
        Returns:
        The generated SQL
      • getBindValues

        java.util.List<java.lang.Object> getBindValues()
        Retrieve the bind values that will be bound by this Query. This List cannot be modified. To modify bind values, use getParams() instead.

        Unlike getParams(), which returns also inlined parameters, this returns only actual bind values that will render an actual bind value as a question mark "?"

        See Also:
        DSLContext.extractBindValues(QueryPart)
      • bind

        Query bind​(java.lang.String param,
                   java.lang.Object value)
            throws java.lang.IllegalArgumentException,
                   DataTypeException
        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 keepStatement(boolean), the underlying PreparedStatement will be closed automatically in order for new bind values to have an effect.

        Parameters:
        param - The named parameter name. If this is a number, then this is the same as calling bind(int, Object)
        value - The new bind value.
        Throws:
        java.lang.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

        Query bind​(int index,
                   java.lang.Object value)
            throws java.lang.IllegalArgumentException,
                   DataTypeException
        Bind a new value to an indexed parameter.

        [#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 keepStatement(boolean), the underlying PreparedStatement will be closed automatically in order for new bind values to have an effect.

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

        Query poolable​(boolean poolable)
        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.

        See Also:
        Statement.setPoolable(boolean)
      • queryTimeout

        Query queryTimeout​(int seconds)
        Specify the query timeout in number of seconds for the underlying JDBC Statement.
        See Also:
        Statement.setQueryTimeout(int)
      • keepStatement

        Query keepStatement​(boolean keepStatement)
        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()

        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 java.lang.AutoCloseable
        Throws:
        DataAccessException - If something went wrong closing the statement
        See Also:
        Statement.close()
      • cancel

        void cancel()
             throws DataAccessException
        Cancel the underlying statement.

        This cancels the query's underlying Statement or PreparedStatement. If there is no underlying open and running statement, this call is simply ignored.

        Throws:
        DataAccessException - If something went wrong cancelling the statement
        See Also:
        Statement.cancel()