Mercurial > dive4elements > river
changeset 1218:00e37d22a589
Added importer models for HYKs.
flys-backend/trunk@2344 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 17 Jul 2011 19:03:33 +0000 |
parents | d5e39c16fd2a |
children | d80997bd94ce |
files | flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/importer/ImportHYK.java flys-backend/src/main/java/de/intevation/flys/importer/ImportHYKEntry.java flys-backend/src/main/java/de/intevation/flys/importer/ImportHYKFlowZone.java flys-backend/src/main/java/de/intevation/flys/importer/ImportHYKFormation.java |
diffstat | 5 files changed, 317 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-backend/ChangeLog Sun Jul 17 10:24:20 2011 +0000 +++ b/flys-backend/ChangeLog Sun Jul 17 19:03:33 2011 +0000 @@ -1,3 +1,11 @@ +2011-07-17 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/importer/ImportHYKFormation.java, + src/main/java/de/intevation/flys/importer/ImportHYKFlowZone.java, + src/main/java/de/intevation/flys/importer/ImportHYKEntry.java, + src/main/java/de/intevation/flys/importer/ImportHYK.java: New. + Importer models for HYKs. + 2011-07-17 Sascha L. Teichmann <sascha.teichmann@intevation.de> * doc/schema/postgresql.sql: Each entry in a HYK can have
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportHYK.java Sun Jul 17 19:03:33 2011 +0000 @@ -0,0 +1,57 @@ +package de.intevation.flys.importer; + +import de.intevation.flys.model.HYK; +import de.intevation.flys.model.River; + +import java.util.List; +import java.util.ArrayList; + +import org.hibernate.Session; +import org.hibernate.Query; + +public class ImportHYK +{ + protected ImportRiver river; + protected String description; + + protected List<ImportHYKEntry> entries; + + protected HYK peer; + + public ImportHYK() { + entries = new ArrayList<ImportHYKEntry>(); + } + + public ImportHYK(ImportRiver river, String description) { + this(); + this.river = river; + this.description = description; + } + + public void addEntry(ImportHYKEntry entry) { + entries.add(entry); + entry.setHYK(this); + } + + public HYK getPeer() { + if (peer == null) { + River r = river.getPeer(); + Session session = ImporterSession.getInstance() + .getDatabaseSession(); + Query query = session.createQuery( + "from HYK where river=:river and description=:description"); + query.setParameter("river", r); + query.setParameter("description", description); + List<HYK> hyks = query.list(); + if (hyks.isEmpty()) { + peer = new HYK(r, description); + session.save(peer); + } + else { + peer = hyks.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/ImportHYKEntry.java Sun Jul 17 19:03:33 2011 +0000 @@ -0,0 +1,77 @@ +package de.intevation.flys.importer; + +import de.intevation.flys.model.HYKEntry; +import de.intevation.flys.model.HYK; + +import java.util.Date; +import java.util.List; +import java.util.ArrayList; + +import java.math.BigDecimal; + +import org.hibernate.Session; +import org.hibernate.Query; + +public class ImportHYKEntry +{ + protected ImportHYK hyk; + protected BigDecimal km; + protected Date measure; + + protected List<ImportHYKFormation> formations; + + protected HYKEntry peer; + + public ImportHYKEntry() { + formations = new ArrayList<ImportHYKFormation>(); + } + + public ImportHYKEntry( + ImportHYK hyk, + BigDecimal km, + Date measure + ) { + this.hyk = hyk; + this.km = km; + this.measure = measure; + } + + public ImportHYK getHYK() { + return hyk; + } + + public void setHYK(ImportHYK hyk) { + this.hyk = hyk; + } + + public void addFormation(ImportHYKFormation formation) { + int numFormation = formations.size(); + formations.add(formation); + formation.setFormationNum(numFormation); + formation.setEntry(this); + } + + public HYKEntry getPeer() { + if (peer == null) { + HYK h = hyk.getPeer(); + Session session = ImporterSession.getInstance() + .getDatabaseSession(); + Query query = session.createQuery( + "from HYKEntry where hyk=:hyk " + + "and km=:km and measure=:measure"); + query.setParameter("hyk", h); + query.setParameter("km", km); + query.setParameter("measure", measure); + List<HYKEntry> entries = query.list(); + if (entries.isEmpty()) { + peer = new HYKEntry(h, km, measure); + session.save(peer); + } + else { + peer = entries.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/ImportHYKFlowZone.java Sun Jul 17 19:03:33 2011 +0000 @@ -0,0 +1,72 @@ +package de.intevation.flys.importer; + +import de.intevation.flys.model.HYKFormation; +import de.intevation.flys.model.HYKFlowZone; +import de.intevation.flys.model.HYKFlowZoneType; + +import org.hibernate.Session; +import org.hibernate.Query; + +import java.util.List; + +import java.math.BigDecimal; + +public class ImportHYKFlowZone +{ + protected ImportHYKFormation formation; + protected ImportHYKFlowZoneType type; + protected BigDecimal a; + protected BigDecimal b; + + protected HYKFlowZone peer; + + public ImportHYKFlowZone() { + } + + public ImportHYKFlowZone( + ImportHYKFormation formation, + ImportHYKFlowZoneType type, + BigDecimal a, + BigDecimal b + ) { + this.formation = formation; + this.type = type; + this.a = a; + this.b = b; + } + + public ImportHYKFormation getFormation() { + return formation; + } + + public void setFormation(ImportHYKFormation formation) { + this.formation = formation; + } + + public HYKFlowZone getPeer() { + if (peer == null) { + HYKFormation f = formation.getPeer(); + HYKFlowZoneType t = type.getPeer(); + Session session = ImporterSession.getInstance() + .getDatabaseSession(); + Query query = session.createQuery( + "from HYKFlowZone where formation=:formation " + + "and type=:type and a=:a and b=:b"); + query.setParameter("formation", f); + query.setParameter("type", t); + query.setParameter("a", a); + query.setParameter("b", b); + List<HYKFlowZone> zones = query.list(); + if (zones.isEmpty()) { + peer = new HYKFlowZone(f, t, a, b); + session.save(peer); + } + else { + peer = zones.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/ImportHYKFormation.java Sun Jul 17 19:03:33 2011 +0000 @@ -0,0 +1,103 @@ +package de.intevation.flys.importer; + +import de.intevation.flys.model.HYKFormation; +import de.intevation.flys.model.HYKEntry; + +import java.util.ArrayList; +import java.util.List; + +import org.hibernate.Session; +import org.hibernate.Query; + +import java.math.BigDecimal; + +public class ImportHYKFormation +{ + protected int formationNum; + protected ImportHYKEntry entry; + protected BigDecimal top; + protected BigDecimal bottom; + protected BigDecimal distanceVL; + protected BigDecimal distanceHF; + protected BigDecimal distanceVR; + + protected List<ImportHYKFlowZone> zones; + + protected HYKFormation peer; + + public ImportHYKFormation() { + zones = new ArrayList<ImportHYKFlowZone>(); + } + + public ImportHYKFormation( + int formationNum, + ImportHYKEntry entry, + BigDecimal top, + BigDecimal bottom, + BigDecimal distanceVL, + BigDecimal distanceHF, + BigDecimal distanceVR + ) { + this(); + this.formationNum = formationNum; + this.entry = entry; + this.top = top; + this.bottom = bottom; + this.distanceVL = distanceVL; + this.distanceHF = distanceHF; + this.distanceVR = distanceVR; + } + + public void addFlowZone(ImportHYKFlowZone zone) { + zones.add(zone); + zone.setFormation(this); + } + + public int getFormationNum() { + return formationNum; + } + + public void setFormationNum(int formationNum) { + this.formationNum = formationNum; + } + + public ImportHYKEntry getEntry() { + return entry; + } + + public void setEntry(ImportHYKEntry entry) { + this.entry = entry; + } + + public HYKFormation getPeer() { + if (peer == null) { + HYKEntry e = entry.getPeer(); + Session session = ImporterSession.getInstance() + .getDatabaseSession(); + Query query = session.createQuery( + "from HYKFormation where formationNum=:formationNum " + + "and entry=:entry and top=:top and bottom=:bottom " + + "and distanceVL=:distanceVL and distanceHF=:distanceHF " + + "and distanceVR=:distanceVR"); + query.setParameter("formationNum", formationNum); + query.setParameter("entry", e); + query.setParameter("top", top); + query.setParameter("bottom", bottom); + query.setParameter("distanceVL", distanceVL); + query.setParameter("distanceHF", distanceHF); + query.setParameter("distanceVR", distanceVR); + List<HYKFormation> formations = query.list(); + if (formations.isEmpty()) { + peer = new HYKFormation( + formationNum, e, top, bottom, + distanceVL, distanceHF, distanceVR); + session.save(peer); + } + else { + peer = formations.get(0); + } + } + return peer; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :