Class AbstractMongoQuery

java.lang.Object
org.springframework.data.mongodb.repository.query.AbstractMongoQuery
All Implemented Interfaces:
org.springframework.data.repository.query.RepositoryQuery
Direct Known Subclasses:
PartTreeMongoQuery, StringBasedAggregation, StringBasedMongoQuery

public abstract class AbstractMongoQuery extends Object implements org.springframework.data.repository.query.RepositoryQuery
Base class for RepositoryQuery implementations for Mongo.
Author:
Oliver Gierke, Thomas Darimont, Christoph Strobl, Mark Paluch
  • Constructor Details

    • AbstractMongoQuery

      public AbstractMongoQuery(MongoQueryMethod method, MongoOperations operations, org.springframework.expression.ExpressionParser expressionParser, org.springframework.data.repository.query.QueryMethodEvaluationContextProvider evaluationContextProvider)
      Creates a new AbstractMongoQuery from the given MongoQueryMethod and MongoOperations.
      Parameters:
      method - must not be null.
      operations - must not be null.
      expressionParser - must not be null.
      evaluationContextProvider - must not be null.
  • Method Details

    • getQueryMethod

      public MongoQueryMethod getQueryMethod()
      Specified by:
      getQueryMethod in interface org.springframework.data.repository.query.RepositoryQuery
    • execute

      public Object execute(Object[] parameters)
      Specified by:
      execute in interface org.springframework.data.repository.query.RepositoryQuery
    • doExecute

      @Nullable protected Object doExecute(MongoQueryMethod method, org.springframework.data.repository.query.ResultProcessor processor, ConvertingParameterAccessor accessor, @Nullable Class<?> typeToRead)
      Execute the RepositoryQuery of the given method with the parameters provided by the accessor
      Parameters:
      method - the MongoQueryMethod invoked. Never null.
      processor - ResultProcessor for post procession. Never null.
      accessor - for providing invocation arguments. Never null.
      typeToRead - the desired component target type. Can be null.
    • createCountQuery

      protected Query createCountQuery(ConvertingParameterAccessor accessor)
      Creates a Query instance using the given ConvertingParameterAccessor. Will delegate to createQuery(ConvertingParameterAccessor) by default but allows customization of the count query to be triggered.
      Parameters:
      accessor - must not be null.
      Returns:
    • createUpdate

      protected UpdateDefinition createUpdate(ConvertingParameterAccessor accessor)
      Retrieves the update from the given accessor or creates one via by parsing the annotated statement extracted from Update.
      Parameters:
      accessor - never null.
      Returns:
      the computed UpdateDefinition.
      Throws:
      IllegalStateException - if no update could be found.
      Since:
      3.4
    • parseAggregationPipeline

      protected List<AggregationOperation> parseAggregationPipeline(String[] sourcePipeline, ConvertingParameterAccessor accessor)
      Parse the given aggregation pipeline stages applying values to placeholders to compute the actual list of operations.
      Parameters:
      sourcePipeline - must not be null.
      accessor - must not be null.
      Returns:
      the parsed aggregation pipeline.
      Since:
      3.4
    • decode

      protected org.bson.Document decode(String source, ParameterBindingContext bindingContext)
    • prepareBindingContext

      protected ParameterBindingContext prepareBindingContext(String source, ConvertingParameterAccessor accessor)
      Create the binding context used for SpEL evaluation.
      Parameters:
      source - the JSON source.
      accessor - value provider for parameter binding.
      Returns:
      never null.
      Since:
      3.4
    • getParameterBindingCodec

      protected ParameterBindingDocumentCodec getParameterBindingCodec()
      Obtain the ParameterBindingDocumentCodec used for parsing JSON expressions.
      Returns:
      never null.
      Since:
      3.4
    • getSpELExpressionEvaluatorFor

      protected org.springframework.data.mapping.model.SpELExpressionEvaluator getSpELExpressionEvaluatorFor(org.springframework.data.spel.ExpressionDependencies dependencies, ConvertingParameterAccessor accessor)
      Obtain a the EvaluationContext suitable to evaluate expressions backed by the given dependencies.
      Parameters:
      dependencies - must not be null.
      accessor - must not be null.
      Returns:
      the SpELExpressionEvaluator.
      Since:
      2.4
    • getCodecRegistry

      protected org.bson.codecs.configuration.CodecRegistry getCodecRegistry()
      Returns:
      the CodecRegistry used.
      Since:
      2.4
    • createQuery

      protected abstract Query createQuery(ConvertingParameterAccessor accessor)
      Creates a Query instance using the given ParameterAccessor
      Parameters:
      accessor - must not be null.
      Returns:
    • isCountQuery

      protected abstract boolean isCountQuery()
      Returns whether the query should get a count projection applied.
      Returns:
    • isExistsQuery

      protected abstract boolean isExistsQuery()
      Returns whether the query should get an exists projection applied.
      Returns:
      Since:
      1.10
    • isDeleteQuery

      protected abstract boolean isDeleteQuery()
      Return weather the query should delete matching documents.
      Returns:
      Since:
      1.5
    • isLimiting

      protected abstract boolean isLimiting()
      Return whether the query has an explicit limit set.
      Returns:
      Since:
      2.0.4