Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/model/Wst.java @ 468:8d76556c9616
Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
flys-backend/trunk@1705 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 15 Apr 2011 13:45:06 +0000 |
parents | c8c09e31cdb8 |
children | b5ca22aae092 |
comparison
equal
deleted
inserted
replaced
467:c8c09e31cdb8 | 468:8d76556c9616 |
---|---|
1 package de.intevation.flys.model; | 1 package de.intevation.flys.model; |
2 | 2 |
3 import java.io.Serializable; | 3 import java.io.Serializable; |
4 import java.math.BigDecimal; | |
5 import java.util.List; | |
4 | 6 |
5 import javax.persistence.Entity; | 7 import javax.persistence.Entity; |
6 import javax.persistence.Id; | 8 import javax.persistence.Id; |
7 import javax.persistence.Table; | 9 import javax.persistence.Table; |
8 import javax.persistence.GeneratedValue; | 10 import javax.persistence.GeneratedValue; |
10 import javax.persistence.SequenceGenerator; | 12 import javax.persistence.SequenceGenerator; |
11 import javax.persistence.GenerationType; | 13 import javax.persistence.GenerationType; |
12 import javax.persistence.JoinColumn; | 14 import javax.persistence.JoinColumn; |
13 import javax.persistence.OneToOne; | 15 import javax.persistence.OneToOne; |
14 | 16 |
17 import org.apache.log4j.Logger; | |
18 | |
19 import org.hibernate.Session; | |
20 import org.hibernate.Query; | |
21 | |
22 import de.intevation.flys.backend.SessionHolder; | |
23 | |
24 | |
15 @Entity | 25 @Entity |
16 @Table(name = "wsts") | 26 @Table(name = "wsts") |
17 public class Wst | 27 public class Wst |
18 implements Serializable | 28 implements Serializable |
19 { | 29 { |
30 private static Logger logger = Logger.getLogger(Wst.class); | |
31 | |
20 private Integer id; | 32 private Integer id; |
21 private River river; | 33 private River river; |
22 private String description; | 34 private String description; |
23 private Integer kind; | 35 private Integer kind; |
24 | 36 |
77 } | 89 } |
78 | 90 |
79 public void setKind(Integer kind) { | 91 public void setKind(Integer kind) { |
80 this.kind = kind; | 92 this.kind = kind; |
81 } | 93 } |
94 | |
95 | |
96 /** | |
97 * Determines the min and max Q values of this WST. The min value is placed | |
98 * in the first field of the resulting array - the max value is placed in | |
99 * the second field. | |
100 * | |
101 * @return the min and max Q values of this WST. | |
102 */ | |
103 public double[] determineMinMaxQ() { | |
104 double[] ab = river.determineMinMaxDistance(); | |
105 return determineMinMaxQ(new Range(ab[0], ab[1], river)); | |
106 } | |
107 | |
108 | |
109 /** | |
110 * Determines the min and max Q values of this WST in the given range. The | |
111 * min value is placed in the first field of the resulting array - the max | |
112 * value is placed in the second field. | |
113 * | |
114 * @param range The range used for querying the Q values. | |
115 * | |
116 * @return the min and max Q values of this WST. | |
117 */ | |
118 public double[] determineMinMaxQ(Range range) { | |
119 Session session = SessionHolder.HOLDER.get(); | |
120 | |
121 Query query = session.createQuery( | |
122 "select min(q), max(q) from WstQRange where " + | |
123 " id in " + | |
124 " (select wstQRange.id from WstColumnQRange where " + | |
125 " wstColumn.id in (select id from WstColumn where wst.id = :wst)) " + | |
126 " and range.id in " + | |
127 " (select id from Range where not (a > :end or b < :start))"); | |
128 | |
129 query.setParameter("wst", getId()); | |
130 query.setParameter("start", range.getA()); | |
131 query.setParameter("end", range.getB()); | |
132 | |
133 List results = query.list(); | |
134 Object[] result = (Object[]) results.get(0); | |
135 | |
136 return result != null | |
137 ? new double[] { | |
138 ((BigDecimal) result[0]).doubleValue(), | |
139 ((BigDecimal) result[1]).doubleValue() } | |
140 : null; | |
141 } | |
82 } | 142 } |
83 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 143 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |