changeset 2365:60532f75396b

Adapted 'lines' relation and made lines queryable for a given river. flys-backend/trunk@3219 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 10 Nov 2011 13:35:31 +0000
parents efe19e669092
children 2246348ff90e
files flys-backend/ChangeLog flys-backend/doc/schema/oracle-spatial.sql flys-backend/doc/schema/oracle-spatial_idx.sql flys-backend/doc/schema/postgresql-spatial.sql flys-backend/src/main/java/de/intevation/flys/model/Line.java
diffstat 5 files changed, 35 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Wed Nov 09 16:25:20 2011 +0000
+++ b/flys-backend/ChangeLog	Thu Nov 10 13:35:31 2011 +0000
@@ -1,3 +1,15 @@
+2011-11-10  Ingo Weinzierl <ingo@intevation.de>
+
+	* doc/schema/oracle-spatial.sql,
+	  doc/schema/postgresql-spatial.sql: Adapted the "kind" field of "lines"
+	  relation (Int -> Varchar).
+
+	* doc/schema/oracle-spatial_idx.sql: Added missing spatial index for
+	  "lines" relation.
+
+	* src/main/java/de/intevation/flys/model/Line.java: Added a function that
+	  returns all lines of a given river.
+
 2011-11-09  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/model/Catchment.java: New. A model for
--- a/flys-backend/doc/schema/oracle-spatial.sql	Wed Nov 09 16:25:20 2011 +0000
+++ b/flys-backend/doc/schema/oracle-spatial.sql	Thu Nov 10 13:35:31 2011 +0000
@@ -60,7 +60,7 @@
     OGR_FID NUMBER(38),
     GEOM MDSYS.SDO_GEOMETRY,
     river_id NUMBER(38),
-    kind     NUMBER(38) DEFAULT 0 NOT NULL,
+    kind     VARCHAR2(16) NOT NULL,
     z        NUMBER(38,12) DEFAULT 0,
     ID NUMBER PRIMARY KEY NOT NULL
 );
--- a/flys-backend/doc/schema/oracle-spatial_idx.sql	Wed Nov 09 16:25:20 2011 +0000
+++ b/flys-backend/doc/schema/oracle-spatial_idx.sql	Thu Nov 10 13:35:31 2011 +0000
@@ -6,3 +6,4 @@
 CREATE INDEX CrossSectionTracks_spatial_idx ON cross_section_tracks(GEOM) indextype IS MDSYS.SPATIAL_INDEX parameters ('LAYER_GTYPE=LINE');
 CREATE INDEX hws_spatial_idx ON hws(GEOM) indextype IS MDSYS.SPATIAL_INDEX parameters ('LAYER_GTYPE=LINE');
 CREATE INDEX floodplain_spatial_idx ON floodplain(GEOM) indextype IS MDSYS.SPATIAL_INDEX parameters ('LAYER_GTYPE=POLYGON');
+CREATE INDEX lines_idx ON lines(GEOM) indextype IS MDSYS.SPATIAL_INDEX parameters ('LAYER_GTYPE=LINE');
--- a/flys-backend/doc/schema/postgresql-spatial.sql	Wed Nov 09 16:25:20 2011 +0000
+++ b/flys-backend/doc/schema/postgresql-spatial.sql	Thu Nov 10 13:35:31 2011 +0000
@@ -40,7 +40,7 @@
 CREATE TABLE lines (
     id       int PRIMARY KEY NOT NULL,
     river_id int REFERENCES rivers(id),
-    kind     int             NOT NULL DEFAULT 0,
+    kind     VARCHAR(16) NOT NULL,
     z        NUMERIC DEFAULT 0
 );
 SELECT AddGeometryColumn('lines', 'geom', 31466, 'LINESTRING', 4);
--- a/flys-backend/src/main/java/de/intevation/flys/model/Line.java	Wed Nov 09 16:25:20 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/Line.java	Thu Nov 10 13:35:31 2011 +0000
@@ -2,6 +2,7 @@
 
 import java.io.Serializable;
 import java.math.BigDecimal;
+import java.util.List;
 
 import javax.persistence.Column;
 import javax.persistence.Entity;
@@ -10,10 +11,15 @@
 import javax.persistence.OneToOne;
 import javax.persistence.Table;
 
+import org.hibernate.Session;
+import org.hibernate.Query;
+
 import org.hibernate.annotations.Type;
 
 import com.vividsolutions.jts.geom.LineString;
 
+import de.intevation.flys.backend.SessionHolder;
+
 
 @Entity
 @Table(name = "lines")
@@ -21,7 +27,7 @@
 implements   Serializable
 {
     private Integer    id;
-    private Integer    kind;
+    private String     kind;
     private River      river;
     private LineString geom;
     private BigDecimal z;
@@ -55,12 +61,12 @@
 
 
     @Column(name = "kind")
-    public Integer getKind() {
+    public String getKind() {
         return kind;
     }
 
 
-    public void setKind(Integer kind) {
+    public void setKind(String kind) {
         this.kind = kind;
     }
 
@@ -86,5 +92,16 @@
     public void setZ(BigDecimal z) {
         this.z = z;
     }
+
+
+    public static List<Line> getLines(int riverId) {
+        Session session = SessionHolder.HOLDER.get();
+
+        Query query = session.createQuery(
+            "from Line where river.id =:river_id");
+        query.setParameter("river_id", riverId);
+
+        return query.list();
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org