# HG changeset patch # User Ingo Weinzierl # Date 1314776819 0 # Node ID 324cb486db9f06e2a72b35946c891bd3072d1dc5 # Parent 47ce1fab846471cb446d6ae847e76957ea710458 Added relation and hibernate classes for DGMs. flys-backend/trunk@2613 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 47ce1fab8464 -r 324cb486db9f flys-backend/ChangeLog --- a/flys-backend/ChangeLog Tue Aug 30 15:14:59 2011 +0000 +++ b/flys-backend/ChangeLog Wed Aug 31 07:46:59 2011 +0000 @@ -1,3 +1,15 @@ +2011-08-31 Ingo Weinzierl + + * doc/schema/postgresql-spatial.sql: Added a relation for DGMs. Note, that + no data of the DGM is stored in this relation, but only the file path to + the DGM file. + + * src/main/java/de/intevation/flys/model/DGM.java: New. This class provides + information for a DGM (km range and file path). + + * src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java: + Registered the DGM. + 2011-08-30 Ingo Weinzierl * src/main/java/de/intevation/flys/model/CrossSectionTrack.java: New diff -r 47ce1fab8464 -r 324cb486db9f flys-backend/doc/schema/postgresql-spatial.sql --- a/flys-backend/doc/schema/postgresql-spatial.sql Tue Aug 30 15:14:59 2011 +0000 +++ b/flys-backend/doc/schema/postgresql-spatial.sql Wed Aug 31 07:46:59 2011 +0000 @@ -47,4 +47,15 @@ ); SELECT AddGeometryColumn('fixpoints', 'geom', 31466, 'POINT', 2); + +CREATE TABLE dgm ( + id SERIAL PRIMARY KEY NOT NULL, + river_id int REFERENCES rivers(id), + -- XXX Should we use the ranges table instead? + lower NUMERIC, + upper NUMERIC, + path VARCHAR(256), + UNIQUE (river_id, lower, upper) +); + END; diff -r 47ce1fab8464 -r 324cb486db9f flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java --- a/flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java Tue Aug 30 15:14:59 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/backend/SessionFactoryProvider.java Wed Aug 31 07:46:59 2011 +0000 @@ -17,6 +17,7 @@ import de.intevation.flys.model.CrossSectionLine; import de.intevation.flys.model.CrossSectionPoint; import de.intevation.flys.model.CrossSectionTrack; +import de.intevation.flys.model.DGM; import de.intevation.flys.model.DischargeTable; import de.intevation.flys.model.DischargeTableValue; import de.intevation.flys.model.Edge; @@ -157,6 +158,7 @@ cfg.addAnnotatedClass(CrossSectionLine.class); cfg.addAnnotatedClass(CrossSectionPoint.class); cfg.addAnnotatedClass(CrossSectionTrack.class); + cfg.addAnnotatedClass(DGM.class); cfg.addAnnotatedClass(DischargeTable.class); cfg.addAnnotatedClass(DischargeTableValue.class); cfg.addAnnotatedClass(Edge.class); diff -r 47ce1fab8464 -r 324cb486db9f flys-backend/src/main/java/de/intevation/flys/model/DGM.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/DGM.java Wed Aug 31 07:46:59 2011 +0000 @@ -0,0 +1,102 @@ +package de.intevation.flys.model; + +import java.io.Serializable; +import java.util.List; +import java.math.BigDecimal; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +import org.hibernate.Session; +import org.hibernate.Query; + +import de.intevation.flys.backend.SessionHolder; + + +@Entity +@Table(name = "dgm") +public class DGM implements Serializable { + + private Integer id; + + private River river; + + private BigDecimal lower; + private BigDecimal upper; + + private String path; + + + public DGM() { + } + + + public void setId(Integer id) { + this.id = id; + } + + @Id + @Column(name = "id") + public Integer getId() { + return id; + } + + public void setRiver(River river) { + this.river = river; + } + + @OneToOne + @JoinColumn(name = "river_id") + public River getRiver() { + return river; + } + + public void setLower(BigDecimal lower) { + this.lower = lower; + } + + @Column(name = "lower") + public BigDecimal getLower() { + return lower; + } + + public void setUpper(BigDecimal upper) { + this.upper = upper; + } + + @Column(name = "upper") + public BigDecimal getUpper() { + return upper; + } + + public void setPath(String path) { + this.path = path; + } + + @Column(name = "path") + public String getPath() { + return path; + } + + + public static DGM getDGM(String river, double lower, double upper) { + Session session = SessionHolder.HOLDER.get(); + + Query query = session.createQuery( + "from DGM where river.name =:river and " + + "lower <=:lower and upper >=:lower and " + + "lower <=:upper and upper >=:upper"); + query.setParameter("river", river); + query.setParameter("lower", new BigDecimal(lower)); + query.setParameter("upper", new BigDecimal(upper)); + + List result = query.list(); + + return result.isEmpty() ? null : result.get(0); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :