changeset 2347:0acf28a3d28a

Removed the Unit from Wsts - added a WstUnit column to rivers. flys-backend/trunk@2884 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 04 Oct 2011 15:28:19 +0000
parents f834b411ca57
children 8477965674ce
files flys-backend/ChangeLog flys-backend/doc/schema/postgresql.sql flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java flys-backend/src/main/java/de/intevation/flys/importer/ImportUnit.java flys-backend/src/main/java/de/intevation/flys/importer/ImportWst.java flys-backend/src/main/java/de/intevation/flys/model/River.java flys-backend/src/main/java/de/intevation/flys/model/Wst.java
diffstat 7 files changed, 80 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Tue Oct 04 06:47:00 2011 +0000
+++ b/flys-backend/ChangeLog	Tue Oct 04 15:28:19 2011 +0000
@@ -1,3 +1,25 @@
+2011-10-04  Ingo Weinzierl <ingo@intevation.de>
+
+	* doc/schema/postgresql.sql: Removed unit column from wsts; added a
+	  wst_unit_id column to rivers. We decided to support a single elevation
+	  model for the whole river.
+
+	* src/main/java/de/intevation/flys/model/River.java: Added a WstUnit
+	  column.
+
+	* src/main/java/de/intevation/flys/model/Wst.java: Removed the Unit
+	  column.
+
+	* src/main/java/de/intevation/flys/importer/ImportWst.java: Provide a
+	  getUnit() method that allows querying the elevation unit for this wst.
+
+	* src/main/java/de/intevation/flys/importer/ImportUnit.java: Removed
+	  storeDependencies().
+
+	* src/main/java/de/intevation/flys/importer/ImportRiver.java: Save the
+	  Unit of the wst file or a default one into database before all other
+	  dependencies as well as the river itself is saved to database.
+
 2011-10-04  Ingo Weinzierl <ingo@intevation.de>
 
 	* doc/schema/postgresql.sql: Added a "units" table.
--- a/flys-backend/doc/schema/postgresql.sql	Tue Oct 04 06:47:00 2011 +0000
+++ b/flys-backend/doc/schema/postgresql.sql	Tue Oct 04 15:28:19 2011 +0000
@@ -1,12 +1,20 @@
 BEGIN;
 
+CREATE SEQUENCE UNITS_ID_SEQ;
+
+CREATE TABLE units (
+    id   int PRIMARY KEY NOT NULL,
+    name VARCHAR(32)     NOT NULL UNIQUE
+);
+
 -- Gewaesser
 CREATE SEQUENCE RIVERS_ID_SEQ;
 
 CREATE TABLE rivers (
-    id    int PRIMARY KEY NOT NULL,
-    name  VARCHAR(256)    NOT NULL UNIQUE,
-    km_up BOOLEAN         NOT NULL DEFAULT true
+    id          int PRIMARY KEY NOT NULL,
+    name        VARCHAR(256)    NOT NULL UNIQUE,
+    km_up       BOOLEAN         NOT NULL DEFAULT true,
+    wst_unit_id int             NOT NULL REFERENCES units(id)
 );
 
 -- Bruecke, Haefen, etc.
@@ -17,13 +25,6 @@
     value VARCHAR(256)    NOT NULL UNIQUE
 );
 
-CREATE SEQUENCE UNITS_ID_SEQ;
-
-CREATE TABLE units (
-    id   int PRIMARY KEY NOT NULL,
-    name VARCHAR(32)     NOT NULL UNIQUE
-);
-
 -- segments from/to at a river
 CREATE SEQUENCE RANGES_ID_SEQ;
 
@@ -169,7 +170,6 @@
     river_id    int NOT NULL REFERENCES rivers(id),
     description VARCHAR(256) NOT NULL,
     kind        int NOT NULL DEFAULT 0,
-    unit_id     int NOT NULL REFERENCES units(id),
     -- TODO: more meta infos
     UNIQUE (river_id, description)
 );
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java	Tue Oct 04 06:47:00 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java	Tue Oct 04 15:28:19 2011 +0000
@@ -19,6 +19,7 @@
 import de.intevation.artifacts.common.utils.FileTools.HashedFile;
 
 import de.intevation.flys.model.River;
+import de.intevation.flys.model.Unit;
 
 import de.intevation.flys.importer.parsers.PRFParser;
 import de.intevation.flys.importer.parsers.HYKParser;
@@ -79,6 +80,8 @@
 
     protected ImportWst wst;
 
+    protected ImportUnit wstUnit;
+
     protected AnnotationClassifier annotationClassifier;
 
     protected River peer;
@@ -506,6 +509,7 @@
     }
 
     public void storeDependencies() {
+        storeWstUnit();
         storeAnnotations();
         storeHYKs();
         storeCrossSections();
@@ -518,6 +522,15 @@
         storeFloodProtection();
     }
 
+    public void storeWstUnit() {
+        if (wst == null) {
+            wstUnit = new ImportUnit("NN + m");
+        }
+        else {
+            wstUnit = wst.getUnit();
+        }
+    }
+
     public void storeHYKs() {
         if (!Config.INSTANCE.skipHYKs()) {
             log.info("store HYKs");
@@ -628,10 +641,14 @@
         if (peer == null) {
             Session session = ImporterSession.getInstance().getDatabaseSession();
             Query query = session.createQuery("from River where name=:name");
+
+            Unit u = wstUnit.getPeer();
+
             query.setString("name", name);
             List<River> rivers = query.list();
             if (rivers.isEmpty()) {
-                peer = new River(name);
+                log.info("Store new river '" + name + "'");
+                peer = new River(name, u);
                 session.save(peer);
             }
             else {
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportUnit.java	Tue Oct 04 06:47:00 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportUnit.java	Tue Oct 04 15:28:19 2011 +0000
@@ -30,12 +30,7 @@
     }
 
 
-    public void storeDependencies(River river) {
-        log.info("store '" + name + "'");
-        getPeer(river);
-    }
-
-    public Unit getPeer(River river) {
+    public Unit getPeer() {
         if (peer == null) {
             Session session = ImporterSession.getInstance().getDatabaseSession();
             Query query = session.createQuery("from Unit where name=:name");
@@ -43,13 +38,14 @@
 
             List<Unit> units = query.list();
             if (units.isEmpty()) {
+                log.info("Store new unit '" + name + "'");
+
                 peer = new Unit(name);
                 session.save(peer);
             }
             else {
                 peer = units.get(0);
             }
-
         }
         return peer;
     }
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportWst.java	Tue Oct 04 06:47:00 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportWst.java	Tue Oct 04 15:28:19 2011 +0000
@@ -67,6 +67,10 @@
         return columns.get(index);
     }
 
+    public ImportUnit getUnit() {
+        return unit;
+    }
+
     public void setUnit(ImportUnit unit) {
         this.unit = unit;
     }
@@ -80,15 +84,12 @@
             column.storeDependencies(river);
         }
 
-        unit.storeDependencies(river);
-
         Session session = ImporterSession.getInstance().getDatabaseSession();
         session.flush();
     }
 
     public Wst getPeer(River river) {
         if (peer == null) {
-            Unit u = unit.getPeer(river);
             Session session = ImporterSession.getInstance().getDatabaseSession();
             Query query = session.createQuery(
                 "from Wst where " +
@@ -98,7 +99,7 @@
             query.setParameter("kind",        kind);
             List<Wst> wsts = query.list();
             if (wsts.isEmpty()) {
-                peer = new Wst(river, description, kind, u);
+                peer = new Wst(river, description, kind);
                 session.save(peer);
             }
             else {
--- a/flys-backend/src/main/java/de/intevation/flys/model/River.java	Tue Oct 04 06:47:00 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/River.java	Tue Oct 04 15:28:19 2011 +0000
@@ -12,6 +12,7 @@
 import javax.persistence.Column;
 import javax.persistence.SequenceGenerator;
 import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
 import javax.persistence.JoinColumn;
 import javax.persistence.GenerationType;
 
@@ -38,6 +39,8 @@
 
     private List<Gauge> gauges;
 
+    private Unit wstUnit;
+
     @Id
     @SequenceGenerator(
         name           = "SEQUENCE_RIVERS_ID_SEQ",
@@ -76,8 +79,9 @@
     public River() {
     }
 
-    public River(String name) {
-        this.name = name;
+    public River(String name, Unit wstUnit) {
+        this.name    = name;
+        this.wstUnit = wstUnit;
     }
 
     @OneToMany
@@ -90,6 +94,19 @@
         this.gauges = gauges;
     }
 
+
+    @OneToOne
+    @JoinColumn(name = "wst_unit_id" )
+    public Unit getWstUnit() {
+        return wstUnit;
+    }
+
+    public void setWstUnit(Unit wstUnit) {
+        this.wstUnit = wstUnit;
+    }
+
+
+
     public String toString() {
         return name != null ? name : "";
     }
--- a/flys-backend/src/main/java/de/intevation/flys/model/Wst.java	Tue Oct 04 06:47:00 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/Wst.java	Tue Oct 04 15:28:19 2011 +0000
@@ -34,7 +34,6 @@
     private River   river;
     private String  description;
     private Integer kind;
-    private Unit    unit;
 
     private List<WstColumn> columns;
 
@@ -42,14 +41,13 @@
     }
 
     public Wst(River river, String description) {
-        this(river, description, 0, null);
+        this(river, description, 0);
     }
 
-    public Wst(River river, String description, Integer kind, Unit unit) {
+    public Wst(River river, String description, Integer kind) {
         this.river       = river;
         this.description = description;
         this.kind        = kind;
-        this.unit        = unit;
     }
 
     @Id
@@ -108,16 +106,6 @@
     }
 
 
-    @OneToOne
-    @JoinColumn(name = "unit_id" )
-    public Unit getUnit() {
-        return unit;
-    }
-
-    public void setUnit(Unit unit) {
-        this.unit = unit;
-    }
-
     /**
      * Determines the min and max Q values of this WST. The min value is placed
      * in the first field of the resulting array - the max value is placed in

http://dive4elements.wald.intevation.org