DATAJPA-1234 - Polishing.

General code cleanups.

Original pull request: #239.
This commit is contained in:
Oliver Gierke
2018-01-10 13:09:09 +01:00
parent a75c44f635
commit f202adc7b6
4 changed files with 31 additions and 30 deletions

View File

@@ -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;

View File

@@ -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<T, ID>) 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<?, Serializable> 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;
}
}

View File

@@ -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<T> implements QuerydslPredicateExecutor<T> {
private static final EntityPathResolver DEFAULT_ENTITY_PATH_RESOLVER = SimpleEntityPathResolver.INSTANCE;
private final JpaEntityInformation<T, ?> entityInformation;
private final EntityPath<T> path;
private final Querydsl querydsl;
@@ -65,15 +62,16 @@ public class QuerydslJpaPredicateExecutor<T> 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<T, ?> entityInformation, EntityManager entityManager,
EntityPathResolver resolver, @Nullable CrudMethodMetadata metadata) {
EntityPathResolver resolver, @Nullable CrudMethodMetadata metadata) {
this.entityInformation = entityInformation;
this.metadata = metadata;

View File

@@ -758,6 +758,8 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
@SuppressWarnings("rawtypes")
private static final class ByIdsSpecification<T> implements Specification<T> {
private static final long serialVersionUID = 1L;
private final JpaEntityInformation<T, ?> entityInformation;
@Nullable ParameterExpression<Iterable> parameter;
@@ -788,6 +790,8 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
*/
private static class ExampleSpecification<T> implements Specification<T> {
private static final long serialVersionUID = 1L;
private final Example<T> example;
/**