diff --git a/spring-data-envers/src/main/java/org/springframework/data/envers/repository/support/EnversRevisionRepositoryImpl.java b/spring-data-envers/src/main/java/org/springframework/data/envers/repository/support/EnversRevisionRepositoryImpl.java index 334aa60ee8..46a92c6d8c 100755 --- a/spring-data-envers/src/main/java/org/springframework/data/envers/repository/support/EnversRevisionRepositoryImpl.java +++ b/spring-data-envers/src/main/java/org/springframework/data/envers/repository/support/EnversRevisionRepositoryImpl.java @@ -15,7 +15,15 @@ */ package org.springframework.data.envers.repository.support; +import static org.springframework.data.history.RevisionMetadata.RevisionType.*; + import jakarta.persistence.EntityManager; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + import org.hibernate.Hibernate; import org.hibernate.envers.AuditReader; import org.hibernate.envers.AuditReaderFactory; @@ -43,13 +51,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -import static org.springframework.data.history.RevisionMetadata.RevisionType.*; - /** * Repository implementation using Hibernate Envers to implement revision specific query methods. * @@ -61,6 +62,8 @@ * @author Mark Paluch * @author Sander Bylemans * @author Niklas Loechte + * @author Donghun Shin + * @author Greg Turnquist */ @Transactional(readOnly = true) public class EnversRevisionRepositoryImpl> @@ -73,12 +76,12 @@ public class EnversRevisionRepositoryImpl entityInformation, - RevisionEntityInformation revisionEntityInformation, EntityManager entityManager) { + RevisionEntityInformation revisionEntityInformation, EntityManager entityManager) { Assert.notNull(revisionEntityInformation, "RevisionEntityInformation must not be null!"); @@ -136,7 +139,6 @@ public Revisions findRevisions(ID id) { return Revisions.of(revisionList); } - private AuditOrder mapRevisionSort(RevisionSort revisionSort) { return RevisionSort.getRevisionDirection(revisionSort).isDescending() // @@ -154,9 +156,9 @@ private List mapPropertySort(Sort sort) { for (Sort.Order order : sort) { AuditProperty property = AuditEntity.property(order.getProperty()); - AuditOrder auditOrder = order.getDirection().isAscending() ? - property.asc() : - property.desc(); + AuditOrder auditOrder = order.getDirection().isAscending() // + ? property.asc() // + : property.desc(); result.add(auditOrder); } @@ -169,9 +171,9 @@ public Page> findRevisions(ID id, Pageable pageable) { AuditQuery baseQuery = createBaseQuery(id); - List orderMapped = (pageable.getSort() instanceof RevisionSort revisionSort) ? - Collections.singletonList(mapRevisionSort(revisionSort)) : - mapPropertySort(pageable.getSort()); + List orderMapped = (pageable.getSort()instanceof RevisionSort revisionSort) + ? List.of(mapRevisionSort(revisionSort)) + : mapPropertySort(pageable.getSort()); orderMapped.forEach(baseQuery::addOrder); @@ -235,17 +237,17 @@ RevisionMetadata createRevisionMetadata() { return metadata instanceof DefaultRevisionEntity defaultRevisionEntity // ? new DefaultRevisionMetadata(defaultRevisionEntity, revisionType) // : new AnnotationRevisionMetadata<>(Hibernate.unproxy(metadata), RevisionNumber.class, RevisionTimestamp.class, - revisionType); + revisionType); } private static RevisionMetadata.RevisionType convertRevisionType(RevisionType datum) { - return switch (datum) { - case ADD -> INSERT; - case MOD -> UPDATE; - case DEL -> DELETE; - default -> UNKNOWN; - }; + return switch (datum) { + case ADD -> INSERT; + case MOD -> UPDATE; + case DEL -> DELETE; + default -> UNKNOWN; + }; } } diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/provider/HibernateUtils.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/provider/HibernateUtils.java index 98e65c2d96..ccecfb52a4 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/provider/HibernateUtils.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/provider/HibernateUtils.java @@ -26,6 +26,8 @@ * @author Oliver Gierke * @author Mark Paluch * @author Jens Schauder + * @author Donghun Shin + * @author Greg Turnquist * @since 1.10.2 * @soundtrack Benny Greb - Soulfood (Live, https://www.youtube.com/watch?v=9_ErMa_CtSw) */ @@ -54,8 +56,8 @@ public static String getHibernateQuery(Object query) { // Try the old way, as it still works in some cases (haven't investigated in which exactly) - if (query instanceof Query) { - return ((Query) query).getQueryString(); + if (query instanceof Query hibernateQuery) { + return hibernateQuery.getQueryString(); } else { throw new IllegalArgumentException("Don't know how to extract the query string from " + query); } diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/provider/JpaClassUtils.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/provider/JpaClassUtils.java index 10de0aad25..2bd740a458 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/provider/JpaClassUtils.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/provider/JpaClassUtils.java @@ -28,6 +28,8 @@ * @author Oliver Gierke * @author Christoph Strobl * @author Jens Schauder + * @author Donghun Shin + * @author Greg Turnquist */ abstract class JpaClassUtils { @@ -45,12 +47,9 @@ private JpaClassUtils() {} */ public static boolean isEntityManagerOfType(EntityManager em, String type) { - EntityManager entityManagerToUse = em; - Object delegate = em.getDelegate(); - - if (delegate instanceof EntityManager delegateEntityManager) { - entityManagerToUse = delegateEntityManager; - } + EntityManager entityManagerToUse = em.getDelegate()instanceof EntityManager delegate // + ? delegate // + : em; return isOfType(entityManagerToUse, type, entityManagerToUse.getClass().getClassLoader()); } diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/cdi/JpaRepositoryExtension.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/cdi/JpaRepositoryExtension.java index 2e345c22a0..4329893e44 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/cdi/JpaRepositoryExtension.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/cdi/JpaRepositoryExtension.java @@ -15,6 +15,14 @@ */ package org.springframework.data.jpa.repository.cdi; +import jakarta.enterprise.event.Observes; +import jakarta.enterprise.inject.UnsatisfiedResolutionException; +import jakarta.enterprise.inject.spi.AfterBeanDiscovery; +import jakarta.enterprise.inject.spi.Bean; +import jakarta.enterprise.inject.spi.BeanManager; +import jakarta.enterprise.inject.spi.ProcessBean; +import jakarta.persistence.EntityManager; + import java.lang.annotation.Annotation; import java.lang.reflect.Type; import java.util.HashMap; @@ -24,14 +32,6 @@ import java.util.Optional; import java.util.Set; -import jakarta.enterprise.event.Observes; -import jakarta.enterprise.inject.UnsatisfiedResolutionException; -import jakarta.enterprise.inject.spi.AfterBeanDiscovery; -import jakarta.enterprise.inject.spi.Bean; -import jakarta.enterprise.inject.spi.BeanManager; -import jakarta.enterprise.inject.spi.ProcessBean; -import jakarta.persistence.EntityManager; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.data.repository.cdi.CdiRepositoryBean; @@ -44,6 +44,7 @@ * @author Oliver Gierke * @author Mark Paluch * @author Christoph Strobl + * @author Donghun Shin */ public class JpaRepositoryExtension extends CdiRepositoryExtensionSupport { diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryTransformerSupport.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryTransformerSupport.java index 13ad183fd2..6c730e7924 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryTransformerSupport.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryTransformerSupport.java @@ -18,6 +18,7 @@ * Transformational operations needed to support either {@link HqlQueryTransformer} or {@link JpqlQueryTransformer}. * * @author Greg Turnquist + * @author Donghun Shin * @since 3.1 */ class JpaQueryTransformerSupport { diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/Meta.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/Meta.java index 771d8b5827..f5f7a3fe14 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/Meta.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/Meta.java @@ -27,6 +27,7 @@ * Value object to hold metadata about repository methods. * * @author Greg Turnquist + * @author Donghun Shin * @since 3.0 * @see org.springframework.data.jpa.repository.Meta */ diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/ParameterMetadataProvider.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/ParameterMetadataProvider.java index 52cc951561..0b1d9a0709 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/ParameterMetadataProvider.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/ParameterMetadataProvider.java @@ -18,7 +18,12 @@ import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.ParameterExpression; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -46,6 +51,8 @@ * @author Jens Schauder * @author Andrey Kovalev * @author Yuriy Tsarkov + * @author Donghun Shin + * @author Greg Turnquist */ class ParameterMetadataProvider { @@ -275,7 +282,6 @@ private static Collection toCollection(@Nullable Object value) { } if (value instanceof Collection collection) { - return collection.isEmpty() ? null : collection; } diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java index 0b781b33d4..021e375807 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java @@ -80,6 +80,7 @@ * @author Simon Paradies * @author Vladislav Yukharin * @author Chris Fraser + * @author Donghun Shin */ public abstract class QueryUtils { diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/EntityManagerBeanDefinitionRegistrarPostProcessor.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/EntityManagerBeanDefinitionRegistrarPostProcessor.java index cf3ed03ff0..6e20a4b347 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/EntityManagerBeanDefinitionRegistrarPostProcessor.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/EntityManagerBeanDefinitionRegistrarPostProcessor.java @@ -43,6 +43,7 @@ * @author Oliver Gierke * @author RĂ©da Housni Alaoui * @author Mark Paluch + * @author Donghun Shin */ public class EntityManagerBeanDefinitionRegistrarPostProcessor implements BeanFactoryPostProcessor, Ordered { diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/Querydsl.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/Querydsl.java index 9cc1017a47..ee832ce71a 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/Querydsl.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/Querydsl.java @@ -48,6 +48,7 @@ * @author Mark Paluch * @author Christoph Strobl * @author Marcus Voltolim + * @author Donghun Shin */ public class Querydsl { diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/util/BeanDefinitionUtils.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/util/BeanDefinitionUtils.java index 322cf3095d..6f74e8c563 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/util/BeanDefinitionUtils.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/util/BeanDefinitionUtils.java @@ -18,6 +18,8 @@ import static java.util.Arrays.*; import static org.springframework.beans.factory.BeanFactoryUtils.*; +import jakarta.persistence.EntityManagerFactory; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -25,8 +27,6 @@ import java.util.List; import java.util.Set; -import jakarta.persistence.EntityManagerFactory; - import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.NoSuchBeanDefinitionException; @@ -43,6 +43,7 @@ * * @author Oliver Gierke * @author Mark Paluch + * @author Donghun Shin */ public final class BeanDefinitionUtils {