T
- result typeQ
- concrete subtypepublic abstract class AbstractSQLQuery<T,Q extends AbstractSQLQuery<T,Q>> extends ProjectableSQLQuery<T,Q>
AbstractSQLQuery
is the base type for SQL query implementationsModifier and Type | Field and Description |
---|---|
protected SQLListeners |
listeners |
protected static java.lang.String |
PARENT_CONTEXT |
protected boolean |
useLiterals |
configuration, firstUnionSubQuery, union, unionAll
MDC_PARAMETERS, MDC_QUERY, queryMixin
Constructor and Description |
---|
AbstractSQLQuery(@Nullable java.sql.Connection conn,
Configuration configuration) |
AbstractSQLQuery(@Nullable java.sql.Connection conn,
Configuration configuration,
QueryMetadata metadata) |
AbstractSQLQuery(java.util.function.Supplier<java.sql.Connection> connProvider,
Configuration configuration) |
AbstractSQLQuery(java.util.function.Supplier<java.sql.Connection> connProvider,
Configuration configuration,
QueryMetadata metadata) |
Modifier and Type | Method and Description |
---|---|
void |
addListener(SQLListener listener)
Add a listener
|
SimpleExpression<T> |
as(Path<?> alias)
Create an alias for the expression
|
SimpleExpression<T> |
as(java.lang.String alias)
Create an alias for the expression
|
Q |
clone() |
abstract Q |
clone(java.sql.Connection connection) |
protected void |
clone(Q query) |
protected SQLSerializer |
createSerializer() |
protected void |
endContext(SQLListenerContext context)
Called to end a SQL listener context
|
java.util.List<T> |
fetch()
Get the projection as a typed List
|
long |
fetchCount()
Get the count of matched elements
Note: not all QueryDSL modules might optimize fetchCount using a count query.
|
QueryResults<T> |
fetchResults()
Get the projection in
QueryResults form. |
Q |
forShare()
FOR SHARE causes the rows retrieved by the SELECT statement to be locked as though for update.
|
Q |
forShare(boolean fallbackToForUpdate)
FOR SHARE causes the rows retrieved by the SELECT statement to be locked as though for update.
|
Q |
forUpdate()
If you use forUpdate() with a backend that uses page or row locks, rows examined by the
query are write-locked until the end of the current transaction.
|
protected Configuration |
getConfiguration() |
java.sql.ResultSet |
getResults()
Get the results as a JDBC ResultSet
|
java.sql.ResultSet |
getResults(Expression<?>... exprs)
Deprecated.
Use @{code select(..)} to define the projection and
getResults() to obtain
the result set |
com.mysema.commons.lang.CloseableIterator<T> |
iterate()
Get the projection as a typed closeable Iterator
|
protected void |
logQuery(java.lang.String queryString,
java.util.Collection<java.lang.Object> parameters) |
protected void |
onException(SQLListenerContextImpl context,
java.lang.Exception e)
Called to make the call back to listeners when an exception happens
|
protected void |
setParameters(java.sql.PreparedStatement stmt,
java.util.List<?> objects,
java.util.List<Path<?>> constantPaths,
java.util.Map<ParamExpression<?>,?> params) |
void |
setStatementOptions(StatementOptions statementOptions)
Set the options to be applied to the JDBC statements of this query
|
void |
setUseLiterals(boolean useLiterals)
Set whether literals are used in SQL strings instead of parameter bindings (default: false)
|
protected SQLListenerContextImpl |
startContext(java.sql.Connection connection,
QueryMetadata metadata)
Called to create and start a new SQL Listener context
|
accept, addFlag, addFlag, addFlag, addFlag, addJoinFlag, addJoinFlag, fetchOne, from, from, from, fullJoin, fullJoin, fullJoin, fullJoin, fullJoin, getSQL, getSQL, innerJoin, innerJoin, innerJoin, innerJoin, innerJoin, join, join, join, join, join, leftJoin, leftJoin, leftJoin, leftJoin, leftJoin, on, on, rightJoin, rightJoin, rightJoin, rightJoin, rightJoin, serialize, toString, union, union, union, unionAll, unionAll, unionAll, with, with, with, withRecursive, withRecursive, withRecursive
contains, contains, eq, eq, exists, getMetadata, getType, goe, goe, gt, gt, hashCode, in, in, isNotNull, isNull, loe, loe, lt, lt, ne, ne, notExists
equals, fetchFirst, transform, uniqueResult
distinct, groupBy, groupBy, having, having, limit, offset, orderBy, orderBy, restrict, set, where, where
finalize, getClass, notify, notifyAll, wait, wait, wait
distinct, limit, offset, orderBy, restrict, set
where
select, select, transform
fetchFirst, stream
protected static final java.lang.String PARENT_CONTEXT
protected SQLListeners listeners
protected boolean useLiterals
public AbstractSQLQuery(@Nullable @Nullable java.sql.Connection conn, Configuration configuration)
public AbstractSQLQuery(@Nullable @Nullable java.sql.Connection conn, Configuration configuration, QueryMetadata metadata)
public AbstractSQLQuery(java.util.function.Supplier<java.sql.Connection> connProvider, Configuration configuration)
public AbstractSQLQuery(java.util.function.Supplier<java.sql.Connection> connProvider, Configuration configuration, QueryMetadata metadata)
public SimpleExpression<T> as(java.lang.String alias)
alias
- aliaspublic SimpleExpression<T> as(Path<?> alias)
alias
- aliaspublic void addListener(SQLListener listener)
listener
- listener to addpublic long fetchCount()
Fetchable
fetch().size()
.fetchCount
in interface Fetchable<T>
fetchCount
in class ProjectableSQLQuery<T,Q extends AbstractSQLQuery<T,Q>>
public Q forUpdate()
public Q forShare()
QueryException
- if the FOR SHARE is not supported.public Q forShare(boolean fallbackToForUpdate)
fallbackToForUpdate
- if the FOR SHARE is not supported and this parameter is true
, the
forUpdate()
functionality will be used.QueryException
- if the FOR SHARE is not supported and fallbackToForUpdate is set to
false
.protected SQLSerializer createSerializer()
createSerializer
in class ProjectableSQLQuery<T,Q extends AbstractSQLQuery<T,Q>>
protected SQLListenerContextImpl startContext(java.sql.Connection connection, QueryMetadata metadata)
connection
- the database connectionmetadata
- the meta data for that contextprotected void onException(SQLListenerContextImpl context, java.lang.Exception e)
context
- the current context in playe
- the exceptionprotected void endContext(SQLListenerContext context)
context
- the listener context to end@Deprecated public java.sql.ResultSet getResults(Expression<?>... exprs)
getResults()
to obtain
the result setexprs
- the expression arguments to retrievepublic java.sql.ResultSet getResults()
protected Configuration getConfiguration()
public com.mysema.commons.lang.CloseableIterator<T> iterate()
Fetchable
public java.util.List<T> fetch()
Fetchable
fetch
in interface Fetchable<T>
fetch
in class FetchableQueryBase<T,Q extends AbstractSQLQuery<T,Q>>
public QueryResults<T> fetchResults()
Fetchable
QueryResults
form.
Make sure to use Fetchable.fetch()
instead if you do not rely on the QueryResults.getOffset()
or
QueryResults.getLimit()
, because it will be more performant. Also, count queries cannot be
properly generated for all dialects. For example: in JPA count queries can't be generated for queries
that have multiple group by expressions or a having clause.
Get the projection in QueryResults
form.
Use Fetchable.fetch()
instead if you do not need the total count of rows in the query result.Fetchable.fetch()
protected void setParameters(java.sql.PreparedStatement stmt, java.util.List<?> objects, java.util.List<Path<?>> constantPaths, java.util.Map<ParamExpression<?>,?> params)
protected void logQuery(java.lang.String queryString, java.util.Collection<java.lang.Object> parameters)
public void setUseLiterals(boolean useLiterals)
Warning: When literals are used, prepared statement won't have any parameter bindings and also batch statements will only be simulated, but not executed as actual batch statements.
useLiterals
- true for literals and false for bindingsprotected void clone(Q query)
clone
in class ProjectableSQLQuery<T,Q extends AbstractSQLQuery<T,Q>>
public Q clone()
clone
in class ProjectableSQLQuery<T,Q extends AbstractSQLQuery<T,Q>>
public abstract Q clone(java.sql.Connection connection)
public void setStatementOptions(StatementOptions statementOptions)
statementOptions
- options to be applied to statementsCopyright © 2007–2021 Querydsl. All rights reserved.