Mercurial > dive4elements > river
changeset 2831:8fe9c6584b93
Added importer classes used during the import process of flow velocity measurements.
flys-backend/trunk@4249 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 17 Apr 2012 12:00:13 +0000 |
parents | 6faa47ca1fee |
children | ac5bd90697c1 |
files | flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurement.java flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurementValue.java |
diffstat | 3 files changed, 185 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-backend/ChangeLog Tue Apr 17 11:58:43 2012 +0000 +++ b/flys-backend/ChangeLog Tue Apr 17 12:00:13 2012 +0000 @@ -1,3 +1,10 @@ +2012-04-17 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurementValue.java, + src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurement.java: + New temp classes used during the import process of flow velocity + measurements. + 2012-04-17 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/model/FlowVelocityMeasurementValue.java,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurement.java Tue Apr 17 12:00:13 2012 +0000 @@ -0,0 +1,80 @@ +package de.intevation.flys.importer; + +import java.sql.SQLException; +import java.util.List; + +import org.apache.log4j.Logger; + +import org.hibernate.Session; +import org.hibernate.Query; +import org.hibernate.exception.ConstraintViolationException; + +import de.intevation.flys.model.FlowVelocityMeasurement; +import de.intevation.flys.model.River; + + +public class ImportFlowVelocityMeasurement { + + private static final Logger log = + Logger.getLogger(ImportFlowVelocityMeasurement.class); + + + private String description; + + private List<ImportFlowVelocityMeasurementValue> values; + + private FlowVelocityMeasurement peer; + + + public ImportFlowVelocityMeasurement() { + this(null); + } + + + public ImportFlowVelocityMeasurement(String description) { + this.description = description; + } + + + public void storeDependencies(River river) + throws SQLException, ConstraintViolationException + { + log.debug("store dependencies"); + + FlowVelocityMeasurement peer = getPeer(river); + + for (ImportFlowVelocityMeasurementValue value: values) { + value.storeDependencies(peer); + } + } + + + public FlowVelocityMeasurement getPeer(River river) { + if (peer == null) { + Session session = ImporterSession.getInstance().getDatabaseSession(); + + Query query = session.createQuery( + "from FlowVelocityMeasurement where " + + " river:=river and " + + " description:=description" + ); + + query.setParameter("river", river); + query.setParameter("description", description); + + List<FlowVelocityMeasurement> measurement = query.list(); + + if (measurement.isEmpty()) { + peer = new FlowVelocityMeasurement(river, description); + + session.save(peer); + } + else { + peer = measurement.get(0); + } + } + + return peer; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurementValue.java Tue Apr 17 12:00:13 2012 +0000 @@ -0,0 +1,98 @@ +package de.intevation.flys.importer; + +import java.math.BigDecimal; +import java.sql.SQLException; +import java.util.Date; +import java.util.List; + +import org.apache.log4j.Logger; + +import org.hibernate.Session; +import org.hibernate.Query; +import org.hibernate.exception.ConstraintViolationException; + +import de.intevation.flys.model.FlowVelocityMeasurement; +import de.intevation.flys.model.FlowVelocityMeasurementValue; + + +public class ImportFlowVelocityMeasurementValue { + + private static final Logger log = + Logger.getLogger(ImportFlowVelocityMeasurementValue.class); + + + private Date datetime; + + private String description; + + private BigDecimal station; + private BigDecimal w; + private BigDecimal q; + private BigDecimal v; + + private FlowVelocityMeasurementValue peer; + + + public ImportFlowVelocityMeasurementValue( + Date datetime, + BigDecimal station, + BigDecimal w, + BigDecimal q, + BigDecimal v, + String description + ) { + this.datetime = datetime; + this.station = station; + this.w = w; + this.q = q; + this.v = v; + this.description = description; + } + + + + public void storeDependencies(FlowVelocityMeasurement measurement) + throws SQLException, ConstraintViolationException + { + log.debug("store dependencies"); + + getPeer(measurement); + } + + + public FlowVelocityMeasurementValue getPeer(FlowVelocityMeasurement m) { + if (peer == null) { + Session session = ImporterSession.getInstance().getDatabaseSession(); + + Query query = session.createQuery( + "from FlowVelocityMeasurementValue where " + + " measurement:=measurement and " + + " station:=station" + ); + + query.setParameter("measurement", m); + query.setParameter("station", station); + + List<FlowVelocityMeasurementValue> values = query.list(); + + if (values.isEmpty()) { + peer = new FlowVelocityMeasurementValue( + m, + datetime, + station, + w, + q, + v, + description); + + session.save(peer); + } + else { + peer = values.get(0); + } + } + + return peer; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :