QueryMethodDataOperationResolver implements DataOperationResolver { @Override public DataStoreOperation<?, ?, ?> resolve(Method method) { if (AnnotationUtils.findAnnotation(method, QueryAnnotation.class) != null) { log.info("Found a @Query annotation on the method " + method); return null; } log.info("Extracting query description from the method by parsing the method"); final QueryDescriptor descriptor = descriptionExtractor.extract(repositoryMetadata, configuration, method); return new DescribedDataStoreOperation<>(new SelectDataStoreOperation<>(descriptor), functionRegistry); } QueryMethodDataOperationResolver(MethodQueryDescriptionExtractor descriptionExtractor,
                                            RepositoryMetadata repositoryMetadata,
                                            DataFunctionRegistry functionRegistry,
                                            RepositoryFactoryConfiguration configuration); @Override DataStoreOperation<?, ?, ?> resolve(Method method);  }
@Test public void testThatItCallsAQueryExtractor() throws Exception { final NoOpMethodQueryDescriptionExtractor extractor = new NoOpMethodQueryDescriptionExtractor(); final QueryMethodDataOperationResolver resolver = new QueryMethodDataOperationResolver(extractor, null, null, null); assertThat(extractor.isCalled(), is(false)); final DataStoreOperation<?, ?, ?> operation = resolver.resolve( SampleMappedRepository.class.getMethod("normalMethodBy")); assertThat(operation, is(notNullValue())); assertThat(operation, is(instanceOf(DescribedDataStoreOperation.class))); assertThat(extractor.isCalled(), is(true)); }
@Test public void testMethodThatIsAnnotatedWithVendorQuery() throws Exception { final QueryMethodDataOperationResolver resolver = new QueryMethodDataOperationResolver( new NoOpMethodQueryDescriptionExtractor(), null, null, null); final DataStoreOperation<?, ?, ?> method = resolver.resolve( SampleMappedRepository.class.getMethod("nativeMethod")); assertThat(method, is(nullValue())); }