diff --git a/settings.gradle b/settings.gradle index cb106d3b38..1620f914cb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -140,7 +140,7 @@ dependencyResolutionManagement { def elVersion = version "el", "5.0.0" def injectVersion = version "inject", "2.0.1" def interceptorsVersion = version "interceptors", "2.1.0" - def dataVersion = version "data", "1.0.0-M3" + def dataVersion = version "data", "1.0.0-SNAPSHOT" def jaccVersion = version "jacc", "2.1.0" def jaxbApiVersion = version "jaxbApi", "4.0.0" def jaxbRuntimeVersion = version "jaxbRuntime", "4.0.2" diff --git a/tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/data/BookAuthorRepository.java b/tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/data/BookAuthorRepository.java index b2c1038b7b..0099514304 100644 --- a/tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/data/BookAuthorRepository.java +++ b/tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/data/BookAuthorRepository.java @@ -3,11 +3,9 @@ package org.hibernate.processor.test.data; import jakarta.data.Limit; import jakarta.data.Order; import jakarta.data.Sort; +import jakarta.data.page.CursoredPage; import jakarta.data.page.PageRequest; import jakarta.data.page.Page; -import jakarta.data.page.Slice; -import jakarta.data.page.KeysetAwarePage; -import jakarta.data.page.KeysetAwareSlice; import jakarta.data.repository.By; import jakarta.data.repository.Delete; import jakarta.data.repository.Find; @@ -115,28 +113,28 @@ public interface BookAuthorRepository { List everyBook3(PageRequest pageRequest); @Find - KeysetAwareSlice everyBook4(PageRequest pageRequest); + CursoredPage everyBook4(PageRequest pageRequest); @Find - KeysetAwareSlice everyBook5(String title, PageRequest pageRequest); + CursoredPage everyBook5(String title, PageRequest pageRequest); @Query("from Book") - KeysetAwareSlice everyBook6(PageRequest pageRequest); + CursoredPage everyBook6(PageRequest pageRequest); @Query("from Book where title like :titlePattern") - KeysetAwareSlice everyBook7(String titlePattern, PageRequest pageRequest); + CursoredPage everyBook7(String titlePattern, PageRequest pageRequest); @Find - KeysetAwarePage everyBook8(String title, PageRequest pageRequest); + CursoredPage everyBook8(String title, PageRequest pageRequest); @Query("from Book where title like :titlePattern") - KeysetAwarePage everyBook9(String titlePattern, PageRequest pageRequest); + CursoredPage everyBook9(String titlePattern, PageRequest pageRequest); @Find Page booksByTitle1(String title, PageRequest pageRequest); @Query("from Book where title like :titlePattern") - Slice booksByTitle2(String titlePattern, PageRequest pageRequest); + Page booksByTitle2(String titlePattern, PageRequest pageRequest); @Find List allBooksWithLotsOfSorting(Sort s1, Order order, Sort... s3); diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AbstractQueryMethod.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AbstractQueryMethod.java index 077bf9db3c..86aaee21b8 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AbstractQueryMethod.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AbstractQueryMethod.java @@ -259,7 +259,7 @@ public abstract class AbstractQueryMethod implements MetaAttribute { boolean applyOrder( StringBuilder declaration, List paramTypes, @Nullable String containerType, boolean unwrapped) { - if ( !isJakartaKeyedSlice(containerType) && hasOrdering(paramTypes) ) { + if ( !isJakartaCursoredPage(containerType) && hasOrdering(paramTypes) ) { unwrapQuery( declaration, unwrapped ); declaration .append("\t\t\t.setOrder(_orders)\n"); @@ -271,7 +271,7 @@ public abstract class AbstractQueryMethod implements MetaAttribute { void handlePageParameters( StringBuilder declaration, List paramTypes, @Nullable String containerType) { - if ( !isJakartaKeyedSlice(containerType) ) { + if ( !isJakartaCursoredPage(containerType) ) { for ( int i = 0; i < paramNames.size(); i ++ ) { final String paramName = paramNames.get(i); final String paramType = paramTypes.get(i); @@ -354,14 +354,12 @@ public abstract class AbstractQueryMethod implements MetaAttribute { || parameterType.startsWith(JD_PAGE_REQUEST); } - static boolean isJakartaKeyedSlice(@Nullable String containerType) { - return JD_KEYED_SLICE.equals(containerType) - || JD_KEYED_PAGE.equals(containerType); + static boolean isJakartaCursoredPage(@Nullable String containerType) { + return JD_CURSORED_PAGE.equals(containerType); } - static boolean isJakartaSlice(@Nullable String containerType) { - return JD_SLICE.equals(containerType) - || JD_PAGE.equals(containerType); + static boolean isJakartaPage(@Nullable String containerType) { + return JD_PAGE.equals(containerType); } void makeKeyedPage(StringBuilder declaration, List paramTypes) { @@ -386,16 +384,16 @@ public abstract class AbstractQueryMethod implements MetaAttribute { = "\t\tvar _cursors =\n" + "\t\t\t\t_results.getKeyList()\n" + "\t\t\t\t\t\t.stream()\n" + - "\t\t\t\t\t\t.map(_key -> Cursor.forKeyset(_key.toArray()))\n" + + "\t\t\t\t\t\t.map(_key -> Cursor.forKey(_key.toArray()))\n" + "\t\t\t\t\t\t.collect(toList());\n" + "\t\tvar _page =\n" + "\t\t\t\tPageRequest.of(Entity.class)\n" + "\t\t\t\t\t\t.sortBy(pageRequest.sorts())\n" + "\t\t\t\t\t\t.size(pageRequest.size())\n" + "\t\t\t\t\t\t.page(pageRequest.page() + 1);\n" + - "\t\treturn new KeysetAwareSliceRecord<>( _results.getResultList(), _cursors, _totalResults, pageRequest,\n" + - "\t\t\t\t_results.isLastPage() ? null : _page.afterKeyset(_results.getNextPage().getKey().toArray()),\n" + - "\t\t\t\t_results.isFirstPage() ? null : _page.beforeKeyset(_results.getPreviousPage().getKey().toArray()) );\n"; + "\t\treturn new CursoredPageRecord<>( _results.getResultList(), _cursors, _totalResults, pageRequest,\n" + + "\t\t\t\t_results.isLastPage() ? null : _page.afterKey(_results.getNextPage().getKey().toArray()),\n" + + "\t\t\t\t_results.isFirstPage() ? null : _page.beforeKey(_results.getPreviousPage().getKey().toArray()) );\n"; static final String MAKE_KEYED_PAGE = "\tvar _unkeyedPage =\n" + @@ -418,14 +416,14 @@ public abstract class AbstractQueryMethod implements MetaAttribute { void setParameters(StringBuilder declaration, List paramTypes) {} void tryReturn(StringBuilder declaration, List paramTypes, @Nullable String containerType) { - if ( isJakartaKeyedSlice(containerType) ) { + if ( isJakartaCursoredPage(containerType) ) { makeKeyedPage( declaration, paramTypes ); } if ( dataRepository ) { declaration .append("\ttry {\n"); } - if ( JD_KEYED_PAGE.equals(containerType) + if ( JD_CURSORED_PAGE.equals(containerType) || JD_PAGE.equals(containerType) ) { if ( dataRepository ) { declaration @@ -439,8 +437,8 @@ public abstract class AbstractQueryMethod implements MetaAttribute { } declaration .append('\t'); - if ( isJakartaKeyedSlice(containerType) - || isJakartaSlice(containerType) ) { + if ( isJakartaCursoredPage(containerType) + || isJakartaPage(containerType) ) { if ( returnTypeName != null && isUsingEntityManager() ) { // this is necessary to avoid losing the type // after unwrapping the Query object @@ -589,7 +587,7 @@ public abstract class AbstractQueryMethod implements MetaAttribute { } boolean unwrapIfNecessary(StringBuilder declaration, @Nullable String containerType, boolean unwrapped) { - if ( OPTIONAL.equals(containerType) || isJakartaKeyedSlice(containerType) ) { + if ( OPTIONAL.equals(containerType) || isJakartaCursoredPage(containerType) ) { unwrapQuery( declaration, unwrapped ); unwrapped = true; } @@ -639,26 +637,16 @@ public abstract class AbstractQueryMethod implements MetaAttribute { .append(parameterName(HIB_KEYED_PAGE, paramTypes, paramNames)) .append(");"); break; - case JD_SLICE: - declaration - .append(".getResultList();\n") - .append("\t\treturn new ") - .append(implType(containerType)) - .append('(') - .append(parameterName(JD_PAGE_REQUEST, paramTypes, paramNames)) - .append(", _results);\n"); - break; case JD_PAGE: declaration .append(".getResultList();\n") .append("\t\treturn new ") - .append(implType(containerType)) + .append(annotationMetaEntity.importType("jakarta.data.page.impl.PageRecord")) .append('(') .append(parameterName(JD_PAGE_REQUEST, paramTypes, paramNames)) .append(", _results, _totalResults);\n"); break; - case JD_KEYED_SLICE: - case JD_KEYED_PAGE: + case JD_CURSORED_PAGE: if ( returnTypeName == null ) { throw new AssertionFailure("entity class cannot be null"); } @@ -667,14 +655,12 @@ public abstract class AbstractQueryMethod implements MetaAttribute { .append(".getKeyedResultList(_keyedPage);\n"); annotationMetaEntity.importType("jakarta.data.page.PageRequest"); annotationMetaEntity.importType("jakarta.data.page.PageRequest.Cursor"); + annotationMetaEntity.importType("jakarta.data.page.impl.CursoredPageRecord"); String fragment = MAKE_KEYED_SLICE .replace("pageRequest", parameterName(JD_PAGE_REQUEST, paramTypes, paramNames)) - .replace("Entity", annotationMetaEntity.importType(returnTypeName)) - .replace("KeysetAwareSliceRecord", implType(containerType)); - if ( JD_KEYED_SLICE.equals(containerType) ) { - fragment = fragment.replace("_totalResults, ", ""); - } + .replace("Entity", + annotationMetaEntity.importType(returnTypeName)); declaration .append(fragment); } @@ -703,19 +689,4 @@ public abstract class AbstractQueryMethod implements MetaAttribute { } throw new AssertionFailure("could not find parameter"); } - - private String implType(String containerType) { - switch (containerType) { - case JD_SLICE: - return annotationMetaEntity.importType("jakarta.data.page.impl.SliceRecord"); - case JD_PAGE: - return annotationMetaEntity.importType("jakarta.data.page.impl.PageRecord"); - case JD_KEYED_SLICE: - return annotationMetaEntity.importType("jakarta.data.page.impl.KeysetAwareSliceRecord"); - case JD_KEYED_PAGE: - return annotationMetaEntity.importType("jakarta.data.page.impl.KeysetAwarePageRecord"); - default: - throw new AssertionFailure("unrecognized slice type"); - } - } } diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java index 960cf65aed..5b6abec3f9 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java @@ -721,9 +721,7 @@ public class AnnotationMetaEntity extends AnnotationMeta { final String typeName = typeElement.getQualifiedName().toString(); switch ( typeName ) { case JD_PAGE: - case JD_SLICE: - case JD_KEYED_PAGE: - case JD_KEYED_SLICE: + case JD_CURSORED_PAGE: if ( method.getParameters().stream() .noneMatch(param -> param.asType().toString() .startsWith(JD_PAGE_REQUEST))) { @@ -788,7 +786,7 @@ public class AnnotationMetaEntity extends AnnotationMeta { private static final Set LEGAL_GENERIC_RESULT_TYPES = Set.of(LIST, STREAM, OPTIONAL, TYPED_QUERY, HIB_QUERY, HIB_SELECTION_QUERY, HIB_KEYED_RESULT_LIST, - JD_SLICE, JD_PAGE, JD_KEYED_SLICE, JD_KEYED_PAGE); + JD_PAGE, JD_CURSORED_PAGE); private void addQueryMethod( ExecutableElement method, diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/Constants.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/Constants.java index 35b99307cd..70c6ccd446 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/Constants.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/Constants.java @@ -72,10 +72,8 @@ public final class Constants { public static final String JD_SORT = "jakarta.data.Sort"; public static final String JD_ORDER = "jakarta.data.Order"; public static final String JD_PAGE_REQUEST = "jakarta.data.page.PageRequest"; - public static final String JD_SLICE = "jakarta.data.page.Slice"; public static final String JD_PAGE = "jakarta.data.page.Page"; - public static final String JD_KEYED_SLICE = "jakarta.data.page.KeysetAwareSlice"; - public static final String JD_KEYED_PAGE = "jakarta.data.page.KeysetAwarePage"; + public static final String JD_CURSORED_PAGE = "jakarta.data.page.CursoredPage"; public static final String HIB_ORDER = "org.hibernate.query.Order"; public static final String HIB_PAGE = "org.hibernate.query.Page";