6ee36445c5b22e836ff781e8340ddd49f20edca9
[JavaForFun] /
1 package de.spring.example.persistence.domain.specifications;
2
3 import java.time.LocalDate;
4
5 import javax.persistence.criteria.CriteriaBuilder;
6 import javax.persistence.criteria.CriteriaQuery;
7 import javax.persistence.criteria.Predicate;
8 import javax.persistence.criteria.Root;
9
10 import org.springframework.data.jpa.domain.Specification;
11
12 import de.spring.example.persistence.domain.Ad;
13
14 public class AdSpectifications {
15         
16         public static Specification<Ad> createdToday() {
17                 return new Specification<Ad>() {
18
19                         @Override
20                         public Predicate toPredicate(Root<Ad> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
21                                 final LocalDate date = LocalDate.now();
22                                 
23                                 return cb.equal(root.get("createdAt"), date);
24                         }
25
26                 };
27                 
28         }
29         
30         public static Specification<Ad> mobileImage(String image) {
31                 return new Specification<Ad>() {
32
33                         @Override
34                         public Predicate toPredicate(Root<Ad> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
35                                 
36                                 return cb.equal(root.get("adMobileImage"), image);
37                         }
38
39                 };
40                 
41         }
42 }