Skip to content

make ComparableExpressions sortable#1455

Open
gavinking wants to merge 2 commits into
jakartaee:mainfrom
gavinking:sortable-expressions
Open

make ComparableExpressions sortable#1455
gavinking wants to merge 2 commits into
jakartaee:mainfrom
gavinking:sortable-expressions

Conversation

@gavinking

Copy link
Copy Markdown
Member

This had a bigger impact than I expected.

Question: do we need SortableExpression?

@gavinking gavinking requested review from njr-11 and otaviojava May 20, 2026 18:23
Comment on lines +223 to 224
@Deprecated(since = "1.1", forRemoval = true)
public Sort(String property, boolean isAscending, boolean ignoreCase) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

👀

Comment on lines -91 to +86
public record Sort<T>(String property,
boolean isAscending,
boolean ignoreCase,
Nulls nullOrdering) {
public final class Sort<T> {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

👀

@njr-11 njr-11 left a comment

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.

I'd rather not introduce Sortable. It doesn't do anything useful for the end user and I don't think we need it. I wanted to try out adding the asc/desc methods to ComparableExpression and the ascIgnoreCase/descIgnoreCase methods to TextExpression. This seems to work fine in a commit of 1400 where I tried it out. I created a couple of new unit tests to verify it as well as updating the test that were previously under 1400 so they test navigable expressions rather than navigable attributes. That all seemed to work.

Comment on lines +34 to +36
default Sort<T> asc() {
return Sort.asc(this);
}

@gavinking gavinking Jun 19, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So @njr-11 the thing I would still defend here after our last conversation is I think this is a much more elegant way to construct a Sort.

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.

I agree Sort.asc(expression) is more elegant than using a constructor, but this is internal usage and the end user already has a better option in directly using the metamodel. Nonetheless, I added it to the other PR given that I don't see anything objectionable about it.

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.

Missing a way to statically reference a sort by an embedded or associated property

2 participants