Search in sources :

Example 1 with ResultProcessor

use of org.springframework.data.repository.query.ResultProcessor in project spring-data-mongodb by spring-projects.

the class ReactiveStringBasedAggregation method doExecute.

/*
	 * (non-Javascript)
	 * @see org.springframework.data.mongodb.repository.query.AbstractReactiveMongoQuery#doExecute(org.springframework.data.mongodb.repository.query.ReactiveMongoQueryMethod, org.springframework.data.repository.query.ResultProcessor, org.springframework.data.mongodb.repository.query.ConvertingParameterAccessor, java.lang.Class)
	 */
@Override
protected Publisher<Object> doExecute(ReactiveMongoQueryMethod method, ResultProcessor processor, ConvertingParameterAccessor accessor, Class<?> typeToRead) {
    return computePipeline(accessor).flatMapMany(it -> {
        Class<?> sourceType = method.getDomainClass();
        Class<?> targetType = typeToRead;
        List<AggregationOperation> pipeline = it;
        AggregationUtils.appendSortIfPresent(pipeline, accessor, typeToRead);
        AggregationUtils.appendLimitAndOffsetIfPresent(pipeline, accessor);
        boolean isSimpleReturnType = isSimpleReturnType(typeToRead);
        boolean isRawReturnType = ClassUtils.isAssignable(org.bson.Document.class, typeToRead);
        if (isSimpleReturnType || isRawReturnType) {
            targetType = Document.class;
        }
        AggregationOptions options = computeOptions(method, accessor);
        TypedAggregation<?> aggregation = new TypedAggregation<>(sourceType, pipeline, options);
        Flux<?> flux = reactiveMongoOperations.aggregate(aggregation, targetType);
        if (isSimpleReturnType && !isRawReturnType) {
            flux = flux.handle((item, sink) -> {
                Object result = AggregationUtils.extractSimpleTypeResult((Document) item, typeToRead, mongoConverter);
                if (result != null) {
                    sink.next(result);
                }
            });
        }
        return method.isCollectionQuery() ? flux : flux.next();
    });
}
Also used : Document(org.bson.Document) ResultProcessor(org.springframework.data.repository.query.ResultProcessor) ClassUtils(org.springframework.util.ClassUtils) AggregationOptions(org.springframework.data.mongodb.core.aggregation.AggregationOptions) Publisher(org.reactivestreams.Publisher) TypedAggregation(org.springframework.data.mongodb.core.aggregation.TypedAggregation) Mono(reactor.core.publisher.Mono) AggregationOperation(org.springframework.data.mongodb.core.aggregation.AggregationOperation) MongoConverter(org.springframework.data.mongodb.core.convert.MongoConverter) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) Query(org.springframework.data.mongodb.core.query.Query) ExpressionParser(org.springframework.expression.ExpressionParser) Flux(reactor.core.publisher.Flux) List(java.util.List) ReactiveMongoOperations(org.springframework.data.mongodb.core.ReactiveMongoOperations) MongoSimpleTypes(org.springframework.data.mongodb.core.mapping.MongoSimpleTypes) ReactiveQueryMethodEvaluationContextProvider(org.springframework.data.repository.query.ReactiveQueryMethodEvaluationContextProvider) AggregationOptions(org.springframework.data.mongodb.core.aggregation.AggregationOptions) TypedAggregation(org.springframework.data.mongodb.core.aggregation.TypedAggregation) Document(org.bson.Document) AggregationOperation(org.springframework.data.mongodb.core.aggregation.AggregationOperation)

Example 2 with ResultProcessor

use of org.springframework.data.repository.query.ResultProcessor in project spring-data-jdbc by spring-projects.

the class StringBasedJdbcQuery method execute.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.repository.query.RepositoryQuery#execute(java.lang.Object[])
	 */
@Override
public Object execute(Object[] objects) {
    RelationalParameterAccessor accessor = new RelationalParametersParameterAccessor(getQueryMethod(), objects);
    ResultProcessor processor = getQueryMethod().getResultProcessor().withDynamicProjection(accessor);
    ResultProcessingConverter converter = new ResultProcessingConverter(processor, this.converter.getMappingContext(), this.converter.getEntityInstantiators());
    RowMapper<Object> rowMapper = determineRowMapper(rowMapperFactory.create(resolveTypeToRead(processor)), converter, accessor.findDynamicProjection() != null);
    JdbcQueryExecution<?> queryExecution = getQueryExecution(// 
    queryMethod, // 
    determineResultSetExtractor(rowMapper), rowMapper);
    return queryExecution.execute(determineQuery(), this.bindParameters(accessor));
}
Also used : RelationalParametersParameterAccessor(org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor) RelationalParameterAccessor(org.springframework.data.relational.repository.query.RelationalParameterAccessor) ResultProcessor(org.springframework.data.repository.query.ResultProcessor)

Example 3 with ResultProcessor

use of org.springframework.data.repository.query.ResultProcessor in project spring-data-jdbc by spring-projects.

the class PartTreeJdbcQuery method execute.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.repository.query.RepositoryQuery#execute(java.lang.Object[])
	 */
@Override
public Object execute(Object[] values) {
    RelationalParametersParameterAccessor accessor = new RelationalParametersParameterAccessor(getQueryMethod(), values);
    ResultProcessor processor = getQueryMethod().getResultProcessor().withDynamicProjection(accessor);
    ParametrizedQuery query = createQuery(accessor, processor.getReturnedType());
    JdbcQueryExecution<?> execution = getQueryExecution(processor, accessor);
    return execution.execute(query.getQuery(), query.getParameterSource());
}
Also used : RelationalParametersParameterAccessor(org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor) ResultProcessor(org.springframework.data.repository.query.ResultProcessor)

Example 4 with ResultProcessor

use of org.springframework.data.repository.query.ResultProcessor in project spring-data-keyvalue by spring-projects.

the class KeyValuePartTreeQuery method execute.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.repository.query.RepositoryQuery#execute(java.lang.Object[])
	 */
@Override
public Object execute(Object[] parameters) {
    ParameterAccessor accessor = new ParametersParameterAccessor(getQueryMethod().getParameters(), parameters);
    KeyValueQuery<?> query = prepareQuery(parameters);
    ResultProcessor processor = queryMethod.getResultProcessor().withDynamicProjection(accessor);
    return processor.processResult(doExecute(parameters, query));
}
Also used : ParametersParameterAccessor(org.springframework.data.repository.query.ParametersParameterAccessor) ParametersParameterAccessor(org.springframework.data.repository.query.ParametersParameterAccessor) ParameterAccessor(org.springframework.data.repository.query.ParameterAccessor) ResultProcessor(org.springframework.data.repository.query.ResultProcessor)

Example 5 with ResultProcessor

use of org.springframework.data.repository.query.ResultProcessor in project spring-data-mongodb by spring-projects.

the class AbstractMongoQuery method execute.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.repository.query.RepositoryQuery#execute(java.lang.Object[])
	 */
@Override
public Object execute(Object[] parameters) {
    ConvertingParameterAccessor accessor = new ConvertingParameterAccessor(operations.getConverter(), new MongoParametersParameterAccessor(method, parameters));
    ResultProcessor processor = method.getResultProcessor().withDynamicProjection(accessor);
    Class<?> typeToRead = processor.getReturnedType().getTypeToRead();
    return processor.processResult(doExecute(method, processor, accessor, typeToRead));
}
Also used : ResultProcessor(org.springframework.data.repository.query.ResultProcessor)

Aggregations

ResultProcessor (org.springframework.data.repository.query.ResultProcessor)6 RelationalParametersParameterAccessor (org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor)2 List (java.util.List)1 Document (org.bson.Document)1 Publisher (org.reactivestreams.Publisher)1 ReactiveMongoOperations (org.springframework.data.mongodb.core.ReactiveMongoOperations)1 Aggregation (org.springframework.data.mongodb.core.aggregation.Aggregation)1 AggregationOperation (org.springframework.data.mongodb.core.aggregation.AggregationOperation)1 AggregationOptions (org.springframework.data.mongodb.core.aggregation.AggregationOptions)1 TypedAggregation (org.springframework.data.mongodb.core.aggregation.TypedAggregation)1 MongoConverter (org.springframework.data.mongodb.core.convert.MongoConverter)1 MongoSimpleTypes (org.springframework.data.mongodb.core.mapping.MongoSimpleTypes)1 Query (org.springframework.data.mongodb.core.query.Query)1 RelationalParameterAccessor (org.springframework.data.relational.repository.query.RelationalParameterAccessor)1 ParameterAccessor (org.springframework.data.repository.query.ParameterAccessor)1 ParametersParameterAccessor (org.springframework.data.repository.query.ParametersParameterAccessor)1 ReactiveQueryMethodEvaluationContextProvider (org.springframework.data.repository.query.ReactiveQueryMethodEvaluationContextProvider)1 ExpressionParser (org.springframework.expression.ExpressionParser)1 ClassUtils (org.springframework.util.ClassUtils)1 Flux (reactor.core.publisher.Flux)1