DefaultDataOperationResolver implements DataOperationResolver { @Override public DataStoreOperation<?, ?, ?> resolve(Method method) { log.info("Resolving the data operation for method " + method); for (DataOperationResolver resolver : resolvers) { log.debug("Attempting to resolve the method call using resolver " + resolver); final DataStoreOperation<?, ?, ?> resolution; try { resolution = resolver.resolve(method); } catch (Exception e) { throw new DataOperationDefinitionException(method, e); } if (resolution != null) { return resolution; } } log.error("No suitable data operation could be found for method " + method); throw new UnknownDataOperationException(method); } DefaultDataOperationResolver(List<TypeMapping<?>> implementations,
                                        MethodQueryDescriptionExtractor descriptionExtractor,
                                        RepositoryMetadata repositoryMetadata, DataFunctionRegistry functionRegistry,
                                        RepositoryFactoryConfiguration configuration); @Override DataStoreOperation<?, ?, ?> resolve(Method method);  }
@Test public void testLookingForMethodThatHasMapping() throws Exception { final DataStoreOperation<?, ?, ?> operation = resolver.resolve( SampleMappedRepository.class.getMethod("mappedSignature", String.class)); assertThat(operation, is(notNullValue())); assertThat(operation, is(instanceOf(MethodInvocationDataStoreOperation.class))); final MethodInvocationDataStoreOperation invocation = (MethodInvocationDataStoreOperation) operation; assertThat(invocation.getInstance(), is(instanceOf(MappedType.class))); assertThat(invocation.getMethod(), is(MappedType.class.getMethod("mappedSignature", CharSequence.class))); }
@Test public void testLookingForQueryMethod() throws Exception { final DataStoreOperation<?, ?, ?> operation = resolver.resolve( SampleMappedRepository.class.getMethod("findByFirstName", String.class)); assertThat(operation, is(notNullValue())); assertThat(operation, is(instanceOf(DescribedDataStoreOperation.class))); }
@Test(expectedExceptions = UnknownDataOperationException.class) public void testLookingForUnmappedMethod() throws Exception { resolver.resolve(SampleMappedRepository.class.getMethod("nativeMethod")); }
@Test(expectedExceptions = DataOperationDefinitionException.class) public void testLookingForMalformedMethod() throws Exception { resolver.resolve(SampleMappedRepository.class.getMethod("normalMethodBy")); }