- All Superinterfaces:
Constraint<String>
A constraint that requires matching a pattern.
A parameter-based repository method can impose a constraint on an
entity attribute by defining a method parameter that is of type
Like or is annotated @Is(Like.class) and is of type
String. For example,
@Find
List<Car> matchVIN(@By(_Car.VIN) Like vinPattern);
@Find // requires the -parameters compiler option to preserve parameter names
List<Car> makeAndModel(Like make, Like model);
@Find
List<Car> search(@By(_Car.MAKE) @Is(Like.class) String makePattern,
@By(_Car.MODEL) @Is(Like.class) String modelPattern,
Order<Car> sorts);
...
found = cars.matchVIN(Like.prefix("1GM"));
found = cars.makeAndModel(Like.contains(makeSubstring),
Like.contains(modelSubstring));
found = cars.search("Chev%",
"% EV",
Order.by(_Car.price.desc()));
Repository methods can also accept Like constraints at run time
in the form of a Restriction on a TextExpression.
For example,
@Find
List<Car> searchAll(Restriction<Car> restrict, Order<Car> sorts);
...
found = cars.searchAll(_Car.make.startsWith("Chev"),
Order.by(_Car.model.asc(),
_Car.year.desc(),
_Car.price.asc());
The entity and static metamodel for the code
examples within this class are shown in the Attribute Javadoc.
- Since:
- 1.1
-
Method Summary
Modifier and TypeMethodDescriptioncharescape()The escape character to use for thepattern().static LikeRequires that the constraint target consist of exactly the same characters as the givenvalue.pattern()An expression that evaluates to a pattern against which the constraint target must match.static Likepattern(TextExpression<?> pattern, char escape) Requires that the constraint target match the givenpatternexpression, in which_and%represent wildcards and the given character represents escape.static LikeRequires that the constraint target match the givenpattern, in which_and%represent wildcards.static LikeRequires that the constraint target match the givenpattern, in which the given characters represent wildcards.static LikeRequires that the constraint target match the givenpattern, in which the given characters represent wildcards and escape.static LikeRequires that the constraint target begin with the givenprefix.static LikeRequires that the constraint target contain the givensubstring.static LikeRequires that the constraint target end with the givensuffix.Methods inherited from interface jakarta.data.constraint.Constraint
negate
-
Method Details
-
pattern
Requires that the constraint target match the given
pattern, in which_and%represent wildcards. The supplied pattern has no escape character.For example, the following requires that the first 3 positions of a VIN number are
JHM, positions 4 through 6 are any character, position 7 isE, and the remaining positions are any characters,found = cars.matchVIN(Like.pattern("JHM___E%"));- Parameters:
pattern- a pattern in which_matches a single character and%matches 0 or more characters.- Returns:
- a
Likeconstraint. - Throws:
NullPointerException- if the pattern isnull.
-
pattern
Requires that the constraint target match the given
pattern, in which the given characters represent wildcards. The supplied pattern has no escape character.For example, the following requires that the first 3 positions of a VIN number are
JHM, positions 4 through 6 are any character, position 7 isF, and the remaining positions are any characters,found = cars.matchVIN(Like.pattern("JHM???F*", '?', '*'));- Parameters:
pattern- a pattern that can include the given wildcard characters.charWildcard- wildcard that represents any single character.stringWildcard- wildcard that represents 0 or more characters.- Returns:
- a
Likeconstraint. - Throws:
NullPointerException- if the pattern isnull.
-
pattern
Requires that the constraint target match the given
pattern, in which the given characters represent wildcards and escape.For example, the following requires that the first 3 positions of a VIN number are
JHM, positions 4 through 6 are any character, position 7 isC, and the remaining positions are any characters,found = cars.matchVIN(Like.pattern("JHM---^CC", '-', 'C', '^'));- Parameters:
pattern- a pattern that can include the given wildcard characters and escape character.charWildcard- wildcard that represents any single character.stringWildcard- wildcard that represents 0 or more characters.escape- escape character.- Returns:
- a
Likeconstraint. - Throws:
NullPointerException- if the pattern isnull.
-
pattern
Requires that the constraint target match the given
patternexpression, in which_and%represent wildcards and the given character represents escape.- Parameters:
pattern- an expression representing a pattern that can include the given escape character.escape- escape character.- Returns:
- a
Likeconstraint. - Throws:
NullPointerException- if the pattern expression isnull.
-
prefix
Requires that the constraint target begin with the given
prefix.For example, the following requires that the first 3 positions of a VIN number are the characters
JTP.found = cars.matchVIN(Like.prefix("JTP"));- Parameters:
prefix- text that the beginning characters of the constraint target must exactly match.- Returns:
- a
Likeconstraint. - Throws:
NullPointerException- if the prefix isnull.
-
substring
Requires that the constraint target contain the given
substring.For example, the following requires that the entity attribute value contain the character string
Hybrid,found = cars.makeAndModel(Like.literal(make), Like.substring("Hybrid"));- Parameters:
substring- text that must be contained in the constraint target.- Returns:
- a
Likeconstraint. - Throws:
NullPointerException- if the substring isnull.
-
suffix
Requires that the constraint target end with the given
suffix.For example, the following requires that the entity attribute value end with the characters
EV,found = cars.makeAndModel(Like.literal(make), Like.suffix("EV"));- Parameters:
suffix- text that the ending characters of the constraint target must exactly match.- Returns:
- a
Likeconstraint. - Throws:
NullPointerException- if the suffix isnull.
-
literal
Requires that the constraint target consist of exactly the same characters as the given
value. A repository method that does not require the flexibility of allowing different types ofLikeconstraints should use theEqualToconstraint instead.For example, the following requires a VIN number to exactly match,
found = cars.matchVIN(Like.literal(vin));
- Parameters:
value- a value that must exactly match.- Returns:
- a
Likeconstraint. - Throws:
NullPointerException- if the literal value isnull.
-
escape
char escape()The escape character to use for the
pattern(). The pattern is assigned an escape character even if the application did not supply one when requesting theLikeconstraint.- Returns:
- the escape character.
-
pattern
TextExpression<?> pattern()An expression that evaluates to a pattern against which the constraint target must match.
Any custom wildcards that were supplied appear as
_and%within the pattern, with theescapecharacter used to indicate where characters are interpreted literally rather than as wildcards or escape.For example,
Like.pattern("is --.-*% of", '-', '*', '^')is represented asis __._%^% ofwhere^is the escape character.- Returns:
- an expression representing the pattern.
-