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");
}
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));
}
Aggregations