Reference Predicates

The following methods are available to all ReferenceFields (i.e. fields that are not primitive fields). The "Condition" in the table below is the condition for which the corresponding Predicate will hold true:

Method Param Type Operation Condition

isNull

N/A

field == null

the field is null

isNotNull

N/A

field != null

the field is not null

A ReferenceField implements the interface trait HasReferenceOperators.

Examples

Below are examples of how the reference predicates can be used. Both examples operate on the JPA entity Film which has a rating field like so:

@Entity
@Table(name = "film", schema = "sakila")
public class Film  {

    // ...

    @Column(name = "rating", nullable = true, columnDefinition = "enum('G','PG','PG-13','R','NC-17')")
    private String rating;

    // ...
}
The referenced table is present in the MySQL example database Sakila.

isNull

All films with a rating that is null can be counted like this:

    long count = jpaStreamer.stream(Film.class)
        .filter(Film$.rating.isNull())
        .count();
    System.out.format("There are %d films with a null rating %n", count);

The code will produce the following output:

There are 0 films with a null rating

isNotNull

All films with a rating that is not null can be counted like this:

long count = jpaStreamer.stream(Film.class)
        .filter(Film$.rating.isNotNull())
        .count();
    System.out.format("There are %d films with a non-null rating %n", count);

The code will produce the following output:

There are 1000 films with a non-null rating