DATAJPA-624 - Polished fixes for SonarQube warnings.

Added missing author tag in BeanDefinitionNames. Instead of providing an accessor for EvaluationContextProvider in AbstractQueryLookupStrategy we now only use the property in the type that actually needs it. Removed obsolete method in ParameterBinder. Polished formatting and JavaDoc in EntityManagerFactoryBeanDefinition.

Original pull request: #114.
This commit is contained in:
Oliver Gierke
2014-11-10 18:21:57 +01:00
parent adee3045a1
commit 571ba3d47e
4 changed files with 42 additions and 41 deletions

View File

@@ -19,6 +19,7 @@ package org.springframework.data.jpa.repository.config;
* Helper class to manage bean definition names in a single place.
*
* @author Oliver Gierke
* @author Thomas Darimont
*/
interface BeanDefinitionNames {

View File

@@ -50,7 +50,6 @@ public final class JpaQueryLookupStrategy {
private final EntityManager em;
private final QueryExtractor provider;
private final EvaluationContextProvider evaluationContextProvider;
/**
* Creates a new {@link AbstractQueryLookupStrategy}.
@@ -59,32 +58,21 @@ public final class JpaQueryLookupStrategy {
* @param extractor
* @param evaluationContextProvider
*/
public AbstractQueryLookupStrategy(EntityManager em, QueryExtractor extractor,
EvaluationContextProvider evaluationContextProvider) {
public AbstractQueryLookupStrategy(EntityManager em, QueryExtractor extractor) {
this.em = em;
this.provider = extractor;
this.evaluationContextProvider = evaluationContextProvider;
}
/*
* (non-Javadoc)
*
* @see org.springframework.data.repository.query.QueryLookupStrategy#
* resolveQuery(java.lang.reflect.Method,
* org.springframework.data.repository.core.RepositoryMetadata,
* org.springframework.data.repository.core.NamedQueries)
* @see org.springframework.data.repository.query.QueryLookupStrategy#resolveQuery(java.lang.reflect.Method, org.springframework.data.repository.core.RepositoryMetadata, org.springframework.data.repository.core.NamedQueries)
*/
public final RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, NamedQueries namedQueries) {
return resolveQuery(new JpaQueryMethod(method, metadata, provider), em, namedQueries);
}
protected abstract RepositoryQuery resolveQuery(JpaQueryMethod method, EntityManager em, NamedQueries namedQueries);
protected EvaluationContextProvider getEvaluationContextProvider() {
return evaluationContextProvider;
}
}
/**
@@ -95,10 +83,8 @@ public final class JpaQueryLookupStrategy {
*/
private static class CreateQueryLookupStrategy extends AbstractQueryLookupStrategy {
public CreateQueryLookupStrategy(EntityManager em, QueryExtractor extractor,
EvaluationContextProvider evaluationContextProvider) {
super(em, extractor, evaluationContextProvider);
public CreateQueryLookupStrategy(EntityManager em, QueryExtractor extractor) {
super(em, extractor);
}
@Override
@@ -123,6 +109,8 @@ public final class JpaQueryLookupStrategy {
*/
private static class DeclaredQueryLookupStrategy extends AbstractQueryLookupStrategy {
private final EvaluationContextProvider evaluationContextProvider;
/**
* Creates a new {@link DeclaredQueryLookupStrategy}.
*
@@ -133,13 +121,18 @@ public final class JpaQueryLookupStrategy {
public DeclaredQueryLookupStrategy(EntityManager em, QueryExtractor extractor,
EvaluationContextProvider evaluationContextProvider) {
super(em, extractor, evaluationContextProvider);
super(em, extractor);
this.evaluationContextProvider = evaluationContextProvider;
}
/*
* (non-Javadoc)
* @see org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy.AbstractQueryLookupStrategy#resolveQuery(org.springframework.data.jpa.repository.query.JpaQueryMethod, javax.persistence.EntityManager, org.springframework.data.repository.core.NamedQueries)
*/
@Override
protected RepositoryQuery resolveQuery(JpaQueryMethod method, EntityManager em, NamedQueries namedQueries) {
RepositoryQuery query = JpaQueryFactory.INSTANCE.fromQueryAnnotation(method, em, getEvaluationContextProvider());
RepositoryQuery query = JpaQueryFactory.INSTANCE.fromQueryAnnotation(method, em, evaluationContextProvider);
if (null != query) {
return query;
@@ -154,7 +147,7 @@ public final class JpaQueryLookupStrategy {
String name = method.getNamedQueryName();
if (namedQueries.hasQuery(name)) {
return JpaQueryFactory.INSTANCE.fromMethodWithQueryString(method, em, namedQueries.getQuery(name),
getEvaluationContextProvider());
evaluationContextProvider);
}
query = NamedQuery.lookupFrom(method, em);
@@ -191,15 +184,18 @@ public final class JpaQueryLookupStrategy {
* @param evaluationContextProvider
*/
public CreateIfNotFoundQueryLookupStrategy(EntityManager em, QueryExtractor extractor,
CreateQueryLookupStrategy createStrategy, DeclaredQueryLookupStrategy lookupStrategy,
EvaluationContextProvider evaluationContextProvider) {
CreateQueryLookupStrategy createStrategy, DeclaredQueryLookupStrategy lookupStrategy) {
super(em, extractor, evaluationContextProvider);
super(em, extractor);
this.createStrategy = createStrategy;
this.lookupStrategy = lookupStrategy;
}
/*
* (non-Javadoc)
* @see org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy.AbstractQueryLookupStrategy#resolveQuery(org.springframework.data.jpa.repository.query.JpaQueryMethod, javax.persistence.EntityManager, org.springframework.data.repository.core.NamedQueries)
*/
@Override
protected RepositoryQuery resolveQuery(JpaQueryMethod method, EntityManager em, NamedQueries namedQueries) {
@@ -229,13 +225,12 @@ public final class JpaQueryLookupStrategy {
switch (key != null ? key : Key.CREATE_IF_NOT_FOUND) {
case CREATE:
return new CreateQueryLookupStrategy(em, extractor, evaluationContextProvider);
return new CreateQueryLookupStrategy(em, extractor);
case USE_DECLARED_QUERY:
return new DeclaredQueryLookupStrategy(em, extractor, evaluationContextProvider);
case CREATE_IF_NOT_FOUND:
return new CreateIfNotFoundQueryLookupStrategy(em, extractor, new CreateQueryLookupStrategy(em, extractor,
evaluationContextProvider), new DeclaredQueryLookupStrategy(em, extractor, evaluationContextProvider),
evaluationContextProvider);
return new CreateIfNotFoundQueryLookupStrategy(em, extractor, new CreateQueryLookupStrategy(em, extractor),
new DeclaredQueryLookupStrategy(em, extractor, evaluationContextProvider));
default:
throw new IllegalArgumentException(String.format("Unsupported query lookup strategy %s!", key));
}

View File

@@ -127,19 +127,6 @@ public class ParameterBinder {
return parameter.isBindable();
}
/**
* Computes the value to bind for the given {@link JpaParameter} and the given {@code value} by potentially using the
* other {@code values}. This is intended to be customized in sub-classes.
*
* @param parameter
* @param value
* @param values
* @return
*/
private Object computeParameterValue(JpaParameter parameter, Object value, Object[] values) {
return value;
}
/**
* Perform the actual query parameter binding.
*

View File

@@ -126,6 +126,8 @@ public class BeanDefinitionUtils {
}
/**
* Value object to represent a {@link BeanDefinition} for an {@link EntityManagerFactory} with a dedicated bean name.
*
* @author Oliver Gierke
* @author Thomas Darimont
*/
@@ -143,19 +145,35 @@ public class BeanDefinitionUtils {
* @param beanDefinition
*/
public EntityManagerFactoryBeanDefinition(String beanName, BeanFactory beanFactory, BeanDefinition beanDefinition) {
this.beanName = beanName;
this.beanFactory = beanFactory;
this.beanDefinition = beanDefinition;
}
/**
* Returns the bean name of the {@link BeanDefinition} for the {@link EntityManagerFactory}.
*
* @return
*/
public String getBeanName() {
return beanName;
}
/**
* Returns the underlying {@link BeanFactory}.
*
* @return
*/
public BeanFactory getBeanFactory() {
return beanFactory;
}
/**
* Returns the {@link BeanDefinition} for the {@link EntityManagerFactory}.
*
* @return
*/
public BeanDefinition getBeanDefinition() {
return beanDefinition;
}