- All Superinterfaces:
Constraint<String>
A constraint that requires not 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
NotLike or is annotated @Is(NotLike.class) and is of
type String. For example,
@Find
List<Car> matchVIN(@By(_Car.VIN) NotLike pattern);
@Find
List<Car> ofMakeNotModel(@By(_Car.MAKE) String manufacturer,
@By(_Car.MODEL) @Is(NotLike.class) String excludePattern,
Order<Car> sorts);
...
found = cars.matchVIN(NotLike.prefix("1GM"));
found = cars.ofMakeNotModel("Jakarta Motors",
"%Hybrid%",
Order.by(_Car.price.desc()));
Repository methods can also accept NotLike 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(Restrict.all(_Car.make.equalTo("Jakarta Motors"),
_Car.model.notContains("Electric"),
_Car.model.notEndsWith("EV")),
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 NotLikeRequires that the constraint target not consist of the same characters as the givenvalue.pattern()An expression that evaluates to a pattern against which the constraint target must not match.static NotLikepattern(TextExpression<?> pattern, char escape) Requires that the constraint target not match the givenpatternexpression, in which_and%represent wildcards and the given character represents escape.static NotLikeRequires that the constraint target not match the givenpattern, in which_and%represent wildcards.static NotLikeRequires that the constraint target not match the givenpattern, in which the given characters represent wildcards.static NotLikeRequires that the constraint target not match the givenpattern, in which the given characters represent wildcards and escape.static NotLikeRequires that the constraint target not begin with the givenprefix.static NotLikeRequires that the constraint target not contain the givensubstring.static NotLikeRequires that the constraint target not end with the givensuffix.Methods inherited from interface jakarta.data.constraint.Constraint
negate
-
Method Details
-
pattern
Requires that the constraint target not match the given
pattern, in which_and%represent wildcards. The supplied pattern has no escape character.For example, the following requires that the VIN number not have
JHMas its first 3 character positions andEin character position 7.found = cars.matchVIN(NotLike.pattern("JHM___E%"));- Parameters:
pattern- a pattern in which_matches a single character and%matches 0 or more characters.- Returns:
- a
NotLikeconstraint. - Throws:
NullPointerException- if the pattern isnull.
-
pattern
Requires that the constraint target not 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 VIN number not have
JHMas its first 3 character positions andFin character position 7.found = cars.matchVIN(NotLike.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
NotLikeconstraint. - Throws:
NullPointerException- if the pattern isnull.
-
pattern
Requires that the constraint target not match the given
pattern, in which the given characters represent wildcards and escape.For example, the following requires that the VIN number not have
JHMas its first 3 character positions andCin character position 7.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
NotLikeconstraint. - Throws:
NullPointerException- if the pattern isnull.
-
pattern
Requires that the constraint target not 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
NotLikeconstraint. - Throws:
NullPointerException- if the pattern expression isnull.
-
prefix
Requires that the constraint target not begin with the given
prefix.For example, the following requires that the first 3 positions of a VIN number are not the characters
JTP.found = cars.matchVIN(NotLike.prefix("JTP"));- Parameters:
prefix- text that the beginning characters of the constraint target must not match.- Returns:
- a
NotLikeconstraint. - Throws:
NullPointerException- if the prefix isnull.
-
substring
Requires that the constraint target not contain the given
substring.For example, the following requires that the entity attribute value not contain the character string
Hybrid,found = cars.ofModel(NotLike.substring("Hybrid"));- Parameters:
substring- text that must not be contained in the constraint target.- Returns:
- a
NotLikeconstraint. - Throws:
NullPointerException- if the substring isnull.
-
suffix
Requires that the constraint target not end with the given
suffix.For example, the following requires that the entity attribute value not end with the characters
EV,found = cars.ofModel(NotLike.suffix("EV"));- Parameters:
suffix- text that the ending characters of the constraint target must not match.- Returns:
- a
NotLikeconstraint. - Throws:
NullPointerException- if the suffix isnull.
-
literal
Requires that the constraint target not consist of the same characters as the given
value. A repository method that does not require the flexibility of allowing different types ofNotLikeconstraints should use theNotEqualToconstraint instead.For example, the following requires a VIN number to exactly match,
found = cars.ofModel(NotLike.literal("J-150"));- Parameters:
value- a value that must not match the constraint target.- Returns:
- a
NotLikeconstraint. - 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 theNotLikeconstraint.- Returns:
- the escape character.
-
pattern
TextExpression<?> pattern()An expression that evaluates to a pattern against which the constraint target must not 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,
NotLike.pattern("is --.-*% of", '-', '*', '^')"is represented asis __._%^% ofwhere^is the escape character.- Returns:
- an expression representing the pattern.
-