Skip to content

Commit 179adee

Browse files
committed
Put the enumeration back, but keep the upper case, and shorten IGNORE_CASE to ANY_CASE
1 parent 142cfd0 commit 179adee

File tree

5 files changed

+61
-33
lines changed

5 files changed

+61
-33
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(LIKE_IGNORE_CASE) String namePattern,
37+
* Product[] named(&#64;By(_Product.NAME) &#64;Is(LIKE_ANY_CASE) String namePattern,
3838
* Limit limit,
3939
* Sort&lt;Product&gt;... sorts);
4040
*

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

+53-25
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
/**
2626
* <p>Annotates a parameter of a repository {@link Find} or {@link Delete} method,
2727
* indicating how a persistent field is compared against the parameter's value.
28-
* The {@link By} annotation is used on the same parameter to identify the
29-
* persistent field.</p>
28+
* The {@link By} annotation can be used on the same parameter to identify the
29+
* persistent field. Otherwise, if the {@code -parameters} compile option is
30+
* enabled, the the persistent field is inferred by matching the name of the
31+
* method parameter.</p>
3032
*
3133
* <p>For example,</p>
3234
*
@@ -40,7 +42,7 @@
4042
*
4143
* // Find a page of Product entities where the name field matches a pattern, ignoring case.
4244
* &#64;Find
43-
* Page&lt;Product&gt; search(&#64;By(_Product.NAME) &#64;Is(LIKE_IGNORE_CASE) String pattern,
45+
* Page&lt;Product&gt; search(&#64;By(_Product.NAME) &#64;Is(LIKE_ANY_CASE) String pattern,
4446
* PageRequest pagination,
4547
* Order&lt;Product&gt; order);
4648
*
@@ -53,28 +55,10 @@
5355
@Retention(RetentionPolicy.RUNTIME)
5456
@Target(ElementType.PARAMETER)
5557
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";
7158

7259
/**
7360
* <p>The type of comparison operation to use when comparing a persistent
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>
61+
* field against a value that is supplied to a repository method..</p>
7862
*
7963
* <p>The following example compares the year a person was born against
8064
* a minimum and maximum year that are supplied as parameters to a repository
@@ -83,7 +67,7 @@
8367
* <pre>
8468
* &#64;Find
8569
* &#64;OrderBy(_Person.YEAR_BORN)
86-
* List&lt;Person&gt; bornWithin(&#64;By(_Person.YEAR_BORN) &#64;Is(TREATER_THAN_EQ) float minYear,
70+
* List&lt;Person&gt; bornWithin(&#64;By(_Person.YEAR_BORN) &#64;Is(GREATER_THAN_EQ) float minYear,
8771
* &#64;By(_Person.YEAR_BORN) &#64;Is(LESS_THAN_EQ) float maxYear);
8872
* </pre>
8973
*
@@ -94,10 +78,54 @@
9478
* statically import one or more constants from this class. For example:</p>
9579
*
9680
* <pre>
97-
* import static jakarta.data.repository.Is.*;
81+
* import static jakarta.data.repository.Is.Op.*;
9882
* </pre>
9983
*
10084
* @return the type of comparison operation.
10185
*/
102-
String value() default EQUAL;
86+
Op value() default Op.EQUAL;
87+
88+
/**
89+
* <p>Comparison operations for the {@link Is} annotation.</p>
90+
*
91+
* <p>For more concise code, it can be convenient to statically import one
92+
* or more comparison operations. For example:</p>
93+
*
94+
* <pre>
95+
* import static jakarta.data.repository.Is.Op.*;
96+
* </pre>
97+
*/
98+
public static enum Op {
99+
// TODO add JavaDoc with examples to these
100+
ANY_CASE,
101+
EQUAL,
102+
GREATER_THAN,
103+
GREATER_THAN_ANY_CASE,
104+
GREATER_THAN_EQ,
105+
GREATER_THAN_EQ_ANY_CASE,
106+
IN,
107+
LESS_THAN,
108+
LESS_THAN_ANY_CASE,
109+
LESS_THAN_EQ,
110+
LESS_THAN_EQ_ANY_CASE,
111+
LIKE,
112+
LIKE_ANY_CASE,
113+
PREFIXED,
114+
PREFIXED_ANY_CASE,
115+
SUBSTRINGED,
116+
SUBSTRINGED_ANY_CASE,
117+
SUFFIXED,
118+
SUFFIXED_ANY_CASE,
119+
NOT,
120+
NOT_ANY_CASE,
121+
NOT_IN,
122+
NOT_LIKE,
123+
NOT_LIKE_ANY_CASE,
124+
NOT_PREFIXED,
125+
NOT_PREFIXED_ANY_CASE,
126+
NOT_SUBSTRINGED,
127+
NOT_SUBSTRINGED_ANY_CASE,
128+
NOT_SUFFIXED,
129+
NOT_SUFFIXED_ANY_CASE;
130+
}
103131
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
* <pre>
119119
* &#64;Find
120120
* &#64;OrderBy("age")
121-
* Stream&lt;Person&gt; withLastName(&#64;By("lastName") &#64;Is(IGNORE_CASE) String surname);
121+
* Stream&lt;Person&gt; withLastName(&#64;By("lastName") &#64;Is(ANY_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(LIKE_IGNORE_CASE) String namePattern);
42+
* List&lt;Product&gt; named(&#64;By("name") &#64;Is(LIKE_ANY_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

+5-5
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
* &#64;Find
7575
* &#64;OrderBy("price")
7676
* List&lt;Product&gt; search(
77-
* &#64;By("name") &#64;Is(LIKE_IGNORE_CASE) String namePattern,
77+
* &#64;By("name") &#64;Is(LIKE_ANY_CASE) String namePattern,
7878
* &#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")
@@ -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(LIKE_IGNORE_CASE) String pattern,
813+
* Product[] named(&#64;By(_Product.NAME) &#64;Is(LIKE_ANY_CASE) String pattern,
814814
* PageRequest pageRequest);
815815
* ...
816816
* page1 = products.named("%phone%", PageRequest.ofSize(20));
@@ -828,7 +828,7 @@
828828
*
829829
* <pre>
830830
* &#64;Find
831-
* Product[] search(&#64;By("name") &#64;Is(LIKE_IGNORE_CASE) String pattern,
831+
* Product[] search(&#64;By("name") &#64;Is(LIKE_ANY_CASE) String pattern,
832832
* &#64;By("price") &#64;Is(GREATER_THAN_EQ) float minPrice,
833833
* &#64;By("price") &#64;Is(LESS_THAN_EQ) float maxPrice,
834834
* PageRequest pageRequest,
@@ -848,7 +848,7 @@
848848
*
849849
* <pre>
850850
* &#64;Find
851-
* Product[] named(&#64;By("name") &#64;Is(LIKE_IGNORE_CASE) String pattern,
851+
* Product[] named(&#64;By("name") &#64;Is(LIKE_ANY_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(LIKE_IGNORE_CASE) String pattern,
869+
* Product[] named(&#64;By("name") &#64;Is(LIKE_ANY_CASE) String pattern,
870870
* Limit max,
871871
* {@code Sort<?>...} sortBy);
872872
*

0 commit comments

Comments
 (0)