Skip to content

minimal API changes for 0-based offsets#1482

Open
njr-11 wants to merge 3 commits into
jakartaee:mainfrom
njr-11:0-based-offsets
Open

minimal API changes for 0-based offsets#1482
njr-11 wants to merge 3 commits into
jakartaee:mainfrom
njr-11:0-based-offsets

Conversation

@njr-11
Copy link
Copy Markdown
Member

@njr-11 njr-11 commented Jun 3, 2026

This PR starts with some of Gavin's updates from #1479 and pares down to a minimum the amount of API updates needed to accommodate a developer that wants to think about making PageRequests as a 0-based offset from the first page and defining Limits in terms of a 0-based offset from first result.

To achieve this, we really only need 2 methods.

pageOffset(offset) for PageRequest:

page0Request = PageRequest.ofSize(10).pageOffset(0);

limit.of(maxResults, offset) for Limit:

limitToFifthGroupOf10 = Limit.of(10, 40);

@njr-11 njr-11 added this to the 1.1 milestone Jun 3, 2026
@njr-11 njr-11 added the enhancement New feature or request label Jun 3, 2026
Comment thread api/src/main/java/jakarta/data/Limit.java Outdated
Good catch - I rearranged some text that was there previously and you spotted an error in it.

Co-authored-by: Stéphane Épardaud <stef@inforealm.org>
Messages.get("004.arg.negative", "offset"));
}

if (offset == Long.MAX_VALUE) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this one here.

  1. the Long.MAX_VALUE still a valid number right?

Why is this not supported?

Copy link
Copy Markdown
Member Author

@njr-11 njr-11 Jun 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1. the Long.MAX_VALUE still a valid number right?

Why is this not supported?

Of course it's a valid number. But an offset of Long.MAX_VALUE from the first result has a page number (Long.MAX_VALUE + 1) that is not representable as a positive long value. If we allowed it, what would you propose to return when a user/Data provider asks the API for the page number?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10^19 is an implausible number of rows.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know, that's precisely how many rows I have. Make it work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants