Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/model/sinfo/InfrastructureValue.java @ 9176:1614cb14308f
Work on calculations for S-Info flood duration workflow
author | mschaefer |
---|---|
date | Mon, 25 Jun 2018 19:21:11 +0200 |
parents | a165cd63099f |
children | d889ffe2fb05 |
comparison
equal
deleted
inserted
replaced
9175:34dc0163ad2d | 9176:1614cb14308f |
---|---|
20 import javax.persistence.Id; | 20 import javax.persistence.Id; |
21 import javax.persistence.JoinColumn; | 21 import javax.persistence.JoinColumn; |
22 import javax.persistence.OneToOne; | 22 import javax.persistence.OneToOne; |
23 import javax.persistence.SequenceGenerator; | 23 import javax.persistence.SequenceGenerator; |
24 import javax.persistence.Table; | 24 import javax.persistence.Table; |
25 import javax.persistence.Transient; | |
25 | 26 |
26 import org.dive4elements.river.backend.SessionHolder; | 27 import org.dive4elements.river.backend.SessionHolder; |
27 import org.dive4elements.river.model.Attribute; | 28 import org.dive4elements.river.model.Attribute; |
29 import org.dive4elements.river.model.Attribute.AttributeKey; | |
30 import org.dive4elements.river.model.River; | |
28 import org.hibernate.Query; | 31 import org.hibernate.Query; |
29 import org.hibernate.Session; | 32 import org.hibernate.Session; |
30 | 33 |
31 | 34 |
32 /** | 35 /** |
115 | 118 |
116 public void setAttribute(final Attribute attribute) { | 119 public void setAttribute(final Attribute attribute) { |
117 this.attribute = attribute; | 120 this.attribute = attribute; |
118 } | 121 } |
119 | 122 |
123 @Transient | |
124 public AttributeKey getAttributeKey() { | |
125 return this.getAttribute().getKey(); | |
126 } | |
127 | |
120 @Column(name = "height") | 128 @Column(name = "height") |
121 public Double getHeight() { | 129 public Double getHeight() { |
122 return this.height; | 130 return this.height; |
123 } | 131 } |
124 | 132 |
125 public void setHeight(final Double height) { | 133 public void setHeight(final Double height) { |
126 this.height = height; | 134 this.height = height; |
127 } | 135 } |
128 | 136 |
129 /** | 137 /** |
130 * Selects the infrastructure values of a data series in a km range from the database | 138 * Selects from the database the infrastructure values of a data series in a km range |
131 */ | 139 */ |
132 public static List<InfrastructureValue> getValues(final Infrastructure parent, final double kmLo, final double kmHi) { | 140 public static List<InfrastructureValue> getValues(final Infrastructure parent, final double kmLo, final double kmHi) { |
133 final Session session = SessionHolder.HOLDER.get(); | 141 final Session session = SessionHolder.HOLDER.get(); |
134 final Query query = session.createQuery("FROM InfrastructureValue WHERE (infrastructure=:parent)" | 142 final Query query = session.createQuery("FROM InfrastructureValue WHERE (infrastructure=:parent)" |
135 + " AND (station >= :kmLo - 0.0001) AND (station <= :kmHi + 0.0001)"); | 143 + " AND (station >= :kmLo - 0.0001) AND (station <= :kmHi + 0.0001)"); |
136 query.setParameter("parent", parent); | 144 query.setParameter("parent", parent); |
137 query.setParameter("kmLo", new Double(kmLo)); | 145 query.setParameter("kmLo", new Double(kmLo)); |
138 query.setParameter("kmHi", new Double(kmHi)); | 146 query.setParameter("kmHi", new Double(kmHi)); |
139 return query.list(); | 147 return query.list(); |
140 } | 148 } |
149 | |
150 /** | |
151 * Selects from the database the infrastructure values of a km range of a river and a river side | |
152 */ | |
153 public static List<InfrastructureValue> getValues(final River river, final double kmLo, final double kmHi, final AttributeKey riverside) { | |
154 final Session session = SessionHolder.HOLDER.get(); | |
155 String riversideClause = ""; | |
156 if ((riverside == AttributeKey.LEFT) || (riverside == AttributeKey.RIGHT)) | |
157 riversideClause = " AND (v.attribute.id=:attr_id)"; | |
158 final Query query = session.createQuery("FROM InfrastructureValue v" | |
159 + " WHERE (v.infrastructure.river=:river)" | |
160 + " AND (v.station BETWEEN :kmLo - 0.0001 AND :kmHi + 0.0001)" | |
161 + riversideClause | |
162 + " ORDER BY v.station, v.attribute.id"); | |
163 query.setParameter("river", river); | |
164 query.setParameter("kmLo", new Double(kmLo)); | |
165 query.setParameter("kmHi", new Double(kmHi)); | |
166 if (!riversideClause.isEmpty()) | |
167 query.setParameter("attr_id", riverside.getId()); | |
168 return query.list(); | |
169 } | |
141 } | 170 } |