use of org.springframework.data.projection.SpelAwareProxyProjectionFactory in project spring-data-commons by spring-projects.
the class ProjectingJackson2HttpMessageConverter method initProjectionFactory.
/**
* Creates a new {@link SpelAwareProxyProjectionFactory} with the {@link JsonProjectingMethodInterceptorFactory}
* registered for the given {@link ObjectMapper}.
*
* @param mapper must not be {@literal null}.
* @return
*/
private static SpelAwareProxyProjectionFactory initProjectionFactory(ObjectMapper mapper) {
Assert.notNull(mapper, "ObjectMapper must not be null!");
SpelAwareProxyProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory();
projectionFactory.registerMethodInvokerFactory(new JsonProjectingMethodInterceptorFactory(new JacksonMappingProvider(mapper)));
return projectionFactory;
}
use of org.springframework.data.projection.SpelAwareProxyProjectionFactory in project spring-data-commons by spring-projects.
the class RepositoryFactorySupport method getProjectionFactory.
/**
* Returns the {@link ProjectionFactory} to be used with the repository instances created.
*
* @param classLoader will never be {@literal null}.
* @param beanFactory will never be {@literal null}.
* @return will never be {@literal null}.
*/
protected ProjectionFactory getProjectionFactory(ClassLoader classLoader, BeanFactory beanFactory) {
SpelAwareProxyProjectionFactory factory = new SpelAwareProxyProjectionFactory();
factory.setBeanClassLoader(classLoader);
factory.setBeanFactory(beanFactory);
return factory;
}
use of org.springframework.data.projection.SpelAwareProxyProjectionFactory in project spring-data-keyvalue by spring-projects.
the class SpelQueryCreatorUnitTests method createQueryForMethodWithArgs.
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;
}
use of org.springframework.data.projection.SpelAwareProxyProjectionFactory in project spring-data-mongodb by spring-projects.
the class MongoQueryMethodUnitTests method rejectsNullMappingContext.
@Test
public void rejectsNullMappingContext() throws Exception {
Method method = PersonRepository.class.getMethod("findByFirstname", String.class, Point.class);
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> new MongoQueryMethod(method, new DefaultRepositoryMetadata(PersonRepository.class), new SpelAwareProxyProjectionFactory(), null));
}
use of org.springframework.data.projection.SpelAwareProxyProjectionFactory in project spring-data-mongodb by spring-projects.
the class StringBasedAggregationUnitTests method createAggregationForMethod.
private StringBasedAggregation createAggregationForMethod(String name, Class<?>... parameters) {
Method method = ClassUtils.getMethod(SampleRepository.class, name, parameters);
ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
MongoQueryMethod queryMethod = new MongoQueryMethod(method, new DefaultRepositoryMetadata(SampleRepository.class), factory, converter.getMappingContext());
return new StringBasedAggregation(queryMethod, operations, PARSER, QueryMethodEvaluationContextProvider.DEFAULT);
}
Aggregations