Browse Source

Refactored internal mechanism to resolve RepositoryQuery instances.

Simplified creation of RepositoryQuery instances by changing the QueryLookupStrategy interface method to take a plain Method instead of a QueryMethod. This way we get rid of an indirection where subclasses have to implement two methods (one creating a QueryMethod, one returning the QueryLookupStrategy). Thus a QueryLookupStrategy is responsible for creating RepositoryQueries from a Method and using a QueryMethod is an implementation detail of QueryLookupStrategy implementations actually.
pull/2/head
Oliver Gierke 15 years ago
parent
commit
e82b896fa9
  1. 5
      spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryLookupStrategy.java
  2. 4
      spring-data-commons-core/src/main/java/org/springframework/data/repository/support/RepositoryFactoryBeanSupport.java
  3. 19
      spring-data-commons-core/src/main/java/org/springframework/data/repository/support/RepositoryFactorySupport.java

5
spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryLookupStrategy.java

@ -1,5 +1,6 @@
package org.springframework.data.repository.query; package org.springframework.data.repository.query;
import java.lang.reflect.Method;
import java.util.Locale; import java.util.Locale;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -10,7 +11,7 @@ import org.springframework.util.StringUtils;
* *
* @author Oliver Gierke * @author Oliver Gierke
*/ */
public interface QueryLookupStrategy<Q extends QueryMethod> { public interface QueryLookupStrategy {
public static enum Key { public static enum Key {
@ -40,5 +41,5 @@ public interface QueryLookupStrategy<Q extends QueryMethod> {
* @param method * @param method
* @return * @return
*/ */
RepositoryQuery resolveQuery(Q method); RepositoryQuery resolveQuery(Method method);
} }

4
spring-data-commons-core/src/main/java/org/springframework/data/repository/support/RepositoryFactoryBeanSupport.java

@ -38,7 +38,7 @@ import org.springframework.util.Assert;
public abstract class RepositoryFactoryBeanSupport<T extends Repository<?, ?>> public abstract class RepositoryFactoryBeanSupport<T extends Repository<?, ?>>
implements FactoryBean<T>, InitializingBean, BeanFactoryAware { implements FactoryBean<T>, InitializingBean, BeanFactoryAware {
private RepositoryFactorySupport<?> factory; private RepositoryFactorySupport factory;
private Key queryLookupStrategyKey; private Key queryLookupStrategyKey;
private Class<? extends T> repositoryInterface; private Class<? extends T> repositoryInterface;
@ -150,7 +150,7 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<?, ?>>
* *
* @return * @return
*/ */
protected abstract RepositoryFactorySupport<?> createRepositoryFactory(); protected abstract RepositoryFactorySupport createRepositoryFactory();
/* /*

19
spring-data-commons-core/src/main/java/org/springframework/data/repository/support/RepositoryFactorySupport.java

@ -49,7 +49,7 @@ import org.springframework.util.Assert;
* *
* @author Oliver Gierke * @author Oliver Gierke
*/ */
public abstract class RepositoryFactorySupport<Q extends QueryMethod> { public abstract class RepositoryFactorySupport {
private QueryLookupStrategy.Key queryLookupStrategyKey; private QueryLookupStrategy.Key queryLookupStrategyKey;
@ -147,15 +147,6 @@ public abstract class RepositoryFactorySupport<Q extends QueryMethod> {
Class<T> domainClass); Class<T> domainClass);
/**
* Create a {@link QueryMethod} instance for the given {@link Method}.
*
* @param method
* @return
*/
protected abstract Q getQueryMethod(Method method);
/** /**
* Determines the base class for the repository to be created. * Determines the base class for the repository to be created.
* *
@ -171,7 +162,7 @@ public abstract class RepositoryFactorySupport<Q extends QueryMethod> {
* @param key can be {@literal null} * @param key can be {@literal null}
* @return * @return
*/ */
protected abstract QueryLookupStrategy<Q> getQueryLookupStrategy(Key key); protected abstract QueryLookupStrategy getQueryLookupStrategy(Key key);
/** /**
@ -360,12 +351,12 @@ public abstract class RepositoryFactorySupport<Q extends QueryMethod> {
this.customImplementation = customImplementation; this.customImplementation = customImplementation;
this.target = target; this.target = target;
QueryLookupStrategy<Q> strategy = QueryLookupStrategy lookupStrategy =
getQueryLookupStrategy(queryLookupStrategyKey); getQueryLookupStrategy(queryLookupStrategyKey);
for (Method method : getFinderMethods(repositoryInterface)) { for (Method method : getFinderMethods(repositoryInterface)) {
Q queryMethod = getQueryMethod(method);
queries.put(method, strategy.resolveQuery(queryMethod)); queries.put(method, lookupStrategy.resolveQuery(method));
} }
} }

Loading…
Cancel
Save