1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
| package dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import beans.Emergency;
import beans.Monitoring_Emergency;
import beans.Status_Emergency;
public class DAOImpl implements DAO {
private static Connexion connexion = new Connexion();
public String fillDatabase(String data){
String monitoring_emergencyQuery = getMonitorings(data.substring(data.indexOf("<Results-monitoring_emergency><Row>")+
"<Results-monitoring_emergency><Row>".length(), data.indexOf("</Row></Results-monitoring_emergency>")));
try{
connexion.OpenCo();
Connection lConnction = connexion.getConnexion();
if(lConnction != null) {
System.out.println("Connection Is OK !");
PreparedStatement lPreparedStatement = lConnction.prepareStatement(monitoring_emergencyQuery);
lPreparedStatement.executeUpdate();
}
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
try {
connexion.CloseCo();
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
public String getMonitorings(String data) {
data = "TRUNCATE destination.monitoring_emergency; INSERT INTO destination.monitoring_emergency VALUES("+data+");";
data = data.replace("</Row><Row>", "),(");
data = data.replace("id_monit>", ">");
data = data.replace("id_emergency>", ">");
data = data.replace("id_status>", ">");
data = data.replace("date_monit>", ">");
data = data.replace("</><>", "','");
data = data.replace("</>", "'");
data = data.replace("<>", "'");
System.out.println(data);
return data;
}
public List<Monitoring_Emergency> getEmergencyMonitoringsByEmergencyID(int id_urg) {
try{
List<Monitoring_Emergency> listUrgence = new ArrayList<Monitoring_Emergency>();
connexion.OpenCo();
Connection lConnction = connexion.getConnexion();
if(lConnction != null) {
System.out.println("Connection Is OK !");
PreparedStatement lPreparedStatement = lConnction.prepareStatement("SELECT u.id_emergency id,"+
" s.statue libelle, m.date_monit FROM destination.monitoring_emergency m, destination.emergency u,"+
" destination.status_emergency s"
+ " where m.id_emergency = u.id_emergency and m.id_status = s.id_status and u.id_emergency= ? order by u.id_emergency desc");
lPreparedStatement.setInt(1, id_urg);
ResultSet executeQuery = lPreparedStatement.executeQuery();
while (executeQuery.next()) {
int lUgenceID = executeQuery.getInt("id");
String lStatut = executeQuery.getString("libelle");
Date lDate = executeQuery.getDate("date_monit");
System.out.println("Trace1 - " + lUgenceID + " - " + lStatut + " - " + lDate);
Monitoring_Emergency ur =new Monitoring_Emergency(lUgenceID,lStatut,lDate);
listUrgence.add(ur);
//String username = executeQuery.getString("USERNAME");
}
return listUrgence;
}
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
try {
connexion.CloseCo();
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
public List<Status_Emergency> getAllStatus() {
try{
List<Status_Emergency> listStatut = new ArrayList<Status_Emergency>();
connexion.OpenCo();
Connection lConnction = connexion.getConnexion();
if(lConnction != null) {
System.out.println("Connection Is OK !");
PreparedStatement lPreparedStatement = lConnction.prepareStatement("SELECT s.id_status id, s.statue libelle FROM destination.status_emergency s order by s.id_status");
ResultSet executeQuery = lPreparedStatement.executeQuery();
while (executeQuery.next()) {
int lStatutID = executeQuery.getInt("id");
String lStatut = executeQuery.getString("libelle");
System.out.println("Trace1 - " + lStatutID + " - " + lStatut );
Status_Emergency st =new Status_Emergency(lStatutID,lStatut);
listStatut.add(st);
//String username = executeQuery.getString("USERNAME");
}
return listStatut;
}
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
try {
connexion.CloseCo();
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
public List<Emergency> getAllEmergencies() {
try {
List<Emergency> listEmergency = new ArrayList<Emergency>();
connexion.OpenCo();
Connection lConnction = connexion.getConnexion();
if(lConnction != null) {
System.out.println("Connection Is OK !");
PreparedStatement lPreparedStatement = lConnction.prepareStatement("SELECT e.id_emergency, e.name, e.phone_number, e.subject,"+
" e.victim_number, p.priority, s.statue" +
" FROM destination.emergency e,destination.priority p,destination.status_emergency s,destination.monitoring_emergency m"+
" where e.id_priority = p.id_priority and e.id_emergency = m.id_emergency"+
" and s.id_status = m.id_status order by id_emergency,s.id_status desc;");
ResultSet executeQuery = lPreparedStatement.executeQuery();
int id_emergencyOld=-1;
while (executeQuery.next()) {
int victim_number,id_emergency;
String name, phone_number,subject,priority,statue;
id_emergency = executeQuery.getInt("id_emergency");
if(id_emergency == id_emergencyOld){
continue;
}else{
id_emergencyOld = id_emergency;
}
name = executeQuery.getString("name");
phone_number = executeQuery.getString("phone_number");
subject = executeQuery.getString("subject");
victim_number = executeQuery.getInt("victim_number");
priority = executeQuery.getString("priority");
statue = executeQuery.getString("statue");
System.out.println("Trace1 - " + id_emergency + " - " + name + " - " + phone_number + " - "+ subject + " - " + victim_number + " - " + priority + " - " + statue);
Emergency em = new Emergency(id_emergency, victim_number,0,name, phone_number, subject, priority,statue);
listEmergency.add(em);
}
return listEmergency;
}
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
try {
connexion.CloseCo();
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
} |
Partager