Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/model/River.java @ 472:1e196c75563b
Added a new method to determine the selected gauge of a river based on a start and end point.
flys-backend/trunk@1711 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 18 Apr 2011 07:29:05 +0000 |
parents | c2c3ad4fda58 |
children | b316d2106598 |
comparison
equal
deleted
inserted
replaced
471:3570e4af8cb2 | 472:1e196c75563b |
---|---|
13 import javax.persistence.OneToMany; | 13 import javax.persistence.OneToMany; |
14 import javax.persistence.JoinColumn; | 14 import javax.persistence.JoinColumn; |
15 import javax.persistence.GenerationType; | 15 import javax.persistence.GenerationType; |
16 | 16 |
17 import java.util.List; | 17 import java.util.List; |
18 | |
19 import org.hibernate.Session; | |
20 import org.hibernate.Query; | |
21 | |
22 import de.intevation.flys.backend.SessionHolder; | |
23 | |
18 | 24 |
19 @Entity | 25 @Entity |
20 @Table(name = "rivers") | 26 @Table(name = "rivers") |
21 public class River | 27 public class River |
22 implements Serializable | 28 implements Serializable |
72 | 78 |
73 public String toString() { | 79 public String toString() { |
74 return name != null ? name : ""; | 80 return name != null ? name : ""; |
75 } | 81 } |
76 | 82 |
83 | |
84 /** | |
85 * This method returns the first gauge that is intersected by <i>a</i> and | |
86 * <i>b</i>, | |
87 * | |
88 * @param a A start point. | |
89 * @param b An end point. | |
90 * | |
91 * @return the first intersecting gauge. | |
92 */ | |
93 public Gauge determineGauge(double a, double b) { | |
94 Session session = SessionHolder.HOLDER.get(); | |
95 | |
96 Query query = session.createQuery( | |
97 "from Gauge where river=:river " + | |
98 "and not (range.a > :b or range.b < :a) order by a"); | |
99 query.setParameter("river", this); | |
100 query.setParameter("a", new BigDecimal(a)); | |
101 query.setParameter("b", new BigDecimal(b)); | |
102 | |
103 List<Gauge> gauges = query.list(); | |
104 | |
105 return gauges != null && gauges.size() > 0 ? gauges.get(0) : null; | |
106 } | |
107 | |
77 /** | 108 /** |
78 * Returns the min and max distance of this river. The first position in the | 109 * Returns the min and max distance of this river. The first position in the |
79 * resulting array contains the min distance, the second position the max | 110 * resulting array contains the min distance, the second position the max |
80 * distance. | 111 * distance. |
81 * | 112 * |