changeset 2871:5a89c2b05e6d

Added functions to retrieve data from database. flys-backend/trunk@4409 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 15 May 2012 14:19:55 +0000
parents 28526b0b0a90
children bcfdaa3a5bfc
files flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/model/DischargeZone.java flys-backend/src/main/java/de/intevation/flys/model/FlowVelocityModel.java flys-backend/src/main/java/de/intevation/flys/model/FlowVelocityModelValue.java
diffstat 4 files changed, 69 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 <ingo@intevation.de>
+
+	* 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 <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/model/DischargeZone.java: Added a
--- 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<DischargeZone> zones = query.list();
+
+        return zones.isEmpty() ? null : zones.get(0);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- 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<FlowVelocityModel> 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 :
--- 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<FlowVelocityModelValue> 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 :

http://dive4elements.wald.intevation.org