Class JavaQueryInMemoryEvaluator
- java.lang.Object
-
- org.datanucleus.store.query.inmemory.JavaQueryInMemoryEvaluator
-
- Direct Known Subclasses:
JDOQLInMemoryEvaluator,JPQLInMemoryEvaluator
public abstract class JavaQueryInMemoryEvaluator extends java.lang.ObjectClass to evaluate a Java "string-based" query in whole or part. Takes in the "generic" compilation, a list of instances and applies the required restrictions to the input giving a final result. Typically extended for JDOQL, JPQL specifics.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringcandidateAliasprotected java.util.Collection<java.lang.Object>candidatesCandidates objects to evaluate.protected ClassLoaderResolverclrprotected QueryCompilationcompilationCompilation of the underlying query, that we are evaluating.protected InMemoryExpressionEvaluatorevaluatorThe evaluator.protected java.lang.Stringlanguageprotected java.util.MapparameterValuesMap of input parameter values, keyed by the parameter name.protected QueryqueryUnderlying "string-based" query.static java.lang.StringRESULTS_SETName under which any set of results are stored in the state map.protected java.util.Map<java.lang.String,java.lang.Object>stateMap of state symbols for the query evaluation.
-
Constructor Summary
Constructors Constructor Description JavaQueryInMemoryEvaluator(java.lang.String language, Query query, QueryCompilation compilation, java.util.Map<java.lang.Object,java.lang.Object> parameterValues, ClassLoaderResolver clr, java.util.Collection<java.lang.Object> candidates)Constructor for the evaluator of a query in the specified language.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private java.lang.BooleanevaluateBooleanExpression(Expression expr, InMemoryExpressionEvaluator eval)Convenience method to evaluate the provided expression returning a boolean.protected abstract java.util.Collection<java.lang.Object>evaluateSubquery(Query subquery, QueryCompilation compilation, java.util.Collection<java.lang.Object> candidates, java.lang.Object outerCandidate)Method to evaluate a subquery of the query being evaluated.java.util.Collection<java.lang.Object>execute(boolean applyFilter, boolean applyOrdering, boolean applyResult, boolean applyResultClass, boolean applyRange)Method to perform the evaluation, applying the query restrictions that are required.private java.util.List<java.lang.Object>handleAggregates(java.util.List<java.lang.Object> resultSet)Checks if there are aggregates and handle it.private java.util.List<java.lang.Object>handleFilter(java.util.List<java.lang.Object> set)private java.util.List<java.lang.Object>handleRange(java.util.List<java.lang.Object> set, long fromIncl, long toExcl)private java.util.List<java.lang.Object>handleResult(java.util.List<java.lang.Object> resultSet)Checks if there are aggregates and handles it.(package private) abstract java.util.Collection<java.lang.Object>mapResultClass(java.util.Collection<java.lang.Object> resultSet)Constructs ResultClassMapper and calls its map functionprivate java.util.List<java.lang.Object>ordering(java.util.List<java.lang.Object> set)private java.lang.Object[]result(java.lang.Object obj)private java.lang.Object[]result(java.util.List<java.lang.Object> set)private booleansatisfiesHavingClause(java.util.List set)Checks if the results set fulfils the having clause.private java.util.List<java.lang.Object>sortByGrouping(java.util.List<java.lang.Object> set)
-
-
-
Field Detail
-
RESULTS_SET
public static final java.lang.String RESULTS_SET
Name under which any set of results are stored in the state map. Used for aggregation.- See Also:
- Constant Field Values
-
language
protected final java.lang.String language
-
candidateAlias
protected java.lang.String candidateAlias
-
candidates
protected java.util.Collection<java.lang.Object> candidates
Candidates objects to evaluate.
-
query
protected Query query
Underlying "string-based" query.
-
compilation
protected QueryCompilation compilation
Compilation of the underlying query, that we are evaluating.
-
parameterValues
protected java.util.Map parameterValues
Map of input parameter values, keyed by the parameter name.
-
evaluator
protected InMemoryExpressionEvaluator evaluator
The evaluator.
-
state
protected java.util.Map<java.lang.String,java.lang.Object> state
Map of state symbols for the query evaluation.
-
clr
protected ClassLoaderResolver clr
-
-
Constructor Detail
-
JavaQueryInMemoryEvaluator
public JavaQueryInMemoryEvaluator(java.lang.String language, Query query, QueryCompilation compilation, java.util.Map<java.lang.Object,java.lang.Object> parameterValues, ClassLoaderResolver clr, java.util.Collection<java.lang.Object> candidates)Constructor for the evaluator of a query in the specified language.- Parameters:
language- Name of the languagequery- The underlying querycompilation- Query compilationparameterValues- Input parameter valuesclr- ClassLoader resolvercandidates- Candidate objects
-
-
Method Detail
-
evaluateSubquery
protected abstract java.util.Collection<java.lang.Object> evaluateSubquery(Query subquery, QueryCompilation compilation, java.util.Collection<java.lang.Object> candidates, java.lang.Object outerCandidate)
Method to evaluate a subquery of the query being evaluated.- Parameters:
subquery- The subquerycompilation- The subquery compilationcandidates- The candidates for the subqueryouterCandidate- The current outer candidate (for use when linking back to outer query)- Returns:
- The result
-
execute
public java.util.Collection<java.lang.Object> execute(boolean applyFilter, boolean applyOrdering, boolean applyResult, boolean applyResultClass, boolean applyRange)Method to perform the evaluation, applying the query restrictions that are required.- Parameters:
applyFilter- Whether to apply any filter constraints on the resultsapplyOrdering- Whether to apply any order constraints on the resultsapplyResult- Whether to apply any result/grouping/having on the resultsapplyResultClass- Whether to apply any resultClass constraint on the resultsapplyRange- Whether to apply any range constraint on the results- Returns:
- The results after evaluation.
-
handleFilter
private java.util.List<java.lang.Object> handleFilter(java.util.List<java.lang.Object> set)
-
evaluateBooleanExpression
private java.lang.Boolean evaluateBooleanExpression(Expression expr, InMemoryExpressionEvaluator eval)
Convenience method to evaluate the provided expression returning a boolean. Caters for variables in the provided expression, attempting to process all possible values for them.- Parameters:
expr- The expressioneval- The evaluator- Returns:
- The result
-
handleRange
private java.util.List<java.lang.Object> handleRange(java.util.List<java.lang.Object> set, long fromIncl, long toExcl)
-
sortByGrouping
private java.util.List<java.lang.Object> sortByGrouping(java.util.List<java.lang.Object> set)
-
ordering
private java.util.List<java.lang.Object> ordering(java.util.List<java.lang.Object> set)
-
handleAggregates
private java.util.List<java.lang.Object> handleAggregates(java.util.List<java.lang.Object> resultSet)
Checks if there are aggregates and handle it.- Parameters:
resultSet- The resultSet containing all elements- Returns:
- A list with aggregated elements
-
satisfiesHavingClause
private boolean satisfiesHavingClause(java.util.List set)
Checks if the results set fulfils the having clause.- Parameters:
set- Set of results- Returns:
- true if fulfilling having clause
-
handleResult
private java.util.List<java.lang.Object> handleResult(java.util.List<java.lang.Object> resultSet)
Checks if there are aggregates and handles it.- Parameters:
resultSet- The resultSet containing all elements- Returns:
- A list with aggregated elements
-
result
private java.lang.Object[] result(java.lang.Object obj)
-
result
private java.lang.Object[] result(java.util.List<java.lang.Object> set)
-
mapResultClass
abstract java.util.Collection<java.lang.Object> mapResultClass(java.util.Collection<java.lang.Object> resultSet)
Constructs ResultClassMapper and calls its map function- Parameters:
resultSet- The resultSet containing the instances handled by setResult- Returns:
- The resultSet containing instances of the Class defined by setResultClass
-
-