Skip to content

Commit 29f16ab

Browse files
dukbongmp911de
authored andcommitted
Extract repeated string literals in SimpleJpaRepository to constants.
Closes #3698
1 parent df04b02 commit 29f16ab

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

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

+13-9
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
100100

101101
private static final String ID_MUST_NOT_BE_NULL = "The given id must not be null";
102102
private static final String IDS_MUST_NOT_BE_NULL = "Ids must not be null";
103+
private static final String ENTITY_MUST_NOT_BE_NULL = "Entity must not be null";
103104
private static final String ENTITIES_MUST_NOT_BE_NULL = "Entities must not be null";
105+
private static final String EXAMPLE_MUST_NOT_BE_NULL = "Example must not be null";
106+
private static final String SPECIFICATION_MUST_NOT_BE_NULL = "Specification must not be null";
107+
private static final String QUERY_FUNCTION_MUST_NOT_BE_NULL = "Query function must not be null";
104108

105109
private final JpaEntityInformation<T, ?> entityInformation;
106110
private final EntityManager entityManager;
@@ -190,7 +194,7 @@ public void deleteById(ID id) {
190194
@SuppressWarnings("unchecked")
191195
public void delete(T entity) {
192196

193-
Assert.notNull(entity, "Entity must not be null");
197+
Assert.notNull(entity, ENTITY_MUST_NOT_BE_NULL);
194198

195199
if (entityInformation.isNew(entity)) {
196200
return;
@@ -495,17 +499,17 @@ public long delete(@Nullable Specification<T> spec) {
495499
@Override
496500
public <S extends T, R> R findBy(Specification<T> spec, Function<FetchableFluentQuery<S>, R> queryFunction) {
497501

498-
Assert.notNull(spec, "Specification must not be null");
499-
Assert.notNull(queryFunction, "Query function must not be null");
502+
Assert.notNull(spec, SPECIFICATION_MUST_NOT_BE_NULL);
503+
Assert.notNull(queryFunction, QUERY_FUNCTION_MUST_NOT_BE_NULL);
500504

501505
return doFindBy(spec, getDomainClass(), queryFunction);
502506
}
503507

504508
private <S extends T, R> R doFindBy(Specification<T> spec, Class<T> domainClass,
505509
Function<FetchableFluentQuery<S>, R> queryFunction) {
506510

507-
Assert.notNull(spec, "Specification must not be null");
508-
Assert.notNull(queryFunction, "Query function must not be null");
511+
Assert.notNull(spec, SPECIFICATION_MUST_NOT_BE_NULL);
512+
Assert.notNull(queryFunction, QUERY_FUNCTION_MUST_NOT_BE_NULL);
509513

510514
ScrollQueryFactory scrollFunction = (sort, scrollPosition) -> {
511515

@@ -594,8 +598,8 @@ public <S extends T> Page<S> findAll(Example<S> example, Pageable pageable) {
594598
@Override
595599
public <S extends T, R> R findBy(Example<S> example, Function<FetchableFluentQuery<S>, R> queryFunction) {
596600

597-
Assert.notNull(example, "Example must not be null");
598-
Assert.notNull(queryFunction, "Query function must not be null");
601+
Assert.notNull(example, EXAMPLE_MUST_NOT_BE_NULL);
602+
Assert.notNull(queryFunction, QUERY_FUNCTION_MUST_NOT_BE_NULL);
599603

600604
ExampleSpecification<S> spec = new ExampleSpecification<>(example, escapeCharacter);
601605
Class<S> probeType = example.getProbeType();
@@ -622,7 +626,7 @@ public long count(@Nullable Specification<T> spec) {
622626
@Transactional
623627
public <S extends T> S save(S entity) {
624628

625-
Assert.notNull(entity, "Entity must not be null");
629+
Assert.notNull(entity, ENTITY_MUST_NOT_BE_NULL);
626630

627631
if (entityInformation.isNew(entity)) {
628632
entityManager.persist(entity);
@@ -997,7 +1001,7 @@ private static class ExampleSpecification<T> implements Specification<T> {
9971001
*/
9981002
ExampleSpecification(Example<T> example, EscapeCharacter escapeCharacter) {
9991003

1000-
Assert.notNull(example, "Example must not be null");
1004+
Assert.notNull(example, EXAMPLE_MUST_NOT_BE_NULL);
10011005
Assert.notNull(escapeCharacter, "EscapeCharacter must not be null");
10021006

10031007
this.example = example;

0 commit comments

Comments
 (0)