Skip to content

Commit df94048

Browse files
committed
add support for 'nulls first' and 'nulls last' in queries
see jakartaee#76.
1 parent 4daf494 commit df94048

File tree

3 files changed

+69
-10
lines changed

3 files changed

+69
-10
lines changed

Diff for: api/src/main/java/jakarta/persistence/criteria/CriteriaBuilder.java

+21-5
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,35 @@ public interface CriteriaBuilder {
117117

118118
/**
119119
* Create an ordering by the ascending value of the expression.
120-
* @param x expression used to define the ordering
120+
* @param expression expression used to define the ordering
121121
* @return ascending ordering corresponding to the expression
122122
*/
123-
Order asc(Expression<?> x);
123+
Order asc(Expression<?> expression);
124124

125125
/**
126126
* Create an ordering by the descending value of the expression.
127-
* @param x expression used to define the ordering
127+
* @param expression expression used to define the ordering
128128
* @return descending ordering corresponding to the expression
129129
*/
130-
Order desc(Expression<?> x);
130+
Order desc(Expression<?> expression);
131+
132+
/**
133+
* Create an ordering by the ascending value of the expression.
134+
* @param expression expression used to define the ordering
135+
* @param nullPrecedence the precedence of null values
136+
* @return ascending ordering corresponding to the expression
137+
*/
138+
Order asc(Expression<?> expression, NullPrecedence nullPrecedence);
139+
140+
/**
141+
* Create an ordering by the descending value of the expression.
142+
* @param expression expression used to define the ordering
143+
* @param nullPrecedence the precedence of null values
144+
* @return descending ordering corresponding to the expression
145+
*/
146+
Order desc(Expression<?> expression, NullPrecedence nullPrecedence);
147+
131148

132-
133149
//aggregate functions:
134150

135151
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2008, 2020 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0,
7+
* or the Eclipse Distribution License v. 1.0 which is available at
8+
* http://www.eclipse.org/org/documents/edl-v10.php.
9+
*
10+
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11+
*/
12+
13+
// Contributors:
14+
// Gavin King - 3.2
15+
16+
package jakarta.persistence.criteria;
17+
18+
/**
19+
* Specifies the precedence of null values within query result sets.
20+
*
21+
* @see CriteriaBuilder#asc(Expression, NullPrecedence)
22+
* @see CriteriaBuilder#desc(Expression, NullPrecedence)
23+
*
24+
* @since 3.2
25+
*/
26+
public enum NullPrecedence {
27+
/**
28+
* Null precedence not specified.
29+
*/
30+
NONE,
31+
/**
32+
* Null values occur at the beginning of the result set.
33+
*/
34+
FIRST,
35+
/**
36+
* Null values occur at the end of the result set.
37+
*/
38+
LAST
39+
}

Diff for: spec/src/main/asciidoc/ch04-query-language.adoc

+9-5
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,10 @@ future use.] are reserved identifiers: ABS, ALL, AND, ANY, AS, ASC,
320320
AVG, BETWEEN, BIT_LENGTH, BOTH, BY, CASE, CEILING, CHAR_LENGTH,
321321
CHARACTER_LENGTH, CLASS, COALESCE, CONCAT, COUNT, CURRENT_DATE,
322322
CURRENT_TIME, CURRENT_TIMESTAMP, DELETE, DESC, DISTINCT, ELSE, EMPTY,
323-
END, ENTRY, ESCAPE, EXISTS, EXP, EXTRACT, FALSE, FETCH, FLOOR, FROM,
324-
FUNCTION, GROUP, HAVING, IN, INDEX, INNER, IS, JOIN, KEY, LEADING,
325-
LEFT, LENGTH, LIKE, LOCAL, LN, LOCATE, LOWER, MAX, MEMBER, MIN, MOD,
326-
NEW, NOT, NULL, NULLIF, OBJECT, OF, ON, OR, ORDER, OUTER, POSITION,
323+
END, ENTRY, ESCAPE, EXISTS, EXP, EXTRACT, FALSE, FETCH, FIRST, FLOOR,
324+
FROM, FUNCTION, GROUP, HAVING, IN, INDEX, INNER, IS, JOIN, KEY, LEADING,
325+
LAST, LEFT, LENGTH, LIKE, LOCAL, LN, LOCATE, LOWER, MAX, MEMBER, MIN, MOD,
326+
NEW, NOT, NULL, NULLS, NULLIF, OBJECT, OF, ON, OR, ORDER, OUTER, POSITION,
327327
POWER, ROUND, SELECT, SET, SIGN, SIZE, SOME, SQRT, SUBSTRING, SUM,
328328
THEN, TRAILING, TREAT, TRIM, TRUE, TYPE, UNKNOWN, UPDATE, UPPER,
329329
VALUE, WHEN, WHERE.
@@ -2510,6 +2510,7 @@ orderby_clause ::= ORDER BY orderby_item {, orderby_item}*
25102510
orderby_item ::=
25112511
{state_field_path_expression | general_identification_variable | result_variable}
25122512
[ASC | DESC]
2513+
[NULLS {FIRST | LAST}]
25132514
----
25142515

25152516
An orderby_item must be one of the following:
@@ -2586,7 +2587,9 @@ ordering be used for the associated _orderby_item_; the keyword DESC
25862587
specifies that descending ordering be used. Ascending ordering is the
25872588
default.
25882589

2589-
SQL rules for the ordering of null values
2590+
The keyword NULLS specifies the ordering of null values, either FIRST or LAST.
2591+
2592+
If NULLS is not specified, SQL rules for the ordering of null values
25902593
apply: that is, all null values must appear before all non-null values
25912594
in the ordering or all null values must appear after all non-null values
25922595
in the ordering, but it is not specified which.
@@ -2985,6 +2988,7 @@ orderby_item ::=
29852988
general_identification_variable |
29862989
result_variable
29872990
[ASC | DESC]
2991+
[NULLS {FIRST | LAST}]
29882992
subquery ::= simple_select_clause subquery_from_clause [where_clause]
29892993
[groupby_clause] [having_clause]
29902994
subquery_from_clause ::=

0 commit comments

Comments
 (0)