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);
@Query("from Book")
List<Book> everyBook1(PageRequest<? super Book> pageRequest);
List<Book> everyBook1(PageRequest pageRequest);
@Find
List<Book> everyBook2(PageRequest<? super Book> pageRequest);
List<Book> everyBook2(PageRequest pageRequest, Order<Book> order);
@Query("from Book")
@OrderBy("isbn")
@OrderBy(value = "publicationDate", descending = true)
List<Book> everyBook3(PageRequest<? super Book> pageRequest);
List<Book> everyBook3(PageRequest pageRequest);
@Find
CursoredPage<Book> everyBook4(PageRequest<Book> pageRequest);
CursoredPage<Book> everyBook4(PageRequest pageRequest, Order<Book> order);
@Find
CursoredPage<Book> everyBook5(String title, PageRequest<Book> pageRequest);
CursoredPage<Book> everyBook5(String title, PageRequest pageRequest, Order<Book> order);
@Query("from Book")
CursoredPage<Book> everyBook6(PageRequest<Book> pageRequest);
CursoredPage<Book> everyBook6(PageRequest pageRequest, Order<Book> order);
@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
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")
CursoredPage<Book> everyBook9(String titlePattern, PageRequest<Book> pageRequest);
CursoredPage<Book> everyBook9(String titlePattern, PageRequest pageRequest, Order<Book> order);
@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")
Page<Book> booksByTitle2(String titlePattern, PageRequest<Book> pageRequest);
Page<Book> booksByTitle2(String titlePattern, PageRequest pageRequest, Order<Book> order);
@Find
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
@OrderBy("isbn")
CursoredPage<Book> allBooks(PageRequest<Book> pageRequest);
CursoredPage<Book> allBooks(PageRequest pageRequest);
@Find
@OrderBy("name")

View File

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

View File

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

View File

@ -1,5 +1,6 @@
package org.hibernate.processor.test.data.superdao.generic;
import jakarta.data.Order;
import jakarta.data.page.Page;
import jakarta.data.page.PageRequest;
import jakarta.data.repository.By;
@ -30,7 +31,7 @@ public interface SuperRepo<T,K> {
Stream<T> findAll();
@Find
Page<T> findAll(PageRequest<T> pageRequest);
Page<T> findAll(PageRequest pageRequest, Order<T> order);
// @Delete
// 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) {
boolean jakartaLimit = JD_LIMIT.equals(paramType);
boolean jakartaPageRequest = paramType.startsWith(JD_PAGE_REQUEST);
final boolean jakartaLimit = JD_LIMIT.equals(paramType);
final boolean jakartaPageRequest = JD_PAGE_REQUEST.equals(paramType);
if ( jakartaLimit || jakartaPageRequest
|| isUsingEntityManager() ) {
final String firstResult;
@ -326,15 +326,14 @@ public abstract class AbstractQueryMethod extends AbstractAnnotatedMethod {
static boolean isPageParam(String parameterType) {
return HIB_PAGE.equals(parameterType)
|| JD_LIMIT.equals(parameterType)
|| parameterType.startsWith(JD_PAGE_REQUEST);
|| JD_PAGE_REQUEST.equals(parameterType);
}
static boolean isOrderParam(String parameterType) {
return parameterType.startsWith(HIB_ORDER)
|| parameterType.startsWith(LIST + "<" + HIB_ORDER)
|| parameterType.startsWith(JD_SORT)
|| parameterType.startsWith(JD_ORDER)
|| parameterType.startsWith(JD_PAGE_REQUEST);
|| parameterType.startsWith(JD_ORDER);
}
static boolean isJakartaCursoredPage(@Nullable String containerType) {
@ -516,8 +515,7 @@ public abstract class AbstractQueryMethod extends AbstractAnnotatedMethod {
.append(name)
.append(");\n");
}
else if ( type.startsWith(JD_ORDER)
|| type.startsWith(JD_PAGE_REQUEST) ) {
else if ( type.startsWith(JD_ORDER) ) {
annotationMetaEntity.staticImport(HIB_SORT_DIRECTION, "*");
declaration
.append("\tfor (var _sort : ")

View File

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