Skip to content

Commit 142cfd0

Browse files
committed
Switch to String constants with capitalized names
1 parent 059afd2 commit 142cfd0

File tree

7 files changed

+53
-68
lines changed

7 files changed

+53
-68
lines changed

api/src/main/java/jakarta/data/Limit.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*
3535
* <pre>
3636
* &#64;Find
37-
* Product[] named(&#64;By(_Product.NAME) &#64;Is(LikeIgnoreCase) String namePattern,
37+
* Product[] named(&#64;By(_Product.NAME) &#64;Is(LIKE_IGNORE_CASE) String namePattern,
3838
* Limit limit,
3939
* Sort&lt;Product&gt;... sorts);
4040
*

api/src/main/java/jakarta/data/page/CursoredPage.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
* &#64;OrderBy(_Employee.FIRSTNAME)
6161
* &#64;OrderBy(_Employee.ID)
6262
* CursoredPage&lt;Employee&gt; withOvertime(
63-
* &#64;By(_Employee.HOURSWORKED) &#64;Is(GreaterThan) int fullTimeHours,
63+
* &#64;By(_Employee.HOURSWORKED) &#64;Is(GREATER_THAN) int fullTimeHours,
6464
* PageRequest pageRequest);
6565
* </pre>
6666
*

api/src/main/java/jakarta/data/page/PageRequest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
* &#64;Find
4141
* &#64;OrderBy("age")
4242
* &#64;OrderBy("ssn")
43-
* Person[] agedBetween(&#64;By("age") &#64;Is(GreaterThanEqual) int minAge,
44-
* &#64;By("age") &#64;Is(LessThanEqual) int maxAge,
43+
* Person[] agedBetween(&#64;By("age") &#64;Is(GREATER_THAN_EQ) int minAge,
44+
* &#64;By("age") &#64;Is(LESS_THAN_EQ) int maxAge,
4545
* PageRequest pageRequest);
4646
* </pre>
4747
*

api/src/main/java/jakarta/data/repository/Is.java

+33-48
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,45 @@
3636
*
3737
* // Find all Product entities where the price field is less than a maximum value.
3838
* &#64;Find
39-
* List&lt;Product&gt; pricedBelow(&#64;By(_Product.PRICE) &#64;Is(LessThan) float max);
39+
* List&lt;Product&gt; pricedBelow(&#64;By(_Product.PRICE) &#64;Is(LESS_THAN) float max);
4040
*
4141
* // Find a page of Product entities where the name field matches a pattern, ignoring case.
4242
* &#64;Find
43-
* Page&lt;Product&gt; search(&#64;By(_Product.NAME) &#64;Is(LikeIgnoreCase) String pattern,
43+
* Page&lt;Product&gt; search(&#64;By(_Product.NAME) &#64;Is(LIKE_IGNORE_CASE) String pattern,
4444
* PageRequest pagination,
4545
* Order&lt;Product&gt; order);
4646
*
4747
* // Remove Product entities with any of the unique identifiers listed.
4848
* &#64;Delete
49-
* void remove(&#64;By(ID) &#64;Is(In) List&lt;Long&gt; productIds);
49+
* void remove(&#64;By(ID) &#64;Is(IN) List&lt;Long&gt; productIds);
5050
* }
5151
* </pre>
5252
*/
5353
@Retention(RetentionPolicy.RUNTIME)
5454
@Target(ElementType.PARAMETER)
5555
public @interface Is {
56+
// TODO add JavaDoc with examples to these
57+
String EQUAL = "EQUAL";
58+
String GREATER_THAN = "GREATER_THAN";
59+
String GREATER_THAN_EQ = "GREATER_THAN_EQ";
60+
String IGNORE_CASE = "IGNORE_CASE";
61+
String IN = "IN";
62+
String LESS_THAN = "LESS_THAN";
63+
String LESS_THAN_EQ = "LESS_THAN_EQ";
64+
String LIKE = "LIKE";
65+
String LIKE_IGNORE_CASE = "LIKE_IGNORE_CASE";
66+
String NOT = "NOT";
67+
String NOT_IGNORE_CASE = "NOT_IGNORE_CASE";
68+
String NOT_IN = "NOT_IN";
69+
String NOT_LIKE = "NOT_LIKE";
70+
String NOT_LIKE_IGNORE_CASE = "NOT_LIKE_IGNORE_CASE";
71+
5672
/**
5773
* <p>The type of comparison operation to use when comparing a persistent
58-
* field against a value that is supplied to a repository method.</p>
74+
* field against a value that is supplied to a repository method.
75+
* For portable applications, the comparison operation must be one of the
76+
* constants defined within this class. Jakarta Data providers might choose
77+
* to provide their own constants as non-portable extensions.</p>
5978
*
6079
* <p>The following example compares the year a person was born against
6180
* a minimum and maximum year that are supplied as parameters to a repository
@@ -64,55 +83,21 @@
6483
* <pre>
6584
* &#64;Find
6685
* &#64;OrderBy(_Person.YEAR_BORN)
67-
* List&lt;Person&gt; bornWithin(&#64;By(_Person.YEAR_BORN) &#64;Is(GreaterThanEqual) float minYear,
68-
* &#64;By(_Person.YEAR_BORN) &#64;Is(LessThanEqual) float maxYear);
86+
* List&lt;Person&gt; bornWithin(&#64;By(_Person.YEAR_BORN) &#64;Is(TREATER_THAN_EQ) float minYear,
87+
* &#64;By(_Person.YEAR_BORN) &#64;Is(LESS_THAN_EQ) float maxYear);
6988
* </pre>
7089
*
71-
* <p>The default comparison operation is the {@linkplain Op#Equal equality}
72-
* comparison.</p>
73-
*
74-
* @return the type of comparison operation.
75-
*/
76-
Op value() default Op.Equal;
77-
78-
/**
79-
* <p>Comparison operations for the {@link Is} annotation.</p>
90+
* <p>The default comparison operation is the {@linkplain #EQUAL equality}
91+
* comparison.</p>
8092
*
81-
* <p>For more concise code, it can be convenient to statically import one
82-
* or more comparison operations. For example:</p>
93+
* <p>For concise code, it can be convenient for a repository interface to
94+
* statically import one or more constants from this class. For example:</p>
8395
*
8496
* <pre>
85-
* import static jakarta.data.repository.Is.Op.*;
97+
* import static jakarta.data.repository.Is.*;
8698
* </pre>
99+
*
100+
* @return the type of comparison operation.
87101
*/
88-
public static enum Op {
89-
// TODO add JavaDoc with examples to these
90-
Equal,
91-
GreaterThan,
92-
GreaterThanEqual,
93-
IgnoreCase,
94-
In,
95-
LessThan,
96-
LessThanEqual,
97-
Like,
98-
LikeIgnoreCase,
99-
// TODO might want to give more thought to the exact names,
100-
Prefixed,
101-
PrefixedIgnoreCase,
102-
Substringed,
103-
SubstringedIgnoreCase,
104-
Suffixed,
105-
SuffixedIgnoreCase,
106-
Not,
107-
NotIgnoreCase,
108-
NotIn,
109-
NotLike,
110-
NotLikeIgnoreCase,
111-
NotPrefixed,
112-
NotPrefixedIgnoreCase,
113-
NotSubstringed,
114-
NotSubstringedIgnoreCase,
115-
NotSuffixed,
116-
NotSuffixedIgnoreCase;
117-
}
102+
String value() default EQUAL;
118103
}

api/src/main/java/jakarta/data/repository/OrderBy.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
* <pre>
6565
* &#64;Find
6666
* &#64;OrderBy(value = _Product.PRICE, descending = true)
67-
* {@code Stream<Product>} pricedBelow(&#64;By(_Product.PRICE) &#64;Is(LessThan) double maxPrice);
67+
* {@code Stream<Product>} pricedBelow(&#64;By(_Product.PRICE) &#64;Is(LESS_THAN) double maxPrice);
6868
* </pre>
6969
*
7070
* <p>A repository method with an {@code @OrderBy} annotation must not
@@ -118,7 +118,7 @@
118118
* <pre>
119119
* &#64;Find
120120
* &#64;OrderBy("age")
121-
* Stream&lt;Person&gt; withLastName(&#64;By("lastName") &#64;Is(IgnoreCase) String surname);
121+
* Stream&lt;Person&gt; withLastName(&#64;By("lastName") &#64;Is(IGNORE_CASE) String surname);
122122
* </pre>
123123
*
124124
* @return entity attribute name.

api/src/main/java/jakarta/data/repository/Repository.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
*
4040
* &#64;Find
4141
* &#64;OrderBy("price")
42-
* List&lt;Product&gt; named(&#64;By("name") &#64;Is(LikeIgnoreCase) String namePattern);
42+
* List&lt;Product&gt; named(&#64;By("name") &#64;Is(LIKE_IGNORE_CASE) String namePattern);
4343
*
4444
* &#64;Query("UPDATE Product SET price = price - (price * ?1) WHERE price * ?1 &lt;= ?2")
4545
* int putOnSale(float rateOfDiscount, float maxDiscount);

api/src/main/java/module-info.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@
7474
* &#64;Find
7575
* &#64;OrderBy("price")
7676
* List&lt;Product&gt; search(
77-
* &#64;By("name") &#64;Is(LikeIgnoreCase) String namePattern,
78-
* &#64;By("price") &#64;Is(LessThanEqual) float max);
77+
* &#64;By("name") &#64;Is(LIKE_IGNORE_CASE) String namePattern,
78+
* &#64;By("price") &#64;Is(lESS_THAN_EQ) float max);
7979
*
8080
* &#64;Query("UPDATE Product SET price = price * (1.0 - ?1) WHERE yearProduced &lt;= ?2")
8181
* int discountOldInventory(float rateOfDiscount, int maxYear);
@@ -157,7 +157,7 @@
157157
* &#64;Find
158158
* &#64;OrderBy("address.zipCode")
159159
* List&lt;Purchase&gt; forZipCodes(
160-
* &#64;By("address.zipCode") &#64;Is(In) List&lt;Integer&gt; zipCodes);
160+
* &#64;By("address.zipCode") &#64;Is(IN) List&lt;Integer&gt; zipCodes);
161161
*
162162
* &#64;Query("WHERE address.zipCode = ?1")
163163
* List&lt;Purchase&gt; forZipCode(int zipCode);
@@ -729,7 +729,7 @@
729729
* &#64;OrderBy("firstName")
730730
* List&lt;Person&gt; ofNationalityAndOlderThan(
731731
* Country nationality,
732-
* &#64;By("age") &#64;Is(GreaterThan) int minAge);
732+
* &#64;By("age") &#64;Is(GREATER_THAN) int minAge);
733733
* </pre>
734734
*
735735
* <pre>
@@ -739,7 +739,7 @@
739739
*
740740
* <pre>
741741
* &#64;Delete
742-
* void remove(&#64;By("status") &#64;Is(In) List&lt;Status&gt; list);
742+
* void remove(&#64;By("status") &#64;Is(IN) List&lt;Status&gt; list);
743743
* </pre>
744744
*
745745
* <p>The {@code _} character may be used in a method parameter name to
@@ -767,8 +767,8 @@
767767
* &#64;Find
768768
* Vehicle[] search(String make,
769769
* String model,
770-
* &#64;By(_Vehicle.YEAR) &#64;Is(GreaterThanEqual) int minYear,
771-
* &#64;By(_Vehicle.YEAR) &#64;Is(LessThanEqual) int maxYear,
770+
* &#64;By(_Vehicle.YEAR) &#64;Is(GREATER_THAN_EQ) int minYear,
771+
* &#64;By(_Vehicle.YEAR) &#64;Is(LESS_THAN_EQ) int maxYear,
772772
* Sort&lt;?&gt;... sorts);
773773
* </pre>
774774
*
@@ -810,7 +810,7 @@
810810
* &#64;Find
811811
* &#64;OrderBy(value = _Product.AMOUNT_SOLD, descending = true)
812812
* &#64;OrderBy(ID)
813-
* Product[] named(&#64;By(_Product.NAME) &#64;Is(LikeIgnoreCase) String pattern,
813+
* Product[] named(&#64;By(_Product.NAME) &#64;Is(LIKE_IGNORE_CASE) String pattern,
814814
* PageRequest pageRequest);
815815
* ...
816816
* page1 = products.named("%phone%", PageRequest.ofSize(20));
@@ -828,9 +828,9 @@
828828
*
829829
* <pre>
830830
* &#64;Find
831-
* Product[] search(&#64;By("name") &#64;Is(LikeIgnoreCase) String pattern,
832-
* &#64;By("price") &#64;Is(GreaterThanEqual) float minPrice,
833-
* &#64;By("price") &#64;Is(LessThanEqual) float maxPrice,
831+
* Product[] search(&#64;By("name") &#64;Is(LIKE_IGNORE_CASE) String pattern,
832+
* &#64;By("price") &#64;Is(GREATER_THAN_EQ) float minPrice,
833+
* &#64;By("price") &#64;Is(LESS_THAN_EQ) float maxPrice,
834834
* PageRequest pageRequest,
835835
* Order&lt;Product&gt; order);
836836
*
@@ -848,7 +848,7 @@
848848
*
849849
* <pre>
850850
* &#64;Find
851-
* Product[] named(&#64;By("name") &#64;Is(LikeIgnoreCase) String pattern,
851+
* Product[] named(&#64;By("name") &#64;Is(LIKE_IGNORE_CASE) String pattern,
852852
* Limit max,
853853
* Order&lt;Product&gt; sortBy);
854854
*
@@ -866,7 +866,7 @@
866866
*
867867
* <pre>
868868
* &#64;Find
869-
* Product[] named(&#64;By("name") &#64;Is(LikeIgnoreCase) String pattern,
869+
* Product[] named(&#64;By("name") &#64;Is(LIKE_IGNORE_CASE) String pattern,
870870
* Limit max,
871871
* {@code Sort<?>...} sortBy);
872872
*

0 commit comments

Comments
 (0)