2.17.2: 2011-06-17

net.sf.basedb.core
Class AbstractEntityQuery

java.lang.Object
  extended by net.sf.basedb.core.AbstractQuery
      extended by net.sf.basedb.core.AbstractHqlQuery
          extended by net.sf.basedb.core.AbstractEntityQuery
All Implemented Interfaces:
EntityQuery, HqlQuery, Query
Direct Known Subclasses:
DataQuery, ItemQuery, ReporterScoreQuery

abstract class AbstractEntityQuery
extends AbstractHqlQuery
implements EntityQuery

An abstract implementation of the EntityQuery interface. This class doesn't support adding selections, groups or having restrictions.

Include options and permission control are implemented using Hibernate filters. See QueryRuntimeFilterFactory.

Version:
2.0
Author:
Nicklas
Last modified
$Date: 2010-04-20 10:02:16 +0200 (Tue, 20 Apr 2010) $

Field Summary
private static boolean debugEnabled
          So we don't always have to call logParam.debug()
private  QueryRuntimeFilterManager filterManager
          The manager of the runtime query filters.
private  EnumSet<Include> includes
          Flags specifying which items to include.
private static Logger logParam
          Log all parameter bindings to prepared statement.
private  QueryRuntimeFilter optionalFilter
          Optional runtime filter.
private  Permission permission
          The logged in user's permission on the items.
private  QueryRuntimeFilter requiredFilter
          The required runtime filter.
private  Item returnType
          The item type returned by the query, eg.
private  Item rootType
          The root item type we start with in the query. eq.
 
Constructor Summary
AbstractEntityQuery(Item returnType, Item rootType, String rootName, String select, boolean stateless, QueryRuntimeFilter optionalFilter)
          Create a new query that may have different return type and root item type.
AbstractEntityQuery(Item returnType, String entityName, boolean stateless)
          Create a new query returning items of the specified item type using the default optional runtime filter.
AbstractEntityQuery(Item returnType, String entityName, boolean stateless, QueryRuntimeFilter optionalFilter)
          Create a new query returning items of the specified type with a non-default optional runtime filter.
 
Method Summary
 long count(DbControl dc)
          Count the number of items/rows that are returned by the query.
(package private)  void disableFilters(DbControl dc)
          Disable all enabled runtime query filters for the query.
(package private)  void enableFilters(DbControl dc)
          Enable runtime query filters for the query.
 void exclude(Collection<Include> includes)
           
 void exclude(Include... excludes)
          Specify options for which items to exclude from the result.
 Permission getItemPermission()
          The logged in user's permission on the items returned by this query.
 Item getItemType()
          The type of items the query returns.
 QueryType getQueryType()
          Get the type of query.
 Item getRootType()
          The type of items that is the root of the query.
 void group(Expression expression)
          Not supported.
 void groupPermanent(Expression expression)
          Not supported.
 void having(Restriction restriction)
          Not supported.
 void havingPermanent(Restriction restriction)
          Not supported.
 void include(Collection<Include> includes)
           
 void include(Include... includes)
          Specify options for which items to include in the result.
 boolean isIncluded(Collection<Include> includes)
           
 boolean isIncluded(Include... includes)
          Check which options are set for the items to include in the result
 void select(Select select)
          Not supported.
 void selectPermanent(Select select)
          Not supported.
 void setAutoJoinType(JoinType joinType)
          Specify the join type of automatic joins.
 void setIncludes(Collection<Include> includes)
          Clears the lists of includes and adds a new collection.
 void setItemPermission(Permission permission)
          Only return items which the logged in user has the specified permission for.
 
Methods inherited from class net.sf.basedb.core.AbstractHqlQuery
getCountHqlQuery, getMainHqlQuery, getRootAlias, isCachingResult, isReadonly, isStateless, postProcessQuery, reset, setCacheResult, setEntityParameter, setPermanentEntityParameter
 
Methods inherited from class net.sf.basedb.core.AbstractQuery
addAutoJoiner, getCountQuery, getFirstResult, getMainQuery, getMaxResults, getParameterNames, getParameters, getParameterType, getParameterValue, getPermanentSelects, getQueryParameter, getQuerySection, getSelects, hasParameterValue, isCounting, isDistinct, isReturningTotalCount, join, joinPermanent, order, orderPermanent, resetTemporary, restrict, restrictPermanent, setCounting, setDistinct, setFirstResult, setMaxResults, setParameter, setPermanentParameter, setReturnTotalCount, temporaryJoin, temporarySelect, toQl, toString
 
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.HqlQuery
isCachingResult, setCacheResult, setEntityParameter, setPermanentEntityParameter
 
Methods inherited from interface net.sf.basedb.core.query.Query
addAutoJoiner, getFirstResult, getMaxResults, getParameterNames, getQueryParameter, getQuerySection, getRootAlias, hasParameterValue, isCounting, isDistinct, isReadonly, isReturningTotalCount, join, joinPermanent, order, orderPermanent, reset, restrict, restrictPermanent, setDistinct, setFirstResult, setMaxResults, setParameter, setPermanentParameter, setReturnTotalCount, toQl
 

Field Detail

logParam

private static final Logger logParam
Log all parameter bindings to prepared statement.


debugEnabled

private static final boolean debugEnabled
So we don't always have to call logParam.debug()


returnType

private final Item returnType
The item type returned by the query, eg. SELECT [returnType] FROM ...


rootType

private final Item rootType
The root item type we start with in the query. eq. SELECT ... FROM [rootTypeTable]

Since:
2.8

requiredFilter

private final QueryRuntimeFilter requiredFilter
The required runtime filter.


optionalFilter

private final QueryRuntimeFilter optionalFilter
Optional runtime filter.


filterManager

private QueryRuntimeFilterManager filterManager
The manager of the runtime query filters.


includes

private EnumSet<Include> includes
Flags specifying which items to include.


permission

private Permission permission
The logged in user's permission on the items.

Constructor Detail

AbstractEntityQuery

AbstractEntityQuery(Item returnType,
                    String entityName,
                    boolean stateless)
Create a new query returning items of the specified item type using the default optional runtime filter.

Parameters:
returnType - The type of items that are returned
entityName - The name of the type of items as known to Hibernate, or null to use the class of the return type
stateless - TRUE if the stateless Hibernate session should be used, FALSE if the regular Hibernate session should be used

AbstractEntityQuery

AbstractEntityQuery(Item returnType,
                    String entityName,
                    boolean stateless,
                    QueryRuntimeFilter optionalFilter)
Create a new query returning items of the specified type with a non-default optional runtime filter.

Parameters:
returnType - The type of items that are returned
entityName - The name of the type of items as known to Hibernate, or null to use the class of the return type
stateless - TRUE if the stateless Hibernate session should be used, FALSE if the regular Hibernate session should be used
optionalFilter - A runtime filter replacing the default optional filter or null to not use any optional filter

AbstractEntityQuery

AbstractEntityQuery(Item returnType,
                    Item rootType,
                    String rootName,
                    String select,
                    boolean stateless,
                    QueryRuntimeFilter optionalFilter)
Create a new query that may have different return type and root item type.

Since:
2.8
See Also:
DataQuery.DataQuery(Class, Item, String, String)
Method Detail

select

public void select(Select select)
Not supported.

Specified by:
select in interface Query
Overrides:
select in class AbstractQuery
Parameters:
select - The query element to add
Throws:
UnsupportedOperationException - Always
See Also:
Query.selectPermanent(Select)

selectPermanent

public void selectPermanent(Select select)
Not supported.

Specified by:
selectPermanent in interface Query
Overrides:
selectPermanent in class AbstractQuery
Parameters:
select - The query element to add
Throws:
UnsupportedOperationException - Always
See Also:
Query.select(Select)

group

public void group(Expression expression)
Not supported.

Specified by:
group in interface Query
Overrides:
group in class AbstractQuery
Parameters:
expression - The query element to add
Throws:
UnsupportedOperationException - Always
See Also:
Query.groupPermanent(Expression)

groupPermanent

public void groupPermanent(Expression expression)
Not supported.

Specified by:
groupPermanent in interface Query
Overrides:
groupPermanent in class AbstractQuery
Parameters:
expression - The query element to add
Throws:
UnsupportedOperationException - Always
See Also:
Query.group(Expression)

having

public void having(Restriction restriction)
Not supported.

Specified by:
having in interface Query
Overrides:
having in class AbstractQuery
Parameters:
restriction - The query element to add
Throws:
UnsupportedOperationException - Always
See Also:
Query.havingPermanent(Restriction)

havingPermanent

public void havingPermanent(Restriction restriction)
Not supported.

Specified by:
havingPermanent in interface Query
Overrides:
havingPermanent in class AbstractQuery
Parameters:
restriction - The query element to add
Throws:
UnsupportedOperationException - Always
See Also:
Query.having(Restriction)

getQueryType

public QueryType getQueryType()
Description copied from interface: Query
Get the type of query. Ie. The query language.

Specified by:
getQueryType in interface Query
Overrides:
getQueryType in class AbstractHqlQuery
Returns:
QueryType.HQL

count

public long count(DbControl dc)
           throws BaseException
Description copied from interface: Query
Count the number of items/rows that are returned by the query. The method ignores the Query.getFirstResult() and Query.getMaxResults() settings.

Specified by:
count in interface Query
Overrides:
count in class AbstractHqlQuery
Returns:
The number of rows/items returned by the query
Throws:
BaseException - If there is an error

getItemType

public Item getItemType()
Description copied from interface: EntityQuery
The type of items the query returns.

Specified by:
getItemType in interface EntityQuery

getRootType

public Item getRootType()
Description copied from interface: EntityQuery
The type of items that is the root of the query. In most cases, this is the same as the EntityQuery.getItemType(), but not always.

Specified by:
getRootType in interface EntityQuery
Since:
2.8

include

public void include(Include... includes)
Description copied from interface: EntityQuery
Specify options for which items to include in the result.

Specified by:
include in interface EntityQuery
Parameters:
includes - An array of items that should be included
See Also:
EntityQuery.exclude(Include[])

include

public void include(Collection<Include> includes)
Specified by:
include in interface EntityQuery
See Also:
EntityQuery.include(Include[])

setIncludes

public void setIncludes(Collection<Include> includes)
Description copied from interface: EntityQuery
Clears the lists of includes and adds a new collection.

Specified by:
setIncludes in interface EntityQuery
Parameters:
includes - The new includes to be hold in the list.
Since:
2.14.2
See Also:
EntityQuery.include(Include...)

exclude

public void exclude(Include... excludes)
Description copied from interface: EntityQuery
Specify options for which items to exclude from the result.

Specified by:
exclude in interface EntityQuery
Parameters:
excludes - An array of options that should be excluded
See Also:
EntityQuery.include(Include[])

exclude

public void exclude(Collection<Include> includes)
Specified by:
exclude in interface EntityQuery
See Also:
EntityQuery.exclude(Include[])

isIncluded

public boolean isIncluded(Include... includes)
Description copied from interface: EntityQuery
Check which options are set for the items to include in the result

Specified by:
isIncluded in interface EntityQuery
Parameters:
includes - The options to check
Returns:
TRUE If all specified options are included, FALSE otherwise

isIncluded

public boolean isIncluded(Collection<Include> includes)
Specified by:
isIncluded in interface EntityQuery
See Also:
EntityQuery.isIncluded(Include[])

setItemPermission

public void setItemPermission(Permission permission)
Description copied from interface: EntityQuery
Only return items which the logged in user has the specified permission for. The default is to return all items which the user has at least read permission for.

Specified by:
setItemPermission in interface EntityQuery
Parameters:
permission - The required permission

getItemPermission

public Permission getItemPermission()
Description copied from interface: EntityQuery
The logged in user's permission on the items returned by this query.

Specified by:
getItemPermission in interface EntityQuery
Returns:
A Permission object

setAutoJoinType

public void setAutoJoinType(JoinType joinType)
Specify the join type of automatic joins. The default join type is JoinType.LEFT. This setting doesn't affect joins that has been made directly to the query.

Parameters:
joinType - The type of the automatic joins
Since:
2.8

enableFilters

void enableFilters(DbControl dc)
Enable runtime query filters for the query.

See Also:
disableFilters(DbControl)

disableFilters

void disableFilters(DbControl dc)
Disable all enabled runtime query filters for the query.

See Also:
enableFilters(DbControl)

2.17.2: 2011-06-17