Top Description Inners Fields Constructors Methods
net.sf.ehcache

pack-priv Class CacheQuery

extends Object
implements Query, StoreQuery
Class Inheritance
All Implemented Interfaces
net.sf.ehcache.store.StoreQuery, net.sf.ehcache.search.Query
Imports
java.util.ArrayList, .Collections, .HashSet, .List, .Set, net.sf.ehcache.search.Attribute, .Direction, .ExecutionHints, .Query, .Results, .SearchException, net.sf.ehcache.search.aggregator.Aggregator, .AggregatorException, .AggregatorInstance, net.sf.ehcache.search.expression.AlwaysMatch, .Criteria, net.sf.ehcache.store.StoreQuery

Query builder implementation. Instances are bound to a specific cache
Author
teck

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
CacheQuery.OrderingImpl

An attribute/direction pair

private class
CacheQuery.StoreQueryImpl

StoreQuery implementation (essentially a snapshot of this (non-frozen) query builder

Field Summary

Modifier and TypeField and Description
private final List<Aggregator>
private final Cache
private final List<Criteria>
private volatile boolean
private final Set<Attribute<?>>
private volatile ExecutionHints
private final Set<Attribute<?>>
private volatile boolean
private volatile boolean
private volatile int
private final List<StoreQuery.Ordering>
private String[]

Constructor Summary

AccessConstructor and Description
public
CacheQuery(Cache cache)

Create a new builder instance

Method Summary

Modifier and TypeMethod and Description
public Query
addCriteria(Criteria criteria)

Implements net.sf.ehcache.search.Query.addCriteria.

Adds a criteria to the query
public Query
addGroupBy(Attribute<?>... attributes)

Implements net.sf.ehcache.search.Query.addGroupBy.

Group result set by unique value(s) of specified attribute(s).
public Query
addOrderBy(Attribute<?>
The attribute to order the results by
attribute
,
Direction
Ascending or descending
direction
)

Implements net.sf.ehcache.search.Query.addOrderBy.

Request result set ordering by the given attribute and direction.
private void
private void
private static List<AggregatorInstance<?>>
public Query
end()

Implements net.sf.ehcache.search.Query.end.

Optional method for terminating query creation.
public Results
execute()

Implements net.sf.ehcache.search.Query.execute.

Execute this query.
public Results
execute(ExecutionHints params)

Implements net.sf.ehcache.search.Query.execute.

Like execute(), but with specified execution parameters.
public List<AggregatorInstance<?>>
getAggregatorInstances()

Implements net.sf.ehcache.store.StoreQuery.getAggregatorInstances.

Get the requested aggregator instances
public List<Aggregator>
getAggregators()

Implements net.sf.ehcache.store.StoreQuery.getAggregators.

Get the requested aggregators
public Cache
getCache()

Implements net.sf.ehcache.store.StoreQuery.getCache.

Get the cache this query originated from
public Criteria
getCriteria()

Implements net.sf.ehcache.store.StoreQuery.getCriteria.

Get the search criteria
private Criteria
public ExecutionHints
getExecutionHints()

Implements net.sf.ehcache.store.StoreQuery.getExecutionHints.

Get execution hints for this query
public List<StoreQuery.Ordering>
getOrdering()

Implements net.sf.ehcache.store.StoreQuery.getOrdering.

Get the requested search orderings
public String[]
getTargets()

Implements net.sf.ehcache.store.StoreQuery.getTargets.

This needs to be cleaned up.
public Set<Attribute<?>>
groupByAttributes()

Implements net.sf.ehcache.store.StoreQuery.groupByAttributes.

Get the set of attributes to group result set by
public Query
includeAggregator(Aggregator... aggregators)

Implements net.sf.ehcache.search.Query.includeAggregator.

Request this query to aggregate the results by the given Aggregator(s)

This method may be called multiple times to request multiple aggregations

public Query
includeAttribute(Attribute<?>...
the query attributes to select
attributes
)

Implements net.sf.ehcache.search.Query.includeAttribute.

Request that the given attribute(s) should be present in the result for this query.
public Query
includeKeys()

Implements net.sf.ehcache.search.Query.includeKeys.

Request that the key object be present in the results.
public Query
includeValues()

Implements net.sf.ehcache.search.Query.includeValues.

Request that the value object be present in the results.
public Query
maxResults(int
the maximum number of results to return
maxResults
)

Implements net.sf.ehcache.search.Query.maxResults.

Restrict the number of results returned from the search.
public int
maxResults()

Implements net.sf.ehcache.store.StoreQuery.maxResults.

Get the maximum number of results to return
public Set<Attribute<?>>
requestedAttributes()

Implements net.sf.ehcache.store.StoreQuery.requestedAttributes.

Get the set of attributes requested by this query
public boolean
public boolean
private StoreQuery
public void
targets(final String[] targets)

Implements net.sf.ehcache.store.StoreQuery.targets.

Set the names of the select targets.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aggregatorsback to summary
private final List<Aggregator> aggregators
cacheback to summary
private final Cache cache
criteriaback to summary
private final List<Criteria> criteria
frozenback to summary
private volatile boolean frozen
groupByAttributesback to summary
private final Set<Attribute<?>> groupByAttributes
hintsback to summary
private volatile ExecutionHints hints
includedAttributesback to summary
private final Set<Attribute<?>> includedAttributes
includeKeysback to summary
private volatile boolean includeKeys
includeValuesback to summary
private volatile boolean includeValues
maxResultsback to summary
private volatile int maxResults
orderingsback to summary
private final List<StoreQuery.Ordering> orderings
targetsback to summary
private String[] targets

Constructor Detail

CacheQueryback to summary
public CacheQuery(Cache cache)

Create a new builder instance

Method Detail

addCriteriaback to summary
public Query addCriteria(Criteria criteria)

Implements net.sf.ehcache.search.Query.addCriteria.

Doc from net.sf.ehcache.search.Query.addCriteria.

Adds a criteria to the query

addGroupByback to summary
public Query addGroupBy(Attribute<?>... attributes)

Implements net.sf.ehcache.search.Query.addGroupBy.

Doc from net.sf.ehcache.search.Query.addGroupBy.

Group result set by unique value(s) of specified attribute(s). Rows with duplicate values for these attributes will be removed. This method may also be chained to achieve the same effect.

addOrderByback to summary
public Query addOrderBy(Attribute<?> attribute, Direction direction)

Implements net.sf.ehcache.search.Query.addOrderBy.

Doc from net.sf.ehcache.search.Query.addOrderBy.

Request result set ordering by the given attribute and direction. This call can be made multiple times to specify second level. third level, etc orderings

Parameters
attribute:Attribute<?>

The attribute to order the results by

direction:Direction

Ascending or descending

Returns:Query

this

assertFrozenback to summary
private void assertFrozen()
checkFrozenback to summary
private void checkFrozen()
createAggregatorInstancesback to summary
private static List<AggregatorInstance<?>> createAggregatorInstances(List<Aggregator> aggregators)
endback to summary
public Query end()

Implements net.sf.ehcache.search.Query.end.

Doc from net.sf.ehcache.search.Query.end.

Optional method for terminating query creation. If called the query becomes immutable, so that attempting any further mutations will result in an exception

executeback to summary
public Results execute() throws SearchException

Implements net.sf.ehcache.search.Query.execute.

Doc from net.sf.ehcache.search.Query.execute.

Execute this query. Every call to this method will re-execute the query and return a distinct results object.

An empty results object will be returned (on timeout) for non-stop enabled caches with net.sf.ehcache.config.TimeoutBehaviorConfiguration.TimeoutBehaviorType#NOOP and net.sf.ehcache.config.TimeoutBehaviorConfiguration.TimeoutBehaviorType#LOCAL_READS behavior

Returns:Results

query results

executeback to summary
public Results execute(ExecutionHints params) throws SearchException

Implements net.sf.ehcache.search.Query.execute.

Doc from net.sf.ehcache.search.Query.execute.

Like execute(), but with specified execution parameters.

getAggregatorInstancesback to summary
public List<AggregatorInstance<?>> getAggregatorInstances()

Implements net.sf.ehcache.store.StoreQuery.getAggregatorInstances.

Doc from net.sf.ehcache.store.StoreQuery.getAggregatorInstances.

Get the requested aggregator instances

Returns:List<AggregatorInstance<?>>

the include aggregator instances (if any)

getAggregatorsback to summary
public List<Aggregator> getAggregators()

Implements net.sf.ehcache.store.StoreQuery.getAggregators.

Doc from net.sf.ehcache.store.StoreQuery.getAggregators.

Get the requested aggregators

Returns:List<Aggregator>

the include aggregators (if any)

getCacheback to summary
public Cache getCache()

Implements net.sf.ehcache.store.StoreQuery.getCache.

Doc from net.sf.ehcache.store.StoreQuery.getCache.

Get the cache this query originated from

Returns:Cache

cache

getCriteriaback to summary
public Criteria getCriteria()

Implements net.sf.ehcache.store.StoreQuery.getCriteria.

Doc from net.sf.ehcache.store.StoreQuery.getCriteria.

Get the search criteria

Returns:Criteria

the search criteria

getEffectiveCriteriaCopyback to summary
private Criteria getEffectiveCriteriaCopy()
getExecutionHintsback to summary
public ExecutionHints getExecutionHints()

Implements net.sf.ehcache.store.StoreQuery.getExecutionHints.

Doc from net.sf.ehcache.store.StoreQuery.getExecutionHints.

Get execution hints for this query

Returns:ExecutionHints

null if no hints were provided

Annotations
@Override
getOrderingback to summary
public List<StoreQuery.Ordering> getOrdering()

Implements net.sf.ehcache.store.StoreQuery.getOrdering.

Doc from net.sf.ehcache.store.StoreQuery.getOrdering.

Get the requested search orderings

Returns:List<StoreQuery.Ordering>

the request sort orders (if any)

getTargetsback to summary
public String[] getTargets()

Implements net.sf.ehcache.store.StoreQuery.getTargets.

Doc from net.sf.ehcache.store.StoreQuery.getTargets.

This needs to be cleaned up. We don't want to introduce any kind of ordering here, as there simply is none.

Meanwhile, this is used to keep the ordering on BMQL created Queries. Yet, QueryManagerBuilder, which creates the QueryManager, doesn't let us qualify the Query type further to add this "ordering" concept of "targets" to it.
And this "ordering" shouldn't become part of the QueryManager API neither as each implementation might require something different.

Returns:String[]

select target names, searchAttribute or aggregator

groupByAttributesback to summary
public Set<Attribute<?>> groupByAttributes()

Implements net.sf.ehcache.store.StoreQuery.groupByAttributes.

Doc from net.sf.ehcache.store.StoreQuery.groupByAttributes.

Get the set of attributes to group result set by

Returns:Set<Attribute<?>>

attributes to group by (if any)

includeAggregatorback to summary
public Query includeAggregator(Aggregator... aggregators) throws SearchException, AggregatorException

Implements net.sf.ehcache.search.Query.includeAggregator.

Doc from net.sf.ehcache.search.Query.includeAggregator.

Request this query to aggregate the results by the given Aggregator(s)

This method may be called multiple times to request multiple aggregations

Returns:Query

this

includeAttributeback to summary
public Query includeAttribute(Attribute<?>... attributes)

Implements net.sf.ehcache.search.Query.includeAttribute.

Doc from net.sf.ehcache.search.Query.includeAttribute.

Request that the given attribute(s) should be present in the result for this query. This call can be made multiple times to add to the set of selected attributes.

Note that in a distributed cache attributes may need to come over the network. To prevent very large network transfers, consider limiting the results size with maxResults(int) or by using Results#range rathern than Results#all()

Parameters
attributes:Attribute<?>[]

the query attributes to select

Returns:Query

this

includeKeysback to summary
public Query includeKeys()

Implements net.sf.ehcache.search.Query.includeKeys.

Doc from net.sf.ehcache.search.Query.includeKeys.

Request that the key object be present in the results.

Returns:Query

this

includeValuesback to summary
public Query includeValues()

Implements net.sf.ehcache.search.Query.includeValues.

Doc from net.sf.ehcache.search.Query.includeValues.

Request that the value object be present in the results.

Returns:Query

this

maxResultsback to summary
public Query maxResults(int maxResults)

Implements net.sf.ehcache.search.Query.maxResults.

Doc from net.sf.ehcache.search.Query.maxResults.

Restrict the number of results returned from the search.

By default an unlimited number of results can be returned. This could cause an OutOfMemoryError to be thrown. It is therefore recommended to add an maxResults clause to your query to limit the size.

Negative values are ignored and result in the default behaviour: unlimited number of results.

Parameters
maxResults:int

the maximum number of results to return

Returns:Query

this

maxResultsback to summary
public int maxResults()

Implements net.sf.ehcache.store.StoreQuery.maxResults.

Doc from net.sf.ehcache.store.StoreQuery.maxResults.

Get the maximum number of results to return

Returns:int

max results. A negative number means unlimited results

requestedAttributesback to summary
public Set<Attribute<?>> requestedAttributes()

Implements net.sf.ehcache.store.StoreQuery.requestedAttributes.

Doc from net.sf.ehcache.store.StoreQuery.requestedAttributes.

Get the set of attributes requested by this query

Returns:Set<Attribute<?>>

the requested attributes (if any)

requestsKeysback to summary
public boolean requestsKeys()

Implements net.sf.ehcache.store.StoreQuery.requestsKeys.

Doc from net.sf.ehcache.store.StoreQuery.requestsKeys.

Are keys requested?

Returns:boolean

true if keys requested

requestsValuesback to summary
public boolean requestsValues()

Implements net.sf.ehcache.store.StoreQuery.requestsValues.

Doc from net.sf.ehcache.store.StoreQuery.requestsValues.

Are values requested?

Returns:boolean

true if values requested

snapshotback to summary
private StoreQuery snapshot()
targetsback to summary
public void targets(final String[] targets)

Implements net.sf.ehcache.store.StoreQuery.targets.

Doc from net.sf.ehcache.store.StoreQuery.targets.

Set the names of the select targets. These will either be searchAttribute names or aggregator display names, eg. 'ave(salary)' This is used by BMQL to form the return results.

Annotations
@Override
net.sf.ehcache back to summary

private Class CacheQuery.OrderingImpl

extends Object
implements Ordering
Class Inheritance
All Implemented Interfaces
net.sf.ehcache.store.StoreQuery.Ordering

An attribute/direction pair

Field Summary

Modifier and TypeField and Description
private final Attribute<?>
private final Direction

Constructor Summary

AccessConstructor and Description
public
OrderingImpl(Attribute<?> attribute, Direction direction)

Method Summary

Modifier and TypeMethod and Description
public Attribute<?>
public Direction
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attributeback to summary
private final Attribute<?> attribute
directionback to summary
private final Direction direction

Constructor Detail

OrderingImplback to summary
public OrderingImpl(Attribute<?> attribute, Direction direction)

Method Detail

getAttributeback to summary
public Attribute<?> getAttribute()

Implements net.sf.ehcache.store.StoreQuery.Ordering.getAttribute.

Doc from net.sf.ehcache.store.StoreQuery.Ordering.getAttribute.

Attribute to order by

Returns:Attribute<?>

attribute

getDirectionback to summary
public Direction getDirection()

Implements net.sf.ehcache.store.StoreQuery.Ordering.getDirection.

Doc from net.sf.ehcache.store.StoreQuery.Ordering.getDirection.

Ordering direction

Returns:Direction

direction

net.sf.ehcache back to summary

private Class CacheQuery.StoreQueryImpl

extends Object
implements StoreQuery
Class Inheritance
All Implemented Interfaces
net.sf.ehcache.store.StoreQuery

StoreQuery implementation (essentially a snapshot of this (non-frozen) query builder

Field Summary

Modifier and TypeField and Description
private final List<AggregatorInstance<?>>
private final List<Aggregator>
private final Set<Attribute<?>>
private final Criteria
private final Set<Attribute<?>>
private final boolean
private final boolean
private final int
private final List<StoreQuery.Ordering>
private final ExecutionHints

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public List<AggregatorInstance<?>>
getAggregatorInstances()

Implements net.sf.ehcache.store.StoreQuery.getAggregatorInstances.

Get the requested aggregator instances
public List<Aggregator>
getAggregators()

Implements net.sf.ehcache.store.StoreQuery.getAggregators.

Get the requested aggregators
public Cache
getCache()

Implements net.sf.ehcache.store.StoreQuery.getCache.

Get the cache this query originated from
public Criteria
getCriteria()

Implements net.sf.ehcache.store.StoreQuery.getCriteria.

Get the search criteria
public ExecutionHints
getExecutionHints()

Implements net.sf.ehcache.store.StoreQuery.getExecutionHints.

Get execution hints for this query
public List<StoreQuery.Ordering>
getOrdering()

Implements net.sf.ehcache.store.StoreQuery.getOrdering.

Get the requested search orderings
public String[]
getTargets()

Implements net.sf.ehcache.store.StoreQuery.getTargets.

This needs to be cleaned up.
public Set<Attribute<?>>
groupByAttributes()

Implements net.sf.ehcache.store.StoreQuery.groupByAttributes.

Get the set of attributes to group result set by
public int
maxResults()

Implements net.sf.ehcache.store.StoreQuery.maxResults.

Get the maximum number of results to return
public Set<Attribute<?>>
requestedAttributes()

Implements net.sf.ehcache.store.StoreQuery.requestedAttributes.

Get the set of attributes requested by this query
public boolean
public boolean
public void
targets(String[] targets)

Implements net.sf.ehcache.store.StoreQuery.targets.

Set the names of the select targets.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

copiedAggregatorInstancesback to summary
private final List<AggregatorInstance<?>> copiedAggregatorInstances
copiedAggregatorsback to summary
private final List<Aggregator> copiedAggregators
copiedAttributesback to summary
private final Set<Attribute<?>> copiedAttributes
copiedCriteriaback to summary
private final Criteria copiedCriteria
copiedGroupByAttributesback to summary
private final Set<Attribute<?>> copiedGroupByAttributes
copiedIncludeKeysback to summary
private final boolean copiedIncludeKeys
copiedIncludeValuesback to summary
private final boolean copiedIncludeValues
copiedMaxResultsback to summary
private final int copiedMaxResults
copiedOrderingback to summary
private final List<StoreQuery.Ordering> copiedOrdering
execHintsback to summary
private final ExecutionHints execHints

Constructor Detail

StoreQueryImplback to summary
private StoreQueryImpl()

Method Detail

getAggregatorInstancesback to summary
public List<AggregatorInstance<?>> getAggregatorInstances()

Implements net.sf.ehcache.store.StoreQuery.getAggregatorInstances.

Doc from net.sf.ehcache.store.StoreQuery.getAggregatorInstances.

Get the requested aggregator instances

Returns:List<AggregatorInstance<?>>

the include aggregator instances (if any)

getAggregatorsback to summary
public List<Aggregator> getAggregators()

Implements net.sf.ehcache.store.StoreQuery.getAggregators.

Doc from net.sf.ehcache.store.StoreQuery.getAggregators.

Get the requested aggregators

Returns:List<Aggregator>

the include aggregators (if any)

getCacheback to summary
public Cache getCache()

Implements net.sf.ehcache.store.StoreQuery.getCache.

Doc from net.sf.ehcache.store.StoreQuery.getCache.

Get the cache this query originated from

Returns:Cache

cache

getCriteriaback to summary
public Criteria getCriteria()

Implements net.sf.ehcache.store.StoreQuery.getCriteria.

Doc from net.sf.ehcache.store.StoreQuery.getCriteria.

Get the search criteria

Returns:Criteria

the search criteria

getExecutionHintsback to summary
public ExecutionHints getExecutionHints()

Implements net.sf.ehcache.store.StoreQuery.getExecutionHints.

Doc from net.sf.ehcache.store.StoreQuery.getExecutionHints.

Get execution hints for this query

Returns:ExecutionHints

null if no hints were provided

getOrderingback to summary
public List<StoreQuery.Ordering> getOrdering()

Implements net.sf.ehcache.store.StoreQuery.getOrdering.

Doc from net.sf.ehcache.store.StoreQuery.getOrdering.

Get the requested search orderings

Returns:List<StoreQuery.Ordering>

the request sort orders (if any)

getTargetsback to summary
public String[] getTargets()

Implements net.sf.ehcache.store.StoreQuery.getTargets.

Doc from net.sf.ehcache.store.StoreQuery.getTargets.

This needs to be cleaned up. We don't want to introduce any kind of ordering here, as there simply is none.

Meanwhile, this is used to keep the ordering on BMQL created Queries. Yet, QueryManagerBuilder, which creates the QueryManager, doesn't let us qualify the Query type further to add this "ordering" concept of "targets" to it.
And this "ordering" shouldn't become part of the QueryManager API neither as each implementation might require something different.

Returns:String[]

select target names, searchAttribute or aggregator

groupByAttributesback to summary
public Set<Attribute<?>> groupByAttributes()

Implements net.sf.ehcache.store.StoreQuery.groupByAttributes.

Doc from net.sf.ehcache.store.StoreQuery.groupByAttributes.

Get the set of attributes to group result set by

Returns:Set<Attribute<?>>

attributes to group by (if any)

maxResultsback to summary
public int maxResults()

Implements net.sf.ehcache.store.StoreQuery.maxResults.

Doc from net.sf.ehcache.store.StoreQuery.maxResults.

Get the maximum number of results to return

Returns:int

max results. A negative number means unlimited results

requestedAttributesback to summary
public Set<Attribute<?>> requestedAttributes()

Implements net.sf.ehcache.store.StoreQuery.requestedAttributes.

Doc from net.sf.ehcache.store.StoreQuery.requestedAttributes.

Get the set of attributes requested by this query

Returns:Set<Attribute<?>>

the requested attributes (if any)

requestsKeysback to summary
public boolean requestsKeys()

Implements net.sf.ehcache.store.StoreQuery.requestsKeys.

Doc from net.sf.ehcache.store.StoreQuery.requestsKeys.

Are keys requested?

Returns:boolean

true if keys requested

requestsValuesback to summary
public boolean requestsValues()

Implements net.sf.ehcache.store.StoreQuery.requestsValues.

Doc from net.sf.ehcache.store.StoreQuery.requestsValues.

Are values requested?

Returns:boolean

true if values requested

targetsback to summary
public void targets(String[] targets)

Implements net.sf.ehcache.store.StoreQuery.targets.

Doc from net.sf.ehcache.store.StoreQuery.targets.

Set the names of the select targets. These will either be searchAttribute names or aggregator display names, eg. 'ave(salary)' This is used by BMQL to form the return results.