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 Summary
ConstructorDescriptionAbstractMongoQuery
(MongoQueryMethod method, MongoOperations operations, ExpressionParser expressionParser, org.springframework.data.repository.query.QueryMethodEvaluationContextProvider evaluationContextProvider) -
Method Summary
Modifier and TypeMethodDescriptionprotected Query
createCountQuery
(ConvertingParameterAccessor accessor) Creates aQuery
instance using the givenConvertingParameterAccessor
.protected abstract Query
createQuery
(ConvertingParameterAccessor accessor) Creates aQuery
instance using the givenParameterAccessor
protected UpdateDefinition
createUpdate
(ConvertingParameterAccessor accessor) protected org.bson.Document
decode
(String source, ParameterBindingContext bindingContext) protected Object
doExecute
(MongoQueryMethod method, org.springframework.data.repository.query.ResultProcessor processor, ConvertingParameterAccessor accessor, Class<?> typeToRead) Execute theRepositoryQuery
of the given method with the parameters provided by theaccessor
protected org.bson.codecs.configuration.CodecRegistry
protected ParameterBindingDocumentCodec
Obtain theParameterBindingDocumentCodec
used for parsing JSON expressions.protected org.springframework.data.mapping.model.SpELExpressionEvaluator
getSpELExpressionEvaluatorFor
(org.springframework.data.spel.ExpressionDependencies dependencies, ConvertingParameterAccessor accessor) Obtain a theEvaluationContext
suitable to evaluate expressions backed by the given dependencies.protected abstract boolean
Returns whether the query should get a count projection applied.protected abstract boolean
Return weather the query should delete matching documents.protected abstract boolean
Returns whether the query should get an exists projection applied.protected abstract boolean
Return whether the query has an explicit limit set.protected List<AggregationOperation>
parseAggregationPipeline
(String[] sourcePipeline, ConvertingParameterAccessor accessor) Parse the given aggregation pipeline stages applying values to placeholders to compute the actual list ofoperations
.protected ParameterBindingContext
prepareBindingContext
(String source, ConvertingParameterAccessor accessor) Create thebinding context
used for SpEL evaluation.
-
Constructor Details
-
AbstractMongoQuery
public AbstractMongoQuery(MongoQueryMethod method, MongoOperations operations, ExpressionParser expressionParser, org.springframework.data.repository.query.QueryMethodEvaluationContextProvider evaluationContextProvider) - Parameters:
method
- must not be null.operations
- must not be null.expressionParser
- must not be null.evaluationContextProvider
- must not be null.
-
-
Method Details
-
getQueryMethod
- Specified by:
getQueryMethod
in interfaceorg.springframework.data.repository.query.RepositoryQuery
-
execute
- Specified by:
execute
in interfaceorg.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 theRepositoryQuery
of the given method with the parameters provided by theaccessor
- Parameters:
method
- theMongoQueryMethod
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
Creates aQuery
instance using the givenConvertingParameterAccessor
. Will delegate tocreateQuery(ConvertingParameterAccessor)
by default but allows customization of the count query to be triggered.- Parameters:
accessor
- must not be null.- Returns:
-
createUpdate
Retrieves theupdate
from the givenaccessor
or creates one via by parsing the annotated statement extracted fromUpdate
.- 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 ofoperations
.- Parameters:
sourcePipeline
- must not be null.accessor
- must not be null.- Returns:
- the parsed aggregation pipeline.
- Since:
- 3.4
-
decode
-
prepareBindingContext
protected ParameterBindingContext prepareBindingContext(String source, ConvertingParameterAccessor accessor) Create thebinding context
used for SpEL evaluation.- Parameters:
source
- the JSON source.accessor
- value provider for parameter binding.- Returns:
- never null.
- Since:
- 3.4
-
getParameterBindingCodec
Obtain theParameterBindingDocumentCodec
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 theEvaluationContext
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
Creates aQuery
instance using the givenParameterAccessor
- 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
-