changeset 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 43aa1ac8614b
children 5fea100c5334
files flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightEpoch.java flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightSingle.java flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurement.java flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModel.java flys-backend/src/main/java/de/intevation/flys/importer/ImportMorphWidth.java flys-backend/src/main/java/de/intevation/flys/importer/ImportSQRelation.java flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensity.java flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentYield.java flys-backend/src/main/java/de/intevation/flys/importer/ImportWaterlevel.java flys-backend/src/main/java/de/intevation/flys/importer/ImportWaterlevelDifference.java
diffstat 11 files changed, 182 insertions(+), 248 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Tue Sep 18 15:58:28 2012 +0000
+++ b/flys-backend/ChangeLog	Wed Sep 19 10:05:36 2012 +0000
@@ -1,3 +1,18 @@
+2012-09-19  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/importer/ImportSedimentDensity.java,
+	  src/main/java/de/intevation/flys/importer/ImportWaterlevelDifference.java,
+	  src/main/java/de/intevation/flys/importer/ImportBedHeightSingle.java,
+	  src/main/java/de/intevation/flys/importer/ImportSedimentYield.java,
+	  src/main/java/de/intevation/flys/importer/ImportBedHeightEpoch.java,
+	  src/main/java/de/intevation/flys/importer/ImportWaterlevel.java,
+	  src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurement.java,
+	  src/main/java/de/intevation/flys/importer/ImportMorphWidth.java,
+	  src/main/java/de/intevation/flys/importer/ImportFlowVelocityModel.java,
+	  src/main/java/de/intevation/flys/importer/ImportSQRelation.java: Store
+	  values into database only if its peer has been successfully stored,
+	  otherwise skip values.
+
 2012-09-18	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	 * src/main/java/de/intevation/flys/importer/ImportSedimentDensity.java,
--- 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);
             }
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightSingle.java	Tue Sep 18 15:58:28 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightSingle.java	Wed Sep 19 10:05:36 2012 +0000
@@ -123,8 +123,10 @@
 
         BedHeightSingle peer = getPeer(river);
 
-        for (ImportBedHeightSingleValue value: values) {
-            value.storeDependencies(peer);
+        if (peer != null) {
+            for (ImportBedHeightSingleValue value: values) {
+                value.storeDependencies(peer);
+            }
         }
 
         Session session = ImporterSession.getInstance().getDatabaseSession();
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurement.java	Tue Sep 18 15:58:28 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurement.java	Wed Sep 19 10:05:36 2012 +0000
@@ -16,9 +16,8 @@
 
 public class ImportFlowVelocityMeasurement {
 
-    private static final Logger log =
-        Logger.getLogger(ImportFlowVelocityMeasurement.class);
-
+    private static final Logger log = Logger
+        .getLogger(ImportFlowVelocityMeasurement.class);
 
     private String description;
 
@@ -26,50 +25,44 @@
 
     private FlowVelocityMeasurement peer;
 
-
     public ImportFlowVelocityMeasurement() {
         this(null);
     }
 
-
     public ImportFlowVelocityMeasurement(String description) {
         this.description = description;
-        this.values      = new ArrayList<ImportFlowVelocityMeasurementValue>();
+        this.values = new ArrayList<ImportFlowVelocityMeasurementValue>();
     }
 
-
     public void setDescription(String description) {
         this.description = description;
     }
 
-
     public void addValue(ImportFlowVelocityMeasurementValue value) {
         this.values.add(value);
     }
 
-
-    public void storeDependencies(River river)
-    throws SQLException, ConstraintViolationException
-    {
+    public void storeDependencies(River river) throws SQLException,
+        ConstraintViolationException {
         log.debug("store dependencies");
 
         FlowVelocityMeasurement peer = getPeer(river);
 
-        for (ImportFlowVelocityMeasurementValue value: values) {
-            value.storeDependencies(peer);
+        if (peer != null) {
+            for (ImportFlowVelocityMeasurementValue value : values) {
+                value.storeDependencies(peer);
+            }
         }
     }
 
-
     public FlowVelocityMeasurement getPeer(River river) {
         if (peer == null) {
-            Session session = ImporterSession.getInstance().getDatabaseSession();
+            Session session = ImporterSession.getInstance()
+                .getDatabaseSession();
 
-            Query query = session.createQuery(
-                "from FlowVelocityMeasurement where " +
-                "   river=:river and " +
-                "   description=:description"
-            );
+            Query query = session
+                .createQuery("from FlowVelocityMeasurement where "
+                    + "   river=:river and " + "   description=:description");
 
             query.setParameter("river", river);
             query.setParameter("description", description);
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModel.java	Tue Sep 18 15:58:28 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModel.java	Wed Sep 19 10:05:36 2012 +0000
@@ -17,9 +17,8 @@
 
 public class ImportFlowVelocityModel {
 
-    private static final Logger log =
-        Logger.getLogger(ImportFlowVelocityModel.class);
-
+    private static final Logger log = Logger
+        .getLogger(ImportFlowVelocityModel.class);
 
     private String description;
 
@@ -29,41 +28,32 @@
 
     private FlowVelocityModel peer;
 
-
     public ImportFlowVelocityModel() {
         values = new ArrayList<ImportFlowVelocityModelValue>();
     }
 
-
-    public ImportFlowVelocityModel(
-        ImportDischargeZone dischargeZone,
-        String              description
-    ) {
+    public ImportFlowVelocityModel(ImportDischargeZone dischargeZone,
+        String description) {
         this();
 
         this.dischargeZone = dischargeZone;
-        this.description   = description;
+        this.description = description;
     }
 
-
     public void setDischargeZone(ImportDischargeZone dischargeZone) {
         this.dischargeZone = dischargeZone;
     }
 
-
     public void setDescription(String description) {
         this.description = description;
     }
 
-
     public void addValue(ImportFlowVelocityModelValue value) {
         this.values.add(value);
     }
 
-
-    public void storeDependencies(River river)
-    throws SQLException, ConstraintViolationException
-    {
+    public void storeDependencies(River river) throws SQLException,
+        ConstraintViolationException {
         log.debug("store dependencies");
 
         if (dischargeZone == null) {
@@ -75,28 +65,27 @@
 
         FlowVelocityModel peer = getPeer(river);
 
-        int i = 0;
+        if (peer != null) {
+            int i = 0;
 
-        for (ImportFlowVelocityModelValue value: values) {
-            value.storeDependencies(peer);
-            i++;
+            for (ImportFlowVelocityModelValue value : values) {
+                value.storeDependencies(peer);
+                i++;
+            }
+
+            log.info("stored " + i + " flow velocity model values.");
         }
-
-        log.info("stored " + i + " flow velocity model values.");
     }
 
-
     public FlowVelocityModel getPeer(River river) {
         if (peer == null) {
-            Session session = ImporterSession.getInstance().getDatabaseSession();
+            Session session = ImporterSession.getInstance()
+                .getDatabaseSession();
 
             DischargeZone zone = dischargeZone.getPeer(river);
 
-            Query query = session.createQuery(
-                "from FlowVelocityModel where " +
-                "   river=:river and " +
-                "   dischargeZone=:dischargeZone"
-            );
+            Query query = session.createQuery("from FlowVelocityModel where "
+                + "   river=:river and " + "   dischargeZone=:dischargeZone");
 
             query.setParameter("river", river);
             query.setParameter("dischargeZone", zone);
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportMorphWidth.java	Tue Sep 18 15:58:28 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportMorphWidth.java	Wed Sep 19 10:05:36 2012 +0000
@@ -1,14 +1,12 @@
 package de.intevation.flys.importer;
 
 import java.sql.SQLException;
-
 import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.log4j.Logger;
-
+import org.hibernate.Query;
 import org.hibernate.Session;
-import org.hibernate.Query;
 import org.hibernate.exception.ConstraintViolationException;
 
 import de.intevation.flys.model.MorphologicalWidth;
@@ -19,54 +17,48 @@
 
     private static Logger log = Logger.getLogger(ImportMorphWidth.class);
 
-
     protected MorphologicalWidth peer;
 
     protected ImportUnit unit;
 
     protected List<ImportMorphWidthValue> values;
 
-
     public ImportMorphWidth() {
         this.values = new ArrayList<ImportMorphWidthValue>();
     }
 
-
     public void addValue(ImportMorphWidthValue value) {
         this.values.add(value);
     }
 
-
     public void setUnit(ImportUnit unit) {
         this.unit = unit;
     }
 
-
-    public void storeDependencies(River river)
-    throws SQLException, ConstraintViolationException
-    {
+    public void storeDependencies(River river) throws SQLException,
+        ConstraintViolationException {
         log.info("store dependencies");
 
         MorphologicalWidth peer = getPeer(river);
 
-        log.info("store morphological width values");
+        if (peer != null) {
+            log.info("store morphological width values");
 
-        for (ImportMorphWidthValue value: values) {
-            value.storeDependencies(peer);
+            for (ImportMorphWidthValue value : values) {
+                value.storeDependencies(peer);
+            }
         }
     }
 
-
     public MorphologicalWidth getPeer(River river) {
         log.info("get peer");
 
         if (peer == null) {
-            Session session = ImporterSession.getInstance().getDatabaseSession();
+            Session session = ImporterSession.getInstance()
+                .getDatabaseSession();
 
-            Query query = session.createQuery(
-                "from MorphologicalWidth where " +
-                "   river=:river and " +
-                "   unit=:unit");
+            Query query = session.createQuery("from MorphologicalWidth where "
+                + "   river=:river and " + "   unit=:unit");
 
             query.setParameter("river", river);
             query.setParameter("unit", unit.getPeer());
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportSQRelation.java	Tue Sep 18 15:58:28 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportSQRelation.java	Wed Sep 19 10:05:36 2012 +0000
@@ -19,7 +19,6 @@
 
     private static Logger log = Logger.getLogger(ImportSQRelation.class);
 
-
     private ImportTimeInterval timeInterval;
 
     private String description;
@@ -28,40 +27,38 @@
 
     private SQRelation peer;
 
-
     public ImportSQRelation() {
         this.values = new ArrayList<ImportSQRelationValue>();
     }
 
-
-    public void storeDependencies(River river)
-    throws SQLException, ConstraintViolationException
-    {
+    public void storeDependencies(River river) throws SQLException,
+        ConstraintViolationException {
         log.info("store dependencies");
 
         SQRelation peer = getPeer(river);
 
         timeInterval.getPeer();
 
-        int count = 0;
+        if (peer != null) {
+            int count = 0;
 
-        for (ImportSQRelationValue value: values) {
-            try {
-                value.storeDependencies(peer);
-                count++;
+            for (ImportSQRelationValue value : values) {
+                try {
+                    value.storeDependencies(peer);
+                    count++;
+                }
+                catch (SQLException sqle) {
+                    log.warn("ISQ: Unable to store sq relation value.", sqle);
+                }
+                catch (ConstraintViolationException cve) {
+                    log.warn("ISQ: Unable to store sq relation value.", cve);
+                }
             }
-            catch (SQLException sqle) {
-                log.warn("ISQ: Unable to store sq relation value.", sqle);
-            }
-            catch (ConstraintViolationException cve) {
-                log.warn("ISQ: Unable to store sq relation value.", cve);
-            }
+
+            log.info("stored " + count + " sq relation values.");
         }
-
-        log.info("stored " + count + " sq relation values.");
     }
 
-
     public SQRelation getPeer(River river) {
         log.debug("getPeer()");
 
@@ -73,11 +70,11 @@
                 return null;
             }
 
-            Session session = ImporterSession.getInstance().getDatabaseSession();
+            Session session = ImporterSession.getInstance()
+                .getDatabaseSession();
 
-            Query query = session.createQuery(
-                "FROM SQRelation WHERE river=:river AND timeInterval=:timeInter"
-            );
+            Query query = session
+                .createQuery("FROM SQRelation WHERE river=:river AND timeInterval=:timeInter");
 
             query.setParameter("river", river);
             query.setParameter("timeInter", timeInter);
@@ -87,11 +84,7 @@
             if (sq.isEmpty()) {
                 log.info("create new SQ relation '" + description + "'");
 
-                peer = new SQRelation(
-                    river,
-                    timeInter,
-                    description
-                );
+                peer = new SQRelation(river, timeInter, description);
                 session.save(peer);
             }
             else {
@@ -102,17 +95,14 @@
         return peer;
     }
 
-
     public void setDescription(String description) {
         this.description = description;
     }
 
-
     public void setTimeInterval(ImportTimeInterval timeInterval) {
         this.timeInterval = timeInterval;
     }
 
-
     public void addValue(ImportSQRelationValue value) {
         if (value != null) {
             this.values.add(value);
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensity.java	Tue Sep 18 15:58:28 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensity.java	Wed Sep 19 10:05:36 2012 +0000
@@ -1,14 +1,12 @@
 package de.intevation.flys.importer;
 
 import java.sql.SQLException;
-
 import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.log4j.Logger;
-
+import org.hibernate.Query;
 import org.hibernate.Session;
-import org.hibernate.Query;
 import org.hibernate.exception.ConstraintViolationException;
 
 import de.intevation.flys.model.River;
@@ -19,7 +17,6 @@
 
     private static Logger log = Logger.getLogger(ImportSedimentDensity.class);
 
-
     protected SedimentDensity peer;
 
     protected ImportDepth depth;
@@ -30,73 +27,67 @@
 
     protected List<ImportSedimentDensityValue> values;
 
-
     public ImportSedimentDensity(String description) {
         this.description = description;
-        this.values      = new ArrayList<ImportSedimentDensityValue>();
+        this.values = new ArrayList<ImportSedimentDensityValue>();
     }
 
-
     public String getDescription() {
         return description;
     }
 
-
     public void setDepth(ImportDepth depth) {
         this.depth = depth;
     }
 
-
     public void setUnit(ImportUnit unit) {
         this.unit = unit;
     }
 
-
     public void addValue(ImportSedimentDensityValue value) {
         values.add(value);
     }
 
-
-    public void storeDependencies(River river)
-    throws SQLException, ConstraintViolationException
-    {
+    public void storeDependencies(River river) throws SQLException,
+        ConstraintViolationException {
         log.info("store dependencies");
 
         if (depth != null) {
             depth.storeDependencies();
         }
 
-        log.info("store sediment density values.");
-
         SedimentDensity peer = getPeer(river);
 
-        for (ImportSedimentDensityValue value: values) {
-            value.storeDependencies(peer);
+        if (peer != null) {
+            log.info("store sediment density values.");
+            for (ImportSedimentDensityValue value : values) {
+                value.storeDependencies(peer);
+            }
         }
     }
 
-
     public SedimentDensity getPeer(River river) {
         log.info("get peer");
 
         if (depth == null) {
-            log.warn("cannot store sediment density '" + description + "': no depth");
+            log.warn("cannot store sediment density '" + description
+                + "': no depth");
             return null;
         }
 
         if (unit == null) {
-            log.warn("cannot store sediment density '" + description + "': no unit");
+            log.warn("cannot store sediment density '" + description
+                + "': no unit");
             return null;
         }
 
         if (peer == null) {
-            Session session = ImporterSession.getInstance().getDatabaseSession();
+            Session session = ImporterSession.getInstance()
+                .getDatabaseSession();
 
-            Query query = session.createQuery(
-                "from SedimentDensity where " +
-                "   river=:river and " +
-                "   depth=:depth and " +
-                "   unit=:unit");
+            Query query = session.createQuery("from SedimentDensity where "
+                + "   river=:river and " + "   depth=:depth and "
+                + "   unit=:unit");
 
             query.setParameter("river", river);
             query.setParameter("depth", depth.getPeer());
@@ -107,11 +98,8 @@
             if (density.isEmpty()) {
                 log.debug("Create new SedimentDensity DB instance.");
 
-                peer = new SedimentDensity(
-                    river,
-                    depth.getPeer(),
-                    unit.getPeer(),
-                    description);
+                peer = new SedimentDensity(river, depth.getPeer(),
+                    unit.getPeer(), description);
 
                 session.save(peer);
             }
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentYield.java	Tue Sep 18 15:58:28 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentYield.java	Wed Sep 19 10:05:36 2012 +0000
@@ -33,36 +33,29 @@
 
     private SedimentYield peer;
 
-
     public ImportSedimentYield(String description) {
-        this.values      = new ArrayList<ImportSedimentYieldValue>();
+        this.values = new ArrayList<ImportSedimentYieldValue>();
         this.description = description;
     }
 
-
     public void setTimeInterval(ImportTimeInterval timeInterval) {
         this.timeInterval = timeInterval;
     }
 
-
     public void setUnit(ImportUnit unit) {
         this.unit = unit;
     }
 
-
     public void setGrainFraction(ImportGrainFraction grainFraction) {
         this.grainFraction = grainFraction;
     }
 
-
     public void addValue(ImportSedimentYieldValue value) {
         this.values.add(value);
     }
 
-
-    public void storeDependencies(River river)
-    throws SQLException, ConstraintViolationException
-    {
+    public void storeDependencies(River river) throws SQLException,
+        ConstraintViolationException {
         log.debug("store dependencies");
 
         if (grainFraction != null) {
@@ -71,22 +64,22 @@
 
         SedimentYield peer = getPeer(river);
 
-        int i = 0;
+        if (peer != null) {
+            int i = 0;
 
-        for (ImportSedimentYieldValue value: values) {
-            value.storeDependencies(peer);
-            i++;
+            for (ImportSedimentYieldValue value : values) {
+                value.storeDependencies(peer);
+                i++;
+            }
+
+            log.info("stored " + i + " sediment yield values.");
         }
-
-        log.info("stored " + i + " sediment yield values.");
     }
 
-
     public SedimentYield getPeer(River river) {
         log.debug("get peer");
 
-        GrainFraction gf = grainFraction != null
-            ? grainFraction.getPeer()
+        GrainFraction gf = grainFraction != null ? grainFraction.getPeer()
             : null;
 
         Unit u = unit != null ? unit.getPeer() : null;
@@ -99,15 +92,13 @@
         }
 
         if (peer == null) {
-            Session session = ImporterSession.getInstance().getDatabaseSession();
-            Query query = session.createQuery(
-                "from SedimentYield where " +
-                "   river=:river and " +
-                "   grainFraction=:grainFraction and " +
-                "   unit=:unit and " +
-                "   timeInterval=:timeInterval and " +
-                "   description=:description"
-            );
+            Session session = ImporterSession.getInstance()
+                .getDatabaseSession();
+            Query query = session.createQuery("from SedimentYield where "
+                + "   river=:river and "
+                + "   grainFraction=:grainFraction and " + "   unit=:unit and "
+                + "   timeInterval=:timeInterval and "
+                + "   description=:description");
 
             query.setParameter("river", river);
             query.setParameter("grainFraction", gf);
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportWaterlevel.java	Tue Sep 18 15:58:28 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportWaterlevel.java	Wed Sep 19 10:05:36 2012 +0000
@@ -17,7 +17,6 @@
 
     private static final Logger log = Logger.getLogger(ImportWaterlevel.class);
 
-
     private ImportUnit unit;
 
     private String description;
@@ -26,40 +25,37 @@
 
     private Waterlevel peer;
 
-
     public ImportWaterlevel(String description) {
         this.qRanges = new ArrayList<ImportWaterlevelQRange>();
 
         this.description = description;
     }
 
-
     public void setUnit(ImportUnit unit) {
         this.unit = unit;
     }
 
-
     public void addValue(ImportWaterlevelQRange qRange) {
         this.qRanges.add(qRange);
     }
 
-
     public void storeDependencies(River river) {
         log.info("store dependencies");
 
         Waterlevel peer = getPeer(river);
 
-        int i = 0;
+        if (peer != null) {
+            int i = 0;
 
-        for (ImportWaterlevelQRange qRange: qRanges) {
-            qRange.storeDependencies(peer);
-            i++;
+            for (ImportWaterlevelQRange qRange : qRanges) {
+                qRange.storeDependencies(peer);
+                i++;
+            }
+
+            log.info("stored " + i + " waterlevel q ranges");
         }
-
-        log.info("stored " + i + " waterlevel q ranges");
     }
 
-
     public Waterlevel getPeer(River river) {
         Unit u = unit != null ? unit.getPeer() : null;
         if (u == null) {
@@ -68,13 +64,11 @@
         }
 
         if (peer == null) {
-            Session session = ImporterSession.getInstance().getDatabaseSession();
-            Query query = session.createQuery(
-                "from Waterlevel where " +
-                "   river=:river and " +
-                "   unit=:unit and " +
-                "   description=:description"
-            );
+            Session session = ImporterSession.getInstance()
+                .getDatabaseSession();
+            Query query = session.createQuery("from Waterlevel where "
+                + "   river=:river and " + "   unit=:unit and "
+                + "   description=:description");
 
             query.setParameter("river", river);
             query.setParameter("unit", u);
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportWaterlevelDifference.java	Tue Sep 18 15:58:28 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportWaterlevelDifference.java	Wed Sep 19 10:05:36 2012 +0000
@@ -17,9 +17,8 @@
 
 public class ImportWaterlevelDifference {
 
-    private static final Logger log =
-        Logger.getLogger(ImportWaterlevelDifference.class);
-
+    private static final Logger log = Logger
+        .getLogger(ImportWaterlevelDifference.class);
 
     private ImportUnit unit;
 
@@ -29,42 +28,38 @@
 
     private WaterlevelDifference peer;
 
-
     public ImportWaterlevelDifference(String description) {
         this.columns = new ArrayList<ImportWaterlevelDifferenceColumn>();
 
         this.description = description;
     }
 
-
     public void setUnit(ImportUnit unit) {
         this.unit = unit;
     }
 
-
     public void addValue(ImportWaterlevelDifferenceColumn column) {
         this.columns.add(column);
     }
 
-
-    public void storeDependencies(River river)
-    throws SQLException, ConstraintViolationException
-    {
+    public void storeDependencies(River river) throws SQLException,
+        ConstraintViolationException {
         log.info("store dependencies");
 
         WaterlevelDifference peer = getPeer(river);
 
-        int i = 0;
+        if (peer != null) {
+            int i = 0;
 
-        for (ImportWaterlevelDifferenceColumn column: columns) {
-            column.storeDependencies(peer);
-            i++;
+            for (ImportWaterlevelDifferenceColumn column : columns) {
+                column.storeDependencies(peer);
+                i++;
+            }
+
+            log.info("stored " + i + " waterlevel difference columns");
         }
-
-        log.info("stored " + i + " waterlevel difference columns");
     }
 
-
     public WaterlevelDifference getPeer(River river) {
         Unit u = unit != null ? unit.getPeer() : null;
         if (u == null) {
@@ -73,13 +68,12 @@
         }
 
         if (peer == null) {
-            Session session = ImporterSession.getInstance().getDatabaseSession();
-            Query query = session.createQuery(
-                "from WaterlevelDifference where " +
-                "   river=:river and " +
-                "   unit=:unit and " +
-                "   description=:description"
-            );
+            Session session = ImporterSession.getInstance()
+                .getDatabaseSession();
+            Query query = session
+                .createQuery("from WaterlevelDifference where "
+                    + "   river=:river and " + "   unit=:unit and "
+                    + "   description=:description");
 
             query.setParameter("river", river);
             query.setParameter("unit", u);

http://dive4elements.wald.intevation.org