DATACMNS-193 - Introduced isQueryMethod(…) on RepositoryInformation.

This commit is contained in:
Oliver Gierke
2012-07-16 10:02:44 +02:00
parent 4a51ce2b84
commit 4d326faa25
4 changed files with 41 additions and 6 deletions

View File

@@ -43,11 +43,18 @@ public interface RepositoryInformation extends RepositoryMetadata {
* Returns whether the given method is a custom repository method.
*
* @param method
* @param baseClass
* @return
*/
boolean isCustomMethod(Method method);
/**
* Returns whether the given method is a query method.
*
* @param method
* @return
*/
boolean isQueryMethod(Method method);
/**
* Returns all methods considered to be query methods.
*

View File

@@ -22,6 +22,7 @@ import java.io.Serializable;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -101,7 +102,6 @@ class DefaultRepositoryInformation extends AbstractRepositoryMetadata implements
* @see org.springframework.data.repository.support.RepositoryInformation#getRepositoryBaseClass()
*/
public Class<?> getRepositoryBaseClass() {
return this.repositoryBaseClass;
}
@@ -152,7 +152,7 @@ class DefaultRepositoryInformation extends AbstractRepositoryMetadata implements
* (non-Javadoc)
* @see org.springframework.data.repository.support.RepositoryInformation#getQueryMethods()
*/
public Iterable<Method> getQueryMethods() {
public Set<Method> getQueryMethods() {
Set<Method> result = new HashSet<Method>();
@@ -163,7 +163,7 @@ class DefaultRepositoryInformation extends AbstractRepositoryMetadata implements
}
}
return result;
return Collections.unmodifiableSet(result);
}
/*
@@ -174,6 +174,14 @@ class DefaultRepositoryInformation extends AbstractRepositoryMetadata implements
return isTargetClassMethod(method, customImplementationClass);
}
/*
* (non-Javadoc)
* @see org.springframework.data.repository.core.RepositoryInformation#isQueryMethod(java.lang.reflect.Method)
*/
public boolean isQueryMethod(Method method) {
return getQueryMethods().contains(method);
}
/**
* Returns whether the given method is a method covered by the base implementation.
*

View File

@@ -142,6 +142,21 @@ public class DefaultRepositoryInformationUnitTests {
assertThat(queryMethods, not(hasItem(intermediateMethod)));
}
/**
* @see DATACMNS-193
*/
@Test
public void detectsQueryMethodCorrectly() {
RepositoryMetadata metadata = new DefaultRepositoryMetadata(ConcreteRepository.class);
RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class, null);
Method queryMethod = getMethodFrom(ConcreteRepository.class, "findBySomethingDifferent");
assertThat(information.getQueryMethods(), hasItem(queryMethod));
assertThat(information.isQueryMethod(queryMethod), is(true));
}
private Method getMethodFrom(Class<?> type, String name) {
for (Method method : type.getMethods()) {
if (method.getName().equals(name)) {

View File

@@ -18,6 +18,7 @@ package org.springframework.data.repository.support;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Set;
import org.springframework.data.repository.core.RepositoryInformation;
import org.springframework.data.repository.core.RepositoryMetadata;
@@ -59,11 +60,15 @@ public final class DummyRepositoryInformation implements RepositoryInformation {
return false;
}
public Iterable<Method> getQueryMethods() {
public boolean isQueryMethod(Method method) {
return false;
}
public Set<Method> getQueryMethods() {
return Collections.emptySet();
}
public Method getTargetClassMethod(Method method) {
return method;
}
}
}