Skip to content

Commit

Permalink
Extract repeated string literals in SimpleJpaRepository to constants.
Browse files Browse the repository at this point in the history
Closes #3698
  • Loading branch information
dukbong authored and mp911de committed Dec 10, 2024
1 parent a1be5bc commit 2812496
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T

private static final String ID_MUST_NOT_BE_NULL = "The given id must not be null";
private static final String IDS_MUST_NOT_BE_NULL = "Ids must not be null";
private static final String ENTITY_MUST_NOT_BE_NULL = "Entity must not be null";
private static final String ENTITIES_MUST_NOT_BE_NULL = "Entities must not be null";
private static final String EXAMPLE_MUST_NOT_BE_NULL = "Example must not be null";
private static final String SPECIFICATION_MUST_NOT_BE_NULL = "Specification 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 EntityManager entityManager;
Expand Down Expand Up @@ -190,7 +194,7 @@ public void deleteById(ID id) {
@SuppressWarnings("unchecked")
public void delete(T entity) {

Assert.notNull(entity, "Entity must not be null");
Assert.notNull(entity, ENTITY_MUST_NOT_BE_NULL);

if (entityInformation.isNew(entity)) {
return;
Expand Down Expand Up @@ -490,17 +494,17 @@ public long delete(@Nullable Specification<T> spec) {
@Override
public <S extends T, R> R findBy(Specification<T> spec, Function<FetchableFluentQuery<S>, R> queryFunction) {

Assert.notNull(spec, "Specification must not be null");
Assert.notNull(queryFunction, "Query function must not be null");
Assert.notNull(spec, SPECIFICATION_MUST_NOT_BE_NULL);
Assert.notNull(queryFunction, QUERY_FUNCTION_MUST_NOT_BE_NULL);

return doFindBy(spec, getDomainClass(), queryFunction);
}

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

Assert.notNull(spec, "Specification must not be null");
Assert.notNull(queryFunction, "Query function must not be null");
Assert.notNull(spec, SPECIFICATION_MUST_NOT_BE_NULL);
Assert.notNull(queryFunction, QUERY_FUNCTION_MUST_NOT_BE_NULL);

ScrollQueryFactory scrollFunction = (sort, scrollPosition) -> {

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

Assert.notNull(example, "Example must not be null");
Assert.notNull(queryFunction, "Query function must not be null");
Assert.notNull(example, EXAMPLE_MUST_NOT_BE_NULL);
Assert.notNull(queryFunction, QUERY_FUNCTION_MUST_NOT_BE_NULL);

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

Assert.notNull(entity, "Entity must not be null");
Assert.notNull(entity, ENTITY_MUST_NOT_BE_NULL);

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

Assert.notNull(example, "Example must not be null");
Assert.notNull(example, EXAMPLE_MUST_NOT_BE_NULL);
Assert.notNull(escapeCharacter, "EscapeCharacter must not be null");

this.example = example;
Expand Down

0 comments on commit 2812496

Please sign in to comment.