diff --git a/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryMethod.java b/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryMethod.java index bdd488d5e..7534bd1ba 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryMethod.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryMethod.java @@ -17,7 +17,6 @@ package org.springframework.data.jpa.repository.query; import java.lang.annotation.Annotation; import java.lang.reflect.Method; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; diff --git a/src/main/java/org/springframework/data/jpa/repository/support/JpaRepositoryFactory.java b/src/main/java/org/springframework/data/jpa/repository/support/JpaRepositoryFactory.java index ecd9471b6..0c25eab04 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/JpaRepositoryFactory.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/JpaRepositoryFactory.java @@ -59,7 +59,7 @@ public class JpaRepositoryFactory extends RepositoryFactorySupport { private final QueryExtractor extractor; private final CrudMethodMetadataPostProcessor crudMethodMetadataPostProcessor; - private EntityPathResolver entityPathResolver = SimpleEntityPathResolver.INSTANCE; + private EntityPathResolver entityPathResolver; /** * Creates a new {@link JpaRepositoryFactory}. @@ -73,6 +73,7 @@ public class JpaRepositoryFactory extends RepositoryFactorySupport { this.entityManager = entityManager; this.extractor = PersistenceProvider.fromEntityManager(entityManager); this.crudMethodMetadataPostProcessor = new CrudMethodMetadataPostProcessor(); + this.entityPathResolver = SimpleEntityPathResolver.INSTANCE; addRepositoryProxyPostProcessor(crudMethodMetadataPostProcessor); } @@ -88,6 +89,18 @@ public class JpaRepositoryFactory extends RepositoryFactorySupport { this.crudMethodMetadataPostProcessor.setBeanClassLoader(classLoader); } + /** + * Configures the {@link EntityPathResolver} to be used. Defaults to {@link SimpleEntityPathResolver#INSTANCE}. + * + * @param entityPathResolver must not be {@literal null}. + */ + public void setEntityPathResolver(EntityPathResolver entityPathResolver) { + + Assert.notNull(entityPathResolver, "EntityPathResolver must not be null!"); + + this.entityPathResolver = entityPathResolver; + } + /* * (non-Javadoc) * @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getTargetRepository(org.springframework.data.repository.core.RepositoryMetadata) @@ -142,17 +155,6 @@ public class JpaRepositoryFactory extends RepositoryFactorySupport { return factory; } - /** - * Returns whether the given repository interface requires a QueryDsl specific implementation to be chosen. - * - * @param repositoryInterface - * @return - */ - private boolean isQueryDslExecutor(Class repositoryInterface) { - - return QUERY_DSL_PRESENT && QuerydslPredicateExecutor.class.isAssignableFrom(repositoryInterface); - } - /* * (non-Javadoc) * @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getQueryLookupStrategy(org.springframework.data.repository.query.QueryLookupStrategy.Key, org.springframework.data.repository.query.EvaluationContextProvider) @@ -174,6 +176,10 @@ public class JpaRepositoryFactory extends RepositoryFactorySupport { return (JpaEntityInformation) JpaEntityInformationSupport.getEntityInformation(domainClass, entityManager); } + /* + * (non-Javadoc) + * @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getRepositoryFragments(org.springframework.data.repository.core.RepositoryMetadata) + */ @Override protected RepositoryComposition.RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata) { @@ -191,18 +197,12 @@ public class JpaRepositoryFactory extends RepositoryFactorySupport { JpaEntityInformation entityInformation = getEntityInformation(metadata.getDomainType()); - Object querydslFragment = getTargetRepositoryViaReflection(QuerydslJpaPredicateExecutor.class, entityInformation, entityManager, - entityPathResolver, crudMethodMetadataPostProcessor.getCrudMethodMetadata()); + Object querydslFragment = getTargetRepositoryViaReflection(QuerydslJpaPredicateExecutor.class, entityInformation, + entityManager, entityPathResolver, crudMethodMetadataPostProcessor.getCrudMethodMetadata()); fragments = fragments.append(RepositoryFragment.implemented(querydslFragment)); } return fragments; } - - public void setEntityPathResolver(EntityPathResolver entityPathResolver) { - - Assert.notNull(entityPathResolver, "entityPathResolver must not be set to null."); - this.entityPathResolver = entityPathResolver; - } } diff --git a/src/main/java/org/springframework/data/jpa/repository/support/QuerydslJpaPredicateExecutor.java b/src/main/java/org/springframework/data/jpa/repository/support/QuerydslJpaPredicateExecutor.java index ef72c188f..462aa17ec 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/QuerydslJpaPredicateExecutor.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/QuerydslJpaPredicateExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2017 the original author or authors. + * Copyright 2008-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,6 @@ import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.querydsl.EntityPathResolver; import org.springframework.data.querydsl.QSort; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.querydsl.SimpleEntityPathResolver; import org.springframework.data.repository.support.PageableExecutionUtils; import org.springframework.lang.Nullable; import org.springframework.util.Assert; @@ -44,7 +43,7 @@ import com.querydsl.jpa.JPQLQuery; import com.querydsl.jpa.impl.AbstractJPAQuery; /** - * QueryDsl specific fragment for extending {@link SimpleJpaRepository} with an implementation for implementation for + * Querydsl specific fragment for extending {@link SimpleJpaRepository} with an implementation for implementation for * {@link QuerydslPredicateExecutor}. * * @author Oliver Gierke @@ -56,8 +55,6 @@ import com.querydsl.jpa.impl.AbstractJPAQuery; */ public class QuerydslJpaPredicateExecutor implements QuerydslPredicateExecutor { - private static final EntityPathResolver DEFAULT_ENTITY_PATH_RESOLVER = SimpleEntityPathResolver.INSTANCE; - private final JpaEntityInformation entityInformation; private final EntityPath path; private final Querydsl querydsl; @@ -65,15 +62,16 @@ public class QuerydslJpaPredicateExecutor implements QuerydslPredicateExecuto private final CrudMethodMetadata metadata; /** - * Creates a new {@link QuerydslJpaPredicateExecutor} from the given domain class and {@link EntityManager} and uses the - * given {@link EntityPathResolver} to translate the domain class into an {@link EntityPath}. - * @param entityInformation must not be {@literal null}. + * Creates a new {@link QuerydslJpaPredicateExecutor} from the given domain class and {@link EntityManager} and uses + * the given {@link EntityPathResolver} to translate the domain class into an {@link EntityPath}. + * + * @param entityInformation must not be {@literal null}. * @param entityManager must not be {@literal null}. * @param resolver must not be {@literal null}. * @param metadata maybe {@literal null}. */ public QuerydslJpaPredicateExecutor(JpaEntityInformation entityInformation, EntityManager entityManager, - EntityPathResolver resolver, @Nullable CrudMethodMetadata metadata) { + EntityPathResolver resolver, @Nullable CrudMethodMetadata metadata) { this.entityInformation = entityInformation; this.metadata = metadata; diff --git a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java index b87d48317..8ca9b53ea 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java @@ -758,6 +758,8 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation implements Specification { + private static final long serialVersionUID = 1L; + private final JpaEntityInformation entityInformation; @Nullable ParameterExpression parameter; @@ -788,6 +790,8 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation implements Specification { + private static final long serialVersionUID = 1L; + private final Example example; /**