diff flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightEpoch.java @ 3943:a5b003595d6c

Store minfo values into database only if their peer has been successfully stored. flys-backend/trunk@5520 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 19 Sep 2012 10:05:36 +0000
parents 0d27d02b1208
children 145b87bcb10a
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightEpoch.java	Tue Sep 18 15:58:28 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightEpoch.java	Wed Sep 19 10:05:36 2012 +0000
@@ -18,15 +18,15 @@
 import de.intevation.flys.model.TimeInterval;
 
 
-public class ImportBedHeightEpoch implements ImportBedHeight
-{
+public class ImportBedHeightEpoch implements ImportBedHeight {
+
     private static Logger log = Logger.getLogger(ImportBedHeightEpoch.class);
 
     protected String evaluationBy;
     protected String description;
 
-    protected ImportTimeInterval   timeInterval;
-    protected ImportRange          range;
+    protected ImportTimeInterval timeInterval;
+    protected ImportRange range;
     protected ImportElevationModel curElevationModel;
     protected ImportElevationModel oldElevationModel;
 
@@ -34,18 +34,15 @@
 
     protected BedHeightEpoch peer;
 
-
     public ImportBedHeightEpoch(String description) {
         this.description = description;
-        this.values      = new ArrayList<ImportBedHeightEpochValue>();
+        this.values = new ArrayList<ImportBedHeightEpochValue>();
     }
 
-
     public String getDescription() {
         return description;
     }
 
-
     public int getValueCount() {
         return values.size();
     }
@@ -54,7 +51,6 @@
         this.timeInterval = timeInterval;
     }
 
-
     public void setEvaluationBy(String evaluationBy) {
         this.evaluationBy = evaluationBy;
     }
@@ -96,11 +92,9 @@
         values.add((ImportBedHeightEpochValue) value);
     }
 
-
     @Override
-    public void storeDependencies(River river)
-    throws SQLException, ConstraintViolationException
-    {
+    public void storeDependencies(River river) throws SQLException,
+        ConstraintViolationException {
         log.info("Store dependencies for epoch: '" + getDescription() + "'");
 
         if (curElevationModel != null) {
@@ -113,32 +107,31 @@
 
         BedHeightEpoch peer = getPeer(river);
 
-        log.debug("store values now...");
+        if (peer != null) {
+            log.debug("store values now...");
 
-        for (ImportBedHeightEpochValue value: values) {
-            value.storeDependencies(peer);
+            for (ImportBedHeightEpochValue value : values) {
+                value.storeDependencies(peer);
+            }
         }
 
         Session session = ImporterSession.getInstance().getDatabaseSession();
         session.flush();
     }
 
-
     @Override
     public BedHeightEpoch getPeer(River river) {
         if (peer == null) {
-            ElevationModel theCurModel = curElevationModel != null
-                ? curElevationModel.getPeer()
-                : null;
+            ElevationModel theCurModel = curElevationModel != null ? curElevationModel
+                .getPeer() : null;
 
             if (theCurModel == null) {
                 log.warn("BHE: Skip file - invalid current elevation model.");
                 return null;
             }
 
-            TimeInterval theTime = timeInterval != null
-                ? timeInterval.getPeer()
-                : null;
+            TimeInterval theTime = timeInterval != null ? timeInterval
+                .getPeer() : null;
 
             if (theTime == null) {
                 log.warn("BHE: Skip file - invalid time range.");
@@ -152,16 +145,14 @@
                 return null;
             }
 
-            Session session = ImporterSession.getInstance().getDatabaseSession();
+            Session session = ImporterSession.getInstance()
+                .getDatabaseSession();
 
-            Query query = session.createQuery(
-                "from BedHeightEpoch where " +
-                "   river=:river and " +
-                "   timeInterval=:timeInterval and " +
-                "   curElevationModel=:curElevationModel and " +
-                "   range=:range and " +
-                "   evaluationBy=:evaluationBy and " +
-                "   description=:description");
+            Query query = session.createQuery("from BedHeightEpoch where "
+                + "   river=:river and " + "   timeInterval=:timeInterval and "
+                + "   curElevationModel=:curElevationModel and "
+                + "   range=:range and " + "   evaluationBy=:evaluationBy and "
+                + "   description=:description");
 
             query.setParameter("river", river);
             query.setParameter("timeInterval", theTime);
@@ -175,15 +166,10 @@
             if (bedHeights.isEmpty()) {
                 log.info("Create new BedHeightEpoch DB instance.");
 
-                peer = new BedHeightEpoch(
-                    river,
-                    theTime,
-                    theRange,
+                peer = new BedHeightEpoch(river, theTime, theRange,
                     theCurModel,
-                    oldElevationModel != null ? oldElevationModel.getPeer() : null,
-                    evaluationBy,
-                    description
-                );
+                    oldElevationModel != null ? oldElevationModel.getPeer()
+                        : null, evaluationBy, description);
 
                 session.save(peer);
             }

http://dive4elements.wald.intevation.org