source: ether_ndacc/trunk/persistence/implementation/com/ether/dao/plot/PlotDAOImpl.java

Last change on this file was 770, checked in by npipsl, 10 years ago

Mise a à jour commit Nat

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