@Override public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, NamedQueries namedQueries) { ReactiveMongoQueryMethod queryMethod = new ReactiveMongoQueryMethod(method, metadata, factory, mappingContext); String namedQueryName = queryMethod.getNamedQueryName(); if (namedQueries.hasQuery(namedQueryName)) { String namedQuery = namedQueries.getQuery(namedQueryName); return new ReactiveStringBasedMongoQuery(namedQuery, queryMethod, operations, EXPRESSION_PARSER, evaluationContextProvider); } else if (queryMethod.hasAnnotatedQuery()) { return new ReactiveStringBasedMongoQuery(queryMethod, operations, EXPRESSION_PARSER, evaluationContextProvider); } else { return new ReactivePartTreeMongoQuery(queryMethod, operations); } } }
/** * Creates a new {@link ReactiveStringBasedMongoQuery} for the given {@link MongoQueryMethod} and * {@link MongoOperations}. * * @param method must not be {@literal null}. * @param mongoOperations must not be {@literal null}. * @param expressionParser must not be {@literal null}. * @param evaluationContextProvider must not be {@literal null}. */ public ReactiveStringBasedMongoQuery(ReactiveMongoQueryMethod method, ReactiveMongoOperations mongoOperations, SpelExpressionParser expressionParser, QueryMethodEvaluationContextProvider evaluationContextProvider) { this(method.getAnnotatedQuery(), method, mongoOperations, expressionParser, evaluationContextProvider); }
/** * Add a default sort derived from {@link org.springframework.data.mongodb.repository.Query#sort()} to the given * {@link Query} if present. * * @param query the {@link Query} to potentially apply the sort to. * @return the query with potential default sort applied. * @since 2.1 */ Query applyAnnotatedDefaultSortIfPresent(Query query) { if (!method.hasAnnotatedSort()) { return query; } return QueryUtils.decorateSort(query, Document.parse(method.getAnnotatedSort())); }
Query applyQueryMetaAttributesWhenPresent(Query query) { if (method.hasQueryMetaAttributes()) { query.setMeta(method.getQueryMetaAttributes()); } return query; }
/** * Creates a new {@link ReactivePartTreeMongoQuery} from the given {@link QueryMethod} and {@link MongoTemplate}. * * @param method must not be {@literal null}. * @param mongoOperations must not be {@literal null}. */ public ReactivePartTreeMongoQuery(ReactiveMongoQueryMethod method, ReactiveMongoOperations mongoOperations) { super(method, mongoOperations); this.processor = method.getResultProcessor(); this.tree = new PartTree(method.getName(), processor.getReturnedType().getDomainType()); this.isGeoNearQuery = method.isGeoNearQuery(); this.context = mongoOperations.getConverter().getMappingContext(); }
method.getFieldSpecification(), this.fieldSpecParameterBindings); if (method.hasAnnotatedQuery()) { org.springframework.data.mongodb.repository.Query queryAnnotation = method.getQueryAnnotation();
private Object execute(MongoParameterAccessor parameterAccessor) { Query query = createQuery(new ConvertingParameterAccessor(operations.getConverter(), parameterAccessor)); applyQueryMetaAttributesWhenPresent(query); query = applyAnnotatedDefaultSortIfPresent(query); ResultProcessor processor = method.getResultProcessor().withDynamicProjection(parameterAccessor); Class<?> typeToRead = processor.getReturnedType().getTypeToRead(); FindWithQuery<?> find = typeToRead == null // ? findOperationWithProjection // : findOperationWithProjection.as(typeToRead); String collection = method.getEntityInformation().getCollectionName(); ReactiveMongoQueryExecution execution = getExecution(parameterAccessor, new ResultProcessingConverter(processor, operations, instantiators), find); return execution.execute(query, processor.getReturnedType().getDomainType(), collection); }
/** * Check if the given {@link org.springframework.data.repository.query.QueryMethod} receives a reactive parameter * wrapper as one of its parameters. * * @return */ public boolean hasReactiveWrapperParameter() { for (MongoParameter mongoParameter : getParameters()) { if (ReactiveWrapperConverters.supports(mongoParameter.getType())) { return true; } } return false; }
/** * Creates a new {@link AbstractReactiveMongoQuery} from the given {@link MongoQueryMethod} and * {@link MongoOperations}. * * @param method must not be {@literal null}. * @param operations must not be {@literal null}. */ public AbstractReactiveMongoQuery(ReactiveMongoQueryMethod method, ReactiveMongoOperations operations) { Assert.notNull(method, "MongoQueryMethod must not be null!"); Assert.notNull(operations, "ReactiveMongoOperations must not be null!"); this.method = method; this.operations = operations; this.instantiators = new EntityInstantiators(); MongoEntityMetadata<?> metadata = method.getEntityInformation(); Class<?> type = metadata.getCollectionEntity().getType(); this.findOperationWithProjection = operations.query(type); }
/** * Creates a new {@link ReactivePartTreeMongoQuery} from the given {@link QueryMethod} and {@link MongoTemplate}. * * @param method must not be {@literal null}. * @param mongoOperations must not be {@literal null}. */ public ReactivePartTreeMongoQuery(ReactiveMongoQueryMethod method, ReactiveMongoOperations mongoOperations) { super(method, mongoOperations); this.processor = method.getResultProcessor(); this.tree = new PartTree(method.getName(), processor.getReturnedType().getDomainType()); this.isGeoNearQuery = method.isGeoNearQuery(); this.context = mongoOperations.getConverter().getMappingContext(); }
method.getFieldSpecification(), this.fieldSpecParameterBindings); if (method.hasAnnotatedQuery()) { org.springframework.data.mongodb.repository.Query queryAnnotation = method.getQueryAnnotation();
Query applyQueryMetaAttributesWhenPresent(Query query) { if (method.hasQueryMetaAttributes()) { query.setMeta(method.getQueryMetaAttributes()); } return query; }
private Object execute(MongoParameterAccessor parameterAccessor) { Query query = createQuery(new ConvertingParameterAccessor(operations.getConverter(), parameterAccessor)); applyQueryMetaAttributesWhenPresent(query); query = applyAnnotatedDefaultSortIfPresent(query); ResultProcessor processor = method.getResultProcessor().withDynamicProjection(parameterAccessor); Class<?> typeToRead = processor.getReturnedType().getTypeToRead(); FindWithQuery<?> find = typeToRead == null // ? findOperationWithProjection // : findOperationWithProjection.as(typeToRead); String collection = method.getEntityInformation().getCollectionName(); ReactiveMongoQueryExecution execution = getExecution(parameterAccessor, new ResultProcessingConverter(processor, operations, instantiators), find); return execution.execute(query, processor.getReturnedType().getDomainType(), collection); }
/** * Check if the given {@link org.springframework.data.repository.query.QueryMethod} receives a reactive parameter * wrapper as one of its parameters. * * @return */ public boolean hasReactiveWrapperParameter() { for (MongoParameter mongoParameter : getParameters()) { if (ReactiveWrapperConverters.supports(mongoParameter.getType())) { return true; } } return false; }
/** * Creates a new {@link AbstractReactiveMongoQuery} from the given {@link MongoQueryMethod} and * {@link MongoOperations}. * * @param method must not be {@literal null}. * @param operations must not be {@literal null}. */ public AbstractReactiveMongoQuery(ReactiveMongoQueryMethod method, ReactiveMongoOperations operations) { Assert.notNull(method, "MongoQueryMethod must not be null!"); Assert.notNull(operations, "ReactiveMongoOperations must not be null!"); this.method = method; this.operations = operations; this.instantiators = new EntityInstantiators(); MongoEntityMetadata<?> metadata = method.getEntityInformation(); Class<?> type = metadata.getCollectionEntity().getType(); this.findOperationWithProjection = operations.query(type); }
@Override public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, NamedQueries namedQueries) { ReactiveMongoQueryMethod queryMethod = new ReactiveMongoQueryMethod(method, metadata, factory, mappingContext); String namedQueryName = queryMethod.getNamedQueryName(); if (namedQueries.hasQuery(namedQueryName)) { String namedQuery = namedQueries.getQuery(namedQueryName); return new ReactiveStringBasedMongoQuery(namedQuery, queryMethod, operations, EXPRESSION_PARSER, evaluationContextProvider); } else if (queryMethod.hasAnnotatedQuery()) { return new ReactiveStringBasedMongoQuery(queryMethod, operations, EXPRESSION_PARSER, evaluationContextProvider); } else { return new ReactivePartTreeMongoQuery(queryMethod, operations); } } }
/** * Add a default sort derived from {@link org.springframework.data.mongodb.repository.Query#sort()} to the given * {@link Query} if present. * * @param query the {@link Query} to potentially apply the sort to. * @return the query with potential default sort applied. * @since 2.1 */ Query applyAnnotatedDefaultSortIfPresent(Query query) { if (!method.hasAnnotatedSort()) { return query; } return QueryUtils.decorateSort(query, Document.parse(method.getAnnotatedSort())); }
/** * Creates a new {@link ReactiveStringBasedMongoQuery} for the given {@link MongoQueryMethod} and * {@link MongoOperations}. * * @param method must not be {@literal null}. * @param mongoOperations must not be {@literal null}. * @param expressionParser must not be {@literal null}. * @param evaluationContextProvider must not be {@literal null}. */ public ReactiveStringBasedMongoQuery(ReactiveMongoQueryMethod method, ReactiveMongoOperations mongoOperations, SpelExpressionParser expressionParser, QueryMethodEvaluationContextProvider evaluationContextProvider) { this(method.getAnnotatedQuery(), method, mongoOperations, expressionParser, evaluationContextProvider); }