comparison flys-backend/src/main/java/de/intevation/flys/model/CrossSection.java @ 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 31d8638760b1
children e237a08acf6e
comparison
equal deleted inserted replaced
2378:c5d83366d0b1 2379:8be27b950dbe
14 import javax.persistence.OneToOne; 14 import javax.persistence.OneToOne;
15 import javax.persistence.OneToMany; 15 import javax.persistence.OneToMany;
16 import javax.persistence.OrderBy; 16 import javax.persistence.OrderBy;
17 import javax.persistence.JoinColumn; 17 import javax.persistence.JoinColumn;
18 18
19 import java.math.MathContext;
20 import java.math.BigDecimal;
21
22 import org.hibernate.Session;
23 import org.hibernate.Query;
24
25 import de.intevation.flys.backend.SessionHolder;
26
19 @Entity 27 @Entity
20 @Table(name = "cross_sections") 28 @Table(name = "cross_sections")
21 public class CrossSection 29 public class CrossSection
22 implements Serializable 30 implements Serializable
23 { 31 {
32 public static final MathContext PRECISION = new MathContext(6);
33
24 private Integer id; 34 private Integer id;
25 private River river; 35 private River river;
26 private TimeInterval timeInterval; 36 private TimeInterval timeInterval;
27 private String description; 37 private String description;
28 private List<CrossSectionLine> lines; 38 private List<CrossSectionLine> lines;
94 } 104 }
95 105
96 public void setLines(List<CrossSectionLine> lines) { 106 public void setLines(List<CrossSectionLine> lines) {
97 this.lines = lines; 107 this.lines = lines;
98 } 108 }
109
110 public List<CrossSectionLine> getLines(double startKm, double endKm) {
111 Session session = SessionHolder.HOLDER.get();
112 Query query = session.createQuery(
113 "from CrossSectionLine where crossSection=:crossSection " +
114 "and km between :startKm and :endKm order by km");
115 query.setParameter("crossSection", this);
116 query.setParameter("startKm", new BigDecimal(startKm, PRECISION));
117 query.setParameter("endKm", new BigDecimal(endKm, PRECISION));
118
119 return query.list();
120 }
99 } 121 }
100 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 122 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org