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

Last change on this file since 105 was 105, checked in by rboipsl, 13 years ago

Import du projet NDACC _ module persistence

File size: 3.6 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                        .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> getPlotsByDateByInstrument(@NotNull final String instrument, @NotNull final Date pFormatDate_deb, @NotNull final Date pFormatDate_fin) 
46                throws PersistenceException
47        {
48                final DetachedCriteria criteria = DetachedCriteria.forClass(Plot.class);
49                criteria.add(Restrictions.ge("datedeb", pFormatDate_deb));
50                criteria.add(Restrictions.lt("datedeb", pFormatDate_fin));
51                criteria.createCriteria("instrument").add(Restrictions.like("name",instrument));               
52
53                //select pl_name de nd_plot
54                criteria.setProjection(Projections.property("name"));
55       
56                return selectAllByCriteria(String.class, criteria);
57        }
58
59        @Nullable
60        public List<Date> getDatesByInstrument(@NotNull final String instrument) 
61                throws PersistenceException
62        {
63                final DetachedCriteria criteria = DetachedCriteria.forClass(Plot.class);
64                criteria.addOrder(Order.asc("datedeb"));
65                criteria.createCriteria("instrument").add(Restrictions.like("name",instrument));
66       
67                //select pl_name de nd_plot
68                criteria.setProjection(Projections.property("datedeb"));
69       
70                return selectAllByCriteria(Date.class, criteria);
71        }
72
73        @Nullable
74        public Date getLastDateByInstrumentByStation(@NotNull final String instrument, @NotNull final String station) 
75                throws PersistenceException
76        {
77                final DetachedCriteria criteria = DetachedCriteria.forClass(Plot.class,"plot")
78                        .createCriteria("instrument","instrument").add(Restrictions.ilike("instrument.name",instrument,MatchMode.ANYWHERE))
79                        .createCriteria("station", "station").add(Restrictions.ilike("station.name",station,MatchMode.ANYWHERE));
80       
81                criteria.setProjection(Projections.property("plot.datedeb"));
82                criteria.addOrder(Order.asc("plot.datedeb"));
83       
84                //      return selectByCriteria(Date.class, criteria);
85                return (Date)criteria.getExecutableCriteria(getSessionFactory().getCurrentSession()).setMaxResults(1).uniqueResult();
86        }
87
88        @Nullable
89        public List<Date> getListeDistinctDates() 
90                throws PersistenceException
91        {
92                //correspond au select from
93                final DetachedCriteria criteria = DetachedCriteria.forClass(Plot.class)
94                        .setProjection(Projections.distinct(Projections.property("datedeb")));
95       
96                return selectAllByCriteria(Date.class, criteria);
97        }
98}
Note: See TracBrowser for help on using the repository browser.