Skip to content

Commit 9cd3d63

Browse files
dukbongmp911de
authored andcommitted
Extract repeated string literals in SimpleJpaRepository to constants.
Closes #3698
1 parent e4a2416 commit 9cd3d63

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

Lines changed: 13 additions & 9 deletions
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;
@@ -490,17 +494,17 @@ public long delete(@Nullable Specification<T> spec) {
490494
@Override
491495
public <S extends T, R> R findBy(Specification<T> spec, Function<FetchableFluentQuery<S>, R> queryFunction) {
492496

493-
Assert.notNull(spec, "Specification must not be null");
494-
Assert.notNull(queryFunction, "Query function must not be null");
497+
Assert.notNull(spec, SPECIFICATION_MUST_NOT_BE_NULL);
498+
Assert.notNull(queryFunction, QUERY_FUNCTION_MUST_NOT_BE_NULL);
495499

496500
return doFindBy(spec, getDomainClass(), queryFunction);
497501
}
498502

499503
private <S extends T, R> R doFindBy(Specification<T> spec, Class<T> domainClass,
500504
Function<FetchableFluentQuery<S>, R> queryFunction) {
501505

502-
Assert.notNull(spec, "Specification must not be null");
503-
Assert.notNull(queryFunction, "Query function must not be null");
506+
Assert.notNull(spec, SPECIFICATION_MUST_NOT_BE_NULL);
507+
Assert.notNull(queryFunction, QUERY_FUNCTION_MUST_NOT_BE_NULL);
504508

505509
ScrollQueryFactory scrollFunction = (sort, scrollPosition) -> {
506510

@@ -589,8 +593,8 @@ public <S extends T> Page<S> findAll(Example<S> example, Pageable pageable) {
589593
@Override
590594
public <S extends T, R> R findBy(Example<S> example, Function<FetchableFluentQuery<S>, R> queryFunction) {
591595

592-
Assert.notNull(example, "Example must not be null");
593-
Assert.notNull(queryFunction, "Query function must not be null");
596+
Assert.notNull(example, EXAMPLE_MUST_NOT_BE_NULL);
597+
Assert.notNull(queryFunction, QUERY_FUNCTION_MUST_NOT_BE_NULL);
594598

595599
ExampleSpecification<S> spec = new ExampleSpecification<>(example, escapeCharacter);
596600
Class<S> probeType = example.getProbeType();
@@ -617,7 +621,7 @@ public long count(@Nullable Specification<T> spec) {
617621
@Transactional
618622
public <S extends T> S save(S entity) {
619623

620-
Assert.notNull(entity, "Entity must not be null");
624+
Assert.notNull(entity, ENTITY_MUST_NOT_BE_NULL);
621625

622626
if (entityInformation.isNew(entity)) {
623627
entityManager.persist(entity);
@@ -990,7 +994,7 @@ private static class ExampleSpecification<T> implements Specification<T> {
990994
*/
991995
ExampleSpecification(Example<T> example, EscapeCharacter escapeCharacter) {
992996

993-
Assert.notNull(example, "Example must not be null");
997+
Assert.notNull(example, EXAMPLE_MUST_NOT_BE_NULL);
994998
Assert.notNull(escapeCharacter, "EscapeCharacter must not be null");
995999

9961000
this.example = example;

0 commit comments

Comments
 (0)