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

use @Query and @Find for example code in chapter 4 #663

Merged
merged 2 commits into from
Apr 11, 2024

Conversation

gavinking
Copy link
Contributor

instead of Query by Method Name, which has been exiled to a separate document.

@gavinking gavinking force-pushed the query-find-examples branch from a4938c2 to b1d4c56 Compare April 5, 2024 17:00
@gavinking gavinking force-pushed the query-find-examples branch from b1d4c56 to e0248b2 Compare April 5, 2024 17:03
@gavinking gavinking requested a review from njr-11 April 7, 2024 09:10
Comment on lines 358 to 362
@Query("where left(name,length(?1)) = ?1")
@OrderBy(_User.TYPE)
Page<User> findByNamePrefix(String namePrefix,
PageRequest pagination,
Order<User> sorts);
Copy link
Contributor

Choose a reason for hiding this comment

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

Prior to your changes, these examples covered 5 scenarios:

OrderBy keyword + Order param
OrderBy keyword + Sort... param
OrderBy anno + Order param
OrderBy anno + Sort... param
Query without ORDER BY + OrderBy anno + Order param

After changes, it now only covers 2 scenarios with several duplicated:

Query without ORDER BY + OrderBy anno + Order param
Query without ORDER BY + OrderBy anno + Sort... param
Query without ORDER BY + OrderBy anno + Order param
Query without ORDER BY + OrderBy anno + Sort... param
Query without ORDER BY + OrderBy anno + Order param

Adding suggestions to restore to previous:

Suggested change
@Query("where left(name,length(?1)) = ?1")
@OrderBy(_User.TYPE)
Page<User> findByNamePrefix(String namePrefix,
PageRequest pagination,
Order<User> sorts);
Page<User> findByNameStartsWithOrderByType(String namePrefix,
PageRequest pagination,
Order<User> sorts);

Comment on lines 365 to 367
@Query("where left(name,length(?1)) = ?1")
@OrderBy(_User.TYPE)
List<User> findByNamePrefix(String namePrefix, Sort<?>... sorts);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@Query("where left(name,length(?1)) = ?1")
@OrderBy(_User.TYPE)
List<User> findByNamePrefix(String namePrefix, Sort<?>... sorts);
List<User> findByNameStartsWithOrderByType(String namePrefix, Sort<?>... sorts);

Comment on lines 370 to 374
@Query("where left(name,length(?1)) = ?1")
@OrderBy(_User.AGE)
Page<User> findByNamePrefix(String namePrefix,
PageRequest pagination,
Order<User> sorts);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@Query("where left(name,length(?1)) = ?1")
@OrderBy(_User.AGE)
Page<User> findByNamePrefix(String namePrefix,
PageRequest pagination,
Order<User> sorts);
@OrderBy(_User.AGE)
Page<User> findByNameStartsWith(String namePrefix,
PageRequest pagination,
Order<User> sorts);

Comment on lines 377 to 379
@Query("where left(name,length(?1)) = ?1")
@OrderBy(_User.AGE)
List<User> findByNamePrefix(String namePrefix, Sort<?>... sorts);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@Query("where left(name,length(?1)) = ?1")
@OrderBy(_User.AGE)
List<User> findByNamePrefix(String namePrefix, Sort<?>... sorts);
@OrderBy(_User.AGE)
List<User> findByNameStartsWith(String namePrefix, Sort<?>... sorts);

@gavinking
Copy link
Contributor Author

@njr-11 Again, I don't think we should be having examples with QbMN in the main spec, because the main spec does not define what QbMN is. I agree that there is now duplication in the examples; the best fix to that would be to simply delete a couple of them.

@gavinking
Copy link
Contributor Author

I mean, a reader of the Jakarta Data spec is going to encounter those examples and think "WTF is this findByNameStartsWithOrderByType stuff?"

@gavinking
Copy link
Contributor Author

Please see 9c43087, which removes the duplication.

@njr-11
Copy link
Contributor

njr-11 commented Apr 8, 2024

@njr-11 Again, I don't think we should be having examples with QbMN in the main spec, because the main spec does not define what QbMN is. I agree that there is now duplication in the examples; the best fix to that would be to simply delete a couple of them.

Given that Query by Method Name is still part of Jakarta Data, the spec has an obligation to cover how it behaves with respect to the rest of the specification, regardless of whether it is defined in a separate PDF or not. These examples are probably not that important and it could be stated that OrderBy keyword behaves the same as OrderBy annotation here, but I don't want to start a precedent for neglecting to adequately cover Query by Method Name because of where it appears in the spec.

@gavinking
Copy link
Contributor Author

@njr-11 Then move the examples to the Query by Method Name document. I'm not sure they're needed, but I don't object to having them. I've put quite a lot of work into improving the material in that document over the weekend, but any help would be appreciated, which includes anything you think is missing and want to add.

But for sure these examples don't belong where they are right now, because the reader has never encountered a Query by Method Name, and will have no idea how to interpret the examples. Examples have to be examples of something you have properly introduced previously. You have to assume that the reader is reading the text in a linear fashion, even if that's not always the case in practice.

@gavinking
Copy link
Contributor Author

I think this should be merged.

I insist that we should never have examples in the spec which the reader will not understand. What is the point of such an example?

@njr-11
Copy link
Contributor

njr-11 commented Apr 11, 2024

I insist that we should never have examples in the spec which the reader will not understand. What is the point of such an example?

I don't agree that the user will not understand. Query by Method Name is still part of the spec, whether in one document or the other. If having it in the other document causes this much trouble and is used as justification for not being able to refer to it and use it in examples in the rest of the specification, then it should not have been moved. That said, I do not see anything that is incorrect about your changes, and you have at least one other fix to an error in here so I will agree to approve it.

@njr-11 njr-11 added the documentation Improvements or additions to documentation label Apr 11, 2024
@njr-11 njr-11 added this to the Jakarta Data 1.0 milestone Apr 11, 2024
@otaviojava otaviojava merged commit 735525b into jakartaee:main Apr 11, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants