|
25 | 25 | /**
|
26 | 26 | * <p>Annotates a parameter of a repository {@link Find} or {@link Delete} method,
|
27 | 27 | * 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> |
30 | 32 | *
|
31 | 33 | * <p>For example,</p>
|
32 | 34 | *
|
|
40 | 42 | *
|
41 | 43 | * // Find a page of Product entities where the name field matches a pattern, ignoring case.
|
42 | 44 | * @Find
|
43 |
| - * Page<Product> search(@By(_Product.NAME) @Is(LIKE_IGNORE_CASE) String pattern, |
| 45 | + * Page<Product> search(@By(_Product.NAME) @Is(LIKE_ANY_CASE) String pattern, |
44 | 46 | * PageRequest pagination,
|
45 | 47 | * Order<Product> order);
|
46 | 48 | *
|
|
53 | 55 | @Retention(RetentionPolicy.RUNTIME)
|
54 | 56 | @Target(ElementType.PARAMETER)
|
55 | 57 | 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 | 58 |
|
72 | 59 | /**
|
73 | 60 | * <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> |
78 | 62 | *
|
79 | 63 | * <p>The following example compares the year a person was born against
|
80 | 64 | * a minimum and maximum year that are supplied as parameters to a repository
|
|
83 | 67 | * <pre>
|
84 | 68 | * @Find
|
85 | 69 | * @OrderBy(_Person.YEAR_BORN)
|
86 |
| - * List<Person> bornWithin(@By(_Person.YEAR_BORN) @Is(TREATER_THAN_EQ) float minYear, |
| 70 | + * List<Person> bornWithin(@By(_Person.YEAR_BORN) @Is(GREATER_THAN_EQ) float minYear, |
87 | 71 | * @By(_Person.YEAR_BORN) @Is(LESS_THAN_EQ) float maxYear);
|
88 | 72 | * </pre>
|
89 | 73 | *
|
|
94 | 78 | * statically import one or more constants from this class. For example:</p>
|
95 | 79 | *
|
96 | 80 | * <pre>
|
97 |
| - * import static jakarta.data.repository.Is.*; |
| 81 | + * import static jakarta.data.repository.Is.Op.*; |
98 | 82 | * </pre>
|
99 | 83 | *
|
100 | 84 | * @return the type of comparison operation.
|
101 | 85 | */
|
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 | + } |
103 | 131 | }
|
0 commit comments