1 package org.wcb.model.manager.impl;
2
3 import org.wcb.model.dao.ILogbookDAO;
4 import org.wcb.model.vo.hibernate.Logbook;
5 import org.wcb.model.manager.ILogbookManager;
6 import org.wcb.exception.ManagerException;
7 import org.wcb.exception.InfrastructureException;
8 import org.springframework.dao.DataAccessException;
9
10 import java.util.List;
11 import java.util.Collection;
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 public class LogbookManager extends BaseManager implements ILogbookManager {
34
35 private ILogbookDAO iDAO;
36
37
38
39
40
41
42 public void setDao(ILogbookDAO oDAO) {
43 this.iDAO = oDAO;
44 }
45
46
47
48
49
50
51 public ILogbookDAO getDao() {
52 return this.iDAO;
53 }
54
55
56
57
58
59
60 public List<Logbook> findAll() throws ManagerException {
61 List<Logbook> returnValue;
62 try
63 {
64 returnValue = iDAO.findAll();
65 if (returnValue == null)
66 {
67 throw new ManagerException("Failed to find logbook entries: ");
68 }
69 }
70 catch (InfrastructureException ie)
71 {
72 throw new ManagerException("Failed to find logbook entries due to InfrastructureException", ie);
73 }
74 catch (DataAccessException dae) {
75 throw new ManagerException("No access to database", dae);
76 }
77 return returnValue;
78 }
79
80
81
82
83
84
85 public List<Logbook> findByRegistration(String sReg) throws ManagerException {
86 List<Logbook> returnValue;
87 try
88 {
89 returnValue = iDAO.findByRegistration(sReg);
90 if (returnValue == null)
91 {
92 throw new ManagerException("Failed to find logbook entries by registration: ");
93 }
94 }
95 catch (InfrastructureException ie)
96 {
97 throw new ManagerException("Failed to find logbook entries due to InfrastructureException", ie);
98 }
99 return returnValue;
100 }
101
102
103
104
105
106
107 public List<Logbook> findCrossCountry() throws ManagerException {
108 List<Logbook> returnValue;
109 try
110 {
111 returnValue = iDAO.findAllCrossCountry();
112 if (returnValue == null)
113 {
114 throw new ManagerException("Failed to find logbook entries by cross country: ");
115 }
116 }
117 catch (InfrastructureException ie)
118 {
119 throw new ManagerException("Failed to find logbook entries due to InfrastructureException", ie);
120 }
121 return returnValue;
122 }
123
124
125
126
127
128
129
130 public Logbook findEntry(Integer i) throws ManagerException {
131 Logbook returnValue;
132 try
133 {
134 returnValue = iDAO.findEntry(i);
135 if (returnValue == null)
136 {
137 throw new ManagerException("Failed to find logbook entry: " + i.intValue());
138 }
139 }
140 catch (InfrastructureException ie)
141 {
142 throw new ManagerException("Failed to find logbook entry due to InfrastructureException " + i.intValue(), ie);
143 }
144 return returnValue;
145 }
146
147
148
149
150
151
152 public void saveEntry(Logbook entry) throws ManagerException {
153 try
154 {
155 iDAO.saveOrUpdateObject(entry);
156 }
157 catch (Exception ie) {
158 throw new ManagerException("Failed to save logbook entry due to InfrastructureException ", ie);
159 }
160 }
161
162
163
164
165
166
167 public void saveOrUpdateLogbook(Collection<Logbook> entries) throws ManagerException {
168 try
169 {
170 iDAO.saveOrUpdateAllObjects(entries);
171 }
172 catch (Exception ie) {
173 throw new ManagerException("Failed to save all logbook entries due to InfrastructureException ", ie);
174 }
175 }
176
177
178
179
180
181
182 public void deleteEntry(Logbook entry) throws ManagerException {
183 try
184 {
185 iDAO.deleteEntry(entry);
186 }
187 catch (InfrastructureException ie) {
188 throw new ManagerException("Failed to delete logbook entry due to InfrastructureException ", ie);
189 }
190 }
191 }