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

The following examples show how to use org.springframework.data.repository.query.ParametersParameterAccessor. 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: spring-cloud-gcp   Source File: PartTreeDatastoreQuery.java    License: Apache License 2.0 6 votes vote down vote up
private Slice executeSliceQuery(Object[] parameters) {
	StructuredQuery.Builder builder = getEntityOrProjectionQueryBuilder()
			.setKind(this.datastorePersistentEntity.kindName());
	StructuredQuery query = applyQueryBody(parameters, builder, false, false, null);
	DatastoreResultsIterable<?> resultList = this.datastoreOperations.queryKeysOrEntities(query, this.entityType);

	ParameterAccessor paramAccessor = new ParametersParameterAccessor(getQueryMethod().getParameters(), parameters);

	Pageable pageable = DatastorePageable.from(paramAccessor.getPageable(), resultList.getCursor(), null);

	EntityQuery.Builder builderNext = newEntityQueryBuilder().setKind(this.datastorePersistentEntity.kindName());
	StructuredQuery queryNext = applyQueryBody(parameters, builderNext, false, true, resultList.getCursor());
	Iterable nextResult = this.datastoreOperations.query(queryNext, x -> x);

	List<Object> result =
					StreamSupport.stream(resultList.spliterator(), false).collect(Collectors.toList());

	return (Slice) this.processRawObjectForProjection(
			new SliceImpl(result, pageable, nextResult.iterator().hasNext()));
}
 
Example 2
Source Project: spring-cloud-gcp   Source File: SqlSpannerQuery.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public List executeRawResult(Object[] parameters) {

	ParameterAccessor paramAccessor = new ParametersParameterAccessor(getQueryMethod().getParameters(), parameters);
	Object[] params = StreamSupport.stream(paramAccessor.spliterator(), false).toArray();

	QueryTagValue queryTagValue = new QueryTagValue(getParamTags(), parameters,
					params, resolveEntityClassNames(this.sql, this.spannerMappingContext));

	resolveSpELTags(queryTagValue);

	return this.isDml
			? Collections.singletonList(
					this.spannerTemplate.executeDmlStatement(buildStatementFromQueryAndTags(queryTagValue)))
			: executeReadSql(paramAccessor.getPageable(), paramAccessor.getSort(), queryTagValue);
}
 
Example 3
Source Project: spring-cloud-gcp   Source File: PartTreeSpannerQuery.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected List executeRawResult(Object[] parameters) {
	ParameterAccessor paramAccessor = new ParametersParameterAccessor(getQueryMethod().getParameters(),
			parameters);
	if (isCountOrExistsQuery()) {
		return SpannerStatementQueryExecutor.executeQuery(
				(struct) -> isCountQuery() ? struct.getLong(0) : struct.getBoolean(0),
				this.entityType, this.tree, paramAccessor, getQueryMethod().getMethod().getParameters(),
				this.spannerTemplate,
				this.spannerMappingContext);
	}
	if (this.tree.isDelete()) {
		return this.spannerTemplate
				.performReadWriteTransaction(getDeleteFunction(parameters));
	}
	return SpannerStatementQueryExecutor.executeQuery(this.entityType, this.tree,
			paramAccessor, getQueryMethod().getMethod().getParameters(), this.spannerTemplate,
			this.spannerMappingContext);
}
 
Example 4
Source Project: spring-cloud-gcp   Source File: PartTreeSpannerQuery.java    License: Apache License 2.0 6 votes vote down vote up
private Function<SpannerTemplate, List> getDeleteFunction(Object[] parameters) {
	return (transactionTemplate) -> {
		ParameterAccessor paramAccessor = new ParametersParameterAccessor(getQueryMethod().getParameters(),
				parameters);
		List<T> entitiesToDelete = SpannerStatementQueryExecutor
				.executeQuery(this.entityType, this.tree, paramAccessor, getQueryMethod().getMethod().getParameters(),
						transactionTemplate, this.spannerMappingContext);
		transactionTemplate.deleteAll(entitiesToDelete);

		List result = null;
		if (this.queryMethod.isCollectionQuery()) {
			result = entitiesToDelete;
		}
		else if (this.queryMethod.getReturnedObjectType() != void.class) {
			result = Collections.singletonList(entitiesToDelete.size());
		}
		return result;
	};
}
 
Example 5
@Override
protected Query doCreateQuery(Object[] values) {
    String nativeQuery = getQuery(values);
    JpaParameters parameters = getQueryMethod().getParameters();
    ParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
    String sortedQueryString = QueryUtils
            .applySorting(nativeQuery, accessor.getSort(), QueryUtils.detectAlias(nativeQuery));
    Query query = bind(createJpaQuery(sortedQueryString), values);
    if (parameters.hasPageableParameter()) {
        Pageable pageable = (Pageable) (values[parameters.getPageableIndex()]);
        if (pageable != null) {
            query.setFirstResult((int) pageable.getOffset());
            query.setMaxResults(pageable.getPageSize());
        }
    }
    return query;
}
 
Example 6
private KeyValueQuery<SpelExpression> createQueryForMethodWithArgs(String methodName, Object... args)
		throws NoSuchMethodException, SecurityException {

	Class<?>[] argTypes = new Class<?>[args.length];
	if (!ObjectUtils.isEmpty(args)) {

		for (int i = 0; i < args.length; i++) {
			argTypes[i] = args[i].getClass();
		}
	}

	Method method = PersonRepository.class.getMethod(methodName, argTypes);
	doReturn(Person.class).when(metadataMock).getReturnedDomainClass(method);

	PartTree partTree = new PartTree(method.getName(), method.getReturnType());
	SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor(
			new QueryMethod(method, metadataMock, new SpelAwareProxyProjectionFactory()).getParameters(), args));

	KeyValueQuery<SpelExpression> q = creator.createQuery();
	q.getCriteria().setEvaluationContext(
			SimpleEvaluationContext.forReadOnlyDataBinding().withRootObject(args).withInstanceMethods().build());

	return q;
}
 
Example 7
private static SpelCriteria createQueryForMethodWithArgs(String methodName, Object... args) throws Exception {

		List<Class<?>> types = new ArrayList<>(args.length);

		for (Object arg : args) {
			types.add(arg.getClass());
		}

		Method method = PersonRepository.class.getMethod(methodName, types.toArray(new Class<?>[types.size()]));
		RepositoryMetadata metadata = mock(RepositoryMetadata.class);
		doReturn(method.getReturnType()).when(metadata).getReturnedDomainClass(method);

		PartTree partTree = new PartTree(method.getName(), method.getReturnType());
		SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor(
				new QueryMethod(method, metadata, new SpelAwareProxyProjectionFactory()).getParameters(), args));

		return new SpelCriteria(creator.createQuery().getCriteria(),
				SimpleEvaluationContext.forReadOnlyDataBinding().withInstanceMethods().withRootObject(args).build());
	}
 
Example 8
Source Project: sdn-rx   Source File: CypherQueryCreator.java    License: Apache License 2.0 5 votes vote down vote up
CypherQueryCreator(Neo4jMappingContext mappingContext, Class<?> domainType, Neo4jQueryType queryType,
	PartTree tree,
	ParametersParameterAccessor actualParameters,
	List<String> includedProperties,
	Function<Object, Object> parameterConversion
) {
	super(tree, actualParameters);
	this.mappingContext = mappingContext;

	this.domainType = domainType;
	this.nodeDescription = this.mappingContext.getRequiredNodeDescription(this.domainType);

	this.queryType = queryType;

	this.formalParameters = actualParameters.getParameters().iterator();
	this.maxResults = tree.isLimiting() ? tree.getMaxResults() : null;

	this.includedProperties = includedProperties;
	this.parameterConversion = parameterConversion;

	this.pagingParameter = actualParameters.getPageable();

	AtomicInteger symbolicNameIndex = new AtomicInteger();

	propertyPathWrappers = tree.getParts().stream()
		.map(part ->
			new PropertyPathWrapper(symbolicNameIndex.getAndIncrement(),
				mappingContext.getPersistentPropertyPath(part.getProperty())))
		.collect(toList());

}
 
Example 9
Source Project: spring-cloud-gcp   Source File: GqlDatastoreQuery.java    License: Apache License 2.0 5 votes vote down vote up
private Object buildPageOrSlice(Object[] parameters, ParsedQueryWithTagsAndValues parsedQueryWithTagsAndValues,
		DatastoreResultsIterable found) {
	Pageable pageableParam =
			new ParametersParameterAccessor(getQueryMethod().getParameters(), parameters).getPageable();
	List resultsList = found == null ? Collections.emptyList()
			: (List) StreamSupport.stream(found.spliterator(), false).collect(Collectors.toList());

	Cursor cursor = found != null ? found.getCursor() : null;
	Slice result = isPageQuery()
			? buildPage(pageableParam, parsedQueryWithTagsAndValues, cursor, resultsList)
			: buildSlice(pageableParam, parsedQueryWithTagsAndValues, cursor, resultsList);
	return processRawObjectForProjection(result);
}
 
Example 10
Source Project: spring-cloud-gcp   Source File: PartTreeFirestoreQuery.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object execute(Object[] parameters) {
	StructuredQuery.Builder builder = createBuilderWithFilter(parameters);

	// Handle Pageable parameters.
	if (!getQueryMethod().getParameters().isEmpty()) {
		ParameterAccessor paramAccessor = new ParametersParameterAccessor(getQueryMethod().getParameters(),
				parameters);
		Pageable pageable = paramAccessor.getPageable();
		if (pageable != null && pageable.isPaged()) {
			builder.setOffset((int) Math.min(Integer.MAX_VALUE, pageable.getOffset()));
			builder.setLimit(Int32Value.newBuilder().setValue(pageable.getPageSize()));
		}

		Sort sort = paramAccessor.getSort();
		if (sort != null) {
			builder.addAllOrderBy(createFirestoreSortOrders(sort));
		}
	}

	if (this.tree.isCountProjection()) {
		return this.reactiveOperations.count(this.persistentEntity.getType(), builder);
	}
	else {
		return this.reactiveOperations.execute(builder, this.persistentEntity.getType());
	}
}
 
Example 11
Source Project: spring-data-ebean   Source File: PartTreeEbeanQuery.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link Query} for the given parameter values.
 *
 * @param values
 * @return
 */
public EbeanQueryWrapper createQuery(Object[] values) {
    ParametersParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
    EbeanQueryCreator ebeanQueryCreator = createCreator(accessor);
    return
            restrictMaxResultsIfNecessary(
                    invokeBinding(getBinder(values),
                            EbeanQueryWrapper.ofEbeanQuery(ebeanQueryCreator.createQuery())));
}
 
Example 12
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 13
@Override
@SuppressWarnings("unchecked")
protected Object doExecute(AbstractEbeanQuery query, Object[] values) {
    ParametersParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
    EbeanQueryWrapper createQuery = query.createQuery(values);
    return createQuery.findSlice(accessor.getPageable());
}
 
Example 14
@Override
@SuppressWarnings("unchecked")
protected Object doExecute(final AbstractEbeanQuery repositoryQuery, final Object[] values) {
    ParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
    EbeanQueryWrapper createQuery = repositoryQuery.createQuery(values);
    return createQuery.findPage(accessor.getPageable());
}
 
Example 15
Source Project: spring-vault   Source File: VaultQueryCreatorUnitTests.java    License: Apache License 2.0 5 votes vote down vote up
VaultQuery createQuery(String methodName, String value) {

		DefaultParameters defaultParameters = new DefaultParameters(
				ReflectionUtils.findMethod(dummy.class, "someUnrelatedMethod", String.class));

		PartTree partTree = new PartTree(methodName, Credentials.class);
		VaultQueryCreator queryCreator = new VaultQueryCreator(partTree,
				new ParametersParameterAccessor(defaultParameters, new Object[] { value }), this.mappingContext);

		return queryCreator.createQuery().getCriteria();
	}
 
Example 16
Source Project: spring-vault   Source File: VaultQueryCreatorUnitTests.java    License: Apache License 2.0 5 votes vote down vote up
VaultQuery createQuery(String methodName, List<String> value) {

		DefaultParameters defaultParameters = new DefaultParameters(
				ReflectionUtils.findMethod(dummy.class, "someUnrelatedMethod", List.class));

		PartTree partTree = new PartTree(methodName, Credentials.class);
		VaultQueryCreator queryCreator = new VaultQueryCreator(partTree,
				new ParametersParameterAccessor(defaultParameters, new Object[] { value }), this.mappingContext);

		return queryCreator.createQuery().getCriteria();
	}
 
Example 17
Source Project: spring-vault   Source File: VaultQueryCreatorUnitTests.java    License: Apache License 2.0 5 votes vote down vote up
VaultQuery createQuery(String methodName, String value, String anotherValue) {

		DefaultParameters defaultParameters = new DefaultParameters(
				ReflectionUtils.findMethod(dummy.class, "someUnrelatedMethod", String.class, String.class));

		PartTree partTree = new PartTree(methodName, Credentials.class);
		VaultQueryCreator queryCreator = new VaultQueryCreator(partTree,
				new ParametersParameterAccessor(defaultParameters, new Object[] { value, anotherValue }),
				this.mappingContext);

		return queryCreator.createQuery().getCriteria();
	}
 
Example 18
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 19
@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 20
@SuppressWarnings({ "rawtypes", "unchecked" })
protected KeyValueQuery<?> prepareQuery(KeyValueQuery<?> instance, Object[] parameters) {

	ParametersParameterAccessor accessor = new ParametersParameterAccessor(getQueryMethod().getParameters(),
			parameters);

	Object criteria = instance.getCriteria();

	if (criteria instanceof SpelCriteria || criteria instanceof SpelExpression) {

		SpelExpression spelExpression = getSpelExpression(criteria);
		EvaluationContext context = this.evaluationContextProvider.getEvaluationContext(getQueryMethod().getParameters(),
				parameters);
		criteria = new SpelCriteria(spelExpression, context);
	}

	KeyValueQuery<?> query = new KeyValueQuery(criteria);
	Pageable pageable = accessor.getPageable();
	Sort sort = accessor.getSort();

	query.setOffset(pageable.toOptional().map(Pageable::getOffset).orElse(-1L));

	if (pageable.isPaged()) {
		query.setRows(pageable.getPageSize());
	} else if (instance.getRows() >= 0) {
		query.setRows(instance.getRows());
	}

	query.setSort(sort.isUnsorted() ? instance.getSort() : sort);

	return query;
}
 
Example 21
@Override
public Query<T> doCreateQuery(Object[] values) {

	ParametersParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
	DynamoDBQueryCreator<T, ID> queryCreator = createQueryCreator(accessor);
	return queryCreator.createQuery();

}
 
Example 22
@Override
public Query<Long> doCreateCountQuery(Object[] values,boolean pageQuery) {

	ParametersParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
	DynamoDBCountQueryCreator<T, ID> queryCreator = createCountQueryCreator(accessor,pageQuery);
	return queryCreator.createQuery();

}
 
Example 23
@Override
public Object execute(AbstractDynamoDBQuery<T, ID> dynamoDBQuery, Object[] values) {

	ParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
	Pageable pageable = accessor.getPageable();
	Query<T> query = dynamoDBQuery.doCreateQueryWithPermissions(values);

	List<T> results = query.getResultList();
	return createPage(results, pageable,dynamoDBQuery,values);
}
 
Example 24
@Override
public Object execute(AbstractDynamoDBQuery<T, ID> dynamoDBQuery, Object[] values) {

	ParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
	Pageable pageable = accessor.getPageable();
	Query<T> query = dynamoDBQuery.doCreateQueryWithPermissions(values);
	List<T> results = query.getResultList();
	return createSlice(results, pageable);
}
 
Example 25
Source Project: dubbox   Source File: SolrParametersParameterAccessor.java    License: Apache License 2.0 4 votes vote down vote up
public SolrParametersParameterAccessor(SolrQueryMethod solrQueryMethod, Object[] values) {
	this.parameters = solrQueryMethod.getParameters();
	this.parametersParameterAccessorDelegate = new ParametersParameterAccessor(this.parameters, values.clone());
}
 
Example 26
Source Project: spring-cloud-gcp   Source File: PartTreeDatastoreQuery.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Object execute(Object[] parameters) {
	Class<?> returnedObjectType = getQueryMethod().getReturnedObjectType();
	if (isPageQuery()) {
		ExecutionResult executionResult = (ExecutionResult) runQuery(parameters, returnedObjectType, List.class,
				false);

		List<?> resultEntries = (List) executionResult.getPayload();

		ParameterAccessor paramAccessor = new ParametersParameterAccessor(getQueryMethod().getParameters(),
				parameters);

		Pageable pageableParam = paramAccessor.getPageable();

		Long totalCount;
		if (pageableParam instanceof DatastorePageable) {
			Long previousCount = ((DatastorePageable) pageableParam).getTotalCount();
			Assert.notNull(previousCount, "Previous total count can not be null.");

			totalCount = ((DatastorePageable) pageableParam).getTotalCount();
		}
		else {
			totalCount = (Long) runQuery(parameters, Long.class, null, true);
		}

		Pageable pageable = DatastorePageable.from(pageableParam, executionResult.getCursor(), totalCount);

		return new PageImpl<>(resultEntries, pageable, totalCount);
	}

	if (isSliceQuery()) {
		return executeSliceQuery(parameters);
	}

	Object result = runQuery(parameters, returnedObjectType,
			((DatastoreQueryMethod) getQueryMethod()).getCollectionReturnType(), false);

	result = result instanceof PartTreeDatastoreQuery.ExecutionResult ? ((ExecutionResult) result).getPayload()
			: result;
	if (result == null && ((DatastoreQueryMethod) getQueryMethod()).isOptionalReturnType()) {
		return Optional.empty();
	}
	return result;
}
 
Example 27
Source Project: spring-cloud-gcp   Source File: PartTreeDatastoreQuery.java    License: Apache License 2.0 4 votes vote down vote up
private StructuredQuery applyQueryBody(Object[] parameters,
		Builder builder, boolean total, boolean singularResult, Cursor cursor) {
	ParameterAccessor paramAccessor = new ParametersParameterAccessor(getQueryMethod().getParameters(), parameters);
	if (this.tree.hasPredicate()) {
		applySelectWithFilter(parameters, builder);
	}

	Pageable pageable = paramAccessor.getPageable();
	Integer limit = null;
	Integer offset = null;
	if (singularResult || this.tree.isExistsProjection()) {
		limit = 1;
	}
	else if (this.tree.isLimiting()) {
		limit = this.tree.getMaxResults();
	}

	if (!singularResult && !total && pageable.isPaged()) {
		limit = pageable.getPageSize();
	}

	Sort sort = this.tree.getSort();
	if (getQueryMethod().getParameters().hasPageableParameter()) {
		sort = sort.and(pageable.getSort());
	}
	if (getQueryMethod().getParameters().hasSortParameter()) {
		sort = sort.and(paramAccessor.getSort());
	}

	if (pageable.isPaged() && !total) {
		offset = (int) pageable.getOffset();
	}

	Cursor cursorToApply = null;
	if (cursor != null) {
		cursorToApply = cursor;
	}
	else if (pageable instanceof DatastorePageable) {
		cursorToApply = ((DatastorePageable) pageable).toCursor();
	}
	DatastoreTemplate.applyQueryOptions(
			builder, new DatastoreQueryOptions.Builder().setLimit(limit).setOffset(offset).setSort(sort)
					.setCursor(cursorToApply).build(),
			this.datastorePersistentEntity);
	return builder.build();
}
 
Example 28
Source Project: spring-cloud-gcp   Source File: GqlDatastoreQuery.java    License: Apache License 2.0 4 votes vote down vote up
ParsedQueryWithTagsAndValues(List<String> initialTags, Object[] rawParams) {
	this.params = Arrays.stream(rawParams).filter(e -> !(e instanceof Pageable || e instanceof Sort))
			.collect(Collectors.toList());
	this.rawParams = rawParams;
	this.tagsOrdered = new ArrayList<>(initialTags);

	SpelEvaluator spelEvaluator = GqlDatastoreQuery.this.evaluatingSpelQueryContext.parse(
			GqlDatastoreQuery.this.gqlResolvedEntityClassName,
			GqlDatastoreQuery.this.queryMethod.getParameters());
	Map<String, Object> results = spelEvaluator.evaluate(this.rawParams);
	this.finalGql = spelEvaluator.getQueryString();

	for (Map.Entry<String, Object> entry : results.entrySet()) {
		this.params.add(entry.getValue());
		// Cloud Datastore requires the tag name without the @
		this.tagsOrdered.add(entry.getKey().substring(1));
	}

	ParameterAccessor paramAccessor =
			new ParametersParameterAccessor(getQueryMethod().getParameters(), rawParams);
	Sort sort = paramAccessor.getSort();

	this.finalGql = addSort(this.finalGql, sort);

	this.noLimitQuery = this.finalGql;
	Pageable pageable = paramAccessor.getPageable();
	if (!pageable.equals(Pageable.unpaged())) {
		this.finalGql += LIMIT_CLAUSE;
		this.tagsOrdered.add(LIMIT_TAG_NAME);
		this.limitPosition = this.params.size();
		this.params.add(pageable.getPageSize());

		this.finalGql += OFFSET_CLAUSE;
		this.tagsOrdered.add(OFFSET_TAG_NAME);
		this.cursorPosition = this.params.size();
		if (pageable instanceof DatastorePageable && ((DatastorePageable) pageable).toCursor() != null) {
			this.params.add(((DatastorePageable) pageable).toCursor());
		}
		else {
			this.params.add(pageable.getOffset());
		}
	}
}
 
Example 29
Source Project: spring-data-ebean   Source File: PartTreeEbeanQuery.java    License: Apache License 2.0 4 votes vote down vote up
private Sort getDynamicSort(Object[] values) {
    return parameters.potentiallySortsDynamically() ? new ParametersParameterAccessor(parameters, values).getSort()
            : null;
}
 
Example 30
/**
 * <p>
 * Handle {@code @Param}.
 * </P>
 * <OL>
 * <LI><B>Without {@code @Param}</B>
 * <p>
 * Arguments to the call are assumed to follow the same sequence as cited in the method name.
 * </P>
 * <p>
 * Eg.
 * <p>
 * <pre>
 * findBy<U>One</U>And<U>Two</U>(String <U>one</U>, String <U>two</U>);
 * </pre>
 * </P>
 * </LI>
 * <LI><B>With {@code @Param}</B>
 * <p>
 * Arguments to the call are use the {@code @Param} to match them against the fields.
 * <p>
 * Eg.
 * <p>
 * <pre>
 * findBy<U>One</U>And<U>Two</U>(@Param("two") String <U>two</U>, @Param("one") String <U>one</U>);
 * </pre>
 * </P>
 * </LI>
 * </OL>
 *
 * @param originalParameters Possibly empty
 * @param partTree           Query tree to traverse
 * @return Parameters in correct order
 */
private ParametersParameterAccessor prepareAccessor(final Object[] originalParameters, final PartTree partTree) {

    if (!this.isRearrangeKnown) {
        this.prepareRearrange(partTree, this.queryMethod.getParameters().getBindableParameters());
        this.isRearrangeKnown = true;
    }

    Object[] parameters = originalParameters;
    Assert.notNull(parameters, "Parameters must not be null.");

    if (this.isRearrangeRequired) {
        parameters = new Object[originalParameters.length];

        for (int i = 0; i < parameters.length; i++) {
            int index = (i < rearrangeIndex.length) ? rearrangeIndex[i] : i;
            parameters[i] = originalParameters[index];
        }
    }

    return new ParametersParameterAccessor(this.queryMethod.getParameters(), parameters);
}