- Hlavní stránka
- Balíky
- Třídy
- Soubory

# src/cz/neubauer/tomas/hazardanalysis/model/dangers/DangerEstimationBacking.java

Zobrazit dokumentaci tohoto souboru.

    00001
    00004 package cz.neubauer.tomas.hazardanalysis.model.dangers;
    00005
    00006 import java.sql.ResultSet;
    00007 import java.sql.SQLException;
    00008 import java.sql.Statement;
    00009
    00010 import cz.neubauer.tomas.hazardanalysis.Rizika;
    00011 import cz.neubauer.tomas.hazardanalysis.model.stages.VariantStage;
    00012
    00019 public class DangerEstimationBacking {
    00020
    00024         private static int last_insert_id = -1;
    00025
    00029         private Rizika application;
    00030
    00035         private VariantStage variantStage;
    00036
    00040         private String dangerArea;
    00041
    00045         private String persons;
    00046
    00050         private String dangerEventDescription;
    00051
    00055         private String counterAct1;
    00056
    00060         private String counterAct2;
    00061
    00065         private String counterAct3;
    00066
    00070         private int state;
    00071
    00075         private int[] step0, step1, step2, step3;
    00076
    00083         public DangerEstimationBacking(Rizika application) {
    00084                 this.application = application;
    00085                 variantStage = null;
    00086                 dangerArea = "";
    00087                 persons = "";
    00088                 state = 0;
    00089                 dangerEventDescription = "";
    00090                 counterAct1 = "";
    00091                 counterAct2 = "";
    00092                 counterAct3 = "";
    00093                 step0 = new int[4];
    00094                 step1 = new int[4];
    00095                 step2 = new int[4];
    00096                 step3 = new int[4];
    00097         }
    00098
    00104         public VariantStage getVariantStage() {
    00105                 return variantStage;
    00106         }
    00107
    00114         public void setVariantStage(VariantStage variantStage) {
    00115                 this.variantStage = variantStage;
    00116                 int dangerVariantId = variantStage.getDangerVariant().getId();
    00117
    00118                 try {
    00119                         Statement stmt = application.getConnection().createStatement();
    00120
    00121                         stmt
    00122                                         .executeQuery("SELECT * FROM history WHERE danger_variant_id = '"
    00123                                                         + dangerVariantId + "';");
    00124
    00125                         ResultSet rs = stmt.getResultSet();
    00126
    00127                         if (rs.next()) {
    00128                                 setDangerArea(rs.getString("area"));
    00129                                 setPersons(rs.getString("persons"));
    00130                                 setDangerEventDescription(rs.getString("event"));
    00131                                 setCounterAct1(rs.getString("step1"));
    00132                                 setCounterAct2(rs.getString("step2"));
    00133                                 setCounterAct3(rs.getString("step3"));
    00134                                 step0[0] = rs.getInt("s0");
    00135                                 step1[0] = rs.getInt("s1");
    00136                                 step2[0] = rs.getInt("s2");
    00137                                 step3[0] = rs.getInt("s3");
    00138                                 step0[1] = rs.getInt("a0");
    00139                                 step1[1] = rs.getInt("a1");
    00140                                 step2[1] = rs.getInt("a2");
    00141                                 step3[1] = rs.getInt("a3");
    00142                                 step0[2] = rs.getInt("e0");
    00143                                 step1[2] = rs.getInt("e1");
    00144                                 step2[2] = rs.getInt("e2");
    00145                                 step3[2] = rs.getInt("e3");
    00146                                 step0[3] = rs.getInt("w0");
    00147                                 step1[3] = rs.getInt("w1");
    00148                                 step2[3] = rs.getInt("w2");
    00149                                 step3[3] = rs.getInt("w3");
    00150                         } else {
    00151
    00152                                 if (stmt.execute("select max(id) as id from history;")) {
    00153                                         ResultSet res = stmt.getResultSet();
    00154                                         if (res.next()) {
    00155                                                 last_insert_id = res.getInt("id");
    00156                                         }
    00157                                 }
    00158
    00159                                 application
    00160                                                 .getConnection()
    00161                                                 .createStatement()
    00162                                                 .executeUpdate(
    00163                                                                 "INSERT INTO history VALUES ("
    00164                                                                                 + (last_insert_id > 0 ? ++last_insert_id
    00165                                                                                                 : "1")
    00166                                                                                 + ", '"
    00167                                                                                 + dangerVariantId
    00168                                                                                 + "','','','','','','',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);");
    00169                         }
    00170                         stmt.close();
    00171                 } catch (SQLException e) {
    00172                         e.printStackTrace();
    00173                 }
    00174         }
    00175
    00179         public void saveHistory() {
    00180                 int dangerVariantId = variantStage.getDangerVariant().getId();
    00181
    00182                 try {
    00183                         Statement stmt = application.getConnection().createStatement();
    00184                         stmt.executeUpdate("UPDATE history SET area='" + getDangerArea()
    00185                                         + "', persons='" + getPersons() + "',  event='"
    00186                                         + getDangerEventDescription() + "', step1='"
    00187                                         + getCounterAct1() + "', step2='" + getCounterAct2()
    00188                                         + "', step3='" + getCounterAct3() + "', s0='" + step0[0]
    00189                                         + "', s1='" + step1[0] + "', s2='" + step2[0] + "', s3='"
    00190                                         + step3[0] + "', a0='" + step0[1] + "', a1='" + step1[1]
    00191                                         + "', a2='" + step2[1] + "', a3='" + step3[1] + "', e0='"
    00192                                         + step0[2] + "', e1='" + step1[2] + "', e2='" + step2[2]
    00193                                         + "', e3='" + step3[2] + "', w0='" + step0[3] + "', w1='"
    00194                                         + step1[3] + "', w2='" + step2[3] + "', w3='" + step3[3]
    00195                                         + "' WHERE danger_variant_id='" + dangerVariantId + "';");
    00196
    00197                         stmt.close();
    00198                 } catch (SQLException e) {
    00199                         e.printStackTrace();
    00200                 }
    00201         }
    00202
    00208         public String getDangerArea() {
    00209                 return dangerArea;
    00210         }
    00211
    00218         public void setDangerArea(String dangerArea) {
    00219                 this.dangerArea = dangerArea;
    00220         }
    00221
    00227         public String getPersons() {
    00228                 return persons;
    00229         }
    00230
    00237         public void setPersons(String persons) {
    00238                 this.persons = persons;
    00239         }
    00240
    00246         public int getState() {
    00247                 return state;
    00248         }
    00249
    00256         public void setState(int state) {
    00257                 this.state = state;
    00258         }
    00259
    00265         public String getDangerEventDescription() {
    00266                 return dangerEventDescription;
    00267         }
    00268
    00275         public void setDangerEventDescription(String dangerEventDescription) {
    00276                 this.dangerEventDescription = dangerEventDescription;
    00277         }
    00278
    00284         public String getCounterAct1() {
    00285                 return counterAct1;
    00286         }
    00287
    00294         public void setCounterAct1(String counterAct1) {
    00295                 this.counterAct1 = counterAct1;
    00296         }
    00297
    00303         public String getCounterAct2() {
    00304                 return counterAct2;
    00305         }
    00306
    00313         public void setCounterAct2(String counterAct2) {
    00314                 this.counterAct2 = counterAct2;
    00315         }
    00316
    00322         public String getCounterAct3() {
    00323                 return counterAct3;
    00324         }
    00325
    00332         public void setCounterAct3(String counterAct3) {
    00333                 this.counterAct3 = counterAct3;
    00334         }
    00335
    00336         /*
    00337          * (non-Javadoc)
    00338          *
    00339          * @see java.lang.Object#toString()
    00340          */
    00341         @Override
    00342         public String toString() {
    00343                 return variantStage.toString();
    00344         }
    00345
    00351         public int[] getStep0() {
    00352                 return step0;
    00353         }
    00354
    00362         public void setStep0(int[] step0) {
    00363                 this.step0 = step0;
    00364         }
    00365
    00371         public int[] getStep1() {
    00372                 return step1;
    00373         }
    00374
    00381         public void setStep1(int[] step1) {
    00382                 this.step1 = step1;
    00383         }
    00384
    00390         public int[] getStep2() {
    00391                 return step2;
    00392         }
    00393
    00400         public void setStep2(int[] step2) {
    00401                 this.step2 = step2;
    00402         }
    00403
    00409         public int[] getStep3() {
    00410                 return step3;
    00411         }
    00412
    00419         public void setStep3(int[] step3) {
    00420                 this.step3 = step3;
    00421         }
    00422
    00423 }