diff flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightSingleValue.java @ 2809:f283212966e8

Finished work on MINFO bed heights (single). flys-backend/trunk@4221 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 12 Apr 2012 10:42:46 +0000
parents b57c95094b68
children 8926571e47fb
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightSingleValue.java	Wed Apr 11 13:12:52 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightSingleValue.java	Thu Apr 12 10:42:46 2012 +0000
@@ -1,10 +1,24 @@
 package de.intevation.flys.importer;
 
+import java.util.List;
+
 import java.math.BigDecimal;
 
+import org.apache.log4j.Logger;
+
+import org.hibernate.Session;
+import org.hibernate.Query;
+
+import de.intevation.flys.model.BedHeightSingle;
+import de.intevation.flys.model.BedHeightSingleValue;
+
 
 public class ImportBedHeightSingleValue {
 
+    private static final Logger log =
+        Logger.getLogger(ImportBedHeightSingleValue.class);
+
+
     protected ImportBedHeightSingle bedHeight;
 
     protected BigDecimal station;
@@ -14,6 +28,8 @@
     protected BigDecimal soundingWidth;
     protected BigDecimal width;
 
+    protected BedHeightSingleValue peer;
+
 
     public ImportBedHeightSingleValue(
         ImportBedHeightSingle bedHeight,
@@ -32,5 +48,54 @@
         this.soundingWidth = soundingWidth;
         this.width         = width;
     }
+
+
+    public void storeDependencies(BedHeightSingle bedHeight) {
+        getPeer(bedHeight);
+    }
+
+
+    public BedHeightSingleValue getPeer(BedHeightSingle bedHeight) {
+        if (peer == null) {
+            Session session = ImporterSession.getInstance().getDatabaseSession();
+
+            Query query = session.createQuery(
+                "from BedHeightSingleValue where " +
+                "   bedHeight=:bedHeight and " +
+                "   station=:station and " +
+                "   height=:height and " +
+                "   uncertainty=:uncertainty and " +
+                "   dataGap=:dataGap and " +
+                "   soundingWidth=:soundingWidth and " +
+                "   width=:width");
+
+            query.setParameter("bedHeight", bedHeight);
+            query.setParameter("station", station);
+            query.setParameter("height", height);
+            query.setParameter("uncertainty", uncertainty);
+            query.setParameter("dataGap", dataGap);
+            query.setParameter("soundingWidth", soundingWidth);
+            query.setParameter("width", width);
+
+            List<BedHeightSingleValue> values = query.list();
+            if (values.isEmpty()) {
+                peer = new BedHeightSingleValue(
+                    bedHeight,
+                    station,
+                    height,
+                    uncertainty,
+                    dataGap,
+                    soundingWidth,
+                    width
+                );
+                session.save(peer);
+            }
+            else {
+                peer = values.get(0);
+            }
+        }
+
+        return peer;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org