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 package fr.paris.lutece.plugins.stock.modules.billetterie.dao.quartier;
35
36 import fr.paris.lutece.plugins.stock.commons.ResultList;
37 import fr.paris.lutece.plugins.stock.commons.dao.AbstractStockDAO;
38 import fr.paris.lutece.plugins.stock.commons.dao.PaginationProperties;
39 import fr.paris.lutece.plugins.stock.modules.billetterie.business.district.District;
40 import fr.paris.lutece.plugins.stock.modules.billetterie.business.district.DistrictFilter;
41 import fr.paris.lutece.plugins.stock.service.StockPlugin;
42
43 import org.springframework.stereotype.Repository;
44
45 import java.util.LinkedList;
46 import java.util.List;
47
48 import javax.persistence.EntityManager;
49 import javax.persistence.criteria.CriteriaBuilder;
50 import javax.persistence.criteria.CriteriaQuery;
51 import javax.persistence.criteria.Order;
52 import javax.persistence.criteria.Root;
53
54
55
56
57
58
59 @Repository
60 public class DistrictDAO extends AbstractStockDAO<Integer, District>
61 {
62
63
64
65 @Override
66 public String getPluginName( )
67 {
68 return StockPlugin.PLUGIN_NAME;
69 }
70
71
72
73
74
75
76
77
78
79
80 public ResultList<District> findByFilter( DistrictFilter filter, PaginationProperties paginationProperties )
81 {
82 EntityManager em = getEM( );
83 CriteriaBuilder cb = em.getCriteriaBuilder( );
84
85 CriteriaQuery<District> cq = cb.createQuery( District.class );
86
87 Root<District> root = cq.from( District.class );
88 buildCriteriaQuery( filter, root, cq, cb );
89 buildSortQuery( filter, root, cq, cb );
90 cq.distinct( true );
91
92 return createPagedQuery( cq, paginationProperties ).getResultList( );
93 }
94
95
96
97
98
99
100
101
102
103
104
105
106
107 protected void buildSortQuery( DistrictFilter filter, Root<District> root, CriteriaQuery<District> query, CriteriaBuilder builder )
108 {
109 if ( ( filter.getOrders( ) != null ) && !filter.getOrders( ).isEmpty( ) )
110 {
111 List<Order> orderList = new LinkedList<Order>( );
112
113
114 for ( String order : filter.getOrders( ) )
115 {
116 if ( filter.isOrderAsc( ) )
117 {
118 orderList.add( builder.asc( root.get( order ) ) );
119 }
120 else
121 {
122 orderList.add( builder.desc( root.get( order ) ) );
123 }
124 }
125
126 query.orderBy( orderList );
127 }
128 }
129
130
131
132
133
134
135
136
137
138
139
140
141
142 protected void buildCriteriaQuery( Object filter, Root<District> root, CriteriaQuery<District> query, CriteriaBuilder builder )
143 {
144 }
145 }