Mercurial > dive4elements > river
changeset 486:8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
flys-backend/trunk@1813 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 03 May 2011 17:34:52 +0000 |
parents | 6b231041dc18 |
children | cf513cbe88c3 |
files | flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/importer/AtFileParser.java flys-backend/src/main/java/de/intevation/flys/importer/ImportDischargeTable.java flys-backend/src/main/java/de/intevation/flys/importer/ImportTimeInterval.java flys-backend/src/main/java/de/intevation/flys/model/TimeInterval.java |
diffstat | 5 files changed, 101 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-backend/ChangeLog Tue May 03 17:09:38 2011 +0000 +++ b/flys-backend/ChangeLog Tue May 03 17:34:52 2011 +0000 @@ -1,3 +1,18 @@ +2011-05-03 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/importer/ImportTimeInterval.java: + New. Importer model help fetching the database peer. + + * src/main/java/de/intevation/flys/model/TimeInterval.java: + Add convinience constructor with start and stop time. + + * src/main/java/de/intevation/flys/importer/AtFileParser.java: + Attach a time interval to a discharge table if we find one. + + * src/main/java/de/intevation/flys/importer/ImportDischargeTable.java: + Store the reference to the importer model of the + time interval of the discharge table. + 2011-05-03 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/importer/AtFileParser.java:
--- a/flys-backend/src/main/java/de/intevation/flys/importer/AtFileParser.java Tue May 03 17:09:38 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/AtFileParser.java Tue May 03 17:34:52 2011 +0000 @@ -134,6 +134,11 @@ } } + if (from != null) { + ImportTimeInterval interval = new ImportTimeInterval(from, to); + dischargeTable.setTimeInterval(interval); + } + logger.info("Finished parsing AT file: " + file); return dischargeTable;
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportDischargeTable.java Tue May 03 17:09:38 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportDischargeTable.java Tue May 03 17:34:52 2011 +0000 @@ -8,7 +8,7 @@ import de.intevation.flys.model.DischargeTable; import de.intevation.flys.model.Gauge; - +import de.intevation.flys.model.TimeInterval; public class ImportDischargeTable { @@ -18,6 +18,7 @@ protected List<ImportDischargeTableValue> dischargeTableValues; + protected ImportTimeInterval timeInterval; public ImportDischargeTable() { kind = 0; @@ -39,15 +40,28 @@ return dischargeTableValues; } + public ImportTimeInterval getTimeInterval() { + return timeInterval; + } + + public void setTimeInterval(ImportTimeInterval timeInterval) { + this.timeInterval = timeInterval; + } + public DischargeTable getPeer(Gauge gauge) { if (peer == null) { + TimeInterval ti = timeInterval != null + ? timeInterval.getPeer() + : null; Session session = Importer.sessionHolder.get(); Query query = session.createQuery( - "from DischargeTable where gauge.id=:gauge and kind=:kind"); - query.setParameter("gauge", gauge.getId()); - query.setParameter("kind", kind); + "from DischargeTable where " + + "gauge.id=:gauge and kind=:kind and timeInterval=:interval"); + query.setParameter("gauge", gauge.getId()); + query.setParameter("kind", kind); + query.setParameter("interval", ti); List<DischargeTable> dischargeTables = query.list(); if (dischargeTables.isEmpty()) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportTimeInterval.java Tue May 03 17:34:52 2011 +0000 @@ -0,0 +1,58 @@ +package de.intevation.flys.importer; + +import de.intevation.flys.model.TimeInterval; + +import org.hibernate.Session; +import org.hibernate.Query; + +import java.util.List; +import java.util.Date; + +public class ImportTimeInterval +{ + protected Date startTime; + protected Date stopTime; + + protected TimeInterval peer; + + public ImportTimeInterval() { + } + + public ImportTimeInterval(Date startTime, Date stopTime) { + this.startTime = startTime; + this.stopTime = stopTime; + } + + public Date getStartTime() { + return startTime; + } + + public void setStartTime(Date startTime) { + this.startTime = startTime; + } + + public Date getStopTime() { + return stopTime; + } + + public void setStopTime(Date stopTime) { + this.stopTime = stopTime; + } + + public TimeInterval getPeer() { + if (peer != null) { + Session session = Importer.sessionHolder.get(); + Query query = session.createQuery( + "from TimeInterval where startTime=:a and stopTime=:b"); + query.setParameter("a", startTime); + query.setParameter("b", stopTime); + List<TimeInterval> intervals = query.list(); + if (intervals.isEmpty()) { + peer = new TimeInterval(startTime, stopTime); + session.save(peer); + } + } + return peer; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-backend/src/main/java/de/intevation/flys/model/TimeInterval.java Tue May 03 17:09:38 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/TimeInterval.java Tue May 03 17:34:52 2011 +0000 @@ -24,6 +24,11 @@ public TimeInterval() { } + public TimeInterval(Date startTime, Date stopTime) { + this.startTime = startTime; + this.stopTime = stopTime; + } + @Id @SequenceGenerator( name = "SEQUENCE_TIME_INTERVALS_ID_SEQ",