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

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

Zobrazit dokumentaci tohoto souboru.

    00001
    00004 package cz.neubauer.tomas.hazardanalysis.model.dangers;
    00005
    00006 import java.sql.Connection;
    00007 import java.sql.ResultSet;
    00008 import java.sql.SQLException;
    00009 import java.sql.Statement;
    00010 import java.util.ArrayList;
    00011
    00015 public class DangerType {
    00021         private static int last_insert_id = -1;
    00022
    00026         private int id;
    00027
    00031         private String code;
    00032
    00036         private String description;
    00037
    00041         private String situationDescription;
    00042
    00046         private DangerGroup dangerGroup;
    00047
    00051         private ArrayList<DangerVariant> variants;
    00052
    00056         private String column_cast2_a1_1995, column_cast1_r1991,
    00057                         column_cast2_r1991, column_csn_en_iso_12100_1_2003,
    00058                         column_csn_en_iso_12100_2_2003, column_normy_typu_b,
    00059                         column_clanky_csn_en_12415_2001;
    00060
    00089         public DangerType(DangerGroup dangerGroup, int id, String code,
    00090                         String description, String column_cast2_a1_1995,
    00091                         String column_cast1_r1991, String column_cast2_r1991,
    00092                         String column_csn_en_iso_12100_1_2003,
    00093                         String column_csn_en_iso_12100_2_2003, String column_normy_typu_b,
    00094                         String column_clanky_csn_en_12415_2001, String situationDescription) {
    00095                 this.id = id;
    00096                 this.code = code;
    00097                 this.description = description;
    00098                 this.dangerGroup = dangerGroup;
    00099                 this.column_cast2_a1_1995 = column_cast2_a1_1995;
    00100                 this.column_cast1_r1991 = column_cast1_r1991;
    00101                 this.column_cast2_r1991 = column_cast2_r1991;
    00102                 this.column_csn_en_iso_12100_1_2003 = column_csn_en_iso_12100_1_2003;
    00103                 this.column_csn_en_iso_12100_2_2003 = column_csn_en_iso_12100_2_2003;
    00104                 this.column_normy_typu_b = column_normy_typu_b;
    00105                 this.column_clanky_csn_en_12415_2001 = column_clanky_csn_en_12415_2001;
    00106                 this.situationDescription = situationDescription;
    00107                 variants = new ArrayList<DangerVariant>(10);
    00108         }
    00109
    00115         public String getCode() {
    00116                 return code;
    00117         }
    00118
    00125         public void setCode(String code) {
    00126                 this.code = code;
    00127         }
    00128
    00134         public String getDescription() {
    00135                 return description;
    00136         }
    00137
    00144         public void setDescription(String description) {
    00145                 this.description = description;
    00146         }
    00147
    00153         public ArrayList<DangerVariant> getVariants() {
    00154                 return variants;
    00155         }
    00156
    00163         public void setVariants(ArrayList<DangerVariant> variants) {
    00164                 this.variants = variants;
    00165         }
    00166
    00172         public DangerGroup getDangerGroup() {
    00173                 return dangerGroup;
    00174         }
    00175
    00182         public void setDangerGroup(DangerGroup dangerGroup) {
    00183                 this.dangerGroup = dangerGroup;
    00184         }
    00185
    00191         public int getId() {
    00192                 return id;
    00193         }
    00194
    00201         public void setId(int id) {
    00202                 this.id = id;
    00203         }
    00204
    00213         public void saveToDB(Connection connection) {
    00214                 if (connection != null) {
    00215                         String a = "";
    00216                         try {
    00217                                 Statement stmt = connection.createStatement();
    00218                                 if (last_insert_id < 1) {
    00219                                         stmt.executeQuery("SELECT max(id) FROM danger_type;");
    00220                                         ResultSet rs = stmt.getResultSet();
    00221                                         if (rs.next()) {
    00222                                                 last_insert_id = rs.getInt(1);
    00223                                         }
    00224                                 }
    00225
    00226                                 stmt
    00227                                                 .executeQuery("SELECT count(id) as count FROM danger_type WHERE id = '"
    00228                                                                 + id + "';");
    00229                                 ResultSet rs1 = stmt.getResultSet();
    00230                                 if (rs1.next() && rs1.getInt(1) == 0) {
    00231                                         stmt.executeUpdate(a = "INSERT INTO danger_type VALUES ("
    00232                                                         + (last_insert_id > 0 ? "'" + (++last_insert_id)
    00233                                                                         + "'" : "LAST_INSERT_ID()") + ", " + "'"
    00234                                                         + dangerGroup.getId() + "', " + "'" + code + "', "
    00235                                                         + "'" + description + "', " + "'"
    00236                                                         + column_cast2_a1_1995 + "', " + "'"
    00237                                                         + column_cast1_r1991 + "', " + "'"
    00238                                                         + column_cast2_r1991 + "', " + "'"
    00239                                                         + column_csn_en_iso_12100_1_2003 + "', " + "'"
    00240                                                         + column_csn_en_iso_12100_2_2003 + "', " + "'"
    00241                                                         + column_normy_typu_b + "', " + "'"
    00242                                                         + column_clanky_csn_en_12415_2001 + "'," + "'"
    00243                                                         + situationDescription + "');",
    00244                                                         Statement.RETURN_GENERATED_KEYS);
    00245                                         ResultSet rs = stmt.getGeneratedKeys();
    00246                                         if (rs.next()) {
    00247                                                 id = rs.getInt(1);
    00248                                                 last_insert_id = id;
    00249                                         }
    00250                                 } else {
    00251
    00252                                         stmt
    00253                                                         .executeUpdate("UPDATE danger_type SET danger_group_id='"
    00254                                                                         + dangerGroup.getId()
    00255                                                                         + "', code = '"
    00256                                                                         + code
    00257                                                                         + "', description = '"
    00258                                                                         + description
    00259                                                                         + "', "
    00260                                                                         + "column_cast2_a1_1995 = '"
    00261                                                                         + column_cast2_a1_1995
    00262                                                                         + "',"
    00263                                                                         + "column_cast1_r1991 = '"
    00264                                                                         + column_cast1_r1991
    00265                                                                         + "',"
    00266                                                                         + "column_cast2_r1991 = '"
    00267                                                                         + column_cast2_r1991
    00268                                                                         + "',"
    00269                                                                         + "column_csn_en_iso_12100_1_2003 = '"
    00270                                                                         + column_csn_en_iso_12100_1_2003
    00271                                                                         + "',"
    00272                                                                         + "column_csn_en_iso_12100_2_2003 = '"
    00273                                                                         + column_csn_en_iso_12100_2_2003
    00274                                                                         + "',"
    00275                                                                         + "column_normy_typu_b = '"
    00276                                                                         + column_normy_typu_b
    00277                                                                         + "',"
    00278                                                                         + "column_clanky_csn_en_12415_2001 = '"
    00279                                                                         + column_clanky_csn_en_12415_2001
    00280                                                                         + "',"
    00281                                                                         + "situation_description = '"
    00282                                                                         + situationDescription
    00283                                                                         + "' WHERE id='"
    00284                                                                         + id + "';");
    00285                                 }
    00286                                 stmt.close();
    00287                         } catch (SQLException e) {
    00288                                 System.err.println(a);
    00289                                 e.printStackTrace();
    00290                         }
    00291                 }
    00292         }
    00293
    00301         public void deleteFromDB(Connection connection) {
    00302                 if (connection != null) {
    00303                         // smazání variant
    00304                         for (int i = 0; i < variants.size(); i++) {
    00305                                 variants.get(i).deleteFromDB(connection);
    00306                         }
    00307
    00308                         Statement stmt;
    00309                         try {
    00310                                 stmt = connection.createStatement();
    00311
    00312                                 stmt.executeUpdate("DELETE FROM danger_type WHERE id = '" + id
    00313                                                 + "';");
    00314                                 stmt.close();
    00315                                 finalize();
    00316                         } catch (SQLException e) {
    00317                                 e.printStackTrace();
    00318                         } catch (Throwable e) {
    00319                                 e.printStackTrace();
    00320                         }
    00321                 }
    00322         }
    00323
    00330         public void addDangerVariant(DangerVariant dangerVariant) {
    00331                 variants.add(dangerVariant);
    00332         }
    00333
    00339         public int getDangerVariantCount() {
    00340                 return variants.size();
    00341         }
    00342
    00350         public DangerVariant getDangerVariant(int index) {
    00351                 return variants.get(index);
    00352         }
    00353
    00354         /*
    00355          * (non-Javadoc)
    00356          *
    00357          * @see java.lang.Object#toString()
    00358          */
    00359         @Override
    00360         public String toString() {
    00361                 return code + " - " + description;
    00362         }
    00363
    00369         public String getColumn_cast2_a1_1995() {
    00370                 return column_cast2_a1_1995;
    00371         }
    00372
    00379         public void setColumn_cast2_a1_1995(String column_cast2_a1_1995) {
    00380                 this.column_cast2_a1_1995 = column_cast2_a1_1995;
    00381         }
    00382
    00388         public String getColumn_cast1_r1991() {
    00389                 return column_cast1_r1991;
    00390         }
    00391
    00398         public void setColumn_cast1_r1991(String column_cast1_r1991) {
    00399                 this.column_cast1_r1991 = column_cast1_r1991;
    00400         }
    00401
    00407         public String getColumn_cast2_r1991() {
    00408                 return column_cast2_r1991;
    00409         }
    00410
    00417         public void setColumn_cast2_r1991(String column_cast2_r1991) {
    00418                 this.column_cast2_r1991 = column_cast2_r1991;
    00419         }
    00420
    00426         public String getColumn_csn_en_iso_12100_1_2003() {
    00427                 return column_csn_en_iso_12100_1_2003;
    00428         }
    00429
    00436         public void setColumn_csn_en_iso_12100_1_2003(
    00437                         String column_csn_en_iso_12100_1_2003) {
    00438                 this.column_csn_en_iso_12100_1_2003 = column_csn_en_iso_12100_1_2003;
    00439         }
    00440
    00446         public String getColumn_csn_en_iso_12100_2_2003() {
    00447                 return column_csn_en_iso_12100_2_2003;
    00448         }
    00449
    00456         public void setColumn_csn_en_iso_12100_2_2003(
    00457                         String column_csn_en_iso_12100_2_2003) {
    00458                 this.column_csn_en_iso_12100_2_2003 = column_csn_en_iso_12100_2_2003;
    00459         }
    00460
    00466         public String getColumn_normy_typu_b() {
    00467                 return column_normy_typu_b;
    00468         }
    00469
    00476         public void setColumn_normy_typu_b(String column_normy_typu_b) {
    00477                 this.column_normy_typu_b = column_normy_typu_b;
    00478         }
    00479
    00485         public String getColumn_clanky_csn_en_12415_2001() {
    00486                 return column_clanky_csn_en_12415_2001;
    00487         }
    00488
    00495         public void setColumn_clanky_csn_en_12415_2001(
    00496                         String column_clanky_csn_en_12415_2001) {
    00497                 this.column_clanky_csn_en_12415_2001 = column_clanky_csn_en_12415_2001;
    00498         }
    00499
    00500         /*
    00501          * (non-Javadoc)
    00502          *
    00503          * @see java.lang.Object#equals(java.lang.Object)
    00504          */
    00505         @Override
    00506         public boolean equals(Object obj) {
    00507                 if (obj instanceof DangerType) {
    00508                         return ((DangerType) obj).getId() == id;
    00509                 }
    00510                 return false;
    00511         }
    00512
    00518         public String getSituationDescription() {
    00519                 return situationDescription;
    00520         }
    00521
    00528         public void setSituationDescription(String situationDescription) {
    00529                 this.situationDescription = situationDescription;
    00530         }
    00531 }