1 | package com.ether.dao.plot; |
---|
2 | |
---|
3 | import java.util.Date; |
---|
4 | import java.util.List; |
---|
5 | |
---|
6 | import org.hibernate.criterion.DetachedCriteria; |
---|
7 | import org.hibernate.criterion.MatchMode; |
---|
8 | import org.hibernate.criterion.Order; |
---|
9 | import org.hibernate.criterion.Projections; |
---|
10 | import org.hibernate.criterion.Restrictions; |
---|
11 | import org.jetbrains.annotations.NotNull; |
---|
12 | import org.jetbrains.annotations.Nullable; |
---|
13 | |
---|
14 | import com.ether.PersistenceException; |
---|
15 | import com.ether.dao.DomainAccessObjectImpl; |
---|
16 | import com.ether.plot.Plot; |
---|
17 | |
---|
18 | public class PlotDAOImpl extends DomainAccessObjectImpl<Plot, Long> implements PlotDAO { |
---|
19 | |
---|
20 | public PlotDAOImpl() { |
---|
21 | super(Plot.class); |
---|
22 | } |
---|
23 | |
---|
24 | @Nullable |
---|
25 | public List<String> getPlotsByDateByInstrumentByStation(@NotNull final String instrument, @NotNull final Date pFormatDate_deb, @NotNull final Date pFormatDate_fin, @NotNull final String station) |
---|
26 | throws PersistenceException |
---|
27 | { |
---|
28 | |
---|
29 | final DetachedCriteria criteria = DetachedCriteria.forClass(Plot.class,"plot") |
---|
30 | .addOrder(Order.asc("plot.name")) |
---|
31 | .add(Restrictions.ge("datedeb", pFormatDate_deb)) |
---|
32 | .add(Restrictions.lt("datedeb", pFormatDate_fin)) |
---|
33 | .createCriteria("instrument","instrument").add(Restrictions.ilike("instrument.name",instrument,MatchMode.ANYWHERE)) |
---|
34 | .createCriteria("station","station").add(Restrictions.ilike("station.name",station,MatchMode.ANYWHERE)); |
---|
35 | |
---|
36 | |
---|
37 | |
---|
38 | //select pl_name de nd_plot |
---|
39 | criteria.setProjection(Projections.property("plot.name")); |
---|
40 | |
---|
41 | return selectAllByCriteria(String.class, criteria); |
---|
42 | } |
---|
43 | |
---|
44 | @Nullable |
---|
45 | public List<String> getPlotsByDateByInstrumentByStationByType(@NotNull final String instrument, @NotNull final Date pFormatDate_deb, @NotNull final Date pFormatDate_fin, @NotNull final String station, @NotNull final String type) |
---|
46 | throws PersistenceException |
---|
47 | { |
---|
48 | String vtype = type; |
---|
49 | |
---|
50 | final DetachedCriteria criteria = DetachedCriteria.forClass(Plot.class,"plot") |
---|
51 | .addOrder(Order.asc("plot.name")) |
---|
52 | .add(Restrictions.ge("datedeb", pFormatDate_deb)) |
---|
53 | .add(Restrictions.lt("datedeb", pFormatDate_fin)) |
---|
54 | .createCriteria("instrument","instrument").add(Restrictions.ilike("instrument.name",instrument,MatchMode.ANYWHERE)) |
---|
55 | .createCriteria("station","station").add(Restrictions.ilike("station.name",station,MatchMode.ANYWHERE)) |
---|
56 | .add(Restrictions.ilike("plot.name",vtype,MatchMode.ANYWHERE)); |
---|
57 | |
---|
58 | |
---|
59 | //select pl_name de nd_plot |
---|
60 | criteria.setProjection(Projections.property("plot.name")); |
---|
61 | |
---|
62 | return selectAllByCriteria(String.class, criteria); |
---|
63 | } |
---|
64 | |
---|
65 | @Nullable |
---|
66 | public List<String> getPlotsByDateByInstrument(@NotNull final String instrument, @NotNull final Date pFormatDate_deb, @NotNull final Date pFormatDate_fin) |
---|
67 | throws PersistenceException |
---|
68 | { |
---|
69 | final DetachedCriteria criteria = DetachedCriteria.forClass(Plot.class); |
---|
70 | criteria.add(Restrictions.ge("datedeb", pFormatDate_deb)); |
---|
71 | criteria.add(Restrictions.lt("datedeb", pFormatDate_fin)); |
---|
72 | criteria.createCriteria("instrument").add(Restrictions.like("name",instrument)); |
---|
73 | |
---|
74 | //select pl_name de nd_plot |
---|
75 | criteria.setProjection(Projections.property("name")); |
---|
76 | |
---|
77 | return selectAllByCriteria(String.class, criteria); |
---|
78 | } |
---|
79 | |
---|
80 | @Nullable |
---|
81 | public List<Date> getDatesByInstrument(@NotNull final String instrument) |
---|
82 | throws PersistenceException |
---|
83 | { |
---|
84 | final DetachedCriteria criteria = DetachedCriteria.forClass(Plot.class); |
---|
85 | criteria.addOrder(Order.asc("datedeb")); |
---|
86 | criteria.createCriteria("instrument").add(Restrictions.like("name",instrument)); |
---|
87 | |
---|
88 | //select pl_name de nd_plot |
---|
89 | criteria.setProjection(Projections.property("datedeb")); |
---|
90 | |
---|
91 | return selectAllByCriteria(Date.class, criteria); |
---|
92 | } |
---|
93 | |
---|
94 | @Nullable |
---|
95 | public Date getLastDateByInstrumentByStation(@NotNull final String instrument, @NotNull final String station) |
---|
96 | throws PersistenceException |
---|
97 | { |
---|
98 | final DetachedCriteria criteria = DetachedCriteria.forClass(Plot.class,"plot") |
---|
99 | .createCriteria("instrument","instrument").add(Restrictions.ilike("instrument.name",instrument,MatchMode.ANYWHERE)) |
---|
100 | .createCriteria("station", "station").add(Restrictions.ilike("station.name",station,MatchMode.ANYWHERE)); |
---|
101 | |
---|
102 | criteria.setProjection(Projections.property("plot.datedeb")); |
---|
103 | criteria.addOrder(Order.asc("plot.datedeb")); |
---|
104 | |
---|
105 | // return selectByCriteria(Date.class, criteria); |
---|
106 | return (Date)criteria.getExecutableCriteria(getSessionFactory().getCurrentSession()).setMaxResults(1).uniqueResult(); |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | @Nullable |
---|
111 | public List<Date> getListeDistinctDates() |
---|
112 | throws PersistenceException |
---|
113 | { |
---|
114 | //correspond au select from |
---|
115 | final DetachedCriteria criteria = DetachedCriteria.forClass(Plot.class) |
---|
116 | .setProjection(Projections.distinct(Projections.property("datedeb"))); |
---|
117 | |
---|
118 | return selectAllByCriteria(Date.class, criteria); |
---|
119 | } |
---|
120 | } |
---|