public abstract class AbstractSqlQuery extends AbstractQuery implements SqlQuery
SqlQuery
interface.Modifier and Type | Class and Description |
---|---|
(package private) class |
AbstractSqlQuery.CountWork |
Modifier and Type | Field and Description |
---|---|
private static boolean |
debugParamEnabled
So we don't always have to call logParam.debug()
|
private static boolean |
debugSqlEnabled
So we don't always have to call logSql.debug()
|
private static org.slf4j.Logger |
logParam
Log all parameter bindings to prepared statement.
|
private static org.slf4j.Logger |
logSql
Log all SQL statements.
|
private static Pattern |
namedParameter
Pattern that finds a named parameter in an SQL string.
|
Constructor and Description |
---|
AbstractSqlQuery(String rootEntity) |
Modifier and Type | Method and Description |
---|---|
protected void |
closeResultSet(ResultSet result,
String msg)
Close the result set without throwing an exception.
|
protected void |
closeStatement(Statement stmt,
String msg)
Close the statement without throwing an exception.
|
long |
count(DbControl dc)
Count the number of items/rows that are returned by the query.
|
private AbstractSqlQuery.CountWork |
createCountWork(DbControl dc)
Creates a work item for counting the number of total hits by the query.
|
(package private) abstract Select[] |
getDefaultSelects() |
(package private) LimitHandler |
getLimitHandler()
Get a handler for adding LIMIT and OFFSET parameters to
an SQL statement.
|
QueryType |
getQueryType()
Get the type of query.
|
(package private) RowSelection |
getRowSelectionForLimitHandler()
Get a RowSelection object to be used with a LimitHandler so
that it can modify and add parameters to the SQL.
|
DynamicResultIterator |
iterate(DbControl dc)
Execute the query.
|
(package private) String |
parseParameters(String sql,
List<String> parameterOrder)
Parse the given SQL and find named parameters.
|
protected void |
releaseSavepoint(Connection conn,
Savepoint savepoint,
String msg)
Release the given savepoint.
|
protected void |
rollbackToSavepoint(Connection conn,
Savepoint savepoint,
String msg)
Rollback the current transaction to the given savepoint.
|
(package private) int |
setParameters(PreparedStatement ps,
List<String> parameterOrder,
int parameterIndex)
Set parameter values on a prepared statement.
|
private void |
setParameterValue(PreparedStatement ps,
int index,
Object parameterValue,
Type valueType)
Set a parameter value on a prepared statement.
|
addAutoJoiner, getCountQuery, getFirstResult, getIdQuery, getMainQuery, getMaxResults, getParameterNames, getParameters, getParameterType, getParameterValue, getPermanentSelects, getQueryParameter, getQuerySection, getSelects, group, groupPermanent, hasParameterValue, having, havingPermanent, isCounting, isDistinct, isFailSafe, isReadonly, isReturningTotalCount, join, joinPermanent, order, orderPermanent, postProcessQuery, reset, resetTemporary, restrict, restrictPermanent, select, selectPermanent, setCounting, setDistinct, setFailSafe, setFirstResult, setMaxResults, setParameter, setPermanentParameter, setReturnTotalCount, temporaryJoin, temporarySelect, toQl, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addAutoJoiner, getFirstResult, getMaxResults, getParameterNames, getQueryParameter, getQuerySection, getRootAlias, group, groupPermanent, hasParameterValue, having, havingPermanent, isCounting, isDistinct, isFailSafe, isReadonly, isReturningTotalCount, join, joinPermanent, order, orderPermanent, reset, restrict, restrictPermanent, select, selectPermanent, setDistinct, setFailSafe, setFirstResult, setMaxResults, setParameter, setPermanentParameter, setReturnTotalCount, toQl
private static final org.slf4j.Logger logSql
private static final boolean debugSqlEnabled
private static final org.slf4j.Logger logParam
private static final boolean debugParamEnabled
private static final Pattern namedParameter
AbstractSqlQuery(String rootEntity)
public QueryType getQueryType()
Query
getQueryType
in interface Query
QueryType.SQL
public long count(DbControl dc) throws BaseException
Query
Query.getFirstResult()
and Query.getMaxResults()
settings.count
in interface Query
BaseException
- If there is an errorprivate AbstractSqlQuery.CountWork createCountWork(DbControl dc)
abstract Select[] getDefaultSelects()
public DynamicResultIterator iterate(DbControl dc) throws BaseException
iterate
in interface SqlQuery
dc
- The DbControl
to use for database accessDynamicResultIterator
objectBaseException
- If there is an errorString parseParameters(String sql, List<String> parameterOrder)
sql
- The original SQL string, which may contain named
parametersparameterOrder
- A list that should store the name of the
parameters in the correct orderLimitHandler getLimitHandler()
RowSelection getRowSelectionForLimitHandler()
int setParameters(PreparedStatement ps, List<String> parameterOrder, int parameterIndex) throws SQLException
ps
- The prepared statementparameterOrder
- The names of the parameters in the order they
appear in the prepared statementparameterIndex
- The index of the first parameter to bindSQLException
private void setParameterValue(PreparedStatement ps, int index, Object parameterValue, Type valueType) throws SQLException
BasicItem
the id of the object is used a value.ps
- The prepared statementindex
- The index of the parameter, starting at 1parameterValue
- The value of the parameterSQLException
protected void closeResultSet(ResultSet result, String msg)
ResultSet.close()
method throws an exception
it is logged together with the message.msg
- A message to write to the log if the close failsresult
- The result set to closeprotected void closeStatement(Statement stmt, String msg)
Statement.close()
method throws an exception
it is logged together with the message.msg
- A message to write to the log if the close failsstmt
- The statement to closeprotected void rollbackToSavepoint(Connection conn, Savepoint savepoint, String msg)
conn
- The connection to rollbacksavepoint
- The savepoint to rollback tomsg
- A message to write to the log if the rollback failsprotected void releaseSavepoint(Connection conn, Savepoint savepoint, String msg)
conn
- The connection that holds the savepointsavepoint
- The savepoint to releasemsg
- A message to write to the log if the release fails