update to latest JD snapshot build

This commit is contained in:
Gavin King 2024-03-09 11:57:44 +01:00
parent 971d673e88
commit 7773e28b2c
5 changed files with 32 additions and 67 deletions

View File

@ -140,7 +140,7 @@ dependencyResolutionManagement {
def elVersion = version "el", "5.0.0" def elVersion = version "el", "5.0.0"
def injectVersion = version "inject", "2.0.1" def injectVersion = version "inject", "2.0.1"
def interceptorsVersion = version "interceptors", "2.1.0" 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 jaccVersion = version "jacc", "2.1.0"
def jaxbApiVersion = version "jaxbApi", "4.0.0" def jaxbApiVersion = version "jaxbApi", "4.0.0"
def jaxbRuntimeVersion = version "jaxbRuntime", "4.0.2" def jaxbRuntimeVersion = version "jaxbRuntime", "4.0.2"

View File

@ -3,11 +3,9 @@ package org.hibernate.processor.test.data;
import jakarta.data.Limit; import jakarta.data.Limit;
import jakarta.data.Order; import jakarta.data.Order;
import jakarta.data.Sort; import jakarta.data.Sort;
import jakarta.data.page.CursoredPage;
import jakarta.data.page.PageRequest; import jakarta.data.page.PageRequest;
import jakarta.data.page.Page; 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.By;
import jakarta.data.repository.Delete; import jakarta.data.repository.Delete;
import jakarta.data.repository.Find; import jakarta.data.repository.Find;
@ -115,28 +113,28 @@ public interface BookAuthorRepository {
List<Book> everyBook3(PageRequest<? super Book> pageRequest); List<Book> everyBook3(PageRequest<? super Book> pageRequest);
@Find @Find
KeysetAwareSlice<Book> everyBook4(PageRequest<Book> pageRequest); CursoredPage<Book> everyBook4(PageRequest<Book> pageRequest);
@Find @Find
KeysetAwareSlice<Book> everyBook5(String title, PageRequest<Book> pageRequest); CursoredPage<Book> everyBook5(String title, PageRequest<Book> pageRequest);
@Query("from Book") @Query("from Book")
KeysetAwareSlice<Book> everyBook6(PageRequest<Book> pageRequest); CursoredPage<Book> everyBook6(PageRequest<Book> pageRequest);
@Query("from Book where title like :titlePattern") @Query("from Book where title like :titlePattern")
KeysetAwareSlice<Book> everyBook7(String titlePattern, PageRequest<Book> pageRequest); CursoredPage<Book> everyBook7(String titlePattern, PageRequest<Book> pageRequest);
@Find @Find
KeysetAwarePage<Book> everyBook8(String title, PageRequest<Book> pageRequest); CursoredPage<Book> everyBook8(String title, PageRequest<Book> pageRequest);
@Query("from Book where title like :titlePattern") @Query("from Book where title like :titlePattern")
KeysetAwarePage<Book> everyBook9(String titlePattern, PageRequest<Book> pageRequest); CursoredPage<Book> everyBook9(String titlePattern, PageRequest<Book> pageRequest);
@Find @Find
Page<Book> booksByTitle1(String title, PageRequest<Book> pageRequest); Page<Book> booksByTitle1(String title, PageRequest<Book> pageRequest);
@Query("from Book where title like :titlePattern") @Query("from Book where title like :titlePattern")
Slice<Book> booksByTitle2(String titlePattern, PageRequest<Book> pageRequest); Page<Book> booksByTitle2(String titlePattern, PageRequest<Book> pageRequest);
@Find @Find
List<Book> allBooksWithLotsOfSorting(Sort<? super Book> s1, Order<? super Book> order, Sort<? super Book>... s3); List<Book> allBooksWithLotsOfSorting(Sort<? super Book> s1, Order<? super Book> order, Sort<? super Book>... s3);

View File

@ -259,7 +259,7 @@ public abstract class AbstractQueryMethod implements MetaAttribute {
boolean applyOrder( boolean applyOrder(
StringBuilder declaration, List<String> paramTypes, StringBuilder declaration, List<String> paramTypes,
@Nullable String containerType, boolean unwrapped) { @Nullable String containerType, boolean unwrapped) {
if ( !isJakartaKeyedSlice(containerType) && hasOrdering(paramTypes) ) { if ( !isJakartaCursoredPage(containerType) && hasOrdering(paramTypes) ) {
unwrapQuery( declaration, unwrapped ); unwrapQuery( declaration, unwrapped );
declaration declaration
.append("\t\t\t.setOrder(_orders)\n"); .append("\t\t\t.setOrder(_orders)\n");
@ -271,7 +271,7 @@ public abstract class AbstractQueryMethod implements MetaAttribute {
void handlePageParameters( void handlePageParameters(
StringBuilder declaration, List<String> paramTypes, StringBuilder declaration, List<String> paramTypes,
@Nullable String containerType) { @Nullable String containerType) {
if ( !isJakartaKeyedSlice(containerType) ) { if ( !isJakartaCursoredPage(containerType) ) {
for ( int i = 0; i < paramNames.size(); i ++ ) { for ( int i = 0; i < paramNames.size(); i ++ ) {
final String paramName = paramNames.get(i); final String paramName = paramNames.get(i);
final String paramType = paramTypes.get(i); final String paramType = paramTypes.get(i);
@ -354,14 +354,12 @@ public abstract class AbstractQueryMethod implements MetaAttribute {
|| parameterType.startsWith(JD_PAGE_REQUEST); || parameterType.startsWith(JD_PAGE_REQUEST);
} }
static boolean isJakartaKeyedSlice(@Nullable String containerType) { static boolean isJakartaCursoredPage(@Nullable String containerType) {
return JD_KEYED_SLICE.equals(containerType) return JD_CURSORED_PAGE.equals(containerType);
|| JD_KEYED_PAGE.equals(containerType);
} }
static boolean isJakartaSlice(@Nullable String containerType) { static boolean isJakartaPage(@Nullable String containerType) {
return JD_SLICE.equals(containerType) return JD_PAGE.equals(containerType);
|| JD_PAGE.equals(containerType);
} }
void makeKeyedPage(StringBuilder declaration, List<String> paramTypes) { void makeKeyedPage(StringBuilder declaration, List<String> paramTypes) {
@ -386,16 +384,16 @@ public abstract class AbstractQueryMethod implements MetaAttribute {
= "\t\tvar _cursors =\n" + = "\t\tvar _cursors =\n" +
"\t\t\t\t_results.getKeyList()\n" + "\t\t\t\t_results.getKeyList()\n" +
"\t\t\t\t\t\t.stream()\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\t\t\t\t\t.collect(toList());\n" +
"\t\tvar _page =\n" + "\t\tvar _page =\n" +
"\t\t\t\tPageRequest.of(Entity.class)\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.sortBy(pageRequest.sorts())\n" +
"\t\t\t\t\t\t.size(pageRequest.size())\n" + "\t\t\t\t\t\t.size(pageRequest.size())\n" +
"\t\t\t\t\t\t.page(pageRequest.page() + 1);\n" + "\t\t\t\t\t\t.page(pageRequest.page() + 1);\n" +
"\t\treturn new KeysetAwareSliceRecord<>( _results.getResultList(), _cursors, _totalResults, pageRequest,\n" + "\t\treturn new CursoredPageRecord<>( _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.isLastPage() ? null : _page.afterKey(_results.getNextPage().getKey().toArray()),\n" +
"\t\t\t\t_results.isFirstPage() ? null : _page.beforeKeyset(_results.getPreviousPage().getKey().toArray()) );\n"; "\t\t\t\t_results.isFirstPage() ? null : _page.beforeKey(_results.getPreviousPage().getKey().toArray()) );\n";
static final String MAKE_KEYED_PAGE static final String MAKE_KEYED_PAGE
= "\tvar _unkeyedPage =\n" + = "\tvar _unkeyedPage =\n" +
@ -418,14 +416,14 @@ public abstract class AbstractQueryMethod implements MetaAttribute {
void setParameters(StringBuilder declaration, List<String> paramTypes) {} void setParameters(StringBuilder declaration, List<String> paramTypes) {}
void tryReturn(StringBuilder declaration, List<String> paramTypes, @Nullable String containerType) { void tryReturn(StringBuilder declaration, List<String> paramTypes, @Nullable String containerType) {
if ( isJakartaKeyedSlice(containerType) ) { if ( isJakartaCursoredPage(containerType) ) {
makeKeyedPage( declaration, paramTypes ); makeKeyedPage( declaration, paramTypes );
} }
if ( dataRepository ) { if ( dataRepository ) {
declaration declaration
.append("\ttry {\n"); .append("\ttry {\n");
} }
if ( JD_KEYED_PAGE.equals(containerType) if ( JD_CURSORED_PAGE.equals(containerType)
|| JD_PAGE.equals(containerType) ) { || JD_PAGE.equals(containerType) ) {
if ( dataRepository ) { if ( dataRepository ) {
declaration declaration
@ -439,8 +437,8 @@ public abstract class AbstractQueryMethod implements MetaAttribute {
} }
declaration declaration
.append('\t'); .append('\t');
if ( isJakartaKeyedSlice(containerType) if ( isJakartaCursoredPage(containerType)
|| isJakartaSlice(containerType) ) { || isJakartaPage(containerType) ) {
if ( returnTypeName != null && isUsingEntityManager() ) { if ( returnTypeName != null && isUsingEntityManager() ) {
// this is necessary to avoid losing the type // this is necessary to avoid losing the type
// after unwrapping the Query object // after unwrapping the Query object
@ -589,7 +587,7 @@ public abstract class AbstractQueryMethod implements MetaAttribute {
} }
boolean unwrapIfNecessary(StringBuilder declaration, @Nullable String containerType, boolean unwrapped) { boolean unwrapIfNecessary(StringBuilder declaration, @Nullable String containerType, boolean unwrapped) {
if ( OPTIONAL.equals(containerType) || isJakartaKeyedSlice(containerType) ) { if ( OPTIONAL.equals(containerType) || isJakartaCursoredPage(containerType) ) {
unwrapQuery( declaration, unwrapped ); unwrapQuery( declaration, unwrapped );
unwrapped = true; unwrapped = true;
} }
@ -639,26 +637,16 @@ public abstract class AbstractQueryMethod implements MetaAttribute {
.append(parameterName(HIB_KEYED_PAGE, paramTypes, paramNames)) .append(parameterName(HIB_KEYED_PAGE, paramTypes, paramNames))
.append(");"); .append(");");
break; 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: case JD_PAGE:
declaration declaration
.append(".getResultList();\n") .append(".getResultList();\n")
.append("\t\treturn new ") .append("\t\treturn new ")
.append(implType(containerType)) .append(annotationMetaEntity.importType("jakarta.data.page.impl.PageRecord"))
.append('(') .append('(')
.append(parameterName(JD_PAGE_REQUEST, paramTypes, paramNames)) .append(parameterName(JD_PAGE_REQUEST, paramTypes, paramNames))
.append(", _results, _totalResults);\n"); .append(", _results, _totalResults);\n");
break; break;
case JD_KEYED_SLICE: case JD_CURSORED_PAGE:
case JD_KEYED_PAGE:
if ( returnTypeName == null ) { if ( returnTypeName == null ) {
throw new AssertionFailure("entity class cannot be null"); throw new AssertionFailure("entity class cannot be null");
} }
@ -667,14 +655,12 @@ public abstract class AbstractQueryMethod implements MetaAttribute {
.append(".getKeyedResultList(_keyedPage);\n"); .append(".getKeyedResultList(_keyedPage);\n");
annotationMetaEntity.importType("jakarta.data.page.PageRequest"); annotationMetaEntity.importType("jakarta.data.page.PageRequest");
annotationMetaEntity.importType("jakarta.data.page.PageRequest.Cursor"); annotationMetaEntity.importType("jakarta.data.page.PageRequest.Cursor");
annotationMetaEntity.importType("jakarta.data.page.impl.CursoredPageRecord");
String fragment = MAKE_KEYED_SLICE String fragment = MAKE_KEYED_SLICE
.replace("pageRequest", .replace("pageRequest",
parameterName(JD_PAGE_REQUEST, paramTypes, paramNames)) parameterName(JD_PAGE_REQUEST, paramTypes, paramNames))
.replace("Entity", annotationMetaEntity.importType(returnTypeName)) .replace("Entity",
.replace("KeysetAwareSliceRecord", implType(containerType)); annotationMetaEntity.importType(returnTypeName));
if ( JD_KEYED_SLICE.equals(containerType) ) {
fragment = fragment.replace("_totalResults, ", "");
}
declaration declaration
.append(fragment); .append(fragment);
} }
@ -703,19 +689,4 @@ public abstract class AbstractQueryMethod implements MetaAttribute {
} }
throw new AssertionFailure("could not find parameter"); 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");
}
}
} }

View File

@ -721,9 +721,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
final String typeName = typeElement.getQualifiedName().toString(); final String typeName = typeElement.getQualifiedName().toString();
switch ( typeName ) { switch ( typeName ) {
case JD_PAGE: case JD_PAGE:
case JD_SLICE: case JD_CURSORED_PAGE:
case JD_KEYED_PAGE:
case JD_KEYED_SLICE:
if ( method.getParameters().stream() if ( method.getParameters().stream()
.noneMatch(param -> param.asType().toString() .noneMatch(param -> param.asType().toString()
.startsWith(JD_PAGE_REQUEST))) { .startsWith(JD_PAGE_REQUEST))) {
@ -788,7 +786,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
private static final Set<String> LEGAL_GENERIC_RESULT_TYPES private static final Set<String> LEGAL_GENERIC_RESULT_TYPES
= Set.of(LIST, STREAM, OPTIONAL, = Set.of(LIST, STREAM, OPTIONAL,
TYPED_QUERY, HIB_QUERY, HIB_SELECTION_QUERY, HIB_KEYED_RESULT_LIST, 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( private void addQueryMethod(
ExecutableElement method, ExecutableElement method,

View File

@ -72,10 +72,8 @@ public final class Constants {
public static final String JD_SORT = "jakarta.data.Sort"; public static final String JD_SORT = "jakarta.data.Sort";
public static final String JD_ORDER = "jakarta.data.Order"; 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_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_PAGE = "jakarta.data.page.Page";
public static final String JD_KEYED_SLICE = "jakarta.data.page.KeysetAwareSlice"; public static final String JD_CURSORED_PAGE = "jakarta.data.page.CursoredPage";
public static final String JD_KEYED_PAGE = "jakarta.data.page.KeysetAwarePage";
public static final String HIB_ORDER = "org.hibernate.query.Order"; public static final String HIB_ORDER = "org.hibernate.query.Order";
public static final String HIB_PAGE = "org.hibernate.query.Page"; public static final String HIB_PAGE = "org.hibernate.query.Page";