Skip to content

Commit 3cc84e8

Browse files
committed
Polishing.
Extract assertion message constants from QuerydslJpaPredicateExecutor. See #3698
1 parent 29f16ab commit 3cc84e8

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/QuerydslJpaPredicateExecutor.java

+18-12
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@
7575
*/
7676
public class QuerydslJpaPredicateExecutor<T> implements QuerydslPredicateExecutor<T>, JpaRepositoryConfigurationAware {
7777

78+
private static final String PREDICATE_MUST_NOT_BE_NULL = "Predicate must not be null";
79+
private static final String ORDER_SPECIFIERS_MUST_NOT_BE_NULL = "Order specifiers must not be null";
80+
private static final String SORT_MUST_NOT_BE_NULL = "Sort must not be null";
81+
private static final String PAGEABLE_MUST_NOT_BE_NULL = "Pageable must not be null";
82+
private static final String QUERY_FUNCTION_MUST_NOT_BE_NULL = "Query function must not be null";
83+
7884
private final JpaEntityInformation<T, ?> entityInformation;
7985
private final EntityPath<T> path;
8086
private final Querydsl querydsl;
@@ -116,7 +122,7 @@ public void setProjectionFactory(ProjectionFactory projectionFactory) {
116122
@Override
117123
public Optional<T> findOne(Predicate predicate) {
118124

119-
Assert.notNull(predicate, "Predicate must not be null");
125+
Assert.notNull(predicate, PREDICATE_MUST_NOT_BE_NULL);
120126

121127
try {
122128
return Optional.ofNullable(createQuery(predicate).select(path).limit(2).fetchOne());
@@ -128,42 +134,42 @@ public Optional<T> findOne(Predicate predicate) {
128134
@Override
129135
public List<T> findAll(Predicate predicate) {
130136

131-
Assert.notNull(predicate, "Predicate must not be null");
137+
Assert.notNull(predicate, PREDICATE_MUST_NOT_BE_NULL);
132138

133139
return createQuery(predicate).select(path).fetch();
134140
}
135141

136142
@Override
137143
public List<T> findAll(Predicate predicate, OrderSpecifier<?>... orders) {
138144

139-
Assert.notNull(predicate, "Predicate must not be null");
140-
Assert.notNull(orders, "Order specifiers must not be null");
145+
Assert.notNull(predicate, PREDICATE_MUST_NOT_BE_NULL);
146+
Assert.notNull(orders, ORDER_SPECIFIERS_MUST_NOT_BE_NULL);
141147

142148
return executeSorted(createQuery(predicate).select(path), orders);
143149
}
144150

145151
@Override
146152
public List<T> findAll(Predicate predicate, Sort sort) {
147153

148-
Assert.notNull(predicate, "Predicate must not be null");
149-
Assert.notNull(sort, "Sort must not be null");
154+
Assert.notNull(predicate, PREDICATE_MUST_NOT_BE_NULL);
155+
Assert.notNull(sort, SORT_MUST_NOT_BE_NULL);
150156

151157
return executeSorted(createQuery(predicate).select(path), sort);
152158
}
153159

154160
@Override
155161
public List<T> findAll(OrderSpecifier<?>... orders) {
156162

157-
Assert.notNull(orders, "Order specifiers must not be null");
163+
Assert.notNull(orders, ORDER_SPECIFIERS_MUST_NOT_BE_NULL);
158164

159165
return executeSorted(createQuery(new Predicate[0]).select(path), orders);
160166
}
161167

162168
@Override
163169
public Page<T> findAll(Predicate predicate, Pageable pageable) {
164170

165-
Assert.notNull(predicate, "Predicate must not be null");
166-
Assert.notNull(pageable, "Pageable must not be null");
171+
Assert.notNull(predicate, PREDICATE_MUST_NOT_BE_NULL);
172+
Assert.notNull(pageable, PAGEABLE_MUST_NOT_BE_NULL);
167173

168174
final JPQLQuery<?> countQuery = createCountQuery(predicate);
169175
JPQLQuery<T> query = querydsl.applyPagination(pageable, createQuery(predicate).select(path));
@@ -175,8 +181,8 @@ public Page<T> findAll(Predicate predicate, Pageable pageable) {
175181
@Override
176182
public <S extends T, R> R findBy(Predicate predicate, Function<FetchableFluentQuery<S>, R> queryFunction) {
177183

178-
Assert.notNull(predicate, "Predicate must not be null");
179-
Assert.notNull(queryFunction, "Query function must not be null");
184+
Assert.notNull(predicate, PREDICATE_MUST_NOT_BE_NULL);
185+
Assert.notNull(queryFunction, QUERY_FUNCTION_MUST_NOT_BE_NULL);
180186

181187
Function<Sort, AbstractJPAQuery<?, ?>> finder = sort -> {
182188
AbstractJPAQuery<?, ?> select = (AbstractJPAQuery<?, ?>) createQuery(predicate).select(path);
@@ -260,7 +266,7 @@ public boolean exists(Predicate predicate) {
260266
*/
261267
protected AbstractJPAQuery<?, ?> createQuery(Predicate... predicate) {
262268

263-
Assert.notNull(predicate, "Predicate must not be null");
269+
Assert.notNull(predicate, PREDICATE_MUST_NOT_BE_NULL);
264270

265271
AbstractJPAQuery<?, ?> query = doCreateQuery(getQueryHints().withFetchGraphs(entityManager), predicate);
266272
CrudMethodMetadata metadata = getRepositoryMethodMetadata();

0 commit comments

Comments
 (0)