1 | package org.medias.eccad.persistance.jdbc; |
---|
2 | |
---|
3 | import java.sql.Connection; |
---|
4 | import java.sql.ResultSet; |
---|
5 | import java.sql.SQLException; |
---|
6 | import java.sql.Statement; |
---|
7 | import java.util.LinkedList; |
---|
8 | import java.util.List; |
---|
9 | |
---|
10 | import org.medias.eccad.persistance.dao.CodeDAO; |
---|
11 | import org.medias.eccad.persistance.exception.PersistanceException; |
---|
12 | |
---|
13 | public class CodeDAOjdbc extends GeneriqueDAOjdbc implements CodeDAO { |
---|
14 | |
---|
15 | public List<String> getListCodeByGrille(long id_grille) throws PersistanceException { |
---|
16 | Statement requete; |
---|
17 | String sql; |
---|
18 | Connection conn = getConnection(); |
---|
19 | List<String> code = new LinkedList<String>(); |
---|
20 | |
---|
21 | try { |
---|
22 | requete = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); |
---|
23 | sql = " select legend_code" |
---|
24 | + " from grille join codification using (id_codification)" |
---|
25 | + " join code using (id_codification) where id_grille = " + id_grille + " order by id_code;"; |
---|
26 | |
---|
27 | ResultSet resultat = requete.executeQuery(sql); |
---|
28 | |
---|
29 | while (resultat.next()) { |
---|
30 | code.add(resultat.getString("legend_code").toLowerCase()); |
---|
31 | } |
---|
32 | } |
---|
33 | catch (SQLException sqle) { |
---|
34 | throw new PersistanceException(sqle, "getListCodeByGrille"); |
---|
35 | } |
---|
36 | |
---|
37 | finally { |
---|
38 | closeConnection(); |
---|
39 | } |
---|
40 | |
---|
41 | return code; |
---|
42 | } |
---|
43 | |
---|
44 | public Long getNumberCode(long id_grille) throws PersistanceException { |
---|
45 | Statement requete; |
---|
46 | String sql; |
---|
47 | Connection conn = getConnection(); |
---|
48 | Long code = null; |
---|
49 | |
---|
50 | try { |
---|
51 | requete = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); |
---|
52 | sql = " select number_code" |
---|
53 | + " from code where num_code = " + id_grille + ";"; |
---|
54 | |
---|
55 | ResultSet resultat = requete.executeQuery(sql); |
---|
56 | |
---|
57 | if (resultat.next()) { |
---|
58 | code = resultat.getLong("number_code"); |
---|
59 | } |
---|
60 | } |
---|
61 | catch (SQLException sqle) { |
---|
62 | throw new PersistanceException(sqle, "getListCodeByGrille"); |
---|
63 | } |
---|
64 | |
---|
65 | finally { |
---|
66 | closeConnection(); |
---|
67 | } |
---|
68 | |
---|
69 | return code; |
---|
70 | } |
---|
71 | |
---|
72 | } |
---|