@@ -15,7 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.envers.repository.support;
|
package org.springframework.data.envers.repository.support;
|
||||||
|
|
||||||
|
import static org.springframework.data.history.RevisionMetadata.RevisionType.*;
|
||||||
|
|
||||||
import jakarta.persistence.EntityManager;
|
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.Hibernate;
|
||||||
import org.hibernate.envers.AuditReader;
|
import org.hibernate.envers.AuditReader;
|
||||||
import org.hibernate.envers.AuditReaderFactory;
|
import org.hibernate.envers.AuditReaderFactory;
|
||||||
@@ -43,13 +51,6 @@ import org.springframework.data.repository.history.support.RevisionEntityInforma
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.Assert;
|
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.
|
* Repository implementation using Hibernate Envers to implement revision specific query methods.
|
||||||
*
|
*
|
||||||
@@ -61,6 +62,8 @@ import static org.springframework.data.history.RevisionMetadata.RevisionType.*;
|
|||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
* @author Sander Bylemans
|
* @author Sander Bylemans
|
||||||
* @author Niklas Loechte
|
* @author Niklas Loechte
|
||||||
|
* @author Donghun Shin
|
||||||
|
* @author Greg Turnquist
|
||||||
*/
|
*/
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public class EnversRevisionRepositoryImpl<T, ID, N extends Number & Comparable<N>>
|
public class EnversRevisionRepositoryImpl<T, ID, N extends Number & Comparable<N>>
|
||||||
@@ -73,12 +76,12 @@ public class EnversRevisionRepositoryImpl<T, ID, N extends Number & Comparable<N
|
|||||||
* Creates a new {@link EnversRevisionRepositoryImpl} using the given {@link JpaEntityInformation},
|
* Creates a new {@link EnversRevisionRepositoryImpl} using the given {@link JpaEntityInformation},
|
||||||
* {@link RevisionEntityInformation} and {@link EntityManager}.
|
* {@link RevisionEntityInformation} and {@link EntityManager}.
|
||||||
*
|
*
|
||||||
* @param entityInformation must not be {@literal null}.
|
* @param entityInformation must not be {@literal null}.
|
||||||
* @param revisionEntityInformation must not be {@literal null}.
|
* @param revisionEntityInformation must not be {@literal null}.
|
||||||
* @param entityManager must not be {@literal null}.
|
* @param entityManager must not be {@literal null}.
|
||||||
*/
|
*/
|
||||||
public EnversRevisionRepositoryImpl(JpaEntityInformation<T, ?> entityInformation,
|
public EnversRevisionRepositoryImpl(JpaEntityInformation<T, ?> entityInformation,
|
||||||
RevisionEntityInformation revisionEntityInformation, EntityManager entityManager) {
|
RevisionEntityInformation revisionEntityInformation, EntityManager entityManager) {
|
||||||
|
|
||||||
Assert.notNull(revisionEntityInformation, "RevisionEntityInformation must not be null!");
|
Assert.notNull(revisionEntityInformation, "RevisionEntityInformation must not be null!");
|
||||||
|
|
||||||
@@ -136,7 +139,6 @@ public class EnversRevisionRepositoryImpl<T, ID, N extends Number & Comparable<N
|
|||||||
return Revisions.of(revisionList);
|
return Revisions.of(revisionList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private AuditOrder mapRevisionSort(RevisionSort revisionSort) {
|
private AuditOrder mapRevisionSort(RevisionSort revisionSort) {
|
||||||
|
|
||||||
return RevisionSort.getRevisionDirection(revisionSort).isDescending() //
|
return RevisionSort.getRevisionDirection(revisionSort).isDescending() //
|
||||||
@@ -154,9 +156,9 @@ public class EnversRevisionRepositoryImpl<T, ID, N extends Number & Comparable<N
|
|||||||
for (Sort.Order order : sort) {
|
for (Sort.Order order : sort) {
|
||||||
|
|
||||||
AuditProperty<Object> property = AuditEntity.property(order.getProperty());
|
AuditProperty<Object> property = AuditEntity.property(order.getProperty());
|
||||||
AuditOrder auditOrder = order.getDirection().isAscending() ?
|
AuditOrder auditOrder = order.getDirection().isAscending() //
|
||||||
property.asc() :
|
? property.asc() //
|
||||||
property.desc();
|
: property.desc();
|
||||||
|
|
||||||
result.add(auditOrder);
|
result.add(auditOrder);
|
||||||
}
|
}
|
||||||
@@ -169,9 +171,9 @@ public class EnversRevisionRepositoryImpl<T, ID, N extends Number & Comparable<N
|
|||||||
|
|
||||||
AuditQuery baseQuery = createBaseQuery(id);
|
AuditQuery baseQuery = createBaseQuery(id);
|
||||||
|
|
||||||
List<AuditOrder> orderMapped = (pageable.getSort() instanceof RevisionSort revisionSort) ?
|
List<AuditOrder> orderMapped = (pageable.getSort()instanceof RevisionSort revisionSort)
|
||||||
Collections.singletonList(mapRevisionSort(revisionSort)) :
|
? List.of(mapRevisionSort(revisionSort))
|
||||||
mapPropertySort(pageable.getSort());
|
: mapPropertySort(pageable.getSort());
|
||||||
|
|
||||||
orderMapped.forEach(baseQuery::addOrder);
|
orderMapped.forEach(baseQuery::addOrder);
|
||||||
|
|
||||||
@@ -235,17 +237,17 @@ public class EnversRevisionRepositoryImpl<T, ID, N extends Number & Comparable<N
|
|||||||
return metadata instanceof DefaultRevisionEntity defaultRevisionEntity //
|
return metadata instanceof DefaultRevisionEntity defaultRevisionEntity //
|
||||||
? new DefaultRevisionMetadata(defaultRevisionEntity, revisionType) //
|
? new DefaultRevisionMetadata(defaultRevisionEntity, revisionType) //
|
||||||
: new AnnotationRevisionMetadata<>(Hibernate.unproxy(metadata), RevisionNumber.class, RevisionTimestamp.class,
|
: new AnnotationRevisionMetadata<>(Hibernate.unproxy(metadata), RevisionNumber.class, RevisionTimestamp.class,
|
||||||
revisionType);
|
revisionType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static RevisionMetadata.RevisionType convertRevisionType(RevisionType datum) {
|
private static RevisionMetadata.RevisionType convertRevisionType(RevisionType datum) {
|
||||||
|
|
||||||
return switch (datum) {
|
return switch (datum) {
|
||||||
case ADD -> INSERT;
|
case ADD -> INSERT;
|
||||||
case MOD -> UPDATE;
|
case MOD -> UPDATE;
|
||||||
case DEL -> DELETE;
|
case DEL -> DELETE;
|
||||||
default -> UNKNOWN;
|
default -> UNKNOWN;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import org.springframework.lang.Nullable;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
* @author Jens Schauder
|
* @author Jens Schauder
|
||||||
|
* @author Donghun Shin
|
||||||
|
* @author Greg Turnquist
|
||||||
* @since 1.10.2
|
* @since 1.10.2
|
||||||
* @soundtrack Benny Greb - Soulfood (Live, https://www.youtube.com/watch?v=9_ErMa_CtSw)
|
* @soundtrack Benny Greb - Soulfood (Live, https://www.youtube.com/watch?v=9_ErMa_CtSw)
|
||||||
*/
|
*/
|
||||||
@@ -54,8 +56,8 @@ public abstract class HibernateUtils {
|
|||||||
|
|
||||||
// Try the old way, as it still works in some cases (haven't investigated in which exactly)
|
// Try the old way, as it still works in some cases (haven't investigated in which exactly)
|
||||||
|
|
||||||
if (query instanceof Query) {
|
if (query instanceof Query<?> hibernateQuery) {
|
||||||
return ((Query<?>) query).getQueryString();
|
return hibernateQuery.getQueryString();
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Don't know how to extract the query string from " + query);
|
throw new IllegalArgumentException("Don't know how to extract the query string from " + query);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ import org.springframework.util.ClassUtils;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Jens Schauder
|
* @author Jens Schauder
|
||||||
|
* @author Donghun Shin
|
||||||
|
* @author Greg Turnquist
|
||||||
*/
|
*/
|
||||||
abstract class JpaClassUtils {
|
abstract class JpaClassUtils {
|
||||||
|
|
||||||
@@ -45,12 +47,9 @@ abstract class JpaClassUtils {
|
|||||||
*/
|
*/
|
||||||
public static boolean isEntityManagerOfType(EntityManager em, String type) {
|
public static boolean isEntityManagerOfType(EntityManager em, String type) {
|
||||||
|
|
||||||
EntityManager entityManagerToUse = em;
|
EntityManager entityManagerToUse = em.getDelegate()instanceof EntityManager delegate //
|
||||||
Object delegate = em.getDelegate();
|
? delegate //
|
||||||
|
: em;
|
||||||
if (delegate instanceof EntityManager delegateEntityManager) {
|
|
||||||
entityManagerToUse = delegateEntityManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
return isOfType(entityManagerToUse, type, entityManagerToUse.getClass().getClassLoader());
|
return isOfType(entityManagerToUse, type, entityManagerToUse.getClass().getClassLoader());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.jpa.repository.cdi;
|
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.annotation.Annotation;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -24,14 +32,6 @@ import java.util.Map.Entry;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
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.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.data.repository.cdi.CdiRepositoryBean;
|
import org.springframework.data.repository.cdi.CdiRepositoryBean;
|
||||||
@@ -44,6 +44,7 @@ import org.springframework.data.repository.cdi.CdiRepositoryExtensionSupport;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
|
* @author Donghun Shin
|
||||||
*/
|
*/
|
||||||
public class JpaRepositoryExtension extends CdiRepositoryExtensionSupport {
|
public class JpaRepositoryExtension extends CdiRepositoryExtensionSupport {
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import org.springframework.util.ObjectUtils;
|
|||||||
* Transformational operations needed to support either {@link HqlQueryTransformer} or {@link JpqlQueryTransformer}.
|
* Transformational operations needed to support either {@link HqlQueryTransformer} or {@link JpqlQueryTransformer}.
|
||||||
*
|
*
|
||||||
* @author Greg Turnquist
|
* @author Greg Turnquist
|
||||||
|
* @author Donghun Shin
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
class JpaQueryTransformerSupport {
|
class JpaQueryTransformerSupport {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import org.springframework.util.StringUtils;
|
|||||||
* Value object to hold metadata about repository methods.
|
* Value object to hold metadata about repository methods.
|
||||||
*
|
*
|
||||||
* @author Greg Turnquist
|
* @author Greg Turnquist
|
||||||
|
* @author Donghun Shin
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
* @see org.springframework.data.jpa.repository.Meta
|
* @see org.springframework.data.jpa.repository.Meta
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -18,7 +18,12 @@ package org.springframework.data.jpa.repository.query;
|
|||||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||||
import jakarta.persistence.criteria.ParameterExpression;
|
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.function.Supplier;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -46,6 +51,8 @@ import org.springframework.util.ObjectUtils;
|
|||||||
* @author Jens Schauder
|
* @author Jens Schauder
|
||||||
* @author Andrey Kovalev
|
* @author Andrey Kovalev
|
||||||
* @author Yuriy Tsarkov
|
* @author Yuriy Tsarkov
|
||||||
|
* @author Donghun Shin
|
||||||
|
* @author Greg Turnquist
|
||||||
*/
|
*/
|
||||||
class ParameterMetadataProvider {
|
class ParameterMetadataProvider {
|
||||||
|
|
||||||
@@ -275,7 +282,6 @@ class ParameterMetadataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (value instanceof Collection<?> collection) {
|
if (value instanceof Collection<?> collection) {
|
||||||
|
|
||||||
return collection.isEmpty() ? null : collection;
|
return collection.isEmpty() ? null : collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ import org.springframework.util.StringUtils;
|
|||||||
* @author Simon Paradies
|
* @author Simon Paradies
|
||||||
* @author Vladislav Yukharin
|
* @author Vladislav Yukharin
|
||||||
* @author Chris Fraser
|
* @author Chris Fraser
|
||||||
|
* @author Donghun Shin
|
||||||
*/
|
*/
|
||||||
public abstract class QueryUtils {
|
public abstract class QueryUtils {
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import org.springframework.orm.jpa.SharedEntityManagerCreator;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author Réda Housni Alaoui
|
* @author Réda Housni Alaoui
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
|
* @author Donghun Shin
|
||||||
*/
|
*/
|
||||||
public class EntityManagerBeanDefinitionRegistrarPostProcessor implements BeanFactoryPostProcessor, Ordered {
|
public class EntityManagerBeanDefinitionRegistrarPostProcessor implements BeanFactoryPostProcessor, Ordered {
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import com.querydsl.jpa.impl.JPAQuery;
|
|||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Marcus Voltolim
|
* @author Marcus Voltolim
|
||||||
|
* @author Donghun Shin
|
||||||
*/
|
*/
|
||||||
public class Querydsl {
|
public class Querydsl {
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ package org.springframework.data.jpa.util;
|
|||||||
import static java.util.Arrays.*;
|
import static java.util.Arrays.*;
|
||||||
import static org.springframework.beans.factory.BeanFactoryUtils.*;
|
import static org.springframework.beans.factory.BeanFactoryUtils.*;
|
||||||
|
|
||||||
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -25,8 +27,6 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import jakarta.persistence.EntityManagerFactory;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.beans.factory.ListableBeanFactory;
|
import org.springframework.beans.factory.ListableBeanFactory;
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
@@ -43,6 +43,7 @@ import org.springframework.util.ObjectUtils;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
|
* @author Donghun Shin
|
||||||
*/
|
*/
|
||||||
public final class BeanDefinitionUtils {
|
public final class BeanDefinitionUtils {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user