changeset 467:c8c09e31cdb8

Added new column 'kind' in discharge tables and wst to distinguish between different types. flys-backend/trunk@1703 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 15 Apr 2011 10:31:15 +0000
parents 8bd50b41dea6
children 8d76556c9616
files flys-backend/ChangeLog flys-backend/doc/schema/postgresql.sql flys-backend/src/main/java/de/intevation/flys/importer/ImportDischargeTable.java flys-backend/src/main/java/de/intevation/flys/importer/ImportWst.java flys-backend/src/main/java/de/intevation/flys/model/DischargeTable.java flys-backend/src/main/java/de/intevation/flys/model/Wst.java
diffstat 6 files changed, 73 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Fri Apr 15 09:49:21 2011 +0000
+++ b/flys-backend/ChangeLog	Fri Apr 15 10:31:15 2011 +0000
@@ -1,3 +1,22 @@
+2011-04-15	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* doc/schema/postgresql.sql: Added new column 'kind' in
+	  discharge tables and wst to distinguish between different
+	  kinds like 'Haupt-WST', 'zusaetzliche Laengsschnitte',
+	  'amtliche Daten' and so on.
+
+	  Update existing databases with:
+	    BEGIN;
+	      ALTER TABLE discharge_tables ADD COLUMN kind int NOT NULL DEFAULT 0;
+	      ALTER TABLE wsts             ADD COLUMN kind int NOT NULL DEFAULT 0;
+	    END;
+
+	* src/main/java/de/intevation/flys/model/DischargeTable.java
+	  src/main/java/de/intevation/flys/model/Wst.java,
+	  src/main/java/de/intevation/flys/importer/ImportWst.java,
+	  src/main/java/de/intevation/flys/importer/ImportDischargeTable.java:
+	  Adjusted the models.
+
 2011-04-15  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/backend/SessionHolder.java: Moved to
--- a/flys-backend/doc/schema/postgresql.sql	Fri Apr 15 09:49:21 2011 +0000
+++ b/flys-backend/doc/schema/postgresql.sql	Fri Apr 15 10:31:15 2011 +0000
@@ -114,7 +114,7 @@
 CREATE TABLE discharge_tables (
     id               int PRIMARY KEY NOT NULL,
     gauge_id         int NOT NULL REFERENCES gauges(id),
-
+    kind             int NOT NULL DEFAULT 0
     time_interval_id int REFERENCES time_intervals(id),
 
     -- TODO: better checks
@@ -140,6 +140,7 @@
     id          int PRIMARY KEY NOT NULL,
     river_id    int NOT NULL REFERENCES rivers(id),
     description VARCHAR(256) NOT NULL,
+    kind        int NOT NULL DEFAULT 0
     -- TODO: more meta infos
     UNIQUE (river_id, description)
 );
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportDischargeTable.java	Fri Apr 15 09:49:21 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportDischargeTable.java	Fri Apr 15 10:31:15 2011 +0000
@@ -14,10 +14,13 @@
 {
     protected DischargeTable peer;
 
+    protected Integer kind;
+
     protected List<ImportDischargeTableValue> dischargeTableValues;
 
 
     public ImportDischargeTable() {
+        kind = 0;
         dischargeTableValues = new ArrayList<ImportDischargeTableValue>();
     }
 
@@ -44,10 +47,11 @@
             Query query = session.createQuery(
                 "from DischargeTable where gauge.id=:gauge");
             query.setParameter("gauge", gauge.getId());
+            query.setParameter("kind", kind);
 
             List<DischargeTable> dischargeTables = query.list();
             if (dischargeTables.isEmpty()) {
-                peer = new DischargeTable(gauge);
+                peer = new DischargeTable(gauge, kind);
                 session.save(peer);
             }
             else {
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportWst.java	Fri Apr 15 09:49:21 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportWst.java	Fri Apr 15 10:31:15 2011 +0000
@@ -14,11 +14,14 @@
 {
     protected String description;
 
+    protected Integer kind;
+
     protected Map<String, ImportWstColumn> columns;
 
     protected Wst peer;
 
     public ImportWst() {
+        kind = 0;
         columns = new HashMap<String, ImportWstColumn>();
     }
 
@@ -57,12 +60,13 @@
             Session session = Importer.sessionHolder.get();
             Query query = session.createQuery(
                 "from Wst where " +
-                "river=:river and description=:description");
+                "river=:river and description=:description and kind=:kind");
             query.setParameter("river",       river);
             query.setParameter("description", description);
+            query.setParameter("kind",        kind);
             List<Wst> wsts = query.list();
             if (wsts.isEmpty()) {
-                peer = new Wst(river, description);
+                peer = new Wst(river, description, kind);
                 session.save(peer);
             }
             else {
--- a/flys-backend/src/main/java/de/intevation/flys/model/DischargeTable.java	Fri Apr 15 09:49:21 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/DischargeTable.java	Fri Apr 15 10:31:15 2011 +0000
@@ -22,15 +22,22 @@
 {
     private Integer      id;
     private Gauge        gauge;
+    private Integer      kind;
     private TimeInterval timeInterval;
 
     private List<DischargeTableValue> dischargeTableValues;
 
     public DischargeTable() {
+        kind = 0;
     }
 
     public DischargeTable(Gauge gauge) {
+        this(gauge, 0);
+    }
+
+    public DischargeTable(Gauge gauge, Integer kind) {
         this.gauge = gauge;
+        this.kind  = kind;
     }
 
     @Id
@@ -51,6 +58,25 @@
     }
 
     @OneToOne
+    @JoinColumn(name = "gauge_id" )
+    public Gauge getGauge() {
+        return gauge;
+    }
+
+    public void setGauge(Gauge gauge) {
+        this.gauge = gauge;
+    }
+
+    @Column(name = "kind")
+    public Integer getKind() {
+        return kind;
+    }
+
+    public void setKind(Integer kind) {
+        this.kind = kind;
+    }
+
+    @OneToOne
     @JoinColumn(name = "time_interval_id" )
     public TimeInterval getTimeInterval() {
         return timeInterval;
@@ -60,16 +86,6 @@
         this.timeInterval = timeInterval;
     }
 
-    @OneToOne
-    @JoinColumn(name = "gauge_id" )
-    public Gauge getGauge() {
-        return gauge;
-    }
-
-    public void setGauge(Gauge gauge) {
-        this.gauge = gauge;
-    }
-
     @OneToMany
     @JoinColumn(name = "table_id")
     public List<DischargeTableValue> getDischargeTableValues() {
--- a/flys-backend/src/main/java/de/intevation/flys/model/Wst.java	Fri Apr 15 09:49:21 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/Wst.java	Fri Apr 15 10:31:15 2011 +0000
@@ -20,13 +20,19 @@
     private Integer id;
     private River   river;
     private String  description;
+    private Integer kind;
 
     public Wst() {
     }
 
     public Wst(River river, String description) {
+        this(river, description, 0);
+    }
+
+    public Wst(River river, String description, Integer kind) {
         this.river       = river;
         this.description = description;
+        this.kind        = kind;
     }
 
     @Id
@@ -64,5 +70,14 @@
     public void setDescription(String description) {
         this.description = description;
     }
+
+    @Column(name = "kind")
+    public Integer getKind() {
+        return kind;
+    }
+
+    public void setKind(Integer kind) {
+        this.kind = kind;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org