[PATCH] SCHEMA CHANGE: Remove unnecessary direct relation of sq_relation with rivers

Wald Commits scm-commit at wald.intevation.org
Fri Mar 27 17:42:31 CET 2015


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1427474547 -3600
# Node ID c851d1ea543a9154ddf88dc206e128708fbc86a1
# Parent  0d15ebafbd0ec452833b1e9f15afe5091c7f5da6
SCHEMA CHANGE: Remove unnecessary direct relation of sq_relation with rivers.

diff -r 0d15ebafbd0e -r c851d1ea543a backend/doc/schema/postgresql-minfo.sql
--- 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)
 );
diff -r 0d15ebafbd0e -r c851d1ea543a backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java
--- 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++;
             }
 
diff -r 0d15ebafbd0e -r c851d1ea543a backend/src/main/java/org/dive4elements/river/importer/ImportSQRelation.java
--- 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 {
diff -r 0d15ebafbd0e -r c851d1ea543a backend/src/main/java/org/dive4elements/river/model/SQRelation.java
--- 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;


More information about the Dive4Elements-commits mailing list