Mercurial > dive4elements > river
diff flys-backend/src/main/java/de/intevation/flys/importer/ImportHYKFlowZone.java @ 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 | |
children | 979ff070e368 |
line wrap: on
line diff
--- /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 :