Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the Javadoc of @Query after merge of JDQL #551

Merged
merged 14 commits into from
Mar 22, 2024

Conversation

gavinking
Copy link
Contributor

This was now very out of date, and I forgot about it in #520.

Also caught some more instances of 'run time' -> 'runtime', 'life cycle' -> 'lifecycle'.

@gavinking gavinking requested review from njr-11 and otaviojava March 17, 2024 09:33
@gavinking
Copy link
Contributor Author

@njr-11 These restrictions you're worried about made perfect sense when @Query was a generic annotation that could accommodate an open-ended list of languages: SQL, JPQL, etc.

But now the language is JDQL, which is syntactically trivial. Those restrictions no longer make any sense.

@gavinking gavinking force-pushed the query-jdoc branch 2 times, most recently from 306f6ab to 0c81a33 Compare March 18, 2024 15:02
@gavinking
Copy link
Contributor Author

But now the language is JDQL, which is syntactically trivial. Those restrictions no longer make any sense.

In 6041a62 and 0c81a33 I hereby propose simply remove them. :)

@njr-11
Copy link
Contributor

njr-11 commented Mar 18, 2024

But now the language is JDQL, which is syntactically trivial. Those restrictions no longer make any sense.

In 6041a62 and 0c81a33 I hereby propose simply remove them. :)

What we have written is that the language can be JDQL or JPQL. If a Jakarta Persistence-backed Jakarta Data provider is going to handle both, then the additional restrictions do matter.

@gavinking
Copy link
Contributor Author

gavinking commented Mar 18, 2024

If a Jakarta Persistence-backed Jakarta Data provider is going to handle both, then the additional restrictions do matter.

Sure, but I really don't think it's placing an undue burden on a Jakarta Data provider which is backed by Jakarta Persistence to be able to understand JPQL if and only if that Jakarta Data provider voluntarily decides to also support arbitrary JPQL and pagination.

The spec does not place any requirement on such a provider to be able to support pagination with arbitrary JPQL, so if the provider disagrees with me, and thinks that being able to parse JPQL is a burden, then it is between the provider and the user to define how such extensions work.

All the spec requires is that the provider be able to handle JDQL.

@gavinking
Copy link
Contributor Author

To be clear, what we say about this is:

A Jakarta Data provider is not required to support the complete JPQL language, which targets relational data stores.

and in the spec:

A Jakarta Data provider backed by access to a relational database might choose to allow the use of a much larger subset of JPQL—or even the whole language—via the @Query annotation. Such extensions are not required by this specification.

So we do not need to explicitly place limitations on JPQL support.

@gavinking
Copy link
Contributor Author

@njr-11 Please see fa379ad, which makes this explicit.

@gavinking
Copy link
Contributor Author

Force pushed to clean up commit history.

Copy link
Contributor

@njr-11 njr-11 left a comment

Choose a reason for hiding this comment

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

In fact, the separate count() query is just no longer needed. That's one advantage of having our own query language!

I can certainly see the appeal of being able to get rid of the count query now that one can be assembled by replacing the SELECT clause and removing the ORDER BY clause from the primary query if using JDQL. I need to give this some more thought about where we end up with JPQL. It is certain that many users will opt for JPQL given that they are able to accomplish more with it, and we will want to be sure they aren't broken or consider themselves broken because there is no standard assuring them that pagination will still work.

@gavinking gavinking mentioned this pull request Mar 19, 2024
@gavinking
Copy link
Contributor Author

I need to give this some more thought about where we end up with JPQL.

FTR, the thing you would need to do with JPQL is replace everything between select and from with select count(1) from. This is easy in pure JPQL, since JPQL does not allow subqueries in the select clause.

Now, on the other hand, some providers, [i.e. Hibernate, but not, I believe, EclipseLink], do allow subqueries in select, and that makes the problem a bit more difficult. But that's not part of the spec and for multiple reasons not something you would need to implement support for.

@gavinking
Copy link
Contributor Author

Note also, that Hibernate has a method that does this for you: SelectionQuery.getResultCount().

EclipseLink might also have something like that.

@gavinking
Copy link
Contributor Author

FTR, the thing you would need to do with JPQL is replace everything between select and from with select count(1) from.

Oh yes, and remove order by, as you say. Also easy, since subqueries don't have order by clauses.

*
* <p><b>Positional parameters</b> are referred to by a number that corresponds to the
* numerical position, starting with 1, of the repository method parameters.</p>
* <p>Annotates a repository method as a query method, specifying a query written in Jakarta Data Query Language (JDQL)
Copy link
Contributor

Choose a reason for hiding this comment

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

That might lead to a complex discussion, but using the self-continued principle and using JPQL as a sample, we are once again able to cross-database specification.

/**
 * <p>Annotates a repository method as a query method, specifying a query written in Jakarta Data Query Language (JDQL)
 * as the minimum requirement. This encourages the use of JDQL for cross-database compatibility. Additionally, a Jakarta Data
 * provider has the freedom to support extensions to the language, including features from the Jakarta Persistence Query Language (JPQL).
 * While providers are not required to support the complete JPQL language, which primarily targets relational data stores, they are
 * encouraged to provide as broad a support as possible to enhance the flexibility and power of data access queries.</p>
 */

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's nothing wrong with what you just wrote, just not sure it's quite the right place to be saying things like that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I put it here as a sample because it was the first paragraph. The point here is that the documentation leads to JDQL or JPQL.

However, it would be great to allow NoSQL to take advantage of this advantage.

For example:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK I think I understand what you're looking for. Just not quite sure how to say it in a way which isn't out of place in the doc for that annotation. (It's the kind of thing that fits more comfortably in the spec or in module-info.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@otaviojava please see 628abf4. Is that sorta approximately like what you would like to see?

Copy link
Contributor

@njr-11 njr-11 left a comment

Choose a reason for hiding this comment

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

I think it will be acceptable to remove the counting query and have it be generated from the primary query and also to lift the restriction to have parenthesis around WHERE. The other restriction should not be removed.

api/src/main/java/jakarta/data/page/CursoredPage.java Outdated Show resolved Hide resolved
@gavinking
Copy link
Contributor Author

@njr-11 @otaviojava are there any remaining problems with this or is it OK to merge?

Copy link
Contributor

@njr-11 njr-11 left a comment

Choose a reason for hiding this comment

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

@njr-11 @otaviojava are there any remaining problems with this or is it OK to merge?

I was only waiting to review the outcome of the conversation between you and Otavio, but the pull looks find as is so I can approve it. If more commits do get added, I'll try to remember to watch out for that and review them.

@otaviojava otaviojava merged commit c4977b7 into jakartaee:main Mar 22, 2024
3 checks passed
@gavinking
Copy link
Contributor Author

Awesome!!

So according to me, JDQL is done and crossed off the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants