changeset 8641:c851d1ea543a

SCHEMA CHANGE: Remove unnecessary direct relation of sq_relation with rivers.
author Tom Gottfried <tom@intevation.de>
date Fri, 27 Mar 2015 17:42:27 +0100
parents 0d15ebafbd0e
children 9db1f48bfea9
files backend/doc/schema/postgresql-minfo.sql backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java backend/src/main/java/org/dive4elements/river/importer/ImportSQRelation.java backend/src/main/java/org/dive4elements/river/model/SQRelation.java
diffstat 4 files changed, 12 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/backend/doc/schema/postgresql-minfo.sql	Fri Mar 27 17:27:08 2015 +0100
+++ b/backend/doc/schema/postgresql-minfo.sql	Fri Mar 27 17:42:27 2015 +0100
@@ -348,7 +348,7 @@
         REFERENCES sediment_load_kinds(id),
     CONSTRAINT fk_sl_grain_fraction_id FOREIGN KEY (grain_fraction_id)
         REFERENCES grain_fraction(id),
-    CONSTRAINT fk_sl_time_interval_id FOREIGN KEY (time_interval_id) 
+    CONSTRAINT fk_sl_time_interval_id FOREIGN KEY (time_interval_id)
         REFERENCES time_intervals(id),
     CONSTRAINT fk_sl_sq_time_interval_id FOREIGN KEY (sq_time_interval_id)
         REFERENCES time_intervals(id)
@@ -374,12 +374,9 @@
 
 CREATE TABLE sq_relation (
     id               int NOT NULL,
-    river_id         int NOT NULL,
     time_interval_id int NOT NULL,
     description      VARCHAR(256),
     PRIMARY KEY (id),
-    CONSTRAINT fk_sqr_river_id FOREIGN KEY (river_id)
-        REFERENCES rivers(id) ON DELETE CASCADE,
     CONSTRAINT fk_sqr_tinterval_id FOREIGN KEY (time_interval_id)
         REFERENCES time_intervals(id)
 );
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java	Fri Mar 27 17:27:08 2015 +0100
+++ b/backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java	Fri Mar 27 17:42:27 2015 +0100
@@ -1571,12 +1571,10 @@
         if (!Config.INSTANCE.skipSQRelation()) {
             log.info("store sq relations");
 
-            River river = getPeer();
-
             int count = 0;
 
             for (ImportSQRelation sqRelation: sqRelations) {
-                sqRelation.storeDependencies(river);
+                sqRelation.storeDependencies();
                 count++;
             }
 
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportSQRelation.java	Fri Mar 27 17:27:08 2015 +0100
+++ b/backend/src/main/java/org/dive4elements/river/importer/ImportSQRelation.java	Fri Mar 27 17:42:27 2015 +0100
@@ -18,7 +18,6 @@
 import org.hibernate.Session;
 import org.hibernate.exception.ConstraintViolationException;
 
-import org.dive4elements.river.model.River;
 import org.dive4elements.river.model.SQRelation;
 import org.dive4elements.river.model.TimeInterval;
 
@@ -39,10 +38,10 @@
         this.values = new ArrayList<ImportSQRelationValue>();
     }
 
-    public void storeDependencies(River river) {
+    public void storeDependencies() {
         log.info("store dependencies");
 
-        SQRelation peer = getPeer(river);
+        SQRelation peer = getPeer();
 
         if (peer != null) {
             int count = 0;
@@ -64,7 +63,7 @@
         }
     }
 
-    public SQRelation getPeer(River river) {
+    public SQRelation getPeer() {
         log.debug("getPeer()");
 
         if (peer == null) {
@@ -78,10 +77,12 @@
             Session session = ImporterSession.getInstance()
                 .getDatabaseSession();
 
-            Query query = session
-                .createQuery("FROM SQRelation WHERE river=:river AND timeInterval=:timeInter");
+            Query query = session.createQuery(
+                "from SQRelation where " +
+                "    description = :description and " +
+                "    timeInterval=:timeInter");
 
-            query.setParameter("river", river);
+            query.setParameter("description", description);
             query.setParameter("timeInter", timeInter);
 
             List<SQRelation> sq = query.list();
@@ -89,7 +90,7 @@
             if (sq.isEmpty()) {
                 log.info("create new SQ relation '" + description + "'");
 
-                peer = new SQRelation(river, timeInter, description);
+                peer = new SQRelation(timeInter, description);
                 session.save(peer);
             }
             else {
--- a/backend/src/main/java/org/dive4elements/river/model/SQRelation.java	Fri Mar 27 17:27:08 2015 +0100
+++ b/backend/src/main/java/org/dive4elements/river/model/SQRelation.java	Fri Mar 27 17:42:27 2015 +0100
@@ -30,8 +30,6 @@
 
     private Integer id;
 
-    private River river;
-
     private TimeInterval timeInterval;
 
     private String description;
@@ -43,8 +41,7 @@
     }
 
 
-    public SQRelation(River river, TimeInterval timeInterval, String desc) {
-        this.river        = river;
+    public SQRelation(TimeInterval timeInterval, String desc) {
         this.timeInterval = timeInterval;
         this.description  = desc;
     }
@@ -68,17 +65,6 @@
     }
 
 
-    @OneToOne
-    @JoinColumn(name = "river_id")
-    public River getRiver() {
-        return river;
-    }
-
-    public void setRiver(River river) {
-        this.river = river;
-    }
-
-
     @Column(name = "description")
     public String getDescription() {
         return description;

http://dive4elements.wald.intevation.org