Polishing.
Extract assertion message constants from QuerydslJpaPredicateExecutor. See #3698
This commit is contained in:
@@ -75,6 +75,12 @@ import com.querydsl.jpa.impl.AbstractJPAQuery;
|
||||
*/
|
||||
public class QuerydslJpaPredicateExecutor<T> implements QuerydslPredicateExecutor<T>, JpaRepositoryConfigurationAware {
|
||||
|
||||
private static final String PREDICATE_MUST_NOT_BE_NULL = "Predicate must not be null";
|
||||
private static final String ORDER_SPECIFIERS_MUST_NOT_BE_NULL = "Order specifiers must not be null";
|
||||
private static final String SORT_MUST_NOT_BE_NULL = "Sort must not be null";
|
||||
private static final String PAGEABLE_MUST_NOT_BE_NULL = "Pageable must not be null";
|
||||
private static final String QUERY_FUNCTION_MUST_NOT_BE_NULL = "Query function must not be null";
|
||||
|
||||
private final JpaEntityInformation<T, ?> entityInformation;
|
||||
private final EntityPath<T> path;
|
||||
private final Querydsl querydsl;
|
||||
@@ -116,7 +122,7 @@ public class QuerydslJpaPredicateExecutor<T> implements QuerydslPredicateExecuto
|
||||
@Override
|
||||
public Optional<T> findOne(Predicate predicate) {
|
||||
|
||||
Assert.notNull(predicate, "Predicate must not be null");
|
||||
Assert.notNull(predicate, PREDICATE_MUST_NOT_BE_NULL);
|
||||
|
||||
try {
|
||||
return Optional.ofNullable(createQuery(predicate).select(path).limit(2).fetchOne());
|
||||
@@ -128,7 +134,7 @@ public class QuerydslJpaPredicateExecutor<T> implements QuerydslPredicateExecuto
|
||||
@Override
|
||||
public List<T> findAll(Predicate predicate) {
|
||||
|
||||
Assert.notNull(predicate, "Predicate must not be null");
|
||||
Assert.notNull(predicate, PREDICATE_MUST_NOT_BE_NULL);
|
||||
|
||||
return createQuery(predicate).select(path).fetch();
|
||||
}
|
||||
@@ -136,8 +142,8 @@ public class QuerydslJpaPredicateExecutor<T> implements QuerydslPredicateExecuto
|
||||
@Override
|
||||
public List<T> findAll(Predicate predicate, OrderSpecifier<?>... orders) {
|
||||
|
||||
Assert.notNull(predicate, "Predicate must not be null");
|
||||
Assert.notNull(orders, "Order specifiers must not be null");
|
||||
Assert.notNull(predicate, PREDICATE_MUST_NOT_BE_NULL);
|
||||
Assert.notNull(orders, ORDER_SPECIFIERS_MUST_NOT_BE_NULL);
|
||||
|
||||
return executeSorted(createQuery(predicate).select(path), orders);
|
||||
}
|
||||
@@ -145,8 +151,8 @@ public class QuerydslJpaPredicateExecutor<T> implements QuerydslPredicateExecuto
|
||||
@Override
|
||||
public List<T> findAll(Predicate predicate, Sort sort) {
|
||||
|
||||
Assert.notNull(predicate, "Predicate must not be null");
|
||||
Assert.notNull(sort, "Sort must not be null");
|
||||
Assert.notNull(predicate, PREDICATE_MUST_NOT_BE_NULL);
|
||||
Assert.notNull(sort, SORT_MUST_NOT_BE_NULL);
|
||||
|
||||
return executeSorted(createQuery(predicate).select(path), sort);
|
||||
}
|
||||
@@ -154,7 +160,7 @@ public class QuerydslJpaPredicateExecutor<T> implements QuerydslPredicateExecuto
|
||||
@Override
|
||||
public List<T> findAll(OrderSpecifier<?>... orders) {
|
||||
|
||||
Assert.notNull(orders, "Order specifiers must not be null");
|
||||
Assert.notNull(orders, ORDER_SPECIFIERS_MUST_NOT_BE_NULL);
|
||||
|
||||
return executeSorted(createQuery(new Predicate[0]).select(path), orders);
|
||||
}
|
||||
@@ -162,8 +168,8 @@ public class QuerydslJpaPredicateExecutor<T> implements QuerydslPredicateExecuto
|
||||
@Override
|
||||
public Page<T> findAll(Predicate predicate, Pageable pageable) {
|
||||
|
||||
Assert.notNull(predicate, "Predicate must not be null");
|
||||
Assert.notNull(pageable, "Pageable must not be null");
|
||||
Assert.notNull(predicate, PREDICATE_MUST_NOT_BE_NULL);
|
||||
Assert.notNull(pageable, PAGEABLE_MUST_NOT_BE_NULL);
|
||||
|
||||
final JPQLQuery<?> countQuery = createCountQuery(predicate);
|
||||
JPQLQuery<T> query = querydsl.applyPagination(pageable, createQuery(predicate).select(path));
|
||||
@@ -175,8 +181,8 @@ public class QuerydslJpaPredicateExecutor<T> implements QuerydslPredicateExecuto
|
||||
@Override
|
||||
public <S extends T, R> R findBy(Predicate predicate, Function<FetchableFluentQuery<S>, R> queryFunction) {
|
||||
|
||||
Assert.notNull(predicate, "Predicate must not be null");
|
||||
Assert.notNull(queryFunction, "Query function must not be null");
|
||||
Assert.notNull(predicate, PREDICATE_MUST_NOT_BE_NULL);
|
||||
Assert.notNull(queryFunction, QUERY_FUNCTION_MUST_NOT_BE_NULL);
|
||||
|
||||
Function<Sort, AbstractJPAQuery<?, ?>> finder = sort -> {
|
||||
AbstractJPAQuery<?, ?> select = (AbstractJPAQuery<?, ?>) createQuery(predicate).select(path);
|
||||
@@ -260,7 +266,7 @@ public class QuerydslJpaPredicateExecutor<T> implements QuerydslPredicateExecuto
|
||||
*/
|
||||
protected AbstractJPAQuery<?, ?> createQuery(Predicate... predicate) {
|
||||
|
||||
Assert.notNull(predicate, "Predicate must not be null");
|
||||
Assert.notNull(predicate, PREDICATE_MUST_NOT_BE_NULL);
|
||||
|
||||
AbstractJPAQuery<?, ?> query = doCreateQuery(getQueryHints().withFetchGraphs(entityManager), predicate);
|
||||
CrudMethodMetadata metadata = getRepositoryMethodMetadata();
|
||||
|
||||
Reference in New Issue
Block a user