1 |
34310
|
nikon.gasp
|
package eu.dnetlib.validator.commons.dao.rules;
|
2 |
17673
|
nikon.gasp
|
|
3 |
34780
|
nikon.gasp
|
import java.sql.Array;
|
4 |
17673
|
nikon.gasp
|
import java.sql.Connection;
|
5 |
|
|
import java.sql.PreparedStatement;
|
6 |
|
|
import java.sql.ResultSet;
|
7 |
|
|
import java.sql.SQLException;
|
8 |
|
|
import java.util.ArrayList;
|
9 |
34780
|
nikon.gasp
|
import java.util.Arrays;
|
10 |
34310
|
nikon.gasp
|
import java.util.HashSet;
|
11 |
17673
|
nikon.gasp
|
import java.util.List;
|
12 |
34310
|
nikon.gasp
|
import java.util.Set;
|
13 |
17673
|
nikon.gasp
|
|
14 |
34310
|
nikon.gasp
|
import eu.dnetlib.domain.functionality.validator.Rule;
|
15 |
|
|
import eu.dnetlib.domain.functionality.validator.RuleSet;
|
16 |
|
|
import eu.dnetlib.validator.commons.dao.AbstractDAO;
|
17 |
36835
|
nikon.gasp
|
import eu.dnetlib.validator.commons.dao.DaoException;
|
18 |
34310
|
nikon.gasp
|
import eu.dnetlib.validator.commons.dao.Utilities;
|
19 |
17673
|
nikon.gasp
|
|
20 |
34310
|
nikon.gasp
|
public class RulesetsDAOimpl extends AbstractDAO<RuleSet> implements RulesetsDAO{
|
21 |
|
|
|
22 |
17673
|
nikon.gasp
|
@Override
|
23 |
36835
|
nikon.gasp
|
public Integer save(RuleSet t) throws DaoException {
|
24 |
34780
|
nikon.gasp
|
Connection con = null;
|
25 |
|
|
PreparedStatement stmt = null;
|
26 |
|
|
Integer retId = -1;
|
27 |
|
|
logger.debug("Accessing DB to save/update Rule");
|
28 |
|
|
try {
|
29 |
|
|
logger.debug("Accessing DB to update Rule");
|
30 |
|
|
con = getConnection();
|
31 |
|
|
String query="UPDATE rulesets SET name=?, description=?, guidelines_acronym = ?, visibility = ?, short_name=? WHERE id=?";
|
32 |
|
|
stmt = con.prepareStatement(query);
|
33 |
|
|
stmt.setString(1, t.getName());
|
34 |
|
|
stmt.setString(2, t.getDescription());
|
35 |
|
|
stmt.setString(3, t.getGuidelinesAcronym());
|
36 |
|
|
String[] data = t.getVisibility().toArray(new String[t.getVisibility().size()]);
|
37 |
|
|
stmt.setArray(4, con.createArrayOf("text", data));
|
38 |
|
|
stmt.setString(5, t.getShortName());
|
39 |
|
|
stmt.setInt(6, t.getId());
|
40 |
|
|
|
41 |
|
|
if (stmt.executeUpdate() == 0) {
|
42 |
|
|
stmt.close();
|
43 |
|
|
logger.debug("Accessing DB to save RuleSet with name: "+t.getName());
|
44 |
|
|
query="INSERT INTO rulesets(name,description,guidelines_acronym,visibility,short_name) VALUES(?,?,?,?,?)";
|
45 |
|
|
stmt = con.prepareStatement(query);
|
46 |
|
|
stmt.setString(1, t.getName());
|
47 |
|
|
stmt.setString(2, t.getDescription());
|
48 |
|
|
stmt.setString(3, t.getGuidelinesAcronym());
|
49 |
|
|
data = t.getVisibility().toArray(new String[t.getVisibility().size()]);
|
50 |
|
|
stmt.setArray(4, con.createArrayOf("text", data));
|
51 |
|
|
stmt.setString(5, t.getShortName());
|
52 |
|
|
stmt.executeUpdate();
|
53 |
|
|
retId = this.getLastId();
|
54 |
|
|
} else {
|
55 |
|
|
logger.debug("Accessing DB to update RuleSet-done");
|
56 |
|
|
retId=t.getId();
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
stmt.close();
|
60 |
|
|
logger.debug("Accessing DB to delete ruleSet_has_rules values");
|
61 |
|
|
query="DELETE FROM ruleset_has_rules " + " WHERE ruleset_id=?";
|
62 |
|
|
stmt = con.prepareStatement(query);
|
63 |
|
|
stmt.setInt(1, retId);
|
64 |
|
|
if (stmt.executeUpdate() == 0) {
|
65 |
|
|
stmt.close();
|
66 |
|
|
}
|
67 |
|
|
logger.debug("Accessing DB to insert ruleSet_has_rules properties");
|
68 |
|
|
query="INSERT INTO ruleset_has_rules(ruleset_id, rule_id) VALUES (?,?)";
|
69 |
|
|
stmt= con.prepareStatement(query);
|
70 |
|
|
for (int id : t.getContentRulesIds()) {
|
71 |
|
|
stmt.setInt(1,retId);
|
72 |
|
|
stmt.setInt(2,id);
|
73 |
|
|
stmt.addBatch();
|
74 |
|
|
}
|
75 |
|
|
for (int id : t.getUsageRulesIds()) {
|
76 |
|
|
stmt.setInt(1,retId);
|
77 |
|
|
stmt.setInt(2,id);
|
78 |
|
|
stmt.addBatch();
|
79 |
|
|
}
|
80 |
|
|
stmt.executeBatch();
|
81 |
|
|
logger.debug("Ruleset_has_rules values inserted/updated");
|
82 |
|
|
|
83 |
36835
|
nikon.gasp
|
} catch (Exception e) {
|
84 |
36204
|
nikon.gasp
|
logger.error("Error accessing DB to save ruleset.", e);
|
85 |
36835
|
nikon.gasp
|
throw new DaoException(e);
|
86 |
34780
|
nikon.gasp
|
} finally {
|
87 |
|
|
if (stmt != null) {
|
88 |
|
|
try {
|
89 |
|
|
stmt.close();
|
90 |
|
|
} catch (SQLException e) {
|
91 |
36204
|
nikon.gasp
|
logger.error("Error accessing DB to save ruleset.", e);
|
92 |
36835
|
nikon.gasp
|
throw new DaoException(e);
|
93 |
34780
|
nikon.gasp
|
}
|
94 |
|
|
}
|
95 |
56893
|
ioannis.di
|
closeConnection(con);
|
96 |
34780
|
nikon.gasp
|
}
|
97 |
|
|
return retId;
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
@Override
|
101 |
36835
|
nikon.gasp
|
public RuleSet get(int id) throws DaoException {
|
102 |
17673
|
nikon.gasp
|
ResultSet rs = null;
|
103 |
|
|
Connection con = null;
|
104 |
|
|
PreparedStatement stmt = null;
|
105 |
|
|
RuleSet retSet = null;
|
106 |
34780
|
nikon.gasp
|
logger.debug("Accessing DB to get RuleSet with id: " + id);
|
107 |
17673
|
nikon.gasp
|
try {
|
108 |
|
|
con = getConnection();
|
109 |
34780
|
nikon.gasp
|
String query="SELECT name, description, guidelines_acronym, visibility, short_name FROM rulesets WHERE id=?";
|
110 |
17673
|
nikon.gasp
|
stmt = con.prepareStatement(query);
|
111 |
34310
|
nikon.gasp
|
stmt.setInt(1, id);
|
112 |
17673
|
nikon.gasp
|
rs = stmt.executeQuery();
|
113 |
|
|
if (rs!=null){
|
114 |
|
|
retSet = new RuleSet();
|
115 |
|
|
while (rs.next()) {
|
116 |
|
|
retSet.setName(rs.getString(1));
|
117 |
|
|
retSet.setDescription(rs.getString(2));
|
118 |
28400
|
nikon.gasp
|
retSet.setGuidelinesAcronym(rs.getString(3));
|
119 |
34780
|
nikon.gasp
|
List<String> visibility = new ArrayList<String>();
|
120 |
|
|
Array tt = rs.getArray("visibility");
|
121 |
|
|
if (tt != null) {
|
122 |
|
|
String[] ent = (String[])tt.getArray();
|
123 |
|
|
visibility.addAll(Arrays.asList(ent));
|
124 |
|
|
}
|
125 |
|
|
retSet.setVisibility(visibility);
|
126 |
|
|
retSet.setShortName(rs.getString(5));
|
127 |
34310
|
nikon.gasp
|
retSet.setId(id);
|
128 |
34780
|
nikon.gasp
|
List <Rule> rules = this.getRulesOfRuleset(id);
|
129 |
|
|
List <Rule> contentRules = new ArrayList<Rule>();
|
130 |
|
|
List <Rule> usageRules = new ArrayList<Rule>();
|
131 |
|
|
Set <Integer> contentRulesIds = new HashSet<Integer>();
|
132 |
|
|
Set <Integer> usageRulesIds = new HashSet<Integer>();
|
133 |
|
|
for (Rule rule : rules) {
|
134 |
|
|
if (rule.getJob_type().equals("content")) {
|
135 |
|
|
contentRules.add(rule);
|
136 |
|
|
contentRulesIds.add(rule.getId());
|
137 |
|
|
} else if (rule.getJob_type().equals("usage")) {
|
138 |
|
|
usageRules.add(rule);
|
139 |
|
|
usageRulesIds.add(rule.getId());
|
140 |
|
|
}
|
141 |
|
|
}
|
142 |
|
|
retSet.setContentRules(contentRules);
|
143 |
|
|
retSet.setUsageRules(usageRules);
|
144 |
|
|
retSet.setContentRulesIds(contentRulesIds);
|
145 |
|
|
retSet.setUsageRulesIds(usageRulesIds);
|
146 |
17673
|
nikon.gasp
|
}
|
147 |
|
|
}
|
148 |
36835
|
nikon.gasp
|
} catch (Exception e) {
|
149 |
36204
|
nikon.gasp
|
logger.error("Accessing DB to get RuleSet.", e);
|
150 |
17673
|
nikon.gasp
|
} finally {
|
151 |
|
|
if (stmt != null) {
|
152 |
|
|
try {
|
153 |
|
|
stmt.close();
|
154 |
|
|
} catch (SQLException e) {
|
155 |
36204
|
nikon.gasp
|
logger.error("Accessing DB to get RuleSet.", e);
|
156 |
17673
|
nikon.gasp
|
}
|
157 |
|
|
}
|
158 |
56893
|
ioannis.di
|
closeConnection(con);
|
159 |
17673
|
nikon.gasp
|
}
|
160 |
|
|
return retSet;
|
161 |
|
|
}
|
162 |
34780
|
nikon.gasp
|
|
163 |
36835
|
nikon.gasp
|
public List<RuleSet> updateRuleSetHasRules() throws DaoException {
|
164 |
34310
|
nikon.gasp
|
ResultSet rs = null;
|
165 |
|
|
Connection con = null;
|
166 |
|
|
PreparedStatement stmt = null, stmt1 = null;;
|
167 |
|
|
List<RuleSet> retList = new ArrayList<RuleSet>();
|
168 |
|
|
RuleSet retSet = null;
|
169 |
|
|
logger.debug("Accessing DB to get all RuleSets");
|
170 |
|
|
try {
|
171 |
|
|
con = getConnection();
|
172 |
|
|
String query="SELECT name, description, guidelines_acronym, visibility, content_rules, usage_rules, id, short_name FROM rulesets";
|
173 |
|
|
stmt = con.prepareStatement(query);
|
174 |
|
|
rs = stmt.executeQuery();
|
175 |
|
|
if (rs!=null){
|
176 |
|
|
|
177 |
|
|
while (rs.next()) {
|
178 |
|
|
retSet = new RuleSet();
|
179 |
|
|
retSet.setName(rs.getString(1));
|
180 |
|
|
retSet.setDescription(rs.getString(2));
|
181 |
|
|
retSet.setGuidelinesAcronym(rs.getString(3));
|
182 |
|
|
retSet.setVisibility(Utilities.convertStringToList(rs.getString(4)));
|
183 |
|
|
retSet.setId(rs.getInt(7));
|
184 |
|
|
retSet.setShortName(rs.getString(8));
|
185 |
|
|
retList.add(retSet);
|
186 |
|
|
String query1="INSERT INTO ruleset_has_rules(ruleset_id, rule_id) values (?,?)";
|
187 |
|
|
stmt1 = con.prepareStatement(query1);
|
188 |
|
|
for (String id : Utilities.convertStringToList(rs.getString(5))) {
|
189 |
|
|
stmt1.setInt(1,retSet.getId());
|
190 |
|
|
stmt1.setInt(2,Integer.parseInt(id));
|
191 |
|
|
stmt1.addBatch();
|
192 |
|
|
}
|
193 |
|
|
for (String id : Utilities.convertStringToList(rs.getString(6))) {
|
194 |
|
|
stmt1.setInt(1,retSet.getId());
|
195 |
|
|
stmt1.setInt(2,Integer.parseInt(id));
|
196 |
|
|
stmt1.addBatch();
|
197 |
|
|
}
|
198 |
|
|
stmt1.executeBatch();
|
199 |
|
|
}
|
200 |
|
|
}
|
201 |
|
|
|
202 |
36835
|
nikon.gasp
|
} catch (Exception e) {
|
203 |
36204
|
nikon.gasp
|
logger.error("Accessing DB to get all RuleSets.", e);
|
204 |
34310
|
nikon.gasp
|
} finally {
|
205 |
|
|
if (stmt != null) {
|
206 |
|
|
try {
|
207 |
|
|
stmt.close();
|
208 |
|
|
} catch (SQLException e) {
|
209 |
36204
|
nikon.gasp
|
logger.error("Accessing DB to get all RuleSets.", e);
|
210 |
34310
|
nikon.gasp
|
}
|
211 |
|
|
}
|
212 |
56893
|
ioannis.di
|
closeConnection(con);
|
213 |
34310
|
nikon.gasp
|
}
|
214 |
|
|
return retList;
|
215 |
|
|
}
|
216 |
57005
|
ioannis.di
|
|
217 |
17673
|
nikon.gasp
|
@Override
|
218 |
36835
|
nikon.gasp
|
public List<RuleSet> getRuleSets() throws DaoException {
|
219 |
17673
|
nikon.gasp
|
ResultSet rs = null;
|
220 |
|
|
Connection con = null;
|
221 |
|
|
PreparedStatement stmt = null;
|
222 |
|
|
List<RuleSet> retList = new ArrayList<RuleSet>();
|
223 |
|
|
logger.debug("Accessing DB to get all RuleSets");
|
224 |
56916
|
ioannis.di
|
|
225 |
17673
|
nikon.gasp
|
try {
|
226 |
|
|
con = getConnection();
|
227 |
34780
|
nikon.gasp
|
String query="SELECT name, description, guidelines_acronym, visibility, id, short_name FROM rulesets ORDER BY id";
|
228 |
17673
|
nikon.gasp
|
stmt = con.prepareStatement(query);
|
229 |
|
|
rs = stmt.executeQuery();
|
230 |
56916
|
ioannis.di
|
|
231 |
|
|
while (rs.next()) {
|
232 |
|
|
RuleSet retSet = new RuleSet();
|
233 |
|
|
|
234 |
|
|
retSet.setName(rs.getString(1));
|
235 |
|
|
retSet.setDescription(rs.getString(2));
|
236 |
|
|
retSet.setGuidelinesAcronym(rs.getString(3));
|
237 |
|
|
List<String> visibility = new ArrayList<String>();
|
238 |
|
|
Array tt = rs.getArray("visibility");
|
239 |
|
|
if (tt != null) {
|
240 |
|
|
String[] ent = (String[])tt.getArray();
|
241 |
|
|
visibility.addAll(Arrays.asList(ent));
|
242 |
|
|
}
|
243 |
|
|
retSet.setVisibility(visibility);
|
244 |
|
|
retSet.setId(rs.getInt(5));
|
245 |
|
|
retSet.setShortName(rs.getString(6));
|
246 |
|
|
List <Rule> rules = this.getRulesOfRuleset(retSet.getId());
|
247 |
|
|
List <Rule> contentRules = new ArrayList<Rule>();
|
248 |
|
|
List <Rule> usageRules = new ArrayList<Rule>();
|
249 |
|
|
Set <Integer> contentRulesIds = new HashSet<Integer>();
|
250 |
|
|
Set <Integer> usageRulesIds = new HashSet<Integer>();
|
251 |
|
|
for (Rule rule : rules) {
|
252 |
|
|
if (rule.getJob_type().equals("content")) {
|
253 |
|
|
contentRules.add(rule);
|
254 |
|
|
contentRulesIds.add(rule.getId());
|
255 |
|
|
} else if (rule.getJob_type().equals("usage")) {
|
256 |
|
|
usageRules.add(rule);
|
257 |
|
|
usageRulesIds.add(rule.getId());
|
258 |
34780
|
nikon.gasp
|
}
|
259 |
56916
|
ioannis.di
|
}
|
260 |
|
|
retSet.setContentRules(contentRules);
|
261 |
|
|
retSet.setUsageRules(usageRules);
|
262 |
|
|
retSet.setContentRulesIds(contentRulesIds);
|
263 |
|
|
retSet.setUsageRulesIds(usageRulesIds);
|
264 |
|
|
retList.add(retSet);
|
265 |
17673
|
nikon.gasp
|
}
|
266 |
36835
|
nikon.gasp
|
} catch (Exception e) {
|
267 |
36204
|
nikon.gasp
|
logger.error("Accessing DB to get all RuleSets.", e);
|
268 |
17673
|
nikon.gasp
|
} finally {
|
269 |
|
|
if (stmt != null) {
|
270 |
|
|
try {
|
271 |
|
|
stmt.close();
|
272 |
|
|
} catch (SQLException e) {
|
273 |
36204
|
nikon.gasp
|
logger.error("Accessing DB to get all RuleSets.", e);
|
274 |
17673
|
nikon.gasp
|
}
|
275 |
|
|
}
|
276 |
56893
|
ioannis.di
|
closeConnection(con);
|
277 |
17673
|
nikon.gasp
|
}
|
278 |
|
|
return retList;
|
279 |
57005
|
ioannis.di
|
}
|
280 |
|
|
|
281 |
|
|
@Override
|
282 |
|
|
public List<RuleSet> getRuleSets(String guidelineAcronym) throws DaoException {
|
283 |
|
|
ResultSet rs = null;
|
284 |
|
|
Connection con = null;
|
285 |
|
|
PreparedStatement stmt = null;
|
286 |
|
|
List<RuleSet> retList = new ArrayList<RuleSet>();
|
287 |
|
|
logger.debug("Accessing DB to get all RuleSets");
|
288 |
|
|
|
289 |
|
|
try {
|
290 |
|
|
con = getConnection();
|
291 |
|
|
String query="SELECT name, description, guidelines_acronym, visibility, id, short_name FROM rulesets WHERE guidelines_acronym=? ORDER BY id";
|
292 |
|
|
stmt = con.prepareStatement(query);
|
293 |
|
|
stmt.setString(1,guidelineAcronym);
|
294 |
|
|
rs = stmt.executeQuery();
|
295 |
|
|
|
296 |
|
|
while (rs.next()) {
|
297 |
|
|
RuleSet retSet = new RuleSet();
|
298 |
|
|
|
299 |
|
|
retSet.setName(rs.getString(1));
|
300 |
|
|
retSet.setDescription(rs.getString(2));
|
301 |
|
|
retSet.setGuidelinesAcronym(rs.getString(3));
|
302 |
|
|
List<String> visibility = new ArrayList<String>();
|
303 |
|
|
Array tt = rs.getArray("visibility");
|
304 |
|
|
if (tt != null) {
|
305 |
|
|
String[] ent = (String[])tt.getArray();
|
306 |
|
|
visibility.addAll(Arrays.asList(ent));
|
307 |
|
|
}
|
308 |
|
|
retSet.setVisibility(visibility);
|
309 |
|
|
retSet.setId(rs.getInt(5));
|
310 |
|
|
retSet.setShortName(rs.getString(6));
|
311 |
|
|
List <Rule> rules = this.getRulesOfRuleset(retSet.getId());
|
312 |
|
|
List <Rule> contentRules = new ArrayList<Rule>();
|
313 |
|
|
List <Rule> usageRules = new ArrayList<Rule>();
|
314 |
|
|
Set <Integer> contentRulesIds = new HashSet<Integer>();
|
315 |
|
|
Set <Integer> usageRulesIds = new HashSet<Integer>();
|
316 |
|
|
for (Rule rule : rules) {
|
317 |
|
|
if (rule.getJob_type().equals("content")) {
|
318 |
|
|
contentRules.add(rule);
|
319 |
|
|
contentRulesIds.add(rule.getId());
|
320 |
|
|
} else if (rule.getJob_type().equals("usage")) {
|
321 |
|
|
usageRules.add(rule);
|
322 |
|
|
usageRulesIds.add(rule.getId());
|
323 |
|
|
}
|
324 |
|
|
}
|
325 |
|
|
retSet.setContentRules(contentRules);
|
326 |
|
|
retSet.setUsageRules(usageRules);
|
327 |
|
|
retSet.setContentRulesIds(contentRulesIds);
|
328 |
|
|
retSet.setUsageRulesIds(usageRulesIds);
|
329 |
|
|
retList.add(retSet);
|
330 |
|
|
}
|
331 |
|
|
} catch (Exception e) {
|
332 |
|
|
logger.error("Accessing DB to get all RuleSets.", e);
|
333 |
|
|
} finally {
|
334 |
|
|
if (stmt != null) {
|
335 |
|
|
try {
|
336 |
|
|
stmt.close();
|
337 |
|
|
} catch (SQLException e) {
|
338 |
|
|
logger.error("Accessing DB to get all RuleSets.", e);
|
339 |
|
|
}
|
340 |
|
|
}
|
341 |
|
|
closeConnection(con);
|
342 |
|
|
}
|
343 |
|
|
return retList;
|
344 |
17673
|
nikon.gasp
|
}
|
345 |
|
|
|
346 |
36835
|
nikon.gasp
|
public List<Rule> getRulesOfRuleset(int ruleSetId) throws DaoException {
|
347 |
34310
|
nikon.gasp
|
ResultSet rs = null;
|
348 |
|
|
Connection con = null;
|
349 |
|
|
PreparedStatement stmt = null;
|
350 |
|
|
Rule retRule = null;
|
351 |
|
|
List<Rule> retList = null;
|
352 |
|
|
logger.debug("Accessing DB to get All Rules of ruleset");
|
353 |
|
|
try {
|
354 |
|
|
con = getConnection();
|
355 |
34918
|
nikon.gasp
|
String query="SELECT * FROM rules r, ruleset_has_rules rhs WHERE rhs.rule_id = r.id AND rhs.ruleset_id=?";
|
356 |
34310
|
nikon.gasp
|
stmt = con.prepareStatement(query);
|
357 |
|
|
stmt.setInt(1, ruleSetId);
|
358 |
|
|
rs = stmt.executeQuery();
|
359 |
|
|
if (rs!=null){
|
360 |
|
|
retList = new ArrayList<Rule>();
|
361 |
|
|
while (rs.next()) {
|
362 |
|
|
retRule = new Rule();
|
363 |
34918
|
nikon.gasp
|
retRule.setName(rs.getString("name"));
|
364 |
|
|
retRule.setDescription(rs.getString("description"));
|
365 |
|
|
retRule.setType(rs.getString("type"));
|
366 |
|
|
retRule.setMandatory(rs.getBoolean("mandatory"));
|
367 |
|
|
retRule.setWeight(rs.getInt("weight"));
|
368 |
|
|
retRule.setProvider_information(rs.getString("provider_information"));
|
369 |
|
|
retRule.setId(rs.getInt("id"));
|
370 |
|
|
retRule.setEntity_type(rs.getString("entity_type"));
|
371 |
|
|
retRule.setFor_cris(rs.getBoolean("for_cris"));
|
372 |
|
|
retRule.setJob_type(rs.getString("job_type"));
|
373 |
|
|
// retRule.setConfiguration(this.getProperties(rs.getInt("id")));
|
374 |
34310
|
nikon.gasp
|
retList.add(retRule);
|
375 |
|
|
}
|
376 |
|
|
}
|
377 |
34918
|
nikon.gasp
|
logger.debug("rules: " + retList.size());
|
378 |
34310
|
nikon.gasp
|
|
379 |
36835
|
nikon.gasp
|
} catch (Exception e) {
|
380 |
36204
|
nikon.gasp
|
logger.error("Error accessing DB to get All Rules by jobType.", e);
|
381 |
36835
|
nikon.gasp
|
throw new DaoException(e);
|
382 |
34310
|
nikon.gasp
|
} finally {
|
383 |
|
|
if (stmt != null) {
|
384 |
|
|
try {
|
385 |
|
|
stmt.close();
|
386 |
|
|
} catch (SQLException e) {
|
387 |
36204
|
nikon.gasp
|
logger.error("Error accessing DB to get All Rules by jobType.", e);
|
388 |
36835
|
nikon.gasp
|
throw new DaoException(e);
|
389 |
34310
|
nikon.gasp
|
}
|
390 |
|
|
}
|
391 |
56893
|
ioannis.di
|
closeConnection(con);
|
392 |
34310
|
nikon.gasp
|
}
|
393 |
|
|
return retList;
|
394 |
|
|
|
395 |
17673
|
nikon.gasp
|
}
|
396 |
|
|
|
397 |
|
|
@Override
|
398 |
34310
|
nikon.gasp
|
protected PreparedStatement getDeleteStatement(int id, Connection con)
|
399 |
17673
|
nikon.gasp
|
throws SQLException {
|
400 |
|
|
String query="DELETE FROM rulesets WHERE id=?";
|
401 |
|
|
PreparedStatement stmt = con.prepareStatement(query);
|
402 |
34310
|
nikon.gasp
|
stmt.setInt(1,id);
|
403 |
17673
|
nikon.gasp
|
return stmt;
|
404 |
|
|
}
|
405 |
|
|
|
406 |
|
|
@Override
|
407 |
36835
|
nikon.gasp
|
protected int getLastId() throws DaoException {
|
408 |
17673
|
nikon.gasp
|
ResultSet rs = null;
|
409 |
|
|
Connection con = null;
|
410 |
|
|
PreparedStatement stmt = null;
|
411 |
|
|
int retId = -1;
|
412 |
|
|
logger.debug("Accessing DB to get RuleSet's next available id");
|
413 |
|
|
try {
|
414 |
|
|
con = getConnection();
|
415 |
|
|
String query="SELECT currval(pg_get_serial_sequence(?,?)) FROM rulesets";
|
416 |
|
|
stmt = con.prepareStatement(query);
|
417 |
|
|
stmt.setString(1, "rulesets");
|
418 |
|
|
stmt.setString(2, "id");
|
419 |
|
|
|
420 |
|
|
rs = stmt.executeQuery();
|
421 |
|
|
if (rs!=null){
|
422 |
|
|
rs.next();
|
423 |
|
|
retId=rs.getInt(1);
|
424 |
|
|
}
|
425 |
36835
|
nikon.gasp
|
} catch (Exception e) {
|
426 |
36204
|
nikon.gasp
|
logger.error("Error while accessing DB to get RuleSet's next available id.", e);
|
427 |
36835
|
nikon.gasp
|
throw new DaoException(e);
|
428 |
17673
|
nikon.gasp
|
} finally {
|
429 |
|
|
if (stmt != null) {
|
430 |
|
|
try {
|
431 |
|
|
stmt.close();
|
432 |
|
|
} catch (SQLException e) {
|
433 |
36204
|
nikon.gasp
|
logger.error("Error while accessing DB to get RuleSet's next available id.", e);
|
434 |
36835
|
nikon.gasp
|
throw new DaoException(e);
|
435 |
17673
|
nikon.gasp
|
}
|
436 |
|
|
}
|
437 |
56893
|
ioannis.di
|
closeConnection(con);
|
438 |
17673
|
nikon.gasp
|
}
|
439 |
|
|
return retId;
|
440 |
|
|
}
|
441 |
|
|
|
442 |
34310
|
nikon.gasp
|
@Override
|
443 |
34780
|
nikon.gasp
|
protected PreparedStatement getUpdateStatement(RuleSet t, Connection con)
|
444 |
|
|
throws SQLException {
|
445 |
34310
|
nikon.gasp
|
// TODO Auto-generated method stub
|
446 |
|
|
return null;
|
447 |
|
|
}
|
448 |
|
|
|
449 |
34780
|
nikon.gasp
|
@Override
|
450 |
|
|
protected PreparedStatement getInsertStatement(RuleSet t, Connection con)
|
451 |
|
|
throws SQLException {
|
452 |
|
|
// TODO Auto-generated method stub
|
453 |
|
|
return null;
|
454 |
|
|
}
|
455 |
17673
|
nikon.gasp
|
}
|