Module jakarta.data

Interface EqualTo<V>

Type Parameters:
V - type of the entity attribute or a subtype or primitive wrapper type for the entity attribute.
All Superinterfaces:
Constraint<V>

public interface EqualTo<V> extends Constraint<V>

A constraint that requires equality.

A parameter-based repository method can impose a constraint on an entity attribute by defining a method parameter that is of type EqualTo or is annotated @Is(EqualTo.class) and is of the same type or a subtype of the entity attribute. The equality constraint is also the default when the @Is annotation is omitted. For example,

 @Find
 List<Car> fromManufacturer(@By(_Car.MAKE) EqualTo<String> manufacturer);

 @Find
 List<Car> ofMakeAndModel(@By(_Car.MAKE) @Is(EqualTo.class) String manufacturer,
                          @By(_Car.MODEL) @Is(EqualTo.class) String model,
                          Order<Car> sorts);

 @Find
 List<Car> ofMakeAndModelAndYear(@By(_Car.MAKE) String manufacturer,
                                 @By(_Car.MODEL) String model,
                                 @By(_Car.YEAR) int modelYear,
                                 Order<Car> sorts);
 ...

 found = cars.fromManufacturer(EqualTo.value("Jakarta Motors"));

 found = cars.ofMakeAndModel("Jakarta Motors",
                             "J-150",
                             Order.by(_Car.price.desc()));

 found = cars.ofMakeAndModelAndYear("Jakarta Motors",
                                    "J-150",
                                    2025,
                                    Order.by(_Car.price.desc()));
 

Repository methods can also accept EqualTo constraints at runtime in the form of a Restriction on an Expression. For example,

 @Find
 List<Car> searchAll(Restriction<Car> restrict, Order<Car> sorts);

 ...

 found = cars.searchAll(Restrict.all(_Car.make.equalTo("Jakarta Motors"),
                                     _Car.model.equalTo("J-150")),
                        Order.by(_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 Type
    Method
    Description
    An expression that evaluates to the value against which the constraint target is compared.
    static <V> EqualTo<V>
    expression(Expression<?,V> expression)
    Requires that the constraint target equal the value to which the given expression evaluates.
    static <V> EqualTo<V>
    value(V value)
    Requires that the constraint target equal the given value.

    Methods inherited from interface jakarta.data.constraint.Constraint

    negate
  • Method Details

    • expression

      static <V> EqualTo<V> expression(Expression<?,V> expression)

      Requires that the constraint target equal the value to which the given expression evaluates. For example,

       found = cars.fromManufacturer(
                       EqualTo.expression(_Car.model.left(_Car.make.length())));
       
      Type Parameters:
      V - type of the entity attribute or a subtype or primitive wrapper type for the entity attribute.
      Parameters:
      expression - an expression that evaluates to a value against which the constraint target is compared.
      Returns:
      an EqualTo constraint.
      Throws:
      NullPointerException - if the expression is null.
    • value

      static <V> EqualTo<V> value(V value)

      Requires that the constraint target equal the given value. For example,

       found = cars.fromManufacturer(EqualTo.value("Jakarta Motors"));
       
      Type Parameters:
      V - type of the entity attribute or a subtype or primitive wrapper type for the entity attribute.
      Parameters:
      value - a value against which the constraint target is compared.
      Returns:
      an EqualTo constraint.
      Throws:
      NullPointerException - if the value is null.
    • expression

      Expression<?,V> expression()

      An expression that evaluates to the value against which the constraint target is compared.

      Returns:
      an expression representing the value.