# HG changeset patch # User Ingo Weinzierl # Date 1337091595 0 # Node ID 5a89c2b05e6da13ffecc55ab2bf1e9523b878ea0 # Parent 28526b0b0a900f27fd38a719f5c86a6bf8136069 Added functions to retrieve data from database. flys-backend/trunk@4409 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 28526b0b0a90 -r 5a89c2b05e6d flys-backend/ChangeLog --- a/flys-backend/ChangeLog Tue May 15 07:06:31 2012 +0000 +++ b/flys-backend/ChangeLog Tue May 15 14:19:55 2012 +0000 @@ -1,3 +1,10 @@ +2012-05-15 Ingo Weinzierl + + * src/main/java/de/intevation/flys/model/FlowVelocityModel.java, + src/main/java/de/intevation/flys/model/FlowVelocityModelValue.java, + src/main/java/de/intevation/flys/model/DischargeZone.java: Added static + functions to retrieve data from database. + 2012-05-15 Ingo Weinzierl * src/main/java/de/intevation/flys/model/DischargeZone.java: Added a diff -r 28526b0b0a90 -r 5a89c2b05e6d flys-backend/src/main/java/de/intevation/flys/model/DischargeZone.java --- a/flys-backend/src/main/java/de/intevation/flys/model/DischargeZone.java Tue May 15 07:06:31 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/DischargeZone.java Tue May 15 14:19:55 2012 +0000 @@ -134,5 +134,19 @@ return query.list(); } + + + public static DischargeZone getDischargeZoneById(int id) { + Session session = SessionHolder.HOLDER.get(); + + Query query = session.createQuery( + "from DischargeZone where id=:id"); + + query.setParameter("id", id); + + List zones = query.list(); + + return zones.isEmpty() ? null : zones.get(0); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 28526b0b0a90 -r 5a89c2b05e6d flys-backend/src/main/java/de/intevation/flys/model/FlowVelocityModel.java --- a/flys-backend/src/main/java/de/intevation/flys/model/FlowVelocityModel.java Tue May 15 07:06:31 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/FlowVelocityModel.java Tue May 15 14:19:55 2012 +0000 @@ -13,8 +13,13 @@ import javax.persistence.JoinColumn; import javax.persistence.OneToOne; +import org.hibernate.Session; +import org.hibernate.Query; + import org.apache.log4j.Logger; +import de.intevation.flys.backend.SessionHolder; + @Entity @Table(name = "flow_velocity_model") @@ -99,5 +104,21 @@ public void setDescription(String description) { this.description = description; } + + + public static List getModels( + River river, + DischargeZone zone + ) { + Session session = SessionHolder.HOLDER.get(); + + Query query = session.createQuery( + "from FlowVelocityModel where river=:river and dischargeZone=:zone"); + + query.setParameter("river", river); + query.setParameter("zone", zone); + + return query.list(); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 28526b0b0a90 -r 5a89c2b05e6d flys-backend/src/main/java/de/intevation/flys/model/FlowVelocityModelValue.java --- a/flys-backend/src/main/java/de/intevation/flys/model/FlowVelocityModelValue.java Tue May 15 07:06:31 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/FlowVelocityModelValue.java Tue May 15 14:19:55 2012 +0000 @@ -2,6 +2,7 @@ import java.io.Serializable; import java.math.BigDecimal; +import java.util.List; import javax.persistence.Entity; import javax.persistence.Id; @@ -13,8 +14,13 @@ import javax.persistence.JoinColumn; import javax.persistence.OneToOne; +import org.hibernate.Session; +import org.hibernate.Query; + import org.apache.log4j.Logger; +import de.intevation.flys.backend.SessionHolder; + @Entity @Table(name = "flow_velocity_model_values") @@ -127,5 +133,26 @@ public void setShearStress(BigDecimal shearStress) { this.shearStress = shearStress; } + + + public static List getValues( + FlowVelocityModel model, + double kmLo, + double kmHi + ) { + Session session = SessionHolder.HOLDER.get(); + + Query query = session.createQuery( + "from FlowVelocityModelValue where " + + " flowVelocity=:model and" + + " station >= :kmLo and " + + " station <= :kmHi"); + + query.setParameter("model", model); + query.setParameter("kmLo", new BigDecimal(kmLo)); + query.setParameter("kmHi", new BigDecimal(kmHi)); + + return query.list(); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :