org.springframework.data.repository.query.ParametersParameterAccessor Java Examples
The following examples show how to use
org.springframework.data.repository.query.ParametersParameterAccessor.
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 File: PartTreeSpannerQuery.java From spring-cloud-gcp with Apache License 2.0 | 6 votes |
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 #2
Source File: FreemarkerTemplateQuery.java From spring-data-jpa-extra with Apache License 2.0 | 6 votes |
@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 #3
Source File: SpelQueryCreatorUnitTests.java From spring-data-keyvalue with Apache License 2.0 | 6 votes |
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 #4
Source File: PartTreeSpannerQuery.java From spring-cloud-gcp with Apache License 2.0 | 6 votes |
@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 #5
Source File: SqlSpannerQuery.java From spring-cloud-gcp with Apache License 2.0 | 6 votes |
@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 #6
Source File: SpelQueryEngineUnitTests.java From spring-data-keyvalue with Apache License 2.0 | 6 votes |
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 #7
Source File: PartTreeDatastoreQuery.java From spring-cloud-gcp with Apache License 2.0 | 6 votes |
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 #8
Source File: PartTreeDynamoDBQuery.java From spring-data-dynamodb with Apache License 2.0 | 5 votes |
@Override public Query<T> doCreateQuery(Object[] values) { ParametersParameterAccessor accessor = new ParametersParameterAccessor(parameters, values); DynamoDBQueryCreator<T, ID> queryCreator = createQueryCreator(accessor); return queryCreator.createQuery(); }
Example #9
Source File: PartTreeDynamoDBQuery.java From spring-data-dynamodb with Apache License 2.0 | 5 votes |
@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 #10
Source File: AbstractDynamoDBQuery.java From spring-data-dynamodb with Apache License 2.0 | 5 votes |
@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 #11
Source File: AbstractDynamoDBQuery.java From spring-data-dynamodb with Apache License 2.0 | 5 votes |
@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 #12
Source File: KeyValuePartTreeQuery.java From spring-data-keyvalue with Apache License 2.0 | 5 votes |
@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 #13
Source File: KeyValuePartTreeQuery.java From spring-data-keyvalue with Apache License 2.0 | 5 votes |
@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 #14
Source File: AbstractMybatisQuery.java From spring-data-mybatis with Apache License 2.0 | 5 votes |
@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 #15
Source File: VaultQueryCreatorUnitTests.java From spring-vault with Apache License 2.0 | 5 votes |
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 #16
Source File: VaultQueryCreatorUnitTests.java From spring-vault with Apache License 2.0 | 5 votes |
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 File: VaultQueryCreatorUnitTests.java From spring-vault with Apache License 2.0 | 5 votes |
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 #18
Source File: CypherQueryCreator.java From sdn-rx with Apache License 2.0 | 5 votes |
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 #19
Source File: AbstractEbeanQueryExecution.java From spring-data-ebean with Apache License 2.0 | 5 votes |
@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 #20
Source File: AbstractEbeanQueryExecution.java From spring-data-ebean with Apache License 2.0 | 5 votes |
@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 #21
Source File: PartTreeEbeanQuery.java From spring-data-ebean with Apache License 2.0 | 5 votes |
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 #22
Source File: PartTreeEbeanQuery.java From spring-data-ebean with Apache License 2.0 | 5 votes |
/** * 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 #23
Source File: PartTreeFirestoreQuery.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@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 #24
Source File: GqlDatastoreQuery.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
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 #25
Source File: PartTreeEbeanQuery.java From spring-data-ebean with Apache License 2.0 | 4 votes |
private Sort getDynamicSort(Object[] values) { return parameters.potentiallySortsDynamically() ? new ParametersParameterAccessor(parameters, values).getSort() : null; }
Example #26
Source File: HazelcastPartTreeQuery.java From spring-data-hazelcast with Apache License 2.0 | 4 votes |
/** * <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); }
Example #27
Source File: KeyValuePartTreeQuery.java From spring-data-keyvalue with Apache License 2.0 | 4 votes |
protected KeyValueQuery<?> prepareQuery(Object[] parameters) { return prepareQuery(createQuery(new ParametersParameterAccessor(getQueryMethod().getParameters(), parameters)), parameters); }
Example #28
Source File: GqlDatastoreQuery.java From spring-cloud-gcp with Apache License 2.0 | 4 votes |
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 File: PartTreeDynamoDBQuery.java From spring-data-dynamodb with Apache License 2.0 | 4 votes |
protected DynamoDBQueryCreator<T, ID> createQueryCreator(ParametersParameterAccessor accessor) { return new DynamoDBQueryCreator<T, ID>(tree, accessor, queryMethod.getEntityInformation(), dynamoDBOperations); }
Example #30
Source File: PartTreeDynamoDBQuery.java From spring-data-dynamodb with Apache License 2.0 | 4 votes |
protected DynamoDBCountQueryCreator<T, ID> createCountQueryCreator(ParametersParameterAccessor accessor,boolean pageQuery) { return new DynamoDBCountQueryCreator<T, ID>(tree, accessor, queryMethod.getEntityInformation(), dynamoDBOperations, pageQuery); }