|
3.2.4: 2013-12-06 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.basedb.core.AbstractQuery
net.sf.basedb.core.AbstractSqlQuery
public abstract class AbstractSqlQuery
An abstract implementation of the SqlQuery
interface.
Nested Class Summary | |
---|---|
(package private) class |
AbstractSqlQuery.CountWork
|
Field Summary | |
---|---|
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.apache.log4j.Logger |
logParam
Log all parameter bindings to prepared statement. |
private static org.apache.log4j.Logger |
logSql
Log all SQL statements. |
private static Pattern |
namedParameter
Pattern that finds a named parameter in an SQL string. |
Constructor Summary | |
---|---|
AbstractSqlQuery(String rootEntity)
|
Method Summary | |
---|---|
(package private) String |
bindLimits(String sql,
List<String> parameterOrder)
Parse the given SQL and add LIMIT and OFFSET parameters to it. |
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()
|
QueryType |
getQueryType()
Get the type of query. |
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) void |
setParameters(PreparedStatement ps,
List<String> parameterOrder)
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface net.sf.basedb.core.query.Query |
---|
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 |
Field Detail |
---|
private static final org.apache.log4j.Logger logSql
private static final boolean debugSqlEnabled
private static final org.apache.log4j.Logger logParam
private static final boolean debugParamEnabled
private static final Pattern namedParameter
Constructor Detail |
---|
AbstractSqlQuery(String rootEntity)
Method Detail |
---|
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 access
DynamicResultIterator
object
BaseException
- 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 order
String bindLimits(String sql, List<String> parameterOrder)
Dialect
and uses it for generating the actual SQL. If limit parameters are added
to the query this method adds entries for those parameters in the
parameterOrder
list and values using the regular
Query.setParameter(String, Object, Type)
method.
The parameter names used are _limit_
and _offset_
.
If the underlying database doesn't support limit parameters the query
will be executed and the result starting point moved forward to the
correct offset and the a limit will be passed to the DynamicResultIterator
object.
sql
- The original SQL without limit parametersparameterOrder
- A list that stores the names of the parameters
in the order they should be binf by JDBC
void setParameters(PreparedStatement ps, List<String> parameterOrder) throws SQLException
ps
- The prepared statementparameterOrder
- The names of the parameters in the order they
appear in the prepared statement
SQLException
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 parameter
SQLException
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
|
3.2.4: 2013-12-06 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |