Package net.sf.basedb.core
Class AbstractEntityQuery
- java.lang.Object
-
- net.sf.basedb.core.AbstractQuery
-
- net.sf.basedb.core.AbstractHqlQuery
-
- 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 theEntityQuery
interface. This class doesn't support adding selections, groups or having restrictions.Include
options and permission control are implemented using Hibernate filters. SeeQueryRuntimeFilterFactory
.- Version:
- 2.0
- Author:
- Nicklas
- Last modified
- $Date: 2017-05-22 14:35:27 +0200 (må, 22 maj 2017) $
-
-
Field Summary
Fields Modifier and Type Field Description 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 org.slf4j.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
Constructors Constructor Description 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.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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.List<Integer>
idList(DbControl dc)
Execute the query and return the ID values of all items matching the query.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 resultvoid
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, getIdHqlQuery, getMainHqlQuery, getRootAlias, isCachingResult, isReadonly, isStateless, postProcessQuery, reset, setCacheResult, setEntityParameter, setPermanentEntityParameter
-
Methods inherited from class net.sf.basedb.core.AbstractQuery
addAutoJoiner, getCountQuery, getFirstResult, getIdQuery, getMainQuery, getMaxResults, getParameterNames, getParameters, getParameterType, getParameterValue, getPermanentSelects, getQueryParameter, getQuerySection, getSelects, hasParameterValue, isCounting, isDistinct, isFailSafe, isReturningTotalCount, join, joinPermanent, order, orderPermanent, resetTemporary, restrict, restrictPermanent, setCounting, setDistinct, setFailSafe, 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, isFailSafe, isReadonly, isReturningTotalCount, join, joinPermanent, order, orderPermanent, reset, restrict, restrictPermanent, setDistinct, setFailSafe, setFirstResult, setMaxResults, setParameter, setPermanentParameter, setReturnTotalCount, toQl
-
-
-
-
Field Detail
-
logParam
private static final org.slf4j.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.
-
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 returnedentityName
- The name of the type of items as known to Hibernate, or null to use the class of the return typestateless
- 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 returnedentityName
- The name of the type of items as known to Hibernate, or null to use the class of the return typestateless
- TRUE if the stateless Hibernate session should be used, FALSE if the regular Hibernate session should be usedoptionalFilter
- A runtime filter replacing the default optional filter or null to not use any optional filter (not supported for stateless sessions)
-
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(Class, Item, String, String)
-
-
Method Detail
-
select
public void select(Select select)
Not supported.- Specified by:
select
in interfaceQuery
- Overrides:
select
in classAbstractQuery
- 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 interfaceQuery
- Overrides:
selectPermanent
in classAbstractQuery
- 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 interfaceQuery
- Overrides:
group
in classAbstractQuery
- 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 interfaceQuery
- Overrides:
groupPermanent
in classAbstractQuery
- 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 interfaceQuery
- Overrides:
having
in classAbstractQuery
- 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 interfaceQuery
- Overrides:
havingPermanent
in classAbstractQuery
- 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 interfaceQuery
- Overrides:
getQueryType
in classAbstractHqlQuery
- 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 theQuery.getFirstResult()
andQuery.getMaxResults()
settings.- Specified by:
count
in interfaceQuery
- Overrides:
count
in classAbstractHqlQuery
- 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 interfaceEntityQuery
-
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 theEntityQuery.getItemType()
, but not always.- Specified by:
getRootType
in interfaceEntityQuery
- 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 interfaceEntityQuery
- 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 interfaceEntityQuery
- 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 interfaceEntityQuery
- 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 interfaceEntityQuery
- 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 interfaceEntityQuery
- 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 interfaceEntityQuery
- 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 interfaceEntityQuery
- 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 interfaceEntityQuery
- 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 interfaceEntityQuery
- Returns:
- A Permission object
-
idList
public List<Integer> idList(DbControl dc)
Description copied from interface:EntityQuery
Execute the query and return the ID values of all items matching the query.- Specified by:
idList
in interfaceEntityQuery
- Parameters:
dc
- TheDbControl
used to access the database and check permissions
-
setAutoJoinType
public void setAutoJoinType(JoinType joinType)
Specify the join type of automatic joins. The default join type isJoinType.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)
-
-