Search in sources :

Example 1 with SpelQueryCreator

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

the class KeyValueRepositoryConfigurationExtension method getQueryCreatorType.

/**
 * Detects the query creator type to be used for the factory to set. Will lookup a {@link QueryCreatorType} annotation
 * on the {@code @Enable}-annotation or use {@link SpelQueryCreator} if not found.
 *
 * @param config must not be {@literal null}.
 * @return
 */
private static Class<?> getQueryCreatorType(AnnotationRepositoryConfigurationSource config) {
    AnnotationMetadata metadata = config.getEnableAnnotationMetadata();
    Map<String, Object> queryCreatorAnnotationAttributes = metadata.getAnnotationAttributes(QueryCreatorType.class.getName());
    if (CollectionUtils.isEmpty(queryCreatorAnnotationAttributes)) {
        return SpelQueryCreator.class;
    }
    AnnotationAttributes queryCreatorAttributes = new AnnotationAttributes(queryCreatorAnnotationAttributes);
    return queryCreatorAttributes.getClass("value");
}
Also used : AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) SpelQueryCreator(org.springframework.data.keyvalue.repository.query.SpelQueryCreator) AnnotationMetadata(org.springframework.core.type.AnnotationMetadata)

Example 2 with SpelQueryCreator

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

the class SpelQueryEngineUnitTests method createQueryForMethodWithArgs.

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));
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) QueryMethod(org.springframework.data.repository.query.QueryMethod) SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) ArrayList(java.util.ArrayList) QueryMethod(org.springframework.data.repository.query.QueryMethod) Method(java.lang.reflect.Method) RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) ParametersParameterAccessor(org.springframework.data.repository.query.ParametersParameterAccessor) PartTree(org.springframework.data.repository.query.parser.PartTree) SpelQueryCreator(org.springframework.data.keyvalue.repository.query.SpelQueryCreator)

Aggregations

SpelQueryCreator (org.springframework.data.keyvalue.repository.query.SpelQueryCreator)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 AnnotationAttributes (org.springframework.core.annotation.AnnotationAttributes)1 AnnotationMetadata (org.springframework.core.type.AnnotationMetadata)1 SpelAwareProxyProjectionFactory (org.springframework.data.projection.SpelAwareProxyProjectionFactory)1 RepositoryMetadata (org.springframework.data.repository.core.RepositoryMetadata)1 ParametersParameterAccessor (org.springframework.data.repository.query.ParametersParameterAccessor)1 QueryMethod (org.springframework.data.repository.query.QueryMethod)1 PartTree (org.springframework.data.repository.query.parser.PartTree)1 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)1