public interface Query extends Statement, Attachable, AutoCloseable
Modifier and Type | Method and Description |
---|---|
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.
|
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.
|
CompletionStage<Integer> |
executeAsync()
Execute the query in a new
CompletionStage . |
CompletionStage<Integer> |
executeAsync(Executor executor)
Execute the query in a new
CompletionStage that is asynchronously
completed by a task running in the given executor. |
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.
|
String |
getSQL(boolean inline)
Deprecated.
- [#2414] - 3.1.0 - Use
getSQL(ParamType) instead |
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 |
queryTimeout(int seconds)
Specify the query timeout in number of seconds for the underlying JDBC
Statement . |
attach, configuration, detach
int execute() throws DataAccessException
Query
:
DataAccessException
- If anything goes wrong in the databaseCompletionStage<Integer> executeAsync()
CompletionStage
.
The result is asynchronously completed by a task running in an
Executor
provided by the underlying
Configuration.executorProvider()
.
Query
:
CompletionStage<Integer> executeAsync(Executor executor)
CompletionStage
that is asynchronously
completed by a task running in the given executor.Query
:
boolean isExecutable()
String getSQL()
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 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.
getSQL(boolean)
@Deprecated String getSQL(boolean inline)
getSQL(ParamType)
instead
[#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.
inline
- Whether to inline bind variables. This overrides values in
Settings.getStatementType()
String getSQL(ParamType paramType)
[#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.
paramType
- How to render parameters. This overrides values in
Settings.getStatementType()
List<Object> getBindValues()
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 "?"
DSLContext.extractBindValues(QueryPart)
Map<String,Param<?>> getParams()
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 DSL.val(Object)
will have their bind
index as name.
Param<?> getParam(String name)
Query
, provided its name.
Bind values created with DSL.val(Object)
will have their bind
index as name.
Query bind(String param, Object value) throws IllegalArgumentException, DataTypeException
[#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.
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.IllegalArgumentException
- if there is no parameter by the given
parameter name or index.DataTypeException
- if value
cannot be converted into
the parameter's data typeQuery bind(int index, Object value) throws IllegalArgumentException, DataTypeException
[#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.
index
- The parameter index, starting with 1value
- The new bind value.IllegalArgumentException
- if there is no parameter by the given
parameter index.DataTypeException
- if value
cannot be converted into
the parameter's data typeQuery queryTimeout(int seconds)
Statement
.Statement.setQueryTimeout(int)
Query keepStatement(boolean keepStatement)
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()
keepStatement
- Whether to keep the underlying statement openvoid close() throws DataAccessException
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.
close
in interface AutoCloseable
DataAccessException
- If something went wrong closing the statementStatement.close()
void cancel() throws DataAccessException
This cancels the query's underlying Statement
or
PreparedStatement
. If there is no underlying open and running
statement, this call is simply ignored.
DataAccessException
- If something went wrong cancelling the
statementStatement.cancel()
Copyright © 2019. All rights reserved.