changeset 2379:8be27b950dbe

CrossSection: Added method to extract the lines of a given km range. flys-backend/trunk@3688 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 16 Jan 2012 14:52:40 +0000
parents c5d83366d0b1
children e237a08acf6e
files flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/model/CrossSection.java
diffstat 2 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Mon Jan 16 14:16:52 2012 +0000
+++ b/flys-backend/ChangeLog	Mon Jan 16 14:52:40 2012 +0000
@@ -1,3 +1,9 @@
+2012-01-16	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/model/CrossSection.java(getLines):
+	  Added method to fetch the lines of a cross section in a given interval.
+	  Useful to have chunked access to the lines.
+
 2012-01-16	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/model/CrossSectionLine.java
--- a/flys-backend/src/main/java/de/intevation/flys/model/CrossSection.java	Mon Jan 16 14:16:52 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/CrossSection.java	Mon Jan 16 14:52:40 2012 +0000
@@ -16,11 +16,21 @@
 import javax.persistence.OrderBy;
 import javax.persistence.JoinColumn;
 
+import java.math.MathContext;
+import java.math.BigDecimal;
+
+import org.hibernate.Session;
+import org.hibernate.Query;
+
+import de.intevation.flys.backend.SessionHolder;
+
 @Entity
 @Table(name = "cross_sections")
 public class CrossSection
 implements   Serializable
 {
+    public static final MathContext PRECISION = new MathContext(6);
+
     private Integer                id;
     private River                  river;
     private TimeInterval           timeInterval;
@@ -96,5 +106,17 @@
     public void setLines(List<CrossSectionLine> lines) {
         this.lines = lines;
     }
+
+    public List<CrossSectionLine> getLines(double startKm, double endKm) {
+        Session session = SessionHolder.HOLDER.get();
+        Query query = session.createQuery(
+            "from CrossSectionLine where crossSection=:crossSection " +
+            "and km between :startKm and :endKm order by km");
+        query.setParameter("crossSection", this);
+        query.setParameter("startKm", new BigDecimal(startKm, PRECISION));
+        query.setParameter("endKm", new BigDecimal(endKm, PRECISION));
+
+        return query.list();
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org