1 package org.wcb.model.dao.impl;
2
3 import org.wcb.model.vo.hibernate.Logbook;
4 import org.wcb.model.dao.ILogbookDAO;
5 import org.wcb.exception.DAOException;
6 import org.wcb.exception.InfrastructureException;
7 import org.hibernate.criterion.DetachedCriteria;
8 import org.hibernate.criterion.Restrictions;
9 import org.hibernate.criterion.Order;
10 import org.springframework.dao.DataAccessException;
11
12 import javax.persistence.OrderBy;
13 import java.util.List;
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 public class LogbookDAO extends AbstractHibernateDAO implements ILogbookDAO {
36
37
38
39
40
41
42 public List<Logbook> findAll() throws InfrastructureException, DataAccessException {
43 DetachedCriteria criteria = DetachedCriteria.forClass(Logbook.class);
44 criteria.addOrder(Order.asc("entryDate"));
45 return getHibernateTemplate().findByCriteria(criteria);
46 }
47
48
49
50
51
52
53
54 public List<Logbook> findByRegistration(String registration) throws InfrastructureException{
55 try {
56 return getObjectsBy(Logbook.class, "registration", registration);
57 } catch (DAOException daoe) {
58 throw new InfrastructureException(daoe);
59 }
60 }
61
62
63
64
65
66
67 public List<Logbook> findAllCrossCountry() throws InfrastructureException {
68 DetachedCriteria criteria = DetachedCriteria.forClass(Logbook.class);
69 criteria.add(Restrictions.gt("crossCountry", 0));
70 return getHibernateTemplate().findByCriteria(criteria);
71
72 }
73
74
75
76
77
78
79
80 public Logbook findEntry(Integer id) throws InfrastructureException {
81 try {
82 return (Logbook) getObjectsBy(Logbook.class, "id", id).get(0);
83 } catch (DAOException daoe) {
84 throw new InfrastructureException(daoe);
85 } catch (IndexOutOfBoundsException ioobe) {
86 throw new InfrastructureException("No entry found");
87 }
88
89
90
91
92
93
94
95 }
96
97
98
99
100
101
102 public void deleteEntry(Logbook oEntry) throws InfrastructureException {
103 getHibernateTemplate().delete(oEntry);
104 }
105 }