@@ -30,7 +30,7 @@ class CollectionUtils {
|
||||
* @param count the number of first elements to be included in the returned list.
|
||||
* @param list must not be {@literal null}
|
||||
* @return the returned sublist if the {@code list} is greater {@code count}.
|
||||
* @param <T>
|
||||
* @param <T> the element type of the lists.
|
||||
*/
|
||||
public static <T> List<T> getFirst(int count, List<T> list) {
|
||||
|
||||
@@ -47,7 +47,7 @@ class CollectionUtils {
|
||||
* @param count the number of last elements to be included in the returned list.
|
||||
* @param list must not be {@literal null}
|
||||
* @return the returned sublist if the {@code list} is greater {@code count}.
|
||||
* @param <T>
|
||||
* @param <T> the element type of the lists.
|
||||
*/
|
||||
public static <T> List<T> getLast(int count, List<T> list) {
|
||||
|
||||
|
||||
@@ -45,7 +45,9 @@ class JpaKeysetScrollQueryCreator extends JpaQueryCreator {
|
||||
public JpaKeysetScrollQueryCreator(PartTree tree, ReturnedType type, CriteriaBuilder builder,
|
||||
ParameterMetadataProvider provider, JpaEntityInformation<?, ?> entityInformation,
|
||||
KeysetScrollPosition scrollPosition) {
|
||||
|
||||
super(tree, type, builder, provider);
|
||||
|
||||
this.entityInformation = entityInformation;
|
||||
this.scrollPosition = scrollPosition;
|
||||
}
|
||||
|
||||
@@ -142,6 +142,7 @@ public abstract class JpaQueryExecution {
|
||||
private final ScrollDelegate<?> delegate;
|
||||
|
||||
ScrollExecution(Sort sort, ScrollDelegate<?> delegate) {
|
||||
|
||||
this.sort = sort;
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ public class KeysetScrollDelegate {
|
||||
/**
|
||||
* Factory method to obtain the right {@link KeysetScrollDelegate}.
|
||||
*
|
||||
* @param direction
|
||||
* @return
|
||||
* @param direction the direction of scrolling.
|
||||
* @return a {@link KeysetScrollDelegate} matching the requested direction.
|
||||
*/
|
||||
public static KeysetScrollDelegate of(Direction direction) {
|
||||
return direction == Direction.Forward ? forward : reverse;
|
||||
@@ -104,7 +104,6 @@ public class KeysetScrollDelegate {
|
||||
return sort;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <T> List<T> postProcessResults(List<T> result) {
|
||||
return result;
|
||||
}
|
||||
@@ -154,7 +153,6 @@ public class KeysetScrollDelegate {
|
||||
* Create an expression object from the given {@code property} path.
|
||||
*
|
||||
* @param property must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
E createExpression(String property);
|
||||
|
||||
@@ -163,8 +161,8 @@ public class KeysetScrollDelegate {
|
||||
*
|
||||
* @param order must not be {@literal null}.
|
||||
* @param propertyExpression must not be {@literal null}.
|
||||
* @param value
|
||||
* @return
|
||||
* @param value the value to compare with. Must not be {@literal null}.
|
||||
* @return an object representing the comparison predicate.
|
||||
*/
|
||||
P compare(Order order, E propertyExpression, Object value);
|
||||
|
||||
@@ -172,24 +170,24 @@ public class KeysetScrollDelegate {
|
||||
* Create an equals-comparison object.
|
||||
*
|
||||
* @param propertyExpression must not be {@literal null}.
|
||||
* @param value
|
||||
* @return
|
||||
* @param value the value to compare with. Must not be {@literal null}.
|
||||
* @return an object representing the comparison predicate.
|
||||
*/
|
||||
P compare(E propertyExpression, @Nullable Object value);
|
||||
|
||||
/**
|
||||
* AND-combine the {@code intermediate} predicates.
|
||||
*
|
||||
* @param intermediate
|
||||
* @return
|
||||
* @param intermediate the predicates to combine. Must not be {@literal null}.
|
||||
* @return a single predicate.
|
||||
*/
|
||||
P and(List<P> intermediate);
|
||||
|
||||
/**
|
||||
* OR-combine the {@code intermediate} predicates.
|
||||
*
|
||||
* @param intermediate
|
||||
* @return
|
||||
* @param intermediate the predicates to combine. Must not be {@literal null}.
|
||||
* @return a single predicate.
|
||||
*/
|
||||
P or(List<P> intermediate);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,6 @@ public record KeysetScrollSpecification<T> (KeysetScrollPosition position, Sort
|
||||
* @param position must not be {@literal null}.
|
||||
* @param sort must not be {@literal null}.
|
||||
* @param entity must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public static Sort createSort(KeysetScrollPosition position, Sort sort, JpaEntityInformation<?, ?> entity) {
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@ final class NamedQuery extends AbstractJpaQuery {
|
||||
private final String queryName;
|
||||
private final String countQueryName;
|
||||
private final @Nullable String countProjection;
|
||||
private final QueryExtractor extractor;
|
||||
private final boolean namedCountQueryIsPresent;
|
||||
private final DeclaredQuery declaredQuery;
|
||||
private final QueryParameterSetter.QueryMetadataCache metadataCache;
|
||||
@@ -63,7 +62,7 @@ final class NamedQuery extends AbstractJpaQuery {
|
||||
|
||||
this.queryName = method.getNamedQueryName();
|
||||
this.countQueryName = method.getNamedCountQueryName();
|
||||
this.extractor = method.getQueryExtractor();
|
||||
QueryExtractor extractor = method.getQueryExtractor();
|
||||
this.countProjection = method.getCountQueryProjection();
|
||||
|
||||
Parameters<?, ?> parameters = method.getParameters();
|
||||
@@ -81,7 +80,7 @@ final class NamedQuery extends AbstractJpaQuery {
|
||||
this.declaredQuery = DeclaredQuery.of(queryString, false);
|
||||
|
||||
boolean weNeedToCreateCountQuery = !namedCountQueryIsPresent && method.getParameters().hasPageableParameter();
|
||||
boolean cantExtractQuery = !this.extractor.canExtractQuery();
|
||||
boolean cantExtractQuery = !extractor.canExtractQuery();
|
||||
|
||||
if (weNeedToCreateCountQuery && cantExtractQuery) {
|
||||
throw QueryCreationException.create(method, CANNOT_EXTRACT_QUERY);
|
||||
@@ -99,9 +98,8 @@ final class NamedQuery extends AbstractJpaQuery {
|
||||
/**
|
||||
* Returns whether the named query with the given name exists.
|
||||
*
|
||||
* @param em must not be {@literal null}.
|
||||
* @param em must not be {@literal null}.
|
||||
* @param queryName must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
static boolean hasNamedQuery(EntityManager em, String queryName) {
|
||||
|
||||
@@ -129,8 +127,7 @@ final class NamedQuery extends AbstractJpaQuery {
|
||||
* Looks up a named query for the given {@link org.springframework.data.repository.query.QueryMethod}.
|
||||
*
|
||||
* @param method must not be {@literal null}.
|
||||
* @param em must not be {@literal null}.
|
||||
* @return
|
||||
* @param em must not be {@literal null}.
|
||||
*/
|
||||
@Nullable
|
||||
public static RepositoryQuery lookupFrom(JpaQueryMethod method, EntityManager em) {
|
||||
|
||||
@@ -233,9 +233,9 @@ class FetchableFluentQueryByPredicate<S, R> extends FluentQuerySupport<S, R> imp
|
||||
|
||||
static class PredicateScrollDelegate<T> extends ScrollDelegate<T> {
|
||||
|
||||
private final ScrollQueryFactory<T> scrollFunction;
|
||||
private final ScrollQueryFactory scrollFunction;
|
||||
|
||||
PredicateScrollDelegate(ScrollQueryFactory<T> scrollQueryFactory, JpaEntityInformation<T, ?> entity) {
|
||||
PredicateScrollDelegate(ScrollQueryFactory scrollQueryFactory, JpaEntityInformation<T, ?> entity) {
|
||||
super(entity);
|
||||
this.scrollFunction = scrollQueryFactory;
|
||||
}
|
||||
|
||||
@@ -224,9 +224,9 @@ class FetchableFluentQueryBySpecification<S, R> extends FluentQuerySupport<S, R>
|
||||
|
||||
static class SpecificationScrollDelegate<T> extends ScrollDelegate<T> {
|
||||
|
||||
private final ScrollQueryFactory<T> scrollFunction;
|
||||
private final ScrollQueryFactory scrollFunction;
|
||||
|
||||
SpecificationScrollDelegate(ScrollQueryFactory<T> scrollQueryFactory, JpaEntityInformation<T, ?> entity) {
|
||||
SpecificationScrollDelegate(ScrollQueryFactory scrollQueryFactory, JpaEntityInformation<T, ?> entity) {
|
||||
super(entity);
|
||||
this.scrollFunction = scrollQueryFactory;
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ abstract class FluentQuerySupport<S, R> {
|
||||
return o -> DefaultConversionService.getSharedInstance().convert(o, targetType);
|
||||
}
|
||||
|
||||
interface ScrollQueryFactory<T> {
|
||||
interface ScrollQueryFactory {
|
||||
Query createQuery(Sort sort, ScrollPosition scrollPosition);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,8 +35,6 @@ public interface JpaEntityInformation<T, ID> extends EntityInformation<T, ID>, J
|
||||
|
||||
/**
|
||||
* Returns the id attribute of the entity.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
SingularAttribute<? super T, ?> getIdAttribute();
|
||||
@@ -62,25 +60,20 @@ public interface JpaEntityInformation<T, ID> extends EntityInformation<T, ID>, J
|
||||
|
||||
/**
|
||||
* Returns {@literal true} if the entity has a composite id.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean hasCompositeId();
|
||||
|
||||
/**
|
||||
* Returns the attribute names of the id attributes. If the entity has a composite id, then all id attribute names are
|
||||
* returned. If the entity has a single id attribute then this single attribute name is returned.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Collection<String> getIdAttributeNames();
|
||||
|
||||
/**
|
||||
* Extracts the value for the given id attribute from a composite id
|
||||
*
|
||||
* @param id
|
||||
* @param idAttribute
|
||||
* @return
|
||||
* @param id the composite id from which to extract the attribute.
|
||||
* @param idAttribute the attribute name to extract.
|
||||
*/
|
||||
@Nullable
|
||||
Object getCompositeIdAttributeValue(Object id, String idAttribute);
|
||||
@@ -88,9 +81,9 @@ public interface JpaEntityInformation<T, ID> extends EntityInformation<T, ID>, J
|
||||
/**
|
||||
* Extract a keyset for {@code propertyPaths} and the primary key (including composite key components if applicable).
|
||||
*
|
||||
* @param propertyPaths
|
||||
* @param entity
|
||||
* @return
|
||||
* @param propertyPaths the property paths that make up the keyset in combination with the composite key components.
|
||||
* @param entity the entity to extract values from
|
||||
* @return a map mapping String representations of the paths to values from the entity.
|
||||
* @since 3.1
|
||||
*/
|
||||
Map<String, Object> getKeyset(Iterable<String> propertyPaths, T entity);
|
||||
|
||||
@@ -85,12 +85,10 @@ public class JpaMetamodelEntityInformation<T, ID> extends JpaEntityInformationSu
|
||||
|
||||
this.entityName = type instanceof EntityType ? ((EntityType<?>) type).getName() : null;
|
||||
|
||||
if (!(type instanceof IdentifiableType)) {
|
||||
if (!(type instanceof IdentifiableType<T> identifiableType)) {
|
||||
throw new IllegalArgumentException("The given domain class does not contain an id attribute");
|
||||
}
|
||||
|
||||
IdentifiableType<T> identifiableType = (IdentifiableType<T>) type;
|
||||
|
||||
this.idMetadata = new IdMetadata<>(identifiableType, PersistenceProvider.fromMetamodel(metamodel));
|
||||
this.versionAttribute = findVersionAttribute(identifiableType, metamodel);
|
||||
|
||||
@@ -108,7 +106,6 @@ public class JpaMetamodelEntityInformation<T, ID> extends JpaEntityInformationSu
|
||||
*
|
||||
* @param type must not be {@literal null}.
|
||||
* @param metamodel must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> Optional<SingularAttribute<? super T, ?>> findVersionAttribute(IdentifiableType<T> type,
|
||||
@@ -262,7 +259,6 @@ public class JpaMetamodelEntityInformation<T, ID> extends JpaEntityInformationSu
|
||||
private final Set<SingularAttribute<? super T, ?>> attributes;
|
||||
private @Nullable Class<?> idType;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
IdMetadata(IdentifiableType<T> source, PersistenceProvider persistenceProvider) {
|
||||
|
||||
this.type = source;
|
||||
|
||||
@@ -73,8 +73,6 @@ public class Querydsl {
|
||||
|
||||
/**
|
||||
* Creates the {@link JPQLQuery} instance based on the configured {@link EntityManager}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public <T> AbstractJPAQuery<T, JPAQuery<T>> createQuery() {
|
||||
|
||||
@@ -93,7 +91,6 @@ public class Querydsl {
|
||||
* Creates the {@link JPQLQuery} instance based on the configured {@link EntityManager}.
|
||||
*
|
||||
* @param paths must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public AbstractJPAQuery<Object, JPAQuery<Object>> createQuery(EntityPath<?>... paths) {
|
||||
|
||||
@@ -167,7 +164,6 @@ public class Querydsl {
|
||||
*
|
||||
* @param sort must not be {@literal null}.
|
||||
* @param query must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
private <T> JPQLQuery<T> addOrderByFrom(Sort sort, JPQLQuery<T> query) {
|
||||
|
||||
@@ -185,7 +181,6 @@ public class Querydsl {
|
||||
* Transforms a plain {@link Order} into a QueryDsl specific {@link OrderSpecifier}.
|
||||
*
|
||||
* @param order must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private OrderSpecifier<?> toOrderSpecifier(Order order) {
|
||||
@@ -200,7 +195,6 @@ public class Querydsl {
|
||||
* {@link NullHandling}.
|
||||
*
|
||||
* @param nullHandling must not be {@literal null}.
|
||||
* @return
|
||||
* @since 1.6
|
||||
*/
|
||||
private NullHandling toQueryDslNullHandling(org.springframework.data.domain.Sort.NullHandling nullHandling) {
|
||||
@@ -225,7 +219,6 @@ public class Querydsl {
|
||||
* Creates an {@link Expression} for the given {@link Order} property.
|
||||
*
|
||||
* @param order must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
private Expression<?> buildOrderPropertyPathFrom(Order order) {
|
||||
|
||||
@@ -250,7 +243,6 @@ public class Querydsl {
|
||||
* Creates an {@link Expression} for the given {@code property} property.
|
||||
*
|
||||
* @param property must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
Expression<?> createExpression(String property) {
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ public class QuerydslJpaPredicateExecutor<T> implements QuerydslPredicateExecuto
|
||||
return select;
|
||||
};
|
||||
|
||||
ScrollQueryFactory<T> scroll = (sort, scrollPosition) -> {
|
||||
ScrollQueryFactory scroll = (sort, scrollPosition) -> {
|
||||
|
||||
Predicate predicateToUse = predicate;
|
||||
|
||||
|
||||
@@ -521,7 +521,7 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
|
||||
Assert.notNull(spec, "Specification must not be null");
|
||||
Assert.notNull(queryFunction, "Query function must not be null");
|
||||
|
||||
ScrollQueryFactory<T> scrollFunction = (sort, scrollPosition) -> {
|
||||
ScrollQueryFactory scrollFunction = (sort, scrollPosition) -> {
|
||||
|
||||
Specification<T> specToUse = spec;
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ public class Item {
|
||||
}
|
||||
|
||||
public Item(Integer id, Integer manufacturerId, String name) {
|
||||
|
||||
this.id = id;
|
||||
this.manufacturerId = manufacturerId;
|
||||
this.name = name;
|
||||
|
||||
Reference in New Issue
Block a user