-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathFruitFragmentImpl.java
67 lines (52 loc) · 1.73 KB
/
FruitFragmentImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package org.acme.spring.data.jpa.repo.fruit;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import org.acme.spring.data.jpa.model.Fruit;
import org.acme.spring.data.jpa.model.QFruit;
import com.querydsl.jpa.impl.JPAQuery;
public class FruitFragmentImpl implements FruitFragment {
@Inject
EntityManager em;
@Override
public List<Fruit> findAllQueryDslName(String name) {
QFruit fruit = QFruit.fruit;
JPAQuery<Fruit> query = new JPAQuery<Fruit>(this.em);
query.from(fruit);
if (name != null && !name.isEmpty()) {
query.where(fruit.name.eq(name));
}
return query.orderBy(fruit.name.desc()).fetch();
}
@Override
public List<Fruit> findAllQueryDslMaxPriceDesc(Float price) {
QFruit fruit = QFruit.fruit;
JPAQuery<Fruit> query = new JPAQuery<Fruit>(this.em);
query.from(fruit);
if (price != null && price != 0) {
query.where(fruit.price.loe(price));
}
return query.orderBy(fruit.price.desc()).fetch();
}
@Override
public List<Fruit> findAllQueryDslMinPriceAsc(Float price) {
QFruit fruit = QFruit.fruit;
JPAQuery<Fruit> query = new JPAQuery<Fruit>(this.em);
query.from(fruit);
if (price != null && price != 0) {
query.where(fruit.price.goe(price));
}
return query.orderBy(fruit.price.asc()).fetch();
}
@Override
public List<Fruit> findAllQueryDslPriceRange(Float min, Float max) {
QFruit fruit = QFruit.fruit;
JPAQuery<Fruit> query = new JPAQuery<Fruit>(this.em);
query.from(fruit);
if (min != null && min != 0 && max != null && max != 0) {
query.where(fruit.price.between(min, max));
}
return query.orderBy(fruit.price.desc()).fetch();
}
}