sync to latest spec and removal of sorting from PageRequest

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-04-04 23:43:05 +02:00
parent ceefdd162a
commit a8f6872249
7 changed files with 28 additions and 39 deletions

View File

@ -141,39 +141,39 @@ public interface BookAuthorRepository {
Stream<Book> everyBook0(Order<? super Book> order); Stream<Book> everyBook0(Order<? super Book> order);
@Query("from Book") @Query("from Book")
List<Book> everyBook1(PageRequest<? super Book> pageRequest); List<Book> everyBook1(PageRequest pageRequest);
@Find @Find
List<Book> everyBook2(PageRequest<? super Book> pageRequest); List<Book> everyBook2(PageRequest pageRequest, Order<Book> order);
@Query("from Book") @Query("from Book")
@OrderBy("isbn") @OrderBy("isbn")
@OrderBy(value = "publicationDate", descending = true) @OrderBy(value = "publicationDate", descending = true)
List<Book> everyBook3(PageRequest<? super Book> pageRequest); List<Book> everyBook3(PageRequest pageRequest);
@Find @Find
CursoredPage<Book> everyBook4(PageRequest<Book> pageRequest); CursoredPage<Book> everyBook4(PageRequest pageRequest, Order<Book> order);
@Find @Find
CursoredPage<Book> everyBook5(String title, PageRequest<Book> pageRequest); CursoredPage<Book> everyBook5(String title, PageRequest pageRequest, Order<Book> order);
@Query("from Book") @Query("from Book")
CursoredPage<Book> everyBook6(PageRequest<Book> pageRequest); CursoredPage<Book> everyBook6(PageRequest pageRequest, Order<Book> order);
@Query("from Book where title like :titlePattern") @Query("from Book where title like :titlePattern")
CursoredPage<Book> everyBook7(String titlePattern, PageRequest<Book> pageRequest); CursoredPage<Book> everyBook7(String titlePattern, PageRequest pageRequest, Order<Book> order);
@Find @Find
CursoredPage<Book> everyBook8(String title, PageRequest<Book> pageRequest); CursoredPage<Book> everyBook8(String title, PageRequest pageRequest, Order<Book> order);
@Query("from Book where title like :titlePattern") @Query("from Book where title like :titlePattern")
CursoredPage<Book> everyBook9(String titlePattern, PageRequest<Book> pageRequest); CursoredPage<Book> everyBook9(String titlePattern, PageRequest pageRequest, Order<Book> order);
@Find @Find
Page<Book> booksByTitle1(String title, PageRequest<Book> pageRequest); Page<Book> booksByTitle1(String title, PageRequest pageRequest, Order<Book> order);
@Query("from Book where title like :titlePattern") @Query("from Book where title like :titlePattern")
Page<Book> booksByTitle2(String titlePattern, PageRequest<Book> pageRequest); Page<Book> booksByTitle2(String titlePattern, PageRequest pageRequest, Order<Book> order);
@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

@ -93,7 +93,7 @@ public interface Library {
@Find @Find
@OrderBy("isbn") @OrderBy("isbn")
CursoredPage<Book> allBooks(PageRequest<Book> pageRequest); CursoredPage<Book> allBooks(PageRequest pageRequest);
@Find @Find
@OrderBy("name") @OrderBy("name")

View File

@ -91,7 +91,7 @@ public interface Library {
@Find @Find
@OrderBy("isbn") @OrderBy("isbn")
Uni<Page<Book>> allBooks(PageRequest<Book> pageRequest); Uni<Page<Book>> allBooks(PageRequest pageRequest);
@Find @Find
@OrderBy("name") @OrderBy("name")

View File

@ -91,7 +91,7 @@ public interface Library2 {
@Find @Find
@OrderBy("isbn") @OrderBy("isbn")
Uni<Page<Book>> allBooks(PageRequest<Book> pageRequest); Uni<Page<Book>> allBooks(PageRequest pageRequest);
@Find @Find
@OrderBy("name") @OrderBy("name")

View File

@ -1,5 +1,6 @@
package org.hibernate.processor.test.data.superdao.generic; package org.hibernate.processor.test.data.superdao.generic;
import jakarta.data.Order;
import jakarta.data.page.Page; import jakarta.data.page.Page;
import jakarta.data.page.PageRequest; import jakarta.data.page.PageRequest;
import jakarta.data.repository.By; import jakarta.data.repository.By;
@ -30,7 +31,7 @@ public interface SuperRepo<T,K> {
Stream<T> findAll(); Stream<T> findAll();
@Find @Find
Page<T> findAll(PageRequest<T> pageRequest); Page<T> findAll(PageRequest pageRequest, Order<T> order);
// @Delete // @Delete
// void deleteById(@By("#id") K id); // void deleteById(@By("#id") K id);

View File

@ -205,8 +205,8 @@ public abstract class AbstractQueryMethod extends AbstractAnnotatedMethod {
} }
void setPage(StringBuilder declaration, String paramName, String paramType) { void setPage(StringBuilder declaration, String paramName, String paramType) {
boolean jakartaLimit = JD_LIMIT.equals(paramType); final boolean jakartaLimit = JD_LIMIT.equals(paramType);
boolean jakartaPageRequest = paramType.startsWith(JD_PAGE_REQUEST); final boolean jakartaPageRequest = JD_PAGE_REQUEST.equals(paramType);
if ( jakartaLimit || jakartaPageRequest if ( jakartaLimit || jakartaPageRequest
|| isUsingEntityManager() ) { || isUsingEntityManager() ) {
final String firstResult; final String firstResult;
@ -326,15 +326,14 @@ public abstract class AbstractQueryMethod extends AbstractAnnotatedMethod {
static boolean isPageParam(String parameterType) { static boolean isPageParam(String parameterType) {
return HIB_PAGE.equals(parameterType) return HIB_PAGE.equals(parameterType)
|| JD_LIMIT.equals(parameterType) || JD_LIMIT.equals(parameterType)
|| parameterType.startsWith(JD_PAGE_REQUEST); || JD_PAGE_REQUEST.equals(parameterType);
} }
static boolean isOrderParam(String parameterType) { static boolean isOrderParam(String parameterType) {
return parameterType.startsWith(HIB_ORDER) return parameterType.startsWith(HIB_ORDER)
|| parameterType.startsWith(LIST + "<" + HIB_ORDER) || parameterType.startsWith(LIST + "<" + HIB_ORDER)
|| parameterType.startsWith(JD_SORT) || parameterType.startsWith(JD_SORT)
|| parameterType.startsWith(JD_ORDER) || parameterType.startsWith(JD_ORDER);
|| parameterType.startsWith(JD_PAGE_REQUEST);
} }
static boolean isJakartaCursoredPage(@Nullable String containerType) { static boolean isJakartaCursoredPage(@Nullable String containerType) {
@ -516,8 +515,7 @@ public abstract class AbstractQueryMethod extends AbstractAnnotatedMethod {
.append(name) .append(name)
.append(");\n"); .append(");\n");
} }
else if ( type.startsWith(JD_ORDER) else if ( type.startsWith(JD_ORDER) ) {
|| type.startsWith(JD_PAGE_REQUEST) ) {
annotationMetaEntity.staticImport(HIB_SORT_DIRECTION, "*"); annotationMetaEntity.staticImport(HIB_SORT_DIRECTION, "*");
declaration declaration
.append("\tfor (var _sort : ") .append("\tfor (var _sort : ")

View File

@ -1501,14 +1501,13 @@ public class AnnotationMetaEntity extends AnnotationMeta {
private void checkFinderParameter(TypeElement entity, VariableElement parameter) { private void checkFinderParameter(TypeElement entity, VariableElement parameter) {
final Types types = context.getTypeUtils(); final Types types = context.getTypeUtils();
final TypeMirror parameterType = parameterType(parameter); final TypeMirror parameterType = parameterType(parameter);
boolean pageRequest = typeNameEquals( parameterType, JD_PAGE_REQUEST ); if ( isOrderParam( typeName(parameterType) ) ) {
if ( isOrderParam( typeName(parameterType) ) || pageRequest ) {
final TypeMirror typeArgument = getTypeArgument( parameterType, entity ); final TypeMirror typeArgument = getTypeArgument( parameterType, entity );
if ( typeArgument == null ) { if ( typeArgument == null ) {
missingTypeArgError( entity.getSimpleName().toString(), parameter, pageRequest ); missingTypeArgError( entity.getSimpleName().toString(), parameter );
} }
else if ( !types.isSameType( typeArgument, entity.asType() ) ) { else if ( !types.isSameType( typeArgument, entity.asType() ) ) {
wrongTypeArgError( entity.getSimpleName().toString(), parameter, pageRequest ); wrongTypeArgError( entity.getSimpleName().toString(), parameter );
} }
} }
} }
@ -1556,21 +1555,13 @@ public class AnnotationMetaEntity extends AnnotationMeta {
} }
} }
private void wrongTypeArgError(String entity, VariableElement parameter, boolean pageRequest) { private void wrongTypeArgError(String entity, VariableElement parameter) {
message(parameter, message(parameter, "mismatched type of order (should be 'Order<? super " + entity + ">')",
(pageRequest
? "mismatched type of page request (should be 'PageRequest<? super "
:"mismatched type of order (should be 'Order<? super ")
+ entity + ">')",
Diagnostic.Kind.ERROR ); Diagnostic.Kind.ERROR );
} }
private void missingTypeArgError(String entity, VariableElement parameter, boolean pageRequest) { private void missingTypeArgError(String entity, VariableElement parameter) {
message(parameter, message(parameter, "missing type of order (should be 'Order<? super " + entity + ">')",
(pageRequest
? "missing type of page request (should be 'PageRequest<? super "
: "missing type of order (should be 'Order<? super ")
+ entity + ">')",
Diagnostic.Kind.ERROR ); Diagnostic.Kind.ERROR );
} }
@ -1635,7 +1626,6 @@ public class AnnotationMetaEntity extends AnnotationMeta {
case HIB_ORDER: case HIB_ORDER:
case JD_SORT: case JD_SORT:
case JD_ORDER: case JD_ORDER:
case JD_PAGE_REQUEST:
for ( TypeMirror arg : type.getTypeArguments() ) { for ( TypeMirror arg : type.getTypeArguments() ) {
switch ( arg.getKind() ) { switch ( arg.getKind() ) {
case WILDCARD: case WILDCARD: