Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Extract assertion message constants from QuerydslJpaPredicateExecutor.

See #3698
  • Loading branch information
mp911de committed Dec 10, 2024
1 parent 9cd3d63 commit c5f0c63
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
*/
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;
Expand Down Expand Up @@ -116,7 +122,7 @@ public void setProjectionFactory(ProjectionFactory projectionFactory) {
@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());
Expand All @@ -128,42 +134,42 @@ public Optional<T> findOne(Predicate predicate) {
@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();
}

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

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

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

@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));
Expand All @@ -175,8 +181,8 @@ public Page<T> findAll(Predicate predicate, Pageable pageable) {
@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);
Expand Down Expand Up @@ -260,7 +266,7 @@ public boolean exists(Predicate predicate) {
*/
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();
Expand Down

0 comments on commit c5f0c63

Please sign in to comment.