Mercurial > dive4elements > river
diff flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensity.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 | 43aa1ac8614b |
children | 4ee97d914501 |
line wrap: on
line diff
--- 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); }