Mercurial > dive4elements > river
diff flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModel.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 | 5b54a648f702 |
children | c7ce7c9e405e |
line wrap: on
line diff
--- 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);