当前位置: 首页>>代码示例>>Java>>正文


Java QueryMethod类代码示例

本文整理汇总了Java中org.springframework.data.repository.query.QueryMethod的典型用法代码示例。如果您正苦于以下问题:Java QueryMethod类的具体用法?Java QueryMethod怎么用?Java QueryMethod使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


QueryMethod类属于org.springframework.data.repository.query包,在下文中一共展示了QueryMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: executeFindQuery

import org.springframework.data.repository.query.QueryMethod; //导入依赖的package包/类
/**
 * <P>
 * Execute a retrieval query. The query engine will return this in an iterator, which may need conversion to a single
 * domain entity or a stream.
 * </P>
 *
 * @param query The query to run
 * @param queryMethod Holds metadata about the query, is paging etc
 * @return Query result
 */
private Object executeFindQuery(final KeyValueQuery<?> query, final QueryMethod queryMethod) {

	Iterable<?> resultSet = this.keyValueOperations.find(query, queryMethod.getEntityInformation().getJavaType());

	if (!queryMethod.isCollectionQuery() && !queryMethod.isPageQuery() && !queryMethod.isSliceQuery()
			&& !queryMethod.isStreamQuery()) {
		// Singleton result
		return resultSet.iterator().hasNext() ? resultSet.iterator().next() : null;
	}

	if (queryMethod.isStreamQuery()) {
		return StreamUtils.createStreamFromIterator(resultSet.iterator());
	}

	return resultSet;
}
 
开发者ID:hazelcast,项目名称:spring-data-hazelcast,代码行数:27,代码来源:HazelcastPartTreeQuery.java

示例2: resolveQuery

import org.springframework.data.repository.query.QueryMethod; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory,
		NamedQueries namedQueries) {

	QueryMethod queryMethod = new QueryMethod(method, metadata, factory);

	Constructor<? extends KeyValuePartTreeQuery> constructor = (Constructor<? extends KeyValuePartTreeQuery>) ClassUtils
			.getConstructorIfAvailable(this.repositoryQueryType, QueryMethod.class, EvaluationContextProvider.class,
					KeyValueOperations.class, Class.class);

	Assert.state(constructor != null,
			String.format(
					"Constructor %s(QueryMethod, EvaluationContextProvider, KeyValueOperations, Class) not available!",
					ClassUtils.getShortName(this.repositoryQueryType)));

	return BeanUtils.instantiateClass(constructor, queryMethod, evaluationContextProvider, this.keyValueOperations,
			this.queryCreator);
}
 
开发者ID:spring-projects,项目名称:spring-data-keyvalue,代码行数:20,代码来源:KeyValueRepositoryFactory.java

示例3: cachedSpelExpressionShouldBeReusedWithNewContext

import org.springframework.data.repository.query.QueryMethod; //导入依赖的package包/类
@Test // DATAKV-137
public void cachedSpelExpressionShouldBeReusedWithNewContext() throws NoSuchMethodException, SecurityException {

	QueryMethod qm = new QueryMethod(Repo.class.getMethod("findByFirstname", String.class), metadataMock,
			projectionFactoryMock);

	KeyValuePartTreeQuery query = new CachingKeyValuePartTreeQuery(qm, DefaultEvaluationContextProvider.INSTANCE,
			kvOpsMock, SpelQueryCreator.class);

	Object[] args = new Object[] { "foo" };

	SpelCriteria first = (SpelCriteria) query.prepareQuery(args).getCriteria();
	SpelCriteria second = (SpelCriteria) query.prepareQuery(args).getCriteria();

	assertThat(first.getExpression(), sameInstance(second.getExpression()));
	assertThat(first.getContext(), not(sameInstance(second.getContext())));
}
 
开发者ID:spring-projects,项目名称:spring-data-keyvalue,代码行数:18,代码来源:CachingKeyValuePartTreeQueryUnitTests.java

示例4: createQueryForMethodWithArgs

import org.springframework.data.repository.query.QueryMethod; //导入依赖的package包/类
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(new StandardEvaluationContext(args));

	return q;
}
 
开发者ID:spring-projects,项目名称:spring-data-keyvalue,代码行数:24,代码来源:SpelQueryCreatorUnitTests.java

示例5: spelExpressionAndContextShouldNotBeReused

import org.springframework.data.repository.query.QueryMethod; //导入依赖的package包/类
@Test // DATAKV-115
@SuppressWarnings({ "unchecked", "rawtypes" })
public void spelExpressionAndContextShouldNotBeReused() throws NoSuchMethodException, SecurityException {

	when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
	when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);

	QueryMethod qm = new QueryMethod(Repo.class.getMethod("findByFirstname", String.class), metadataMock,
			projectionFactoryMock);

	KeyValuePartTreeQuery query = new KeyValuePartTreeQuery(qm, DefaultEvaluationContextProvider.INSTANCE, kvOpsMock,
			SpelQueryCreator.class);

	Object[] args = new Object[] { "foo" };

	Object first = query.prepareQuery(args).getCriteria();
	Object second = query.prepareQuery(args).getCriteria();

	assertThat(first, not(sameInstance(second)));
}
 
开发者ID:spring-projects,项目名称:spring-data-keyvalue,代码行数:21,代码来源:KeyValuePartTreeQueryUnitTests.java

示例6: shouldApplyPageableParameterToCollectionQuery

import org.springframework.data.repository.query.QueryMethod; //导入依赖的package包/类
@Test // DATAKV-142
@SuppressWarnings({ "unchecked", "rawtypes" })
public void shouldApplyPageableParameterToCollectionQuery() throws SecurityException, NoSuchMethodException {

	when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
	when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);

	QueryMethod qm = new QueryMethod(Repo.class.getMethod("findBy", Pageable.class), metadataMock,
			projectionFactoryMock);

	KeyValuePartTreeQuery partTreeQuery = new KeyValuePartTreeQuery(qm, DefaultEvaluationContextProvider.INSTANCE,
			kvOpsMock, SpelQueryCreator.class);

	KeyValueQuery<?> query = partTreeQuery.prepareQuery(new Object[] { PageRequest.of(2, 3) });

	assertThat(query.getOffset(), is(6L));
	assertThat(query.getRows(), is(3));
}
 
开发者ID:spring-projects,项目名称:spring-data-keyvalue,代码行数:19,代码来源:KeyValuePartTreeQueryUnitTests.java

示例7: shouldApplyDerivedMaxResultsToQueryWithParameters

import org.springframework.data.repository.query.QueryMethod; //导入依赖的package包/类
@Test // DATAKV-142
@SuppressWarnings({ "unchecked", "rawtypes" })
public void shouldApplyDerivedMaxResultsToQueryWithParameters() throws SecurityException, NoSuchMethodException {

	when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
	when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);

	QueryMethod qm = new QueryMethod(Repo.class.getMethod("findTop3ByFirstname", String.class), metadataMock,
			projectionFactoryMock);

	KeyValuePartTreeQuery partTreeQuery = new KeyValuePartTreeQuery(qm, DefaultEvaluationContextProvider.INSTANCE,
			kvOpsMock, SpelQueryCreator.class);

	KeyValueQuery<?> query = partTreeQuery.prepareQuery(new Object[] { "firstname" });

	assertThat(query.getCriteria(), is(notNullValue()));
	assertThat(query.getCriteria(), IsInstanceOf.instanceOf(SpelCriteria.class));
	assertThat(((SpelCriteria) query.getCriteria()).getExpression().getExpressionString(),
			is("#it?.firstname?.equals([0])"));
	assertThat(query.getRows(), is(3));
}
 
开发者ID:spring-projects,项目名称:spring-data-keyvalue,代码行数:22,代码来源:KeyValuePartTreeQueryUnitTests.java

示例8: createQueryForMethodWithArgs

import org.springframework.data.repository.query.QueryMethod; //导入依赖的package包/类
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(), new StandardEvaluationContext(args));
	}
 
开发者ID:spring-projects,项目名称:spring-data-keyvalue,代码行数:19,代码来源:SpelQueryEngineUnitTests.java

示例9: executePageSliceQuery

import org.springframework.data.repository.query.QueryMethod; //导入依赖的package包/类
/**
 * <P>
 * Slices and pages are similar ways to iterate through the result set in blocks, mimicking a cursor. A
 * {@link org.springframework.data.domain.Slice Slice} is a simpler concept, only requiring to know if further blocks
 * of data are available. A {@link org.springframework.data.domain.Page Page} requires to know how many blocks of data
 * are available in total.
 * </P>
 *
 * @param parameters For the query
 * @param query The query to run
 * @param queryMethod Holds metadata about the query
 * @return Query result
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private Object executePageSliceQuery(final Object[] parameters, final KeyValueQuery<?> query,
		final QueryMethod queryMethod) {
	long totalElements = -1;

	int indexOfPageRequest = queryMethod.getParameters().getPageableIndex();
	Pageable pageRequest = (Pageable) parameters[indexOfPageRequest];

	/* TODO Eliminate count call for Slice, retrieve "rows+1" instead to determine if next page exists.
	 */
	if (query.getCritieria() == null) {
		totalElements = this.keyValueOperations.count(queryMethod.getEntityInformation().getJavaType());
	} else {
		totalElements = this.keyValueOperations.count(query, queryMethod.getEntityInformation().getJavaType());
	}

	int requiredRows = pageRequest.getPageSize();

	query.setOffset(pageRequest.getOffset());
	query.setRows(pageRequest.getPageSize());

	Iterable<?> resultSet = this.keyValueOperations.find(query, queryMethod.getEntityInformation().getJavaType());
	List<?> content = IterableConverter.toList(resultSet);

	if (queryMethod.isPageQuery()) {
		return new PageImpl(content, pageRequest, totalElements);
	} else {
		boolean hasNext = totalElements > (query.getOffset() + query.getRows());
		if (content.size() > requiredRows) {
			content = content.subList(0, requiredRows);
		}
		return new SliceImpl(content, pageRequest, hasNext);
	}
}
 
开发者ID:hazelcast,项目名称:spring-data-hazelcast,代码行数:48,代码来源:HazelcastPartTreeQuery.java

示例10: JdbcAnnotatedRepositoryQuery

import org.springframework.data.repository.query.QueryMethod; //导入依赖的package包/类
public JdbcAnnotatedRepositoryQuery(QueryMethod method, NamedParameterJdbcOperations template, String query, RowMapper rowMapper,
                                    Strategy strategy, List<String> parametersNames) {
    this.method = method;
    this.query = query;
    this.template = template;
    this.rowMapper = rowMapper;
    this.parametersNames = parametersNames;

    LOGGER.debug("applying strategy {}", strategy.name());

    switch (strategy) {
        case COLLECTION_QUERY:
            this.strategy = new CollectionQueryJdbcRepositoryStrategy();
            break;
        case COUNT:
            this.strategy = new CountJdbcRepositoryStrategy();
            break;
        case SINGLE_QUERY:
            this.strategy = new SingleQueryJdbcRepositoryStrategy();
            break;
        case UPDATE_QUERY:
            this.strategy = new UpdatetJdbcRepositoryStrategy();
            break;
        case PAGE_QUERY:
            this.strategy = new PageJdbcRepositoryStrategy();
            break;
        case EXISTS_QUERY:
            this.strategy = new ExistsJdbcRepositoryStrategy();
            break;
        default:
            throw new IllegalArgumentException("Unkwnown strategy provided");
    }

}
 
开发者ID:rubasace,项目名称:spring-data-jdbc,代码行数:35,代码来源:JdbcAnnotatedRepositoryQuery.java

示例11: JdbcByNameRepositoryQuery

import org.springframework.data.repository.query.QueryMethod; //导入依赖的package包/类
public JdbcByNameRepositoryQuery(QueryMethod method, NamedParameterJdbcOperations template, String query, RowMapper rowMapper,
                                 LookupStrategy lookupStrategy, List<ParameterProperties> parameterProperties) {
    this.method = method;
    this.query = query;
    this.template = template;
    this.rowMapper = rowMapper;

    LOGGER.debug("applying lookupStrategy {}", lookupStrategy.name());

    this.strategy = JdbcRepositoryExecutionStrategyFactory.chooseStrategy(lookupStrategy);
    processMethodParameters(parameterProperties);


}
 
开发者ID:rubasace,项目名称:spring-data-jdbc,代码行数:15,代码来源:JdbcByNameRepositoryQuery.java

示例12: createCreator

import org.springframework.data.repository.query.QueryMethod; //导入依赖的package包/类
private GcloudDatastoreQueryCreator createCreator(Class<?> repositoryClass,
		Method method, Object... values) {

	QueryMethod queryMethod = new QueryMethod(method,
			new DefaultRepositoryMetadata(repositoryClass),
			new SpelAwareProxyProjectionFactory());
	return new GcloudDatastoreQueryCreator(
			new PartTree(method.getName(),
					queryMethod.getResultProcessor().getReturnedType()
							.getDomainType()),
			new ParametersParameterAccessor(queryMethod.getParameters(), values),
			DatastoreOptions.getDefaultInstance());
}
 
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:14,代码来源:GcloudDatastoreQueryCreatorTests.java

示例13: resolveQuery

import org.springframework.data.repository.query.QueryMethod; //导入依赖的package包/类
@Override
public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory,
                                    NamedQueries namedQueries) {
    QueryMethod queryMethod = new QueryMethod(method, metadata, factory);
    
    return new ObjectifyRepositoryQuery(queryMethod);
}
 
开发者ID:nhuttrung,项目名称:spring-data-objectify,代码行数:8,代码来源:ObjectifyQueryLookupStrategy.java

示例14: VaultPartTreeQuery

import org.springframework.data.repository.query.QueryMethod; //导入依赖的package包/类
/**
 * Creates a new {@link VaultPartTreeQuery} for the given {@link QueryMethod},
 * {@link EvaluationContextProvider}, {@link KeyValueOperations} and query creator
 * type.
 *
 * @param queryMethod must not be {@literal null}.
 * @param evaluationContextProvider must not be {@literal null}.
 * @param keyValueOperations must not be {@literal null}.
 * @param queryCreator must not be {@literal null}.
 */
@SuppressWarnings("unchecked")
public VaultPartTreeQuery(QueryMethod queryMethod,
		EvaluationContextProvider evaluationContextProvider,
		KeyValueOperations keyValueOperations,
		Class<? extends AbstractQueryCreator<?, ?>> queryCreator) {

	super(queryMethod, evaluationContextProvider, keyValueOperations,
			new VaultQueryCreatorFactory(
					(MappingContext) keyValueOperations.getMappingContext()));
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:21,代码来源:VaultPartTreeQuery.java

示例15: KeyValuePartTreeQuery

import org.springframework.data.repository.query.QueryMethod; //导入依赖的package包/类
/**
 * Creates a new {@link KeyValuePartTreeQuery} for the given {@link QueryMethod}, {@link EvaluationContextProvider},
 * {@link KeyValueOperations} using the given {@link QueryCreatorFactory} producing the {@link AbstractQueryCreator}
 * in charge of altering the query.
 *
 * @param queryMethod must not be {@literal null}.
 * @param evaluationContextProvider must not be {@literal null}.
 * @param keyValueOperations must not be {@literal null}.
 * @param queryCreatorFactory must not be {@literal null}.
 * @since 2.0
 */
public KeyValuePartTreeQuery(QueryMethod queryMethod, EvaluationContextProvider evaluationContextProvider,
		KeyValueOperations keyValueOperations, QueryCreatorFactory queryCreatorFactory) {

	Assert.notNull(queryMethod, "Query method must not be null!");
	Assert.notNull(evaluationContextProvider, "EvaluationContextprovider must not be null!");
	Assert.notNull(keyValueOperations, "KeyValueOperations must not be null!");
	Assert.notNull(queryCreatorFactory, "QueryCreatorFactory type must not be null!");

	this.queryMethod = queryMethod;
	this.keyValueOperations = keyValueOperations;
	this.evaluationContextProvider = evaluationContextProvider;
	this.queryCreatorFactory = queryCreatorFactory;
}
 
开发者ID:spring-projects,项目名称:spring-data-keyvalue,代码行数:25,代码来源:KeyValuePartTreeQuery.java


注:本文中的org.springframework.data.repository.query.QueryMethod类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。