Skip to content

Commit

Permalink
fix incorrect implementation of PageRequest.page()
Browse files Browse the repository at this point in the history
this operation should not propagate the Cursor value
  • Loading branch information
gavinking committed Apr 7, 2024
1 parent 6de5c96 commit f9bfc03
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions api/src/main/java/jakarta/data/page/Pagination.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* Built-in implementation of PageRequest.
*/
record Pagination(long page, int size, Mode mode, Cursor type, boolean requestTotal) implements PageRequest {
record Pagination(long page, int size, Mode mode, Cursor keys, boolean requestTotal) implements PageRequest {

Pagination {
if (page < 1) {
Expand All @@ -31,19 +31,19 @@ record Pagination(long page, int size, Mode mode, Cursor type, boolean requestTo
throw new IllegalArgumentException("maxPageSize: " + size);
}

if (mode != Mode.OFFSET && (type == null || type.size() == 0)) {
if (mode != Mode.OFFSET && (keys == null || keys.size() == 0)) {
throw new IllegalArgumentException("No key values were provided.");
}
}

@Override
public PageRequest withoutTotal() {
return new Pagination(page, size, mode, type, false);
return new Pagination(page, size, mode, keys, false);
}

@Override
public PageRequest withTotal() {
return new Pagination(page, size, mode, type, true);
return new Pagination(page, size, mode, keys, true);
}

@Override
Expand All @@ -68,7 +68,7 @@ public PageRequest beforeCursor(Cursor cursor) {

@Override
public Optional<Cursor> cursor() {
return Optional.ofNullable(type);
return Optional.ofNullable(keys);
}

@Override
Expand Down Expand Up @@ -97,20 +97,20 @@ public String toString() {
.append("PageRequest{page=").append(page)
.append(", size=").append(size)
.append(", mode=").append(mode);
if (type != null) {
s.append(", ").append(type.size()).append(" keys");
if (keys != null) {
s.append(", ").append(keys.size()).append(" keys");
}
return s.append("}").toString();
}

@Override
public PageRequest page(long pageNumber) {
return new Pagination(pageNumber, size, mode, type, requestTotal);
return new Pagination(pageNumber, size, mode, null, requestTotal);
}

@Override
public PageRequest size(int maxPageSize) {
return new Pagination(page, maxPageSize, mode, type, requestTotal);
return new Pagination(page, maxPageSize, mode, keys, requestTotal);
}

}

0 comments on commit f9bfc03

Please sign in to comment.