org.jooq
Interface Query

All Superinterfaces:
Adapter, Attachable, QueryPart, Serializable
All Known Subinterfaces:
Delete<R>, DeleteConditionStep<R>, DeleteFinalStep<R>, DeleteQuery<R>, DeleteWhereStep<R>, Insert<R>, InsertFinalStep<R>, InsertOnDuplicateSetMoreStep<R>, InsertOnDuplicateStep<R>, InsertQuery<R>, InsertResultStep<R>, InsertSetMoreStep<R>, InsertValuesStep<R>, Merge<R>, MergeFinalStep<R>, MergeMatchedDeleteStep<R>, MergeMatchedSetMoreStep<R>, MergeMatchedStep<R>, MergeMatchedWhereStep<R>, MergeNotMatchedSetMoreStep<R>, MergeNotMatchedStep<R>, MergeNotMatchedWhereStep<R>, MergeOnConditionStep<R>, ResultQuery<R>, Select<R>, SelectConditionStep, SelectConnectByConditionStep, SelectConnectByStep, SelectFinalStep, SelectForUpdateOfStep, SelectForUpdateStep, SelectForUpdateWaitStep, SelectFromStep, SelectGroupByStep, SelectHavingConditionStep, SelectHavingStep, SelectJoinStep, SelectLimitStep, SelectOffsetStep, SelectOnConditionStep, SelectOrderByStep, SelectQuery, SelectSelectStep, SelectStartWithStep, SelectWhereStep, SimpleSelectConditionStep<R>, SimpleSelectFinalStep<R>, SimpleSelectForUpdateOfStep<R>, SimpleSelectForUpdateStep<R>, SimpleSelectForUpdateWaitStep<R>, SimpleSelectLimitStep<R>, SimpleSelectOffsetStep<R>, SimpleSelectOrderByStep<R>, SimpleSelectQuery<R>, SimpleSelectWhereStep<R>, StoreQuery<R>, Truncate<R>, Update<R>, UpdateConditionStep<R>, UpdateFinalStep<R>, UpdateQuery<R>, UpdateSetMoreStep<R>, UpdateWhereStep<R>

public interface Query
extends QueryPart

Any query

Author:
Lukas Eder

Method Summary
 Query bind(int index, Object value)
          Bind a new value to an indexed parameter
 Query bind(String param, Object value)
          Bind a new value to a named parameter
 int execute()
          Execute the query, if it has been created with a properly configured factory
 List<Object> getBindValues()
          Retrieve the bind values that will be bound by this Query.
 Param<?> getParam(String name)
          Get a named parameter from the Query, provided its name.
 Map<String,Param<?>> getParams()
          Get a Map of named parameters.
 String getSQL()
          Retrieve the SQL code rendered by this Query This method can be expected to work correctly for any SQL dialect, as a query is usually "attached" when created from a Factory.
 String getSQL(boolean inline)
          Retrieve the SQL code rendered by this Query See getSQL() for more details
 
Methods inherited from interface org.jooq.Attachable
attach
 
Methods inherited from interface org.jooq.Adapter
internalAPI
 

Method Detail

execute

int execute()
            throws DataAccessException
Execute the query, if it has been created with a properly configured factory

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

getSQL

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

This method can be expected to work correctly for any SQL dialect, as a query is usually "attached" when created from a Factory.

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

Note, this is the same as calling getSQL(boolean). The boolean parameter will depend on your Factory'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

See Also:
getSQL(boolean)

getSQL

String getSQL(boolean inline)
Retrieve the SQL code rendered by this Query

See getSQL() for more details

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

getBindValues

List<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.


getParams

Map<String,Param<?>> getParams()
Get a Map of named parameters. The Map itself cannot be modified, but the Param elements allow for modifying bind values on an existing Query.

Bind values created with Factory.val(Object) will have their bind index as name.

See Also:
Param, Factory.param(String, Object)

getParam

Param<?> getParam(String name)
Get a named parameter from the Query, provided its name.

Bind values created with Factory.val(Object) will have their bind index as name.

See Also:
Param, Factory.param(String, Object)

bind

Query bind(String param,
           Object value)
           throws IllegalArgumentException,
                  DataTypeException
Bind a new value to a named parameter

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:
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,
           Object value)
           throws IllegalArgumentException,
                  DataTypeException
Bind a new value to an indexed parameter

Parameters:
index - The parameter index, 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


Copyright © 2012. All Rights Reserved.