changeset 2819:0c2567626754

Tiny schema modification specific to MINFO morphological width values; added importer classes. flys-backend/trunk@4236 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 13 Apr 2012 12:53:29 +0000
parents 25ed1f18fcc4
children 7dffd28271d0
files flys-backend/ChangeLog flys-backend/doc/schema/oracle-minfo.sql flys-backend/src/main/java/de/intevation/flys/importer/ImportMorphWidth.java flys-backend/src/main/java/de/intevation/flys/importer/ImportMorphWidthValue.java flys-backend/src/main/java/de/intevation/flys/model/MorphologicalWidthValue.java
diffstat 5 files changed, 196 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Fri Apr 13 12:33:26 2012 +0000
+++ b/flys-backend/ChangeLog	Fri Apr 13 12:53:29 2012 +0000
@@ -1,3 +1,15 @@
+2012-04-13  Ingo Weinzierl <ingo@intevation.de>
+
+	* doc/schema/oracle-minfo.sql: Added a description field to morphological
+	  width values.
+
+	* src/main/java/de/intevation/flys/model/MorphologicalWidthValue.java:
+	  Added new instance variable for descriptions.
+
+	* src/main/java/de/intevation/flys/importer/ImportMorphWidthValue.java,
+	  src/main/java/de/intevation/flys/importer/ImportMorphWidth.java: New
+	  temp classes used to store morphological width values during the import.
+
 2012-04-13  Ingo Weinzierl <ingo@intevation.de>
 
 	* doc/schema/oracle-minfo.sql,
--- a/flys-backend/doc/schema/oracle-minfo.sql	Fri Apr 13 12:33:26 2012 +0000
+++ b/flys-backend/doc/schema/oracle-minfo.sql	Fri Apr 13 12:53:29 2012 +0000
@@ -163,6 +163,7 @@
     morphologic_width_id    NUMBER(38,0) NOT NULL,
     station                 NUMBER(38,3) NOT NULL,
     width                   NUMBER(38,3) NOT NULL,
+    description             VARCHAR(256),
     PRIMARY KEY(id),
     CONSTRAINT fk_mwv_morphologic_width_id FOREIGN KEY (morphologic_width_id) REFERENCES morphologic_width(id)
 );
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportMorphWidth.java	Fri Apr 13 12:53:29 2012 +0000
@@ -0,0 +1,82 @@
+package de.intevation.flys.importer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.hibernate.Session;
+import org.hibernate.Query;
+
+import de.intevation.flys.model.MorphologicalWidth;
+import de.intevation.flys.model.River;
+
+
+public class ImportMorphWidth {
+
+    private static Logger log = Logger.getLogger(ImportMorphWidth.class);
+
+
+    protected MorphologicalWidth peer;
+
+    protected ImportUnit unit;
+
+    protected List<ImportMorphWidthValue> values;
+
+
+    public ImportMorphWidth(ImportUnit unit) {
+        this.unit   = unit;
+        this.values = new ArrayList<ImportMorphWidthValue>();
+    }
+
+
+    public void addValue(ImportMorphWidthValue value) {
+        this.values.add(value);
+    }
+
+
+    public void storeDependencies(River river) {
+        log.info("store dependencies");
+
+        MorphologicalWidth peer = getPeer(river);
+
+        log.info("store morphological width values");
+
+        for (ImportMorphWidthValue value: values) {
+            value.storeDependencies(peer);
+        }
+    }
+
+
+    public MorphologicalWidth getPeer(River river) {
+        log.info("get peer");
+
+        if (peer == null) {
+            Session session = ImporterSession.getInstance().getDatabaseSession();
+
+            Query query = session.createQuery(
+                "from MorphologicalWidth where " +
+                "   river=:river and " +
+                "   unit=:unit");
+
+            query.setParameter("river", river);
+            query.setParameter("unit", unit.getPeer());
+
+            List<MorphologicalWidth> widths = query.list();
+
+            if (widths.isEmpty()) {
+                log.debug("Create new MorphologicalWidth DB instance.");
+
+                peer = new MorphologicalWidth(river, unit.getPeer());
+
+                session.save(peer);
+            }
+            else {
+                peer = widths.get(0);
+            }
+        }
+
+        return peer;
+    }
+}
+// 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/importer/ImportMorphWidthValue.java	Fri Apr 13 12:53:29 2012 +0000
@@ -0,0 +1,87 @@
+package de.intevation.flys.importer;
+
+import java.math.BigDecimal;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.hibernate.Session;
+import org.hibernate.Query;
+
+import de.intevation.flys.model.MorphologicalWidth;
+import de.intevation.flys.model.MorphologicalWidthValue;
+
+
+public class ImportMorphWidthValue {
+
+    private static Logger log = Logger.getLogger(ImportMorphWidthValue.class);
+
+
+    protected MorphologicalWidthValue peer;
+
+    protected BigDecimal station;
+    protected BigDecimal width;
+
+    protected String description;
+
+
+    public ImportMorphWidthValue(
+        BigDecimal station,
+        BigDecimal width,
+        String     description
+    ) {
+        this.station     = station;
+        this.width       = width;
+        this.description = description;
+    }
+
+
+    public void storeDependencies(MorphologicalWidth parent) {
+        log.info("store dependencies");
+
+        getPeer(parent);
+    }
+
+
+    public MorphologicalWidthValue getPeer(MorphologicalWidth parent) {
+        log.info("get peer");
+
+        if (peer == null) {
+            Session session = ImporterSession.getInstance().getDatabaseSession();
+
+            Query query = session.createQuery(
+                "from MorphologicalWidthValue where " +
+                "   morphologicalWidth=:morphologicalWidth and " +
+                "   station=:station and " +
+                "   width=:width and " +
+                "   description=:description");
+
+            query.setParameter("morphologicalWidth", parent);
+            query.setParameter("station", station);
+            query.setParameter("width", width);
+            query.setParameter("description", description);
+
+            List<MorphologicalWidthValue> values = query.list();
+
+            if (values.isEmpty()) {
+                log.debug("Create new MorphologicalWidthValue DB instance.");
+
+                peer = new MorphologicalWidthValue(
+                    parent,
+                    station,
+                    width,
+                    description
+                );
+
+                session.save(peer);
+            }
+            else {
+                peer = values.get(0);
+            }
+        }
+
+        return peer;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-backend/src/main/java/de/intevation/flys/model/MorphologicalWidthValue.java	Fri Apr 13 12:33:26 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/MorphologicalWidthValue.java	Fri Apr 13 12:53:29 2012 +0000
@@ -25,6 +25,8 @@
     private BigDecimal station;
     private BigDecimal width;
 
+    private String description;
+
 
     public MorphologicalWidthValue() {
     }
@@ -33,11 +35,13 @@
     public MorphologicalWidthValue(
         MorphologicalWidth morphologicalWidth,
         BigDecimal         station,
-        BigDecimal         width
+        BigDecimal         width,
+        String             description
     ) {
         this.morphologicalWidth = morphologicalWidth;
         this.station            = station;
         this.width              = width;
+        this.description        = description;
     }
 
 
@@ -86,5 +90,14 @@
     public void setWidth(BigDecimal width) {
         this.width = width;
     }
+
+    @Column(name = "description")
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org