Search in sources :

Example 1 with SpelAwareProxyProjectionFactory

use of org.springframework.data.projection.SpelAwareProxyProjectionFactory in project spring-data-mongodb by spring-projects.

the class MongoQueryCreatorUnitTests method assertBindsDistanceToQuery.

private void assertBindsDistanceToQuery(Point point, Distance distance, Query reference) throws Exception {
    PartTree tree = new PartTree("findByLocationNearAndFirstname", org.springframework.data.mongodb.repository.Person.class);
    Method method = PersonRepository.class.getMethod("findByLocationNearAndFirstname", Point.class, Distance.class, String.class);
    MongoQueryMethod queryMethod = new MongoQueryMethod(method, new DefaultRepositoryMetadata(PersonRepository.class), new SpelAwareProxyProjectionFactory(), new MongoMappingContext());
    MongoParameterAccessor accessor = new MongoParametersParameterAccessor(queryMethod, new Object[] { point, distance, "Dave" });
    Query query = new MongoQueryCreator(tree, new ConvertingParameterAccessor(converter, accessor), context).createQuery();
    assertThat(query, is(query));
}
Also used : DefaultRepositoryMetadata(org.springframework.data.repository.core.support.DefaultRepositoryMetadata) Query(org.springframework.data.mongodb.core.query.Query) SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) DefaultRepositoryMetadata(org.springframework.data.repository.core.support.DefaultRepositoryMetadata) Method(java.lang.reflect.Method) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) PartTree(org.springframework.data.repository.query.parser.PartTree)

Example 2 with SpelAwareProxyProjectionFactory

use of org.springframework.data.projection.SpelAwareProxyProjectionFactory in project spring-data-mongodb by spring-projects.

the class MongoQueryMethodUnitTests method queryMethod.

private MongoQueryMethod queryMethod(Class<?> repository, String name, Class<?>... parameters) throws Exception {
    Method method = repository.getMethod(name, parameters);
    ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
    return new MongoQueryMethod(method, new DefaultRepositoryMetadata(repository), factory, context);
}
Also used : ProjectionFactory(org.springframework.data.projection.ProjectionFactory) SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) DefaultRepositoryMetadata(org.springframework.data.repository.core.support.DefaultRepositoryMetadata) Method(java.lang.reflect.Method)

Example 3 with SpelAwareProxyProjectionFactory

use of org.springframework.data.projection.SpelAwareProxyProjectionFactory in project spring-data-mongodb by spring-projects.

the class PartTreeMongoQueryUnitTests method createQueryForMethod.

private PartTreeMongoQuery createQueryForMethod(String methodName, Class<?>... paramTypes) {
    try {
        Method method = Repo.class.getMethod(methodName, paramTypes);
        ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
        MongoQueryMethod queryMethod = new MongoQueryMethod(method, new DefaultRepositoryMetadata(Repo.class), factory, mappingContext);
        return new PartTreeMongoQuery(queryMethod, mongoOperationsMock);
    } catch (Exception e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
Also used : ProjectionFactory(org.springframework.data.projection.ProjectionFactory) SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) DefaultRepositoryMetadata(org.springframework.data.repository.core.support.DefaultRepositoryMetadata) Method(java.lang.reflect.Method) JSONParseException(com.mongodb.util.JSONParseException) ExpectedException(org.junit.rules.ExpectedException)

Example 4 with SpelAwareProxyProjectionFactory

use of org.springframework.data.projection.SpelAwareProxyProjectionFactory in project spring-data-mongodb by spring-projects.

the class ReactiveStringBasedMongoQueryUnitTests method createQueryForMethod.

private ReactiveStringBasedMongoQuery createQueryForMethod(String name, Class<?>... parameters) throws Exception {
    Method method = SampleRepository.class.getMethod(name, parameters);
    ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
    ReactiveMongoQueryMethod queryMethod = new ReactiveMongoQueryMethod(method, new DefaultRepositoryMetadata(SampleRepository.class), factory, converter.getMappingContext());
    return new ReactiveStringBasedMongoQuery(queryMethod, operations, PARSER, DefaultEvaluationContextProvider.INSTANCE);
}
Also used : ProjectionFactory(org.springframework.data.projection.ProjectionFactory) SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) DefaultRepositoryMetadata(org.springframework.data.repository.core.support.DefaultRepositoryMetadata) Method(java.lang.reflect.Method)

Example 5 with SpelAwareProxyProjectionFactory

use of org.springframework.data.projection.SpelAwareProxyProjectionFactory 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

SpelAwareProxyProjectionFactory (org.springframework.data.projection.SpelAwareProxyProjectionFactory)19 Method (java.lang.reflect.Method)11 DefaultRepositoryMetadata (org.springframework.data.repository.core.support.DefaultRepositoryMetadata)9 Test (org.junit.Test)7 ProjectionFactory (org.springframework.data.projection.ProjectionFactory)6 PartTree (org.springframework.data.repository.query.parser.PartTree)3 JacksonMappingProvider (com.jayway.jsonpath.spi.mapper.JacksonMappingProvider)2 ArrayList (java.util.ArrayList)2 ParametersParameterAccessor (org.springframework.data.repository.query.ParametersParameterAccessor)2 QueryMethod (org.springframework.data.repository.query.QueryMethod)2 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MappingProvider (com.jayway.jsonpath.spi.mapper.MappingProvider)1 JSONParseException (com.mongodb.util.JSONParseException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Before (org.junit.Before)1 ExpectedException (org.junit.rules.ExpectedException)1 SpelQueryCreator (org.springframework.data.keyvalue.repository.query.SpelQueryCreator)1 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)1 Query (org.springframework.data.mongodb.core.query.Query)1