|
3.1.1: 2012-03-29 | ||||||||
| 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.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 Query |
lastCountQuery
The most recent count query. |
private DbControl |
lastMainDc
The most recent DbControl used to build/execute the main query. |
private 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) Query |
getCountHqlQuery(DbControl dc)
Build the count query and set parameter values for it. |
(package private) 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(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, isFailSafe, isReturningTotalCount, join, joinPermanent, order, orderPermanent, restrict, restrictPermanent, select, selectPermanent, setDistinct, setFailSafe, 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 Query lastMainQuery
private 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 QueryQueryType.HQLpublic String getRootAlias()
getRootAlias in interface QueryItem.getAlias()public boolean isReadonly()
QueryQuery.reset() would unlock the query and allow it to be modified again.
isReadonly in interface QueryisReadonly in class AbstractQuerypublic void reset()
reset in interface Queryreset in class AbstractQuery
public long count(DbControl dc)
throws BaseException
QueryQuery.getFirstResult() and Query.getMaxResults()
settings.
count in interface QueryBaseException - If there is an errorpublic void setCacheResult(boolean flag)
HqlQuery
setCacheResult in interface HqlQueryflag - TRUE if the query results should be cached, FALSE otherwisepublic boolean isCachingResult()
HqlQuery
isCachingResult in interface HqlQueryHqlQuery.setCacheResult(boolean)
public void setEntityParameter(String name,
BasicItem value)
HqlQueryInvalidDataException is thrown.
setEntityParameter in interface HqlQueryname - The name of the parametervalue - The value of the parameter
public void setPermanentEntityParameter(String name,
BasicItem value)
HqlQueryInvalidDataException is thrown.
setPermanentEntityParameter in interface HqlQueryname - The name of the parametervalue - The value of the parameterQuery 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 objectQuery 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 AbstractQueryprivate 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(Query query,
Map<String,QueryParameter> parameters)
query - The Hibernate query objectparameters - A map containing parameter names and values
|
3.1.1: 2012-03-29 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||