|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.core.AbstractQuery net.sf.basedb.core.AbstractHqlQuery
abstract class AbstractHqlQuery
An abstract implementation of the HqlQuery
interface. The
class can be used to build and manage just about any type of HQL
query. It has no function for executing the query or returning
the result. Subclasses may use getMainHqlQuery(DbControl)
to generate a Hibernate Query object that is ready to be executed.
Field Summary | |
---|---|
private boolean |
cacheResults
If the results should be cached or not. |
private static boolean |
debugEnabled
So we don't always have to call logParam.debug() |
private DbControl |
lastCountDc
The most recent DbControl used to build/execute the count query. |
private org.hibernate.Query |
lastCountQuery
The most recent count query. |
private DbControl |
lastMainDc
The most recent DbControl used to build/execute the main query. |
private org.hibernate.Query |
lastMainQuery
The most recent main query. |
private static Logger |
logParam
Log all parameter bindings to prepared statement. |
private String |
rootAlias
The alias for the root table. |
private boolean |
stateless
If the query should be executed in a stateless session or not. |
private static Set<Integer> |
ZERO_SET
|
Constructor Summary | |
---|---|
AbstractHqlQuery(String root,
String alias,
boolean stateless)
Create a new HQL query. |
Method Summary | |
---|---|
long |
count(DbControl dc)
Count the number of items/rows that are returned by the query. |
(package private) org.hibernate.Query |
getCountHqlQuery(DbControl dc)
Build the count query and set parameter values for it. |
(package private) org.hibernate.Query |
getMainHqlQuery(DbControl dc)
Build the main query and set parameter values for it. |
QueryType |
getQueryType()
Get the type of query. |
String |
getRootAlias()
The alias of the item that is the root of this query. |
boolean |
isCachingResult()
If the query results are cached or not. |
boolean |
isReadonly()
If this query is readonly and cannot be structurally modified. |
protected boolean |
isStateless()
If queries are using the stateless Hibernate session or the regular session. |
protected String |
postProcessQuery(String query)
Processes the query so that joined paths that are found in other parts of the query are replaced with the join alias. |
private String |
replaceWithJoinAliases(String query)
Replaces parts of the query with joined aliases. |
void |
reset()
Reset all non-permanent query elements of the query and clear cached queries. |
void |
setCacheResult(boolean flag)
Specify if the query results should be cached or not. |
void |
setEntityParameter(String name,
BasicItem value)
Set the value of an entity parameter. |
private void |
setParameters(org.hibernate.Query query,
Map<String,QueryParameter> parameters)
Set parameter values on a query. |
void |
setPermanentEntityParameter(String name,
BasicItem value)
Permanently set the value of an entity parameter. |
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, group, groupPermanent, hasParameterValue, having, havingPermanent, isCounting, isDistinct, isReturningTotalCount, join, joinPermanent, order, orderPermanent, restrict, restrictPermanent, select, selectPermanent, setDistinct, setFirstResult, setMaxResults, setParameter, setPermanentParameter, setReturnTotalCount, toQl |
Field Detail |
---|
private static final Logger logParam
private static final boolean debugEnabled
private final String rootAlias
private final boolean stateless
private DbControl lastMainDc
private DbControl lastCountDc
private org.hibernate.Query lastMainQuery
private org.hibernate.Query lastCountQuery
private boolean cacheResults
private static final Set<Integer> ZERO_SET
Constructor Detail |
---|
AbstractHqlQuery(String root, String alias, boolean stateless)
Method Detail |
---|
public QueryType getQueryType()
Query
getQueryType
in interface Query
QueryType.HQL
public String getRootAlias()
getRootAlias
in interface Query
Item.getAlias()
public boolean isReadonly()
Query
Query.reset()
would unlock the query and allow it to be modified again.
isReadonly
in interface Query
isReadonly
in class AbstractQuery
public void reset()
reset
in interface Query
reset
in class AbstractQuery
public long count(DbControl dc) throws BaseException
Query
Query.getFirstResult()
and Query.getMaxResults()
settings.
count
in interface Query
BaseException
- If there is an errorpublic void setCacheResult(boolean flag)
HqlQuery
setCacheResult
in interface HqlQuery
flag
- TRUE if the query results should be cached, FALSE otherwisepublic boolean isCachingResult()
HqlQuery
isCachingResult
in interface HqlQuery
HqlQuery.setCacheResult(boolean)
public void setEntityParameter(String name, BasicItem value)
HqlQuery
InvalidDataException
is thrown.
setEntityParameter
in interface HqlQuery
name
- The name of the parametervalue
- The value of the parameterpublic void setPermanentEntityParameter(String name, BasicItem value)
HqlQuery
InvalidDataException
is thrown.
setPermanentEntityParameter
in interface HqlQuery
name
- The name of the parametervalue
- The value of the parameterorg.hibernate.Query getMainHqlQuery(DbControl dc)
DbControl
before and hasn't been reset()
the cached query is returned. If the parameters values have been changed the new
values are used.
dc
- The DbControl to use for executing the query
org.hibernate.Query
objectorg.hibernate.Query getCountHqlQuery(DbControl dc)
DbControl
before and hasn't been reset()
the cached query is returned. If the parameters values have been changed the new
values are used.
dc
- The DbControl to use for executing the query
org.hibernate.Query
objectprotected boolean isStateless()
protected String postProcessQuery(String query)
postProcessQuery
in class AbstractQuery
private String replaceWithJoinAliases(String query)
We implement this by looking for the joined path and replacing it with the joined alias.
For left fetch joins we also need to make sure that no more than one step is joined at a time since the implicit join created by Hibernate is not a fetch join.
private void setParameters(org.hibernate.Query query, Map<String,QueryParameter> parameters)
query
- The Hibernate query objectparameters
- A map containing parameter names and values
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |