You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Updates Specifications documentation to use java 8 lambdas instead of anonymous classes.
This improves readability and reduces boilerplate code.
Original pull request: #429.
public static Specification<Customer> hasSalesOfMoreThan(MonetaryAmount value) {
824
-
return new Specification<Customer>() {
825
-
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query,
826
-
CriteriaBuilder builder) {
827
-
828
-
// build query here
829
-
}
821
+
return (root, query, builder) -> {
822
+
// build query here
830
823
};
831
824
}
832
825
}
833
826
----
834
827
====
835
828
836
-
Admittedly, the amount of boilerplate leaves room for improvement (that may eventually be reduced by Java 8 closures), but the client side becomes much nicer, as you will see later in this section.
837
829
The `Customer_` type is a metamodel type generated using the JPA Metamodel generator (see the link:$$https://docs.jboss.org/hibernate/jpamodelgen/1.0/reference/en-US/html_single/#whatisit$$[Hibernate implementation's documentation for an example]).
838
830
So the expression, `Customer_.createdAt`, assumes the `Customer` has a `createdAt` attribute of type `Date`.
839
831
Besides that, we have expressed some criteria on a business requirement abstraction level and created executable `Specifications`.
0 commit comments