[PATCH 2 of 3] (issue 1796) Scheme change! Add model for seddb_name lookup table

Wald Commits scm-commit at wald.intevation.org
Mon Apr 13 11:27:36 CEST 2015


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1428917072 -7200
# Node ID cfafe5764509f0c1757e20df98f81b4dc6df6115
# Parent  5102733c4567d24126be49225476682ddbee4df3
(issue 1796) Scheme change! Add model for seddb_name lookup table.

diff -r 5102733c4567 -r cfafe5764509 backend/doc/schema/oracle-drop.sql
--- a/backend/doc/schema/oracle-drop.sql	Mon Apr 13 11:03:00 2015 +0200
+++ b/backend/doc/schema/oracle-drop.sql	Mon Apr 13 11:24:32 2015 +0200
@@ -24,6 +24,7 @@
 ALTER TABLE official_lines DROP CONSTRAINT cOffLinesWstColumns;
 ALTER TABLE ranges DROP CONSTRAINT cRangesRivers;
 ALTER TABLE rivers DROP CONSTRAINT cRiversUnits;
+ALTER TABLE rivers DROP CONSTRAINT cRiversSeddbNames;
 ALTER TABLE wst_column_q_ranges DROP CONSTRAINT cWstColumnQRangesWstColums;
 ALTER TABLE wst_column_q_ranges DROP CONSTRAINT cWstColumnQRangesWstQRanges;
 ALTER TABLE wst_column_values DROP CONSTRAINT cWstColumnValuesWstColumns;
@@ -62,6 +63,7 @@
 DROP TABLE official_lines PURGE;
 DROP TABLE wsts PURGE;
 DROP TABLE wst_kinds PURGE;
+DROP TABLE seddb_names PURGE;
 DROP SEQUENCE ANNOTATION_TYPES_ID_SEQ;
 DROP SEQUENCE ANNOTATIONS_ID_SEQ;
 DROP SEQUENCE ATTRIBUTES_ID_SEQ;
diff -r 5102733c4567 -r cfafe5764509 backend/doc/schema/oracle.sql
--- a/backend/doc/schema/oracle.sql	Mon Apr 13 11:03:00 2015 +0200
+++ b/backend/doc/schema/oracle.sql	Mon Apr 13 11:24:32 2015 +0200
@@ -255,6 +255,14 @@
     CHECK (a < b)
 );
 
+-- SEDDB_NAME
+-- Lookup table for seddb river names
+CREATE TABLE seddb_name (
+    id                  NUMBER(38,0) NOT NULL,
+    name                VARCHAR2(255) NOT NULL,
+    PRIMARY KEY         (id)
+);
+INSERT INTO seddb_name (id, name) VALUES (0, 'Rhein');
 
 
 -- RIVERS
@@ -267,6 +275,7 @@
     km_up               int DEFAULT 0 NOT NULL,
     name                VARCHAR2(255) NOT NULL UNIQUE,
     wst_unit_id         NUMBER(38,0) NOT NULL,
+    seddb_name_id       NUMBER(38,0),
     PRIMARY KEY         (id),
     CHECK(km_up IN(0,1))
 );
@@ -398,6 +407,7 @@
 ALTER TABLE main_values ADD CONSTRAINT cMainValuesTimeIntervals FOREIGN KEY (time_interval_id) REFERENCES time_intervals;
 ALTER TABLE named_main_values ADD CONSTRAINT cNamedMainValuesMainValueTypes FOREIGN KEY (type_id) REFERENCES main_value_types;
 ALTER TABLE rivers ADD CONSTRAINT cRiversUnits FOREIGN KEY (wst_unit_id) REFERENCES units;
+ALTER TABLE rivers ADD CONSTRAINT cRiversSeddbNames FOREIGN KEY (seddb_name_id) REFERENCES seddb_name;
 ALTER TABLE wst_columns ADD CONSTRAINT cWstColumnsTime_intervals FOREIGN KEY (time_interval_id) REFERENCES time_intervals;
 
 -- Cascading references
diff -r 5102733c4567 -r cfafe5764509 backend/doc/schema/postgresql.sql
--- a/backend/doc/schema/postgresql.sql	Mon Apr 13 11:03:00 2015 +0200
+++ b/backend/doc/schema/postgresql.sql	Mon Apr 13 11:24:32 2015 +0200
@@ -7,6 +7,15 @@
     name VARCHAR(32)     NOT NULL UNIQUE
 );
 
+-- SEDDB_NAME
+-- Lookup table for seddb river names
+
+CREATE TABLE seddb_name (
+    id       int PRIMARY KEY NOT NULL,
+    name     VARCHAR(256) NOT NULL
+);
+INSERT INTO seddb_name (id, name) VALUES (0, 'Rhein');
+
 -- Gewaesser
 CREATE SEQUENCE RIVERS_ID_SEQ;
 
@@ -17,6 +26,7 @@
     name            VARCHAR(256)    NOT NULL UNIQUE,
     km_up           int DEFAULT 0   NOT NULL,
     wst_unit_id int                 NOT NULL REFERENCES units(id),
+    seddb_name_id   int REFERENCES seddb_name(id),
     CHECK(km_up IN(0,1))
 );
 
diff -r 5102733c4567 -r cfafe5764509 backend/src/main/java/org/dive4elements/river/backend/FLYSCredentials.java
--- a/backend/src/main/java/org/dive4elements/river/backend/FLYSCredentials.java	Mon Apr 13 11:03:00 2015 +0200
+++ b/backend/src/main/java/org/dive4elements/river/backend/FLYSCredentials.java	Mon Apr 13 11:24:32 2015 +0200
@@ -72,6 +72,7 @@
 import org.dive4elements.river.model.SQRelationValue;
 import org.dive4elements.river.model.SectieKind;
 import org.dive4elements.river.model.SobekKind;
+import org.dive4elements.river.model.SeddbName;
 import org.dive4elements.river.model.SedimentDensity;
 import org.dive4elements.river.model.SedimentDensityValue;
 import org.dive4elements.river.model.SedimentLoad;
@@ -207,6 +208,7 @@
         PorosityValue.class,
         SectieKind.class,
         SobekKind.class,
+        SeddbName.class,
         SedimentDensity.class,
         SedimentDensityValue.class,
         SedimentLoad.class,
diff -r 5102733c4567 -r cfafe5764509 backend/src/main/java/org/dive4elements/river/model/River.java
--- a/backend/src/main/java/org/dive4elements/river/model/River.java	Mon Apr 13 11:03:00 2015 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/River.java	Mon Apr 13 11:24:32 2015 +0200
@@ -66,6 +66,8 @@
 
     private Unit wstUnit;
 
+    private SeddbName seddbName;
+
     @Id
     @SequenceGenerator(
         name           = "SEQUENCE_RIVERS_ID_SEQ",
@@ -149,6 +151,32 @@
     }
 
 
+    /**
+     * Get alternative seddb name.
+     *
+     * This is the name should be used in seddb queries
+     * and might differ from "our" backend db name.
+     *
+     * @return The name River in the seddb.
+     */
+    public String nameForSeddb() {
+        SeddbName alt = getSeddbName();
+        if (alt == null) {
+            return getName();
+        }
+        return alt.getName();
+    }
+
+
+    @OneToOne
+    @JoinColumn(name = "seddb_name_id" )
+    public SeddbName getSeddbName() {
+        return seddbName;
+    }
+
+    public void setSeddbName(SeddbName name) {
+        this.seddbName = name;
+    }
 
     @Override
     public String toString() {
diff -r 5102733c4567 -r cfafe5764509 backend/src/main/java/org/dive4elements/river/model/SeddbName.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backend/src/main/java/org/dive4elements/river/model/SeddbName.java	Mon Apr 13 11:24:32 2015 +0200
@@ -0,0 +1,42 @@
+/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.model;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+ at Entity
+ at Table(name = "seddb_name")
+public class SeddbName implements Serializable {
+    private Integer id;
+    private String name;
+
+    @Id
+    @Column(name = "id")
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    @Column(name = "name")
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}


More information about the Dive4Elements-commits mailing list