Module jakarta.data

Interface NotEqualTo<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 NotEqualTo<V> extends Constraint<V>

A constraint that requires inequality.

A parameter-based repository method can impose a constraint on an entity attribute by defining a method parameter that is of type NotEqualTo or is annotated @Is(NotEqualTo.class) and is of the same type or a subtype of the entity attribute. For example,


 @Find
 List<Car> excludingManufacturer(@By(_Car.MAKE) NotEqualTo<String> excludedManufacturer);

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

 found = cars.excludingManufacturer(NotEqualTo.value("Stallmore Motors"));

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

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


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

 ...

 found = cars.searchAll(_Car.make.notEqualTo("Coalback Motors"),
                        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> NotEqualTo<V>
    expression(Expression<?,V> expression)
    Requires that the constraint target not equal the value to which the given expression evaluates.
    static <V> NotEqualTo<V>
    value(V value)
    Requires that the constraint target not equal the given value.

    Methods inherited from interface jakarta.data.constraint.Constraint

    negate
  • Method Details

    • expression

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

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

      
           found = cars.excludingManufacturer(
                       NotEqualTo.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:
      a NotEqualTo constraint.
      Throws:
      NullPointerException - if the expression is null.
    • value

      static <V> NotEqualTo<V> value(V value)

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

      
           found = cars.excludingManufacturer(NotEqualTo.value("Leakoil 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:
      a NotEqualTo 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.