Java Code Examples for org.springframework.data.repository.query.ResultProcessor

The following examples show how to use org.springframework.data.repository.query.ResultProcessor. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: sdn-rx   Source File: Neo4jQuerySupport.java    License: Apache License 2.0 6 votes vote down vote up
protected final BiFunction<TypeSystem, Record, ?> getMappingFunction(final ResultProcessor resultProcessor) {

		final Class<?> returnedType = resultProcessor.getReturnedType().getReturnedType();

		final BiFunction<TypeSystem, Record, ?> mappingFunction;
		if (Neo4jSimpleTypes.HOLDER.isSimpleType(returnedType)) {
			// Clients automatically selects a single value mapping function.
			// It will thrown an error if the query contains more than one column.
			mappingFunction = null;
		} else if (resultProcessor.getReturnedType().isProjecting()) {

			if (returnedType.isInterface()) {
				mappingFunction = this.mappingContext.getRequiredMappingFunctionFor(domainType);
			} else if (this.mappingContext.hasPersistentEntityFor(returnedType)) {
				mappingFunction = this.mappingContext.getRequiredMappingFunctionFor(returnedType);
			} else {
				this.mappingContext.addPersistentEntity(returnedType);
				mappingFunction = this.mappingContext.getRequiredMappingFunctionFor(returnedType);
			}
		} else {
			mappingFunction = this.mappingContext.getRequiredMappingFunctionFor(domainType);
		}
		return mappingFunction;
	}
 
Example 2
Source Project: sdn-rx   Source File: AbstractNeo4jQuery.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public final Object execute(Object[] parameters) {

	Neo4jParameterAccessor parameterAccessor = getParameterAccessor(parameters);
	ResultProcessor resultProcessor = queryMethod.getResultProcessor().withDynamicProjection(parameterAccessor);

	PreparedQuery<?> preparedQuery = prepareQuery(resultProcessor.getReturnedType().getReturnedType(),
		getInputProperties(resultProcessor), parameterAccessor, null, getMappingFunction(resultProcessor));

	Object rawResult = new DefaultQueryExecution(neo4jOperations).execute(
		preparedQuery, queryMethod.isCollectionLikeQuery() || queryMethod.isPageQuery());

	Object processedResult = resultProcessor.processResult(rawResult, OptionalUnwrappingConverter.INSTANCE);

	if (!queryMethod.isPageQuery()) {
		return processedResult;
	} else {
		return PageableExecutionUtils.getPage((List<?>) processedResult, parameterAccessor.getPageable(), () -> {

			PreparedQuery<Long> countQuery = prepareQuery(Long.class, Collections.emptyList(), parameterAccessor,
				Neo4jQueryType.COUNT, null);
			return neo4jOperations.toExecutableQuery(countQuery).getRequiredSingleResult();
		});
	}
}
 
Example 3
Source Project: sdn-rx   Source File: AbstractReactiveNeo4jQuery.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final Object execute(Object[] parameters) {

	Neo4jParameterAccessor parameterAccessor = getParameterAccessor(parameters);
	ResultProcessor resultProcessor = queryMethod.getResultProcessor().withDynamicProjection(parameterAccessor);

	PreparedQuery<?> preparedQuery = prepareQuery(resultProcessor.getReturnedType().getReturnedType(),
		getInputProperties(resultProcessor), parameterAccessor, null, getMappingFunction(resultProcessor));

	Object rawResult = new Neo4jQueryExecution.ReactiveQueryExecution(neo4jOperations).execute(
		preparedQuery, queryMethod.isCollectionLikeQuery());

	return resultProcessor.processResult(rawResult, OptionalUnwrappingConverter.INSTANCE);
}
 
Example 4
Source Project: spring-data   Source File: AbstractArangoQuery.java    License: Apache License 2.0 5 votes vote down vote up
private Class<?> getTypeToRead(final ResultProcessor processor) {
	if (isExistsQuery()) {
		return Integer.class;
	}

	if (method.isGeoQuery()) {
		return VPackSlice.class;
	}

	final Class<?> typeToRead = processor.getReturnedType().getTypeToRead();
	return typeToRead != null ? typeToRead : Map.class;
}
 
Example 5
Source Project: spring-data-cosmosdb   Source File: AbstractCosmosQuery.java    License: MIT License 5 votes vote down vote up
public Object execute(Object[] parameters) {
    final CosmosParameterAccessor accessor = new CosmosParameterParameterAccessor(method, parameters);
    final DocumentQuery query = createQuery(accessor);

    final ResultProcessor processor = method.getResultProcessor().withDynamicProjection(accessor);
    final String container = ((CosmosEntityMetadata) method.getEntityInformation()).getContainerName();

    final CosmosQueryExecution execution = getExecution(accessor);
    return execution.execute(query, processor.getReturnedType().getDomainType(), container);
}
 
Example 6
Source Project: spring-data-cosmosdb   Source File: AbstractReactiveCosmosQuery.java    License: MIT License 5 votes vote down vote up
public Object execute(Object[] parameters) {
    final ReactiveCosmosParameterAccessor accessor =
        new ReactiveCosmosParameterParameterAccessor(method, parameters);
    final DocumentQuery query = createQuery(accessor);

    final ResultProcessor processor =
        method.getResultProcessor().withDynamicProjection(accessor);
    final String containerName =
        ((ReactiveCosmosEntityMetadata) method.getEntityInformation()).getContainerName();

    final ReactiveCosmosQueryExecution execution = getExecution(accessor);
    return execution.execute(query, processor.getReturnedType().getDomainType(), containerName);
}
 
Example 7
private PartTreeFirestoreQuery setUpPartTreeFirestoreQuery(String methodName) {
	Parameters parametersMock = mock(Parameters.class);
	when(parametersMock.isEmpty()).thenReturn(true);
	when(this.queryMethod.getParameters()).thenReturn(parametersMock);

	when(this.queryMethod.getName()).thenReturn(methodName);
	ReturnedType returnedType = mock(ReturnedType.class);
	when(returnedType.getDomainType()).thenAnswer(invocation -> User.class);
	ResultProcessor resultProcessor = mock(ResultProcessor.class);
	when(resultProcessor.getReturnedType()).thenReturn(returnedType);
	when(this.queryMethod.getResultProcessor()).thenReturn(resultProcessor);

	return new PartTreeFirestoreQuery(this.queryMethod,
			this.firestoreTemplate, new FirestoreMappingContext(), this.classMapper);
}
 
Example 8
Source Project: spring-data-ebean   Source File: PartTreeEbeanQuery.java    License: Apache License 2.0 5 votes vote down vote up
protected EbeanQueryCreator createCreator(ParametersParameterAccessor accessor) {
    EbeanServer ebeanServer = getEbeanServer();
    Query ebeanQuery = ebeanServer.createQuery(domainClass);
    ExpressionList expressionList = ebeanQuery.where();

    ParameterMetadataProvider provider = new ParameterMetadataProvider(accessor);

    ResultProcessor processor = getQueryMethod().getResultProcessor();

    return new EbeanQueryCreator(tree, processor.getReturnedType(), expressionList, provider);
}
 
Example 9
Source Project: spring-data-mybatis   Source File: AbstractMybatisQuery.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
private Object doExecute(MybatisQueryExecution execution, Object[] values) {

	Object result = execution.execute(this, values);

	ParametersParameterAccessor accessor = new ParametersParameterAccessor(
			method.getParameters(), values);
	ResultProcessor withDynamicProjection = method.getResultProcessor()
			.withDynamicProjection(accessor);

	return withDynamicProjection.processResult(result,
			new TupleConverter(withDynamicProjection.getReturnedType()));
}
 
Example 10
@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));
}
 
Example 11
Source Project: sdn-rx   Source File: Neo4jQuerySupport.java    License: Apache License 2.0 4 votes vote down vote up
protected final ResultProcessor getResultProcessor(ParameterAccessor parameterAccessor) {
	return queryMethod.getResultProcessor().withDynamicProjection(parameterAccessor);
}
 
Example 12
Source Project: sdn-rx   Source File: Neo4jQuerySupport.java    License: Apache License 2.0 4 votes vote down vote up
protected final List<String> getInputProperties(final ResultProcessor resultProcessor) {

		ReturnedType returnedType = resultProcessor.getReturnedType();
		return returnedType.isProjecting() ? returnedType.getInputProperties() : Collections.emptyList();
	}