DATAJPA-564 - Renamed ExpressionEvaluationContextProvider to EvaluationContextProvided.

This commit is contained in:
Thomas Darimont
2014-07-04 09:27:27 +02:00
committed by Oliver Gierke
parent 09b6a49146
commit bcdb2881a5
16 changed files with 80 additions and 57 deletions

View File

@@ -38,7 +38,7 @@ import org.springframework.dao.annotation.PersistenceExceptionTranslationPostPro
import org.springframework.data.jpa.mapping.JpaMetamodelMappingContext;
import org.springframework.data.jpa.repository.support.EntityManagerBeanDefinitionRegistrarPostProcessor;
import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean;
import org.springframework.data.jpa.repository.support.StandardExpressionEvaluationContextProvider;
import org.springframework.data.jpa.repository.support.StandardEvaluationContextProvider;
import org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport;
import org.springframework.data.repository.config.RepositoryConfigurationSource;
import org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor;
@@ -175,7 +175,7 @@ public class JpaRepositoryConfigExtension extends RepositoryConfigurationExtensi
registry.registerBeanDefinition(
DEFAULT_EXPRESSION_EVALUATION_CONTEXT_PROVIDER,
BeanDefinitionBuilder.rootBeanDefinition(FieldRetrievingFactoryBean.class)
.addPropertyValue("targetClass", StandardExpressionEvaluationContextProvider.class)
.addPropertyValue("targetClass", StandardEvaluationContextProvider.class)
.addPropertyValue("targetField", "INSTANCE").getBeanDefinition());
}
}

View File

@@ -19,7 +19,7 @@ import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import org.springframework.data.jpa.repository.support.ExpressionEvaluationContextProvider;
import org.springframework.data.jpa.repository.support.EvaluationContextProvider;
import org.springframework.data.repository.query.ParameterAccessor;
import org.springframework.data.repository.query.ParametersParameterAccessor;
import org.springframework.util.Assert;
@@ -34,7 +34,7 @@ abstract class AbstractStringBasedJpaQuery extends AbstractJpaQuery {
private final StringQuery query;
private final StringQuery countQuery;
private final ExpressionEvaluationContextProvider evaluationContextProvider;
private final EvaluationContextProvider evaluationContextProvider;
/**
* Creates a new {@link AbstractStringBasedJpaQuery} from the given {@link JpaQueryMethod}, {@link EntityManager} and
@@ -46,7 +46,7 @@ abstract class AbstractStringBasedJpaQuery extends AbstractJpaQuery {
* @param evaluationContextProvider must not be {@literal null}.
*/
public AbstractStringBasedJpaQuery(JpaQueryMethod method, EntityManager em, String queryString,
ExpressionEvaluationContextProvider evaluationContextProvider) {
EvaluationContextProvider evaluationContextProvider) {
super(method, em);

View File

@@ -19,7 +19,7 @@ import java.util.ArrayList;
import java.util.List;
import org.springframework.data.jpa.repository.query.JpaParameters.JpaParameter;
import org.springframework.data.jpa.repository.support.ExpressionEvaluationContextProvider;
import org.springframework.data.jpa.repository.support.EvaluationContextProvider;
import org.springframework.expression.AccessException;
import org.springframework.expression.BeanResolver;
import org.springframework.expression.ConstructorResolver;
@@ -44,16 +44,15 @@ import org.springframework.util.Assert;
*/
class ExpressionAwareParameterBinder extends ParameterBinder {
private final ExpressionEvaluationContextProvider evaluationContextProvider;
private final EvaluationContextProvider evaluationContextProvider;
/**
* Creates a new {@literal ExpressionAwareParameterBinder}.
*
* @param parameters
* @param evaluationContextProvider
* @param evaluationContextProvider must not be {@literal null}.
*/
public ExpressionAwareParameterBinder(JpaParameters parameters,
ExpressionEvaluationContextProvider evaluationContextProvider) {
public ExpressionAwareParameterBinder(JpaParameters parameters, EvaluationContextProvider evaluationContextProvider) {
this(parameters, new Object[0], evaluationContextProvider);
}
@@ -62,14 +61,14 @@ class ExpressionAwareParameterBinder extends ParameterBinder {
*
* @param parameters
* @param values
* @param evaluationContextProvider
* @param evaluationContextProvider must not be {@literal null}.
*/
public ExpressionAwareParameterBinder(JpaParameters parameters, Object[] values,
ExpressionEvaluationContextProvider evaluationContextProvider) {
EvaluationContextProvider evaluationContextProvider) {
super(parameters, values);
Assert.notNull(evaluationContextProvider, "ExpressionEvaluationContextProvider must not be null!");
Assert.notNull(evaluationContextProvider, "EvaluationContextProvider must not be null!");
this.evaluationContextProvider = evaluationContextProvider;
}

View File

@@ -20,7 +20,7 @@ import javax.persistence.EntityManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.support.ExpressionEvaluationContextProvider;
import org.springframework.data.jpa.repository.support.EvaluationContextProvider;
import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.repository.query.RepositoryQuery;
@@ -45,7 +45,7 @@ enum JpaQueryFactory {
* @return the {@link RepositoryQuery} derived from the annotation or {@code null} if no annotation found.
*/
AbstractJpaQuery fromQueryAnnotation(JpaQueryMethod queryMethod, EntityManager em,
ExpressionEvaluationContextProvider evaluationContextProvider) {
EvaluationContextProvider evaluationContextProvider) {
LOG.debug("Looking up query for method {}", queryMethod.getName());
return fromMethodWithQueryString(queryMethod, em, queryMethod.getAnnotatedQuery(), evaluationContextProvider);
@@ -61,7 +61,7 @@ enum JpaQueryFactory {
* @return
*/
AbstractJpaQuery fromMethodWithQueryString(JpaQueryMethod method, EntityManager em, String queryString,
ExpressionEvaluationContextProvider evaluationContextProvider) {
EvaluationContextProvider evaluationContextProvider) {
if (queryString == null) {
return null;

View File

@@ -19,7 +19,7 @@ import java.lang.reflect.Method;
import javax.persistence.EntityManager;
import org.springframework.data.jpa.repository.support.ExpressionEvaluationContextProvider;
import org.springframework.data.jpa.repository.support.EvaluationContextProvider;
import org.springframework.data.repository.core.NamedQueries;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.query.QueryLookupStrategy;
@@ -37,23 +37,29 @@ public final class JpaQueryLookupStrategy {
/**
* Private constructor to prevent instantiation.
*/
private JpaQueryLookupStrategy() {
}
private JpaQueryLookupStrategy() {}
/**
* Base class for {@link QueryLookupStrategy} implementations that need access to an {@link EntityManager}.
*
* @author Oliver Gierke
* @author Thomas Darimont
*/
private abstract static class AbstractQueryLookupStrategy implements QueryLookupStrategy {
private final EntityManager em;
private final QueryExtractor provider;
protected final ExpressionEvaluationContextProvider evaluationContextProvider;
protected final EvaluationContextProvider evaluationContextProvider;
/**
* Creates a new {@link AbstractQueryLookupStrategy}.
*
* @param em
* @param extractor
* @param evaluationContextProvider
*/
public AbstractQueryLookupStrategy(EntityManager em, QueryExtractor extractor,
ExpressionEvaluationContextProvider evaluationContextProvider) {
EvaluationContextProvider evaluationContextProvider) {
this.em = em;
this.provider = extractor;
@@ -80,11 +86,12 @@ public final class JpaQueryLookupStrategy {
* {@link QueryLookupStrategy} to create a query from the method name.
*
* @author Oliver Gierke
* @author Thomas Darimont
*/
private static class CreateQueryLookupStrategy extends AbstractQueryLookupStrategy {
public CreateQueryLookupStrategy(EntityManager em, QueryExtractor extractor,
ExpressionEvaluationContextProvider evaluationContextProvider) {
EvaluationContextProvider evaluationContextProvider) {
super(em, extractor, evaluationContextProvider);
}
@@ -106,11 +113,19 @@ public final class JpaQueryLookupStrategy {
* a JPA named query lookup.
*
* @author Oliver Gierke
* @author Thomas Darimont
*/
private static class DeclaredQueryLookupStrategy extends AbstractQueryLookupStrategy {
/**
* Creates a new {@link DeclaredQueryLookupStrategy}.
*
* @param em
* @param extractor
* @param evaluationContextProvider
*/
public DeclaredQueryLookupStrategy(EntityManager em, QueryExtractor extractor,
ExpressionEvaluationContextProvider evaluationContextProvider) {
EvaluationContextProvider evaluationContextProvider) {
super(em, extractor, evaluationContextProvider);
}
@@ -153,15 +168,25 @@ public final class JpaQueryLookupStrategy {
* query creation.
*
* @author Oliver Gierke
* @author Thomas Darimont
*/
private static class CreateIfNotFoundQueryLookupStrategy extends AbstractQueryLookupStrategy {
private final DeclaredQueryLookupStrategy lookupStrategy;
private final CreateQueryLookupStrategy createStrategy;
/**
* Creates a new {@link CreateIfNotFoundQueryLookupStrategy}.
*
* @param em
* @param extractor
* @param createStrategy
* @param lookupStrategy
* @param evaluationContextProvider
*/
public CreateIfNotFoundQueryLookupStrategy(EntityManager em, QueryExtractor extractor,
CreateQueryLookupStrategy createStrategy, DeclaredQueryLookupStrategy lookupStrategy,
ExpressionEvaluationContextProvider evaluationContextProvider) {
EvaluationContextProvider evaluationContextProvider) {
super(em, extractor, evaluationContextProvider);
@@ -189,7 +214,7 @@ public final class JpaQueryLookupStrategy {
* @return
*/
public static QueryLookupStrategy create(EntityManager em, Key key, QueryExtractor extractor,
ExpressionEvaluationContextProvider evaluationContextProvider) {
EvaluationContextProvider evaluationContextProvider) {
switch (key != null ? key : Key.CREATE_IF_NOT_FOUND) {
case CREATE:

View File

@@ -18,7 +18,7 @@ package org.springframework.data.jpa.repository.query;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.springframework.data.jpa.repository.support.ExpressionEvaluationContextProvider;
import org.springframework.data.jpa.repository.support.EvaluationContextProvider;
import org.springframework.data.repository.query.Parameters;
import org.springframework.data.repository.query.RepositoryQuery;
@@ -40,7 +40,7 @@ final class NativeJpaQuery extends AbstractStringBasedJpaQuery {
* @param evaluationContextProvider
*/
public NativeJpaQuery(JpaQueryMethod method, EntityManager em, String queryString,
ExpressionEvaluationContextProvider evaluationContextProvider) {
EvaluationContextProvider evaluationContextProvider) {
super(method, em, queryString, evaluationContextProvider);

View File

@@ -18,7 +18,7 @@ package org.springframework.data.jpa.repository.query;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.springframework.data.jpa.repository.support.ExpressionEvaluationContextProvider;
import org.springframework.data.jpa.repository.support.EvaluationContextProvider;
import org.springframework.data.repository.query.RepositoryQuery;
/**
@@ -38,7 +38,7 @@ final class SimpleJpaQuery extends AbstractStringBasedJpaQuery {
* @param em must not be {@literal null}.
*/
public SimpleJpaQuery(JpaQueryMethod method, EntityManager em,
ExpressionEvaluationContextProvider evaluationContextProvider) {
EvaluationContextProvider evaluationContextProvider) {
this(method, em, method.getAnnotatedQuery(), evaluationContextProvider);
}
@@ -50,7 +50,7 @@ final class SimpleJpaQuery extends AbstractStringBasedJpaQuery {
* @param queryString must not be {@literal null} or empty.
*/
public SimpleJpaQuery(JpaQueryMethod method, EntityManager em, String queryString,
ExpressionEvaluationContextProvider evaluationContextProvider) {
EvaluationContextProvider evaluationContextProvider) {
super(method, em, queryString, evaluationContextProvider);

View File

@@ -18,7 +18,7 @@ package org.springframework.data.jpa.repository.query;
import javax.persistence.Query;
import org.springframework.data.jpa.repository.query.StringQuery.ParameterBinding;
import org.springframework.data.jpa.repository.support.ExpressionEvaluationContextProvider;
import org.springframework.data.jpa.repository.support.EvaluationContextProvider;
import org.springframework.expression.Expression;
import org.springframework.util.Assert;
@@ -40,11 +40,11 @@ class SpelExpressionStringQueryParameterBinder extends StringQueryParameterBinde
* @param evaluationContextProvider must not be {@literal null}
*/
public SpelExpressionStringQueryParameterBinder(JpaParameters parameters, Object[] values, StringQuery query,
ExpressionEvaluationContextProvider evaluationContextProvider) {
EvaluationContextProvider evaluationContextProvider) {
super(parameters, values, query, evaluationContextProvider);
Assert.notNull(evaluationContextProvider, "ExpressionEvaluationContextProvider must not be null!");
Assert.notNull(evaluationContextProvider, "EvaluationContextProvider must not be null!");
this.query = query;
}

View File

@@ -20,7 +20,7 @@ import javax.persistence.Query;
import org.springframework.data.jpa.repository.query.JpaParameters.JpaParameter;
import org.springframework.data.jpa.repository.query.StringQuery.LikeParameterBinding;
import org.springframework.data.jpa.repository.query.StringQuery.ParameterBinding;
import org.springframework.data.jpa.repository.support.ExpressionEvaluationContextProvider;
import org.springframework.data.jpa.repository.support.EvaluationContextProvider;
import org.springframework.data.repository.query.Parameter;
import org.springframework.data.repository.query.Parameters;
import org.springframework.util.Assert;
@@ -42,10 +42,10 @@ public class StringQueryParameterBinder extends ExpressionAwareParameterBinder {
* @param parameters must not be {@literal null}.
* @param values must not be {@literal null}.
* @param query must not be {@literal null}.
* @param evaluationContextProvider
* @param evaluationContextProvider must not be {@literal null}.
*/
public StringQueryParameterBinder(JpaParameters parameters, Object[] values, StringQuery query,
ExpressionEvaluationContextProvider evaluationContextProvider) {
EvaluationContextProvider evaluationContextProvider) {
super(parameters, values, evaluationContextProvider);

View File

@@ -22,7 +22,7 @@ import org.springframework.expression.EvaluationContext;
*
* @author Thomas Darimont
*/
public interface ExpressionEvaluationContextProvider {
public interface EvaluationContextProvider {
/**
* Returns the {@link EvaluationContext}.

View File

@@ -41,7 +41,7 @@ public class JpaRepositoryFactory extends RepositoryFactorySupport {
private final EntityManager entityManager;
private final QueryExtractor extractor;
private final CrudMethodMetadataPostProcessor lockModePostProcessor;
private final ExpressionEvaluationContextProvider evaluationContextProvider;
private final EvaluationContextProvider evaluationContextProvider;
/**
* Creates a new {@link JpaRepositoryFactory}.
@@ -49,7 +49,7 @@ public class JpaRepositoryFactory extends RepositoryFactorySupport {
* @param entityManager must not be {@literal null}
*/
public JpaRepositoryFactory(EntityManager entityManager) {
this(entityManager, StandardExpressionEvaluationContextProvider.INSTANCE);
this(entityManager, StandardEvaluationContextProvider.INSTANCE);
}
/**
@@ -58,7 +58,7 @@ public class JpaRepositoryFactory extends RepositoryFactorySupport {
* @param entityManager must not be {@literal null}
* @param evaluationContextProvider must not be {@literal null}
*/
public JpaRepositoryFactory(EntityManager entityManager, ExpressionEvaluationContextProvider evaluationContextProvider) {
public JpaRepositoryFactory(EntityManager entityManager, EvaluationContextProvider evaluationContextProvider) {
Assert.notNull(entityManager);

View File

@@ -39,7 +39,7 @@ public class JpaRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends
private EntityManager entityManager;
private ExpressionEvaluationContextProvider expressionEvaluationContextProvider = StandardExpressionEvaluationContextProvider.INSTANCE;
private EvaluationContextProvider expressionEvaluationContextProvider = StandardEvaluationContextProvider.INSTANCE;
/**
* The {@link EntityManager} to be used.
@@ -64,7 +64,7 @@ public class JpaRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends
* @param expressionEvaluationContextProvider the expressionEvaluationContextProvider to set
*/
public void setExpressionEvaluationContextProvider(
ExpressionEvaluationContextProvider expressionEvaluationContextProvider) {
EvaluationContextProvider expressionEvaluationContextProvider) {
this.expressionEvaluationContextProvider = expressionEvaluationContextProvider;
}

View File

@@ -19,18 +19,17 @@ import org.springframework.expression.EvaluationContext;
import org.springframework.expression.spel.support.StandardEvaluationContext;
/**
* Default implementation of {@link ExpressionEvaluationContextProvider} that always creates a new
* {@link EvaluationContext}.
* Default implementation of {@link EvaluationContextProvider} that always creates a new {@link EvaluationContext}.
*
* @author Thomas Darimont
*/
public enum StandardExpressionEvaluationContextProvider implements ExpressionEvaluationContextProvider {
public enum StandardEvaluationContextProvider implements EvaluationContextProvider {
INSTANCE;
/*
* (non-Javadoc)
* @see org.springframework.data.jpa.repository.support.ExpressionEvaluationContextProvider#getEvaluationContext()
* @see org.springframework.data.jpa.repository.support.EvaluationContextProvider#getEvaluationContext()
*/
@Override
public StandardEvaluationContext getEvaluationContext() {

View File

@@ -16,14 +16,14 @@
package org.springframework.data.jpa.repository;
import org.springframework.data.jpa.repository.SampleSecurity.SampleSecurityContextHolder;
import org.springframework.data.jpa.repository.support.ExpressionEvaluationContextProvider;
import org.springframework.data.jpa.repository.support.EvaluationContextProvider;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.spel.support.StandardEvaluationContext;
/**
* @author Thomas Darimont
*/
public class SampleExpressionEvaluationContextProvider implements ExpressionEvaluationContextProvider {
public class SampleExpressionEvaluationContextProvider implements EvaluationContextProvider {
@Override
public EvaluationContext getEvaluationContext() {

View File

@@ -36,7 +36,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.sample.User;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.support.StandardExpressionEvaluationContextProvider;
import org.springframework.data.jpa.repository.support.StandardEvaluationContextProvider;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.NamedQueries;
import org.springframework.data.repository.core.RepositoryMetadata;
@@ -74,7 +74,7 @@ public class JpaQueryLookupStrategyUnitTests {
public void invalidAnnotatedQueryCausesException() throws Exception {
QueryLookupStrategy strategy = JpaQueryLookupStrategy.create(em, Key.CREATE_IF_NOT_FOUND, extractor,
StandardExpressionEvaluationContextProvider.INSTANCE);
StandardEvaluationContextProvider.INSTANCE);
Method method = UserRepository.class.getMethod("findByFoo", String.class);
RepositoryMetadata metadata = new DefaultRepositoryMetadata(UserRepository.class);
@@ -96,7 +96,7 @@ public class JpaQueryLookupStrategyUnitTests {
public void sholdThrowMorePreciseExceptionIfTryingToUsePaginationInNativeQueries() throws Exception {
QueryLookupStrategy strategy = JpaQueryLookupStrategy.create(em, Key.CREATE_IF_NOT_FOUND, extractor,
StandardExpressionEvaluationContextProvider.INSTANCE);
StandardEvaluationContextProvider.INSTANCE);
Method method = UserRepository.class.getMethod("findByInvalidNativeQuery", String.class, Pageable.class);
RepositoryMetadata metadata = new DefaultRepositoryMetadata(UserRepository.class);

View File

@@ -44,7 +44,7 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.sample.UserRepository;
import org.springframework.data.jpa.repository.support.DefaultJpaEntityMetadata;
import org.springframework.data.jpa.repository.support.JpaEntityMetadata;
import org.springframework.data.jpa.repository.support.StandardExpressionEvaluationContextProvider;
import org.springframework.data.jpa.repository.support.StandardEvaluationContextProvider;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.query.RepositoryQuery;
@@ -97,7 +97,7 @@ public class SimpleJpaQueryUnitTests {
when(em.createQuery("foo", Long.class)).thenReturn(query);
SimpleJpaQuery jpaQuery = new SimpleJpaQuery(method, em, "select u from User u",
StandardExpressionEvaluationContextProvider.INSTANCE);
StandardEvaluationContextProvider.INSTANCE);
assertThat(jpaQuery.createCountQuery(new Object[] {}), is(query));
}
@@ -114,7 +114,7 @@ public class SimpleJpaQueryUnitTests {
JpaQueryMethod queryMethod = new JpaQueryMethod(method, metadata, extractor);
AbstractJpaQuery jpaQuery = new SimpleJpaQuery(queryMethod, em, "select u from User u",
StandardExpressionEvaluationContextProvider.INSTANCE);
StandardEvaluationContextProvider.INSTANCE);
jpaQuery.createCountQuery(new Object[] { new PageRequest(1, 10) });
verify(query, times(0)).setFirstResult(anyInt());
@@ -128,7 +128,7 @@ public class SimpleJpaQueryUnitTests {
Method method = SampleRepository.class.getMethod("findNativeByLastname", String.class);
JpaQueryMethod queryMethod = new JpaQueryMethod(method, metadata, extractor);
AbstractJpaQuery jpaQuery = JpaQueryFactory.INSTANCE.fromQueryAnnotation(queryMethod, em,
StandardExpressionEvaluationContextProvider.INSTANCE);
StandardEvaluationContextProvider.INSTANCE);
assertThat(jpaQuery instanceof NativeJpaQuery, is(true));
@@ -210,7 +210,7 @@ public class SimpleJpaQueryUnitTests {
JpaQueryMethod queryMethod = new JpaQueryMethod(method, metadata, extractor);
return JpaQueryFactory.INSTANCE.fromQueryAnnotation(queryMethod, em,
StandardExpressionEvaluationContextProvider.INSTANCE);
StandardEvaluationContextProvider.INSTANCE);
}
interface SampleRepository {