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

# src/cz/neubauer/tomas/hazardanalysis/model/stages/StageManager.java

Zobrazit dokumentaci tohoto souboru.

    00001
    00004 package cz.neubauer.tomas.hazardanalysis.model.stages;
    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
    00017 public class StageManager {
    00018
    00022         private ArrayList<Stage> stages;
    00023
    00027         public StageManager() {
    00028                 stages = new ArrayList<Stage>(5);
    00029         }
    00030
    00038         public void loadFromDB(Connection connection) {
    00039                 if (connection != null) {
    00040                         Statement stmt;
    00041                         Statement stmt2;
    00042                         try {
    00043                                 stmt = connection.createStatement();
    00044                                 stmt2 = connection.createStatement();
    00045                                 stmt
    00046                                                 .executeQuery("SELECT id, description FROM stage ORDER BY id");
    00047
    00048                                 ResultSet rs = stmt.getResultSet();
    00049
    00050                                 Stage currentStage;
    00051                                 while (rs.next()) {
    00052                                         currentStage = new Stage(rs.getInt("id"), rs
    00053                                                         .getString("description"));
    00054                                         stmt2
    00055                                                         .executeQuery("SELECT pn.name as name FROM phase p JOIN phase_name pn on (p.phase_name_id = pn.id) WHERE p.stage_id = '"
    00056                                                                         + currentStage.getId()
    00057                                                                         + "' ORDER BY pn.id;");
    00058                                         ResultSet rs2 = stmt2.getResultSet();
    00059                                         Phase currentPhase;
    00060                                         while (rs2.next()) {
    00061                                                 currentPhase = new Phase(currentStage, rs2
    00062                                                                 .getString("name"));
    00063                                                 currentStage.addPhase(currentPhase);
    00064                                         }
    00065                                         stages.add(currentStage);
    00066                                 }
    00067
    00068                                 stmt.close();
    00069                         } catch (SQLException e) {
    00070                                 e.printStackTrace();
    00071                         }
    00072                 }
    00073         }
    00074
    00081         public void addStage(Stage stage) {
    00082                 stages.add(stage);
    00083         }
    00084
    00092         public Stage getStage(int index) {
    00093                 return stages.get(index);
    00094         }
    00095
    00102         public void clear() {
    00103                 stages.clear();
    00104         }
    00105
    00111         public ArrayList<Stage> getStages() {
    00112                 return stages;
    00113         }
    00114
    00121         public void setStages(ArrayList<Stage> stages) {
    00122                 this.stages = stages;
    00123         }
    00124
    00125 }