[68] | 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); |
---|
[70] | 23 | // sql = " select num_code,legend_code" |
---|
| 24 | // + " from grille join codification using (id_codification)" |
---|
| 25 | // + " join code using (id_codification) where id_grille = " + id_grille + " order by num_code;"; |
---|
| 26 | sql = " select number_code,legend_code" |
---|
| 27 | + " from grille left join code on id_grille = num_code" |
---|
| 28 | + " where id_grille = " + id_grille + " order by number_code;"; |
---|
| 29 | |
---|
[68] | 30 | ResultSet resultat = requete.executeQuery(sql); |
---|
[70] | 31 | String legend = ""; |
---|
[68] | 32 | while (resultat.next()) { |
---|
[70] | 33 | legend = resultat.getString("legend_code"); |
---|
| 34 | code.add(resultat.getString("number_code")+"-"+legend); |
---|
[68] | 35 | } |
---|
[70] | 36 | if (code.size() == 1) { |
---|
| 37 | code.set(0, "1-"+legend); |
---|
| 38 | } |
---|
[68] | 39 | } |
---|
| 40 | catch (SQLException sqle) { |
---|
| 41 | throw new PersistanceException(sqle, "getListCodeByGrille"); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | finally { |
---|
| 45 | closeConnection(); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | return code; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | public Long getNumberCode(long id_grille) throws PersistanceException { |
---|
| 52 | Statement requete; |
---|
| 53 | String sql; |
---|
| 54 | Connection conn = getConnection(); |
---|
| 55 | Long code = null; |
---|
| 56 | |
---|
| 57 | try { |
---|
| 58 | requete = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); |
---|
| 59 | sql = " select number_code" |
---|
| 60 | + " from code where num_code = " + id_grille + ";"; |
---|
| 61 | |
---|
| 62 | ResultSet resultat = requete.executeQuery(sql); |
---|
| 63 | |
---|
| 64 | if (resultat.next()) { |
---|
| 65 | code = resultat.getLong("number_code"); |
---|
| 66 | } |
---|
| 67 | } |
---|
| 68 | catch (SQLException sqle) { |
---|
| 69 | throw new PersistanceException(sqle, "getListCodeByGrille"); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | finally { |
---|
| 73 | closeConnection(); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | return code; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | } |
---|