Class JavaQueryInMemoryEvaluator

java.lang.Object
org.datanucleus.store.query.inmemory.JavaQueryInMemoryEvaluator
Direct Known Subclasses:
JDOQLInMemoryEvaluator, JPQLInMemoryEvaluator

public abstract class JavaQueryInMemoryEvaluator extends Object
Class 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 Details

    • RESULTS_SET

      public static final String RESULTS_SET
      Name under which any set of results are stored in the state map. Used for aggregation.
      See Also:
    • language

      protected final String language
    • candidateAlias

      protected String candidateAlias
    • candidates

      protected Collection<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 Map parameterValues
      Map of input parameter values, keyed by the parameter name.
    • evaluator

      protected InMemoryExpressionEvaluator evaluator
      The evaluator.
    • state

      protected Map<String,Object> state
      Map of state symbols for the query evaluation.
    • clr

      protected ClassLoaderResolver clr
  • Constructor Details

    • JavaQueryInMemoryEvaluator

      public JavaQueryInMemoryEvaluator(String language, Query query, QueryCompilation compilation, Map<Object,Object> parameterValues, ClassLoaderResolver clr, Collection<Object> candidates)
      Constructor for the evaluator of a query in the specified language.
      Parameters:
      language - Name of the language
      query - The underlying query
      compilation - Query compilation
      parameterValues - Input parameter values
      clr - ClassLoader resolver
      candidates - Candidate objects
  • Method Details

    • evaluateSubquery

      protected abstract Collection<Object> evaluateSubquery(Query subquery, QueryCompilation compilation, Collection<Object> candidates, Object outerCandidate)
      Method to evaluate a subquery of the query being evaluated.
      Parameters:
      subquery - The subquery
      compilation - The subquery compilation
      candidates - The candidates for the subquery
      outerCandidate - The current outer candidate (for use when linking back to outer query)
      Returns:
      The result
    • execute

      public Collection<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 results
      applyOrdering - Whether to apply any order constraints on the results
      applyResult - Whether to apply any result/grouping/having on the results
      applyResultClass - Whether to apply any resultClass constraint on the results
      applyRange - Whether to apply any range constraint on the results
      Returns:
      The results after evaluation.
    • handleFilter

      private List<Object> handleFilter(List<Object> set)
    • evaluateBooleanExpression

      private 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 expression
      eval - The evaluator
      Returns:
      The result
    • handleRange

      private List<Object> handleRange(List<Object> set, long fromIncl, long toExcl)
    • sortByGrouping

      private List<Object> sortByGrouping(List<Object> set)
    • ordering

      private List<Object> ordering(List<Object> set)
    • handleAggregates

      private List<Object> handleAggregates(List<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(List set)
      Checks if the results set fulfils the having clause.
      Parameters:
      set - Set of results
      Returns:
      true if fulfilling having clause
    • handleResult

      private List<Object> handleResult(List<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 Object[] result(Object obj)
    • result

      private Object[] result(List<Object> set)
    • mapResultClass

      abstract Collection<Object> mapResultClass(Collection<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