changeset 1203:3c01bef43a98

Querprofile: Added a table to map the points to a given km. flys-backend/trunk@2308 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 07 Jul 2011 15:59:24 +0000
parents 44581b40b968
children 22858e7cca79
files flys-backend/ChangeLog flys-backend/doc/schema/postgresql.sql flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java flys-backend/src/main/java/de/intevation/flys/model/CrossSection.java flys-backend/src/main/java/de/intevation/flys/model/CrossSectionLine.java flys-backend/src/main/java/de/intevation/flys/model/CrossSectionPoint.java
diffstat 6 files changed, 166 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Thu Jul 07 15:20:19 2011 +0000
+++ b/flys-backend/ChangeLog	Thu Jul 07 15:59:24 2011 +0000
@@ -1,7 +1,55 @@
+2011-07-07	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* doc/schema/postgresql.sql: Introduced a new table cross_section_line
+	  holding the km of a set of points.
+
+	* src/main/java/de/intevation/flys/model/CrossSectionLine.java:
+	  New. Model for a single line of a "Querprofil".
+
+	* src/main/java/de/intevation/flys/model/CrossSection.java: Removed
+	  'km' and 'points' they are part of the line now.
+
+	* src/main/java/de/intevation/flys/model/CrossSectionPoint.java:
+	  They reference to the containing line now.
+
+	* src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java:
+	  Registered new model.
+
+	  To update existing databases:
+	  BEGIN;
+	      DROP SEQUENCE CROSS_SECTIONS_ID_SEQ;
+	      DROP SEQUENCE CROSS_SECTION_POINTS_ID_SEQ;
+	      DROP TABLE cross_section_points;
+	      DROP TABLE cross_sections;
+	      CREATE SEQUENCE CROSS_SECTIONS_ID_SEQ;
+	      CREATE TABLE cross_sections (
+	          id               int PRIMARY KEY NOT NULL,
+	          river_id         int             NOT NULL REFERENCES rivers(id),
+	          time_interval_id int                      REFERENCES time_intervals(id),
+	          description      VARCHAR(256)
+	      );
+	      CREATE SEQUENCE CROSS_SECTION_LINES_SEQ;
+	      CREATE TABLE cross_section_lines (
+	          id               int PRIMARY KEY NOT NULL,
+	          km               NUMERIC         NOT NULL,
+	          cross_section_id int             NOT NULL REFERENCES cross_sections(id),
+	          UNIQUE (km, cross_section_id)
+	      );
+	      CREATE SEQUENCE CROSS_SECTION_POINTS_ID_SEQ;
+	      CREATE TABLE cross_section_points (
+	          id                    int PRIMARY KEY NOT NULL,
+	          cross_section_line_id int             NOT NULL REFERENCES cross_section_lines(id),
+	          col_pos               int             NOT NULL,
+	          x                     NUMERIC         NOT NULL,
+	          y                     NUMERIC         NOT NULL,
+	          UNIQUE (cross_section_line_id, col_pos)
+	      );
+	  COMMIT;
+
 2011-07-07	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* doc/schema/postgresql.sql: Dropped constraint that enforces the
-	  uniquness of km and river. This is violated because there are
+	  uniqueness of km and river. This is violated because there are
 	  more than one sounding in different year at the same km of a river.
 	  Added column 'description' to the cross section table to make it
 	  human readable.
@@ -17,7 +65,7 @@
 2011-07-07	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* doc/schema/postgresql.sql: Dropped constraint that enforces the
-	  uniquness of x in a "Querprofil-Spur". There are vertical lines
+	  uniqueness of x in a "Querprofil-Spur". There are vertical lines
 	  in the soundings so this constraint is violated.
 
 	  To update existing databases:
--- a/flys-backend/doc/schema/postgresql.sql	Thu Jul 07 15:20:19 2011 +0000
+++ b/flys-backend/doc/schema/postgresql.sql	Thu Jul 07 15:59:24 2011 +0000
@@ -266,21 +266,29 @@
 
 CREATE TABLE cross_sections (
     id               int PRIMARY KEY NOT NULL,
-    km               NUMERIC         NOT NULL,
     river_id         int             NOT NULL REFERENCES rivers(id),
-    time_interval_id int             REFERENCES time_intervals(id),
+    time_interval_id int                      REFERENCES time_intervals(id),
     description      VARCHAR(256)
 );
 
+CREATE SEQUENCE CROSS_SECTION_LINES_SEQ;
+
+CREATE TABLE cross_section_lines (
+    id               int PRIMARY KEY NOT NULL,
+    km               NUMERIC         NOT NULL,
+    cross_section_id int             NOT NULL REFERENCES cross_sections(id),
+    UNIQUE (km, cross_section_id)
+);
+
 CREATE SEQUENCE CROSS_SECTION_POINTS_ID_SEQ;
 
 CREATE TABLE cross_section_points (
-    id               int PRIMARY KEY NOT NULL,
-    cross_section_id int NOT NULL REFERENCES cross_sections(id),
-    col_pos          int NOT NULL,
-    x                NUMERIC NOT NULL,
-    y                NUMERIC NOT NULL
-    UNIQUE (cross_section_id, col_pos)
+    id                    int PRIMARY KEY NOT NULL,
+    cross_section_line_id int             NOT NULL REFERENCES cross_section_lines(id),
+    col_pos               int             NOT NULL,
+    x                     NUMERIC         NOT NULL,
+    y                     NUMERIC         NOT NULL,
+    UNIQUE (cross_section_line_id, col_pos)
 );
 
 COMMIT;
--- a/flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java	Thu Jul 07 15:20:19 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java	Thu Jul 07 15:59:24 2011 +0000
@@ -13,6 +13,7 @@
 import de.intevation.flys.model.AnnotationType;
 import de.intevation.flys.model.Attribute;
 import de.intevation.flys.model.CrossSection;
+import de.intevation.flys.model.CrossSectionLine;
 import de.intevation.flys.model.CrossSectionPoint;
 import de.intevation.flys.model.DischargeTable;
 import de.intevation.flys.model.DischargeTableValue;
@@ -120,6 +121,7 @@
         cfg.addAnnotatedClass(AnnotationType.class);
         cfg.addAnnotatedClass(Attribute.class);
         cfg.addAnnotatedClass(CrossSection.class);
+        cfg.addAnnotatedClass(CrossSectionLine.class);
         cfg.addAnnotatedClass(CrossSectionPoint.class);
         cfg.addAnnotatedClass(DischargeTable.class);
         cfg.addAnnotatedClass(DischargeTableValue.class);
--- a/flys-backend/src/main/java/de/intevation/flys/model/CrossSection.java	Thu Jul 07 15:20:19 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/CrossSection.java	Thu Jul 07 15:59:24 2011 +0000
@@ -2,8 +2,6 @@
 
 import java.io.Serializable;
 
-import java.math.BigDecimal;
-
 import java.util.List;
 
 import javax.persistence.Entity;
@@ -22,12 +20,11 @@
 public class CrossSection
 implements   Serializable
 {
-    private Integer                 id;
-    private BigDecimal              km;
-    private River                   river;
-    private TimeInterval            timeInterval;
-    private String                  description;
-    private List<CrossSectionPoint> points;
+    private Integer                id;
+    private River                  river;
+    private TimeInterval           timeInterval;
+    private String                 description;
+    private List<CrossSectionLine> lines;
 
     public CrossSection() {
     }
@@ -49,15 +46,6 @@
         this.id = id;
     }
 
-    @Column(name = "x")
-    public BigDecimal getKm() {
-        return km;
-    }
-
-    public void setKm(BigDecimal km) {
-        this.km = km;
-    }
-
     @OneToOne
     @JoinColumn(name = "river_id")
     public River getRiver() {
@@ -89,12 +77,12 @@
 
     @OneToMany
     @JoinColumn(name="cross_section_id")
-    public List<CrossSectionPoint> getPoints() {
-        return points;
+    public List<CrossSectionLine> getLines() {
+        return lines;
     }
 
-    public void setPoints(List<CrossSectionPoint> points) {
-        this.points = points;
+    public void setLines(List<CrossSectionLine> lines) {
+        this.lines = lines;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/CrossSectionLine.java	Thu Jul 07 15:59:24 2011 +0000
@@ -0,0 +1,79 @@
+package de.intevation.flys.model;
+
+import java.io.Serializable;
+
+import java.math.BigDecimal;
+
+import java.util.List;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Column;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.GenerationType;
+import javax.persistence.OneToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.JoinColumn;
+
+@Entity
+@Table(name = "cross_section_lines")
+public class CrossSectionLine
+implements   Serializable
+{
+    private Integer                 id;
+    private BigDecimal              km;
+    private List<CrossSectionPoint> points;
+    private CrossSection            crossSection;
+
+    public CrossSectionLine() {
+    }
+
+    @Id
+    @SequenceGenerator(
+        name           = "SEQUENCE_CROSS_SECTION_LINES_ID_SEQ",
+        sequenceName   = "CROSS_SECTION_LINES_ID_SEQ",
+        allocationSize = 1)
+    @GeneratedValue(
+        strategy  = GenerationType.SEQUENCE,
+        generator = "SEQUENCE_CROSS_SECTION_LINES_ID_SEQ")
+    @Column(name = "id")
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    @Column(name = "km")
+    public BigDecimal getKm() {
+        return km;
+    }
+
+    public void setKm(BigDecimal km) {
+        this.km = km;
+    }
+
+    @OneToOne
+    @JoinColumn(name = "cross_section_id")
+    public CrossSection getCrossSection() {
+        return crossSection;
+    }
+
+    public void setCrossSection(CrossSection CrossSection) {
+        this.crossSection = crossSection;
+    }
+
+    @OneToMany
+    @JoinColumn(name="cross_section_line_id")
+    public List<CrossSectionPoint> getPoints() {
+        return points;
+    }
+
+    public void setPoints(List<CrossSectionPoint> points) {
+        this.points = points;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-backend/src/main/java/de/intevation/flys/model/CrossSectionPoint.java	Thu Jul 07 15:20:19 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/CrossSectionPoint.java	Thu Jul 07 15:59:24 2011 +0000
@@ -19,11 +19,11 @@
 public class CrossSectionPoint
 implements   Serializable
 {
-    private Integer      id;
-    private CrossSection crossSection;
-    private Integer      colPos;
-    private BigDecimal   x;
-    private BigDecimal   y;
+    private Integer          id;
+    private CrossSectionLine crossSectionLine;
+    private Integer          colPos;
+    private BigDecimal       x;
+    private BigDecimal       y;
 
     public CrossSectionPoint() {
     }
@@ -46,13 +46,13 @@
     }
 
     @OneToOne
-    @JoinColumn(name = "cross_section_id")
-    public CrossSection getCrossSection() {
-        return crossSection;
+    @JoinColumn(name = "cross_section_line_id")
+    public CrossSectionLine getCrossSectionLine() {
+        return crossSectionLine;
     }
 
-    public void setCrossSection(CrossSection crossSection) {
-        this.crossSection = crossSection;
+    public void setCrossSectionLine(CrossSectionLine crossSectionLine) {
+        this.crossSectionLine = crossSectionLine;
     }
 
     @Column(name = "col_pos")

http://dive4elements.wald.intevation.org