public interface SelectQuery<R extends Record> extends Select<R>, ConditionProvider
Modifier and Type | Method and Description | ||
---|---|---|---|
void |
addConditions(Collection<? extends Condition> conditions)
Adds new conditions to the query, connecting them to existing
conditions with
Operator.AND |
||
void |
addConditions(Condition... conditions)
Adds new conditions to the query, connecting them to existing
conditions with
Operator.AND |
||
void |
addConditions(Operator operator,
Collection<? extends Condition> conditions)
Adds new conditions to the query, connecting them to existing
conditions with the provided operator
|
||
void |
addConditions(Operator operator,
Condition... conditions)
Adds new conditions to the query, connecting them to existing
conditions with the provided operator
|
||
void |
addConnectBy(Condition condition)
Add an Oracle-specific
CONNECT BY clause to the query |
||
void |
addConnectByNoCycle(Condition condition)
Add an Oracle-specific
CONNECT BY NOCYCLE clause to the
query |
||
void |
addFrom(Collection<? extends TableLike<?>> from)
Add tables to the table product
|
||
void |
addFrom(TableLike<?>... from)
Add tables to the table product
|
||
void |
addGroupBy(Collection<? extends GroupField> fields)
Adds grouping fields
Calling this with an empty argument list will result in an empty
GROUP BY () clause being rendered. |
||
void |
addGroupBy(GroupField... fields)
Adds grouping fields
Calling this with an empty argument list will result in an empty
GROUP BY () clause being rendered. |
||
void |
addHaving(Collection<? extends Condition> conditions)
Adds new conditions to the having clause of the query, connecting it to
existing conditions with the and operator.
|
||
void |
addHaving(Condition... conditions)
Adds new conditions to the having clause of the query, connecting it to
existing conditions with the and operator.
|
||
void |
addHaving(Operator operator,
Collection<? extends Condition> conditions)
Adds new conditions to the having clause of query, connecting them to
existing conditions with the provided operator
|
||
void |
addHaving(Operator operator,
Condition... conditions)
Adds new conditions to the having clause of query, connecting them to
existing conditions with the provided operator
|
||
void |
addHint(String hint)
Add an Oracle-style hint to the select clause.
|
||
void |
addJoin(TableLike<?> table,
Condition... conditions)
Joins the existing table product to a new table using a condition
|
||
void |
addJoin(TableLike<?> table,
JoinType type,
Condition... conditions)
Joins the existing table product to a new table using a condition
|
||
void |
addJoin(TableLike<?> table,
JoinType type,
Condition[] conditions,
Field<?>[] partitionBy)
Joins the existing table product to a new table using a condition
This adds a
PARTITION BY clause to the right hand side of a
OUTER JOIN expression. |
||
void |
addJoinOnKey(TableLike<?> table,
JoinType type)
Joins the existing table product to a new table using a foreign key
|
||
void |
addJoinOnKey(TableLike<?> table,
JoinType type,
ForeignKey<?,?> key)
Joins the existing table product to a new table using a foreign key
|
||
void |
addJoinOnKey(TableLike<?> table,
JoinType type,
TableField<?,?>... keyFields)
Joins the existing table product to a new table using a foreign key
|
||
void |
addJoinUsing(TableLike<?> table,
Collection<? extends Field<?>> fields)
Joins the existing table product to a new table with a
USING
clause
If this is not supported by your RDBMS, then jOOQ will try to simulate
this behaviour using the information provided in this query. |
||
void |
addJoinUsing(TableLike<?> table,
JoinType type,
Collection<? extends Field<?>> fields)
Joins the existing table product to a new table with a
USING
clause
If this is not supported by your RDBMS, then jOOQ will try to simulate
this behaviour using the information provided in this query. |
||
void |
addLimit(int numberOfRows)
Limit the results of this select
This is the same as calling
addLimit(int, int) with offset = 0 |
||
void |
addLimit(int offset,
int numberOfRows)
Limit the results of this select
Note that some dialects do not support bind values at all in
LIMIT or TOP clauses! |
||
void |
addLimit(int offset,
Param<Integer> numberOfRows)
Limit the results of this select using named parameters
Note that some dialects do not support bind values at all in
LIMIT or TOP clauses! |
||
void |
addLimit(Param<Integer> numberOfRows)
Limit the results of this select using named parameters
Note that some dialects do not support bind values at all in
LIMIT or TOP clauses! |
||
void |
addLimit(Param<Integer> offset,
int numberOfRows)
Limit the results of this select
Note that some dialects do not support bind values at all in
LIMIT or TOP clauses! |
||
void |
addLimit(Param<Integer> offset,
Param<Integer> numberOfRows)
Limit the results of this select using named parameters
Note that some dialects do not support bind values at all in
LIMIT or TOP clauses! |
||
void |
addOption(String option)
Add a SQL Server-style query hint to the select clause.
|
||
void |
addOrderBy(Collection<? extends SortField<?>> fields)
Adds ordering fields
|
||
void |
addOrderBy(Field<?>... fields)
Adds ordering fields, ordering by the default sort order
|
||
void |
addOrderBy(int... fieldIndexes)
Adds ordering fields
Indexes start at
1 in SQL! |
||
void |
addOrderBy(SortField<?>... fields)
Adds ordering fields
|
||
void |
addSeekAfter(Collection<? extends Field<?>> fields)
Adds seeking fields.
|
||
void |
addSeekAfter(Field<?>... fields)
Adds seeking fields.
|
||
void |
addSeekBefore(Collection<? extends Field<?>> fields)
Adds seeking fields.
|
||
void |
addSeekBefore(Field<?>... fields)
Adds seeking fields.
|
||
void |
addSelect(Collection<? extends Field<?>> fields)
Add a list of select fields
|
||
void |
addSelect(Field<?>... fields)
Add a list of select fields
|
||
void |
addWindow(Collection<? extends WindowDefinition> definitions)
Adds new window definitions to the window clause of the query.
|
||
void |
addWindow(WindowDefinition... definitions)
Adds new window definitions to the window clause of the query.
|
||
void |
setConnectByStartWith(Condition condition)
Add an Oracle-specific
START WITH clause to the query's
CONNECT BY clause |
||
void |
setDistinct(boolean distinct)
Add "distinct" keyword to the select clause
|
||
void |
setForShare(boolean forShare)
Sets the "FOR SHARE" flag onto the query
This has been observed to be supported by any of these dialects:
MySQL's InnoDB locking reads
Postgres FOR UPDATE / FOR SHARE
If your dialect does not support this clause, jOOQ will still render it,
if you apply it to your query.
|
||
void |
setForUpdate(boolean forUpdate)
Sets the "FOR UPDATE" flag onto the query
Native implementation
This has been observed to be supported by any of these dialects:
void setForUpdateNoWait()
Some RDBMS allow for specifying the locking mode for the applied
FOR UPDATE clause. | ||
void |
setForUpdateOf(Collection<? extends Field<?>> fields)
Some RDBMS allow for specifying the fields that should be locked by the
FOR UPDATE clause, instead of the full row. |
||
void |
setForUpdateOf(Field<?>... fields)
Some RDBMS allow for specifying the fields that should be locked by the
FOR UPDATE clause, instead of the full row. |
||
void |
setForUpdateOf(Table<?>... tables)
Some RDBMS allow for specifying the tables that should be locked by the
FOR UPDATE clause, instead of the full row. |
||
void |
setForUpdateSkipLocked()
Some RDBMS allow for specifying the locking mode for the applied
FOR UPDATE clause. |
||
void |
setForUpdateWait(int seconds)
Some RDBMS allow for specifying the locking mode for the applied
FOR UPDATE clause. |
||
void |
setOrderBySiblings(boolean orderBySiblings)
Indicate whether the
SIBLINGS keyword should be used in an
ORDER BY clause to form an ORDER SIBLINGS BY
clause. |
except, fetchCount, getSelect, intersect, union, unionAll
bind, bind, fetch, fetch, fetch, fetch, fetch, fetch, fetch, fetch, fetch, fetch, fetch, fetchAny, fetchArray, fetchArray, fetchArray, fetchArray, fetchArray, fetchArray, fetchArray, fetchArray, fetchArray, fetchArrays, fetchGroups, fetchGroups, fetchGroups, fetchGroups, fetchGroups, fetchGroups, fetchGroups, fetchInto, fetchInto, fetchInto, fetchLater, fetchLater, fetchLazy, fetchLazy, fetchMany, fetchMap, fetchMap, fetchMap, fetchMap, fetchMap, fetchMap, fetchMap, fetchMaps, fetchOne, fetchOne, fetchOne, fetchOne, fetchOne, fetchOne, fetchOne, fetchOne, fetchOne, fetchOne, fetchOneArray, fetchOneInto, fetchOneInto, fetchOneMap, fetchResultSet, fetchSize, getRecordType, getResult, intern, intern, intern, keepStatement, maxRows, queryTimeout, resultSetConcurrency, resultSetHoldability, resultSetType
cancel, close, execute, getBindValues, getParam, getParams, getSQL, getSQL, getSQL, isExecutable
attach, detach
@Support void addSelect(Field<?>... fields)
fields
- @Support void addSelect(Collection<? extends Field<?>> fields)
fields
- @Support void setDistinct(boolean distinct)
@Support void addFrom(TableLike<?>... from)
from
- The added tables@Support void addFrom(Collection<? extends TableLike<?>> from)
from
- The added tables@Support void addJoin(TableLike<?> table, Condition... conditions)
table
- The joined tableconditions
- The joining conditions@Support void addJoin(TableLike<?> table, JoinType type, Condition... conditions)
table
- The joined tabletype
- The type of joinconditions
- The joining conditions@Support(value=ORACLE) void addJoin(TableLike<?> table, JoinType type, Condition[] conditions, Field<?>[] partitionBy)
This adds a PARTITION BY
clause to the right hand side of a
OUTER JOIN
expression.
table
- The joined tabletype
- The type of joinconditions
- The joining conditionspartitionBy
- The PARTITION BY
expressionTablePartitionByStep
@Support void addJoinUsing(TableLike<?> table, Collection<? extends Field<?>> fields)
USING
clause
If this is not supported by your RDBMS, then jOOQ will try to simulate this behaviour using the information provided in this query.
table
- The joined tablefields
- The fields for the USING
clause@Support void addJoinUsing(TableLike<?> table, JoinType type, Collection<? extends Field<?>> fields)
USING
clause
If this is not supported by your RDBMS, then jOOQ will try to simulate this behaviour using the information provided in this query.
table
- The joined tabletype
- The type of joinfields
- The fields for the USING
clause@Support void addJoinOnKey(TableLike<?> table, JoinType type) throws DataAccessException
table
- The joined tabletype
- The type of joinDataAccessException
- If there is no non-ambiguous key definition
known to jOOQTableOnStep.onKey(ForeignKey)
@Support void addJoinOnKey(TableLike<?> table, JoinType type, TableField<?,?>... keyFields) throws DataAccessException
table
- The joined tabletype
- The type of joinkeyFields
- The foreign key fieldsDataAccessException
- If there is no non-ambiguous key definition
known to jOOQTableOnStep.onKey(ForeignKey)
@Support void addJoinOnKey(TableLike<?> table, JoinType type, ForeignKey<?,?> key)
table
- The joined tabletype
- The type of joinkey
- The foreign keyTableOnStep.onKey(ForeignKey)
@Support void addGroupBy(GroupField... fields)
Calling this with an empty argument list will result in an empty
GROUP BY ()
clause being rendered.
fields
- The grouping fields@Support void addGroupBy(Collection<? extends GroupField> fields)
Calling this with an empty argument list will result in an empty
GROUP BY ()
clause being rendered.
fields
- The grouping fields@Support void addHaving(Condition... conditions)
conditions
- The condition@Support void addHaving(Collection<? extends Condition> conditions)
conditions
- The condition@Support void addHaving(Operator operator, Condition... conditions)
operator
- The operator to use to add the conditions to the existing
conditionsconditions
- The condition@Support void addHaving(Operator operator, Collection<? extends Condition> conditions)
operator
- The operator to use to add the conditions to the existing
conditionsconditions
- The condition@Support(value={CUBRID,DB2,POSTGRES,ORACLE,SQLSERVER,SYBASE}) void addWindow(WindowDefinition... definitions)
definitions
- The definitions@Support(value={CUBRID,DB2,POSTGRES,ORACLE,SQLSERVER,SYBASE}) void addWindow(Collection<? extends WindowDefinition> definitions)
definitions
- The definitions@Support void addHint(String hint)
Example:
DSLContext create = DSL.using(configuration);
create.select(field1, field2)
.hint("/*+ALL_ROWS*/")
.from(table1)
.execute();
You can also use this clause for any other database, that accepts hints
or options at the same syntactic location, e.g. for MySQL's
SQL_CALC_FOUND_ROWS
option:
create.select(field1, field2)
.hint("SQL_CALC_FOUND_ROWS")
.from(table1)
.fetch();
The outcome of such a query is this:
SELECT [hint] field1, field2 FROM table1
For SQL Server style table hints, see Table.with(String)
Table.with(String)
@Support void addOption(String option)
Example:
DSLContext create = DSL.using(configuration);
create.select(field1, field2)
.from(table1)
.option("OPTION (OPTIMIZE FOR UNKNOWN)")
.execute();
You can also use this clause for any other database, that accepts hints
or options at the same syntactic location, e.g. for DB2's isolation clause:
create.select(field1, field2)
.from(table1)
.option("WITH RR USE AND KEEP EXCLUSIVE LOCKS")
.execute();
The outcome of such a query is this:
SELECT field1, field2 FROM table1 [option]
For SQL Server style table hints, see Table.with(String)
Table.with(String)
@Support(value={CUBRID,ORACLE}) void addConnectBy(Condition condition)
CONNECT BY
clause to the query@Support(value={CUBRID,ORACLE}) void addConnectByNoCycle(Condition condition)
CONNECT BY NOCYCLE
clause to the
query@Support(value={CUBRID,ORACLE}) void setConnectByStartWith(Condition condition)
START WITH
clause to the query's
CONNECT BY
clause@Support void addConditions(Condition... conditions)
Operator.AND
addConditions
in interface ConditionProvider
conditions
- The condition@Support void addConditions(Collection<? extends Condition> conditions)
Operator.AND
addConditions
in interface ConditionProvider
conditions
- The condition@Support void addConditions(Operator operator, Condition... conditions)
addConditions
in interface ConditionProvider
conditions
- The condition@Support void addConditions(Operator operator, Collection<? extends Condition> conditions)
addConditions
in interface ConditionProvider
conditions
- The condition@Support void addOrderBy(Field<?>... fields)
fields
- The ordering fields@Support void addOrderBy(SortField<?>... fields)
fields
- The ordering fields@Support void addOrderBy(Collection<? extends SortField<?>> fields)
fields
- The ordering fields@Support void addOrderBy(int... fieldIndexes)
Indexes start at 1
in SQL!
Note, you can use addOrderBy(DSL.val(1).desc())
or
addOrderBy(DSL.literal(1).desc())
to apply descending
ordering
fieldIndexes
- The ordering fields@Support(value={CUBRID,ORACLE}) void setOrderBySiblings(boolean orderBySiblings)
SIBLINGS
keyword should be used in an
ORDER BY
clause to form an ORDER SIBLINGS BY
clause.
This clause can be used only along with Oracle's CONNECT BY
clause, to indicate that the hierarchical ordering should be preserved
and elements of each hierarchy should be ordered among themselves.
orderBySiblings
- @Support void addSeekAfter(Field<?>... fields)
fields
- The seeking fields@Support void addSeekAfter(Collection<? extends Field<?>> fields)
fields
- The seeking fields@Support void addSeekBefore(Field<?>... fields)
fields
- The seeking fields@Support void addSeekBefore(Collection<? extends Field<?>> fields)
fields
- The seeking fields@Support void addLimit(int numberOfRows)
This is the same as calling addLimit(int, int)
with offset = 0
numberOfRows
- The number of rows to return@Support(value={CUBRID,DB2,DERBY,FIREBIRD,H2,HSQLDB,MARIADB,MYSQL,ORACLE,POSTGRES,SQLITE,SQLSERVER,SYBASE}) void addLimit(Param<Integer> numberOfRows)
Note that some dialects do not support bind values at all in
LIMIT
or TOP
clauses!
If there is no LIMIT
or TOP
clause in your
RDBMS, or the LIMIT
or TOP
clause does not
support bind values, this may be simulated with a
ROW_NUMBER()
window function and nested SELECT
statements.
This is the same as calling addLimit(int, int)
with offset = 0
numberOfRows
- The number of rows to return@Support(value={CUBRID,DB2,DERBY,FIREBIRD,H2,HSQLDB,INGRES,MARIADB,MYSQL,ORACLE,POSTGRES,SQLITE,SQLSERVER,SYBASE}) void addLimit(int offset, int numberOfRows)
Note that some dialects do not support bind values at all in
LIMIT
or TOP
clauses!
If there is no LIMIT
or TOP
clause in your
RDBMS, or if your RDBMS does not natively support offsets, this is
simulated with a ROW_NUMBER()
window function and nested
SELECT
statements.
offset
- The lowest offset starting at 0numberOfRows
- The number of rows to return@Support(value={CUBRID,DB2,DERBY,FIREBIRD,H2,HSQLDB,MARIADB,MYSQL,ORACLE,POSTGRES,SQLITE,SQLSERVER,SYBASE}) void addLimit(Param<Integer> offset, int numberOfRows)
Note that some dialects do not support bind values at all in
LIMIT
or TOP
clauses!
If there is no LIMIT
or TOP
clause in your
RDBMS, or the LIMIT
or TOP
clause does not
support bind values, or if your RDBMS does not natively support offsets,
this may be simulated with a ROW_NUMBER()
window function
and nested SELECT
statements.
offset
- The lowest offset starting at 0numberOfRows
- The number of rows to return@Support(value={CUBRID,DB2,DERBY,FIREBIRD,H2,HSQLDB,MARIADB,MYSQL,ORACLE,POSTGRES,SQLITE,SQLSERVER,SYBASE}) void addLimit(int offset, Param<Integer> numberOfRows)
Note that some dialects do not support bind values at all in
LIMIT
or TOP
clauses!
If there is no LIMIT
or TOP
clause in your
RDBMS, or the LIMIT
or TOP
clause does not
support bind values, or if your RDBMS does not natively support offsets,
this may be simulated with a ROW_NUMBER()
window function
and nested SELECT
statements.
offset
- The lowest offset starting at 0numberOfRows
- The number of rows to return@Support(value={CUBRID,DB2,DERBY,FIREBIRD,H2,HSQLDB,MARIADB,MYSQL,ORACLE,POSTGRES,SQLITE,SQLSERVER,SYBASE}) void addLimit(Param<Integer> offset, Param<Integer> numberOfRows)
Note that some dialects do not support bind values at all in
LIMIT
or TOP
clauses!
If there is no LIMIT
or TOP
clause in your
RDBMS, or the LIMIT
or TOP
clause does not
support bind values, or if your RDBMS does not natively support offsets,
this may be simulated with a ROW_NUMBER()
window function
and nested SELECT
statements.
offset
- The lowest offset starting at 0numberOfRows
- The number of rows to return@Support(value={ASE,CUBRID,DB2,DERBY,FIREBIRD,H2,HSQLDB,INGRES,MARIADB,MYSQL,ORACLE,POSTGRES,SQLSERVER,SYBASE}) void setForUpdate(boolean forUpdate)
This has been observed to be supported by any of these dialects:
These dialects can simulate the FOR UPDATE
clause using a
cursor. The cursor is handled by the JDBC driver, at
PreparedStatement
construction time, when calling
Connection.prepareStatement(String, int, int)
with
ResultSet.CONCUR_UPDATABLE
. jOOQ handles simulation of a
FOR UPDATE
clause using CONCUR_UPDATABLE
for
these dialects:
Note: This simulation may not be efficient for large result sets!
These dialects are known not to support the FOR UPDATE
clause in regular SQL:
If your dialect does not support this clause, jOOQ will still render it, if you apply it to your query. This might then cause syntax errors reported either by your database or your JDBC driver.
You shouldn't combine this with setForShare(boolean)
forUpdate
- The flag's value@Support(value={DB2,DERBY,FIREBIRD,H2,HSQLDB,INGRES,ORACLE,SYBASE}) void setForUpdateOf(Field<?>... fields)
FOR UPDATE
clause, instead of the full row.
This automatically sets the setForUpdate(boolean)
flag, and
unsets the setForShare(boolean)
flag, if it was previously set.
This has been observed to be natively supported by any of these dialects:
Note, that SQLDialect.DB2
has some stricter requirements
regarding the updatability of fields. Refer to the DB2 documentation for
further details
fields
- The fields that should be locked@Support(value={DB2,DERBY,FIREBIRD,H2,HSQLDB,INGRES,ORACLE,SYBASE}) void setForUpdateOf(Collection<? extends Field<?>> fields)
FOR UPDATE
clause, instead of the full row.
setForUpdateOf(Field...)
@Support(value={DB2,DERBY,FIREBIRD,H2,HSQLDB,INGRES,POSTGRES,ORACLE,SYBASE}) void setForUpdateOf(Table<?>... tables)
FOR UPDATE
clause, instead of the full row.
This automatically sets the setForUpdate(boolean)
flag, and
unsets the setForShare(boolean)
flag, if it was previously set.
This has been observed to be natively supported by any of these dialects:
jOOQ simulates this by locking all known fields of [tables
]
for any of these dialects:
tables
- The tables that should be locked@Support(value=ORACLE) void setForUpdateWait(int seconds)
FOR UPDATE
clause. In this case, the session will wait for
some seconds
, before aborting the lock acquirement if the
lock is not available.
This automatically sets the setForUpdate(boolean)
flag, and
unsets the setForShare(boolean)
flag, if it was previously set.
This has been observed to be supported by any of these dialects:
seconds
- The number of seconds to wait for a lock@Support(value={ORACLE,POSTGRES}) void setForUpdateNoWait()
FOR UPDATE
clause. In this case, the session will not wait
before aborting the lock acquirement if the lock is not available.
This automatically sets the setForUpdate(boolean)
flag, and
unsets the setForShare(boolean)
flag, if it was previously set.
This has been observed to be supported by any of these dialects:
@Support(value=ORACLE) void setForUpdateSkipLocked()
FOR UPDATE
clause. In this case, the session will skip all
locked rows from the select statement, whose lock is not available.
This automatically sets the setForUpdate(boolean)
flag, and
unsets the setForShare(boolean)
flag, if it was previously set.
This has been observed to be supported by any of these dialects:
@Support(value={MARIADB,MYSQL,POSTGRES}) void setForShare(boolean forShare)
This has been observed to be supported by any of these dialects:
If your dialect does not support this clause, jOOQ will still render it, if you apply it to your query. This might then cause syntax errors reported either by your database or your JDBC driver.
You shouldn't combine this with setForUpdate(boolean)
forShare
- The flag's valueCopyright © 2014. All Rights Reserved.