Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions api/src/main/java/jakarta/data/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public List<Sort<? super T>> sorts() {
@Override
public boolean equals(Object other) {
return this == other
|| other instanceof Order s && sorts.equals(s.sorts);
|| other instanceof Order<?> s && sorts.equals(s.sorts);
}

/**
Expand All @@ -164,7 +164,6 @@ public Iterator<Sort<? super T>> iterator() {
return sorts.iterator();
}


/**
* Textual representation of this instance, including the result of invoking
* {@link Sort#toString()} on each member of the sort criteria, in order of
Expand Down
304 changes: 251 additions & 53 deletions api/src/main/java/jakarta/data/Sort.java

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions api/src/main/java/jakarta/data/Sortable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2026 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package jakarta.data;

/**
* An entity attribute or expression that can be used to sort query results.
*
* @since 1.1
* @param <T> the entity type
*/
public interface Sortable<T> {

/**
* Obtain an ascending {@linkplain Sort sorting criterion} based on
* this entity attribute or expression.
*
* @return the sorting criterion.
*/
default Sort<T> asc() {
return Sort.asc(this);
}

/**
* Obtain a descending {@linkplain Sort sorting criterion} based on
* this entity attribute or expression.
*
* @return the sorting criterion.
*/
default Sort<T> desc() {
return Sort.desc(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package jakarta.data.expression;

import jakarta.data.Sortable;
import jakarta.data.constraint.Between;
import jakarta.data.constraint.GreaterThan;
import jakarta.data.constraint.AtLeast;
Expand Down Expand Up @@ -44,7 +45,7 @@
* @since 1.1
*/
public interface ComparableExpression<T, V extends Comparable<?>>
extends Expression<T, V> {
extends Expression<T, V>, Sortable<T> {

/**
* <p>Obtains a {@link Restriction} that requires that this expression
Expand Down
24 changes: 2 additions & 22 deletions api/src/main/java/jakarta/data/metamodel/SortableAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package jakarta.data.metamodel;

import jakarta.data.Sort;
import jakarta.data.Sortable;
import jakarta.data.messages.Messages;

/**
Expand All @@ -38,27 +38,7 @@
*
* @param <T> entity class of the static metamodel.
*/
public interface SortableAttribute<T> extends Attribute<T> {

/**
* Obtain a request for an ascending {@link Sort} based on the entity
* attribute.
*
* @return a request for an ascending sort on the entity attribute.
*/
default Sort<T> asc() {
return Sort.asc(name());
}

/**
* Obtain a request for a descending {@link Sort} based on the entity
* attribute.
*
* @return a request for a descending sort on the entity attribute.
*/
default Sort<T> desc() {
return Sort.desc(name());
}
public interface SortableAttribute<T> extends Attribute<T>, Sortable<T> {

/**
* <p>Creates a static metamodel {@code SortableAttribute} representing the
Expand Down
24 changes: 12 additions & 12 deletions api/src/main/java/jakarta/data/metamodel/TextAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,6 @@
*/
public interface TextAttribute<T> extends ComparableAttribute<T, String>, TextExpression<T> {

/**
* Obtain a request for an ascending, case-insensitive {@link Sort} based on
* the entity attribute.
*
* @return a request for an ascending, case-insensitive sort on the entity
* attribute.
*/
default Sort<T> ascIgnoreCase() {
return Sort.ascIgnoreCase(name());
}

/**
* Returns {@code String.class} as the entity attribute type for text
* attributes.
Expand All @@ -51,6 +40,17 @@ default Class<String> type() {
return String.class;
}

/**
* Obtain a request for an ascending, case-insensitive {@link Sort} based on
* the entity attribute.
*
* @return a request for an ascending, case-insensitive sort on the entity
* attribute.
*/
default Sort<T> ascIgnoreCase() {
return Sort.ascIgnoreCase(this);
}

/**
* Obtain a request for a descending, case insensitive {@link Sort} based on
* the entity attribute.
Expand All @@ -59,7 +59,7 @@ default Class<String> type() {
* attribute.
*/
default Sort<T> descIgnoreCase() {
return Sort.descIgnoreCase(name());
return Sort.descIgnoreCase(this);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions api/src/test/java/jakarta/data/SortTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ class SortTest {
@DisplayName("Should throw NullPointerException when one of the properties are null")
void shouldReturnErrorWhenPropertyDirectionNull() {
assertThatNullPointerException().isThrownBy(() ->
Sort.of(null, null, false));
Sort.of((String) null, null, false));
assertThatNullPointerException().isThrownBy(() ->
Sort.of(NAME, null, true));
assertThatNullPointerException().isThrownBy(() ->
Sort.of(null, Direction.ASC, false));
Sort.of((String) null, Direction.ASC, false));
assertThatNullPointerException().isThrownBy(() ->
Sort.of(null, null, false, Sort.Nulls.FIRST));
Sort.of((String) null, null, false, Sort.Nulls.FIRST));
assertThatNullPointerException().isThrownBy(() ->
Sort.of(NAME, null, true, Sort.Nulls.LAST));
assertThatNullPointerException().isThrownBy(() ->
Sort.of(null, Direction.ASC, false, Sort.Nulls.UNSPECIFIED));
Sort.of((String) null, Direction.ASC, false, Sort.Nulls.UNSPECIFIED));
assertThatNullPointerException().isThrownBy(() ->
Sort.of(NAME, Direction.ASC, false, null));
}
Expand Down