Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/model/sinfo/InfrastructureValue.java @ 9624:02ca823ec9c6
zu Pos 20 Nachtrag; infrastructureChoice
author | dnt_bjoernsen <d.tironi@bjoernsen.de> |
---|---|
date | Fri, 11 Oct 2019 18:30:36 +0200 |
parents | 26e113e8224f |
children | 07f02019065e |
comparison
equal
deleted
inserted
replaced
9623:677ff7ed9a60 | 9624:02ca823ec9c6 |
---|---|
30 import org.dive4elements.river.model.Attribute.AttributeKey; | 30 import org.dive4elements.river.model.Attribute.AttributeKey; |
31 import org.dive4elements.river.model.River; | 31 import org.dive4elements.river.model.River; |
32 import org.hibernate.Query; | 32 import org.hibernate.Query; |
33 import org.hibernate.Session; | 33 import org.hibernate.Session; |
34 | 34 |
35 | |
36 /** | 35 /** |
37 * Hibernate binding for the DB table infrastructure_values | 36 * Hibernate binding for the DB table infrastructure_values |
38 * | 37 * |
39 * @author Matthias Schäfer | 38 * @author Matthias Schäfer |
40 * | 39 * |
55 | 54 |
56 private Attribute attribute; | 55 private Attribute attribute; |
57 | 56 |
58 private Double height; | 57 private Double height; |
59 | 58 |
60 | |
61 /***** CONSTRUCTORS *****/ | 59 /***** CONSTRUCTORS *****/ |
62 | 60 |
63 public InfrastructureValue() { | 61 public InfrastructureValue() { |
64 } | 62 } |
65 | 63 |
74 * Parameter constructor with primitive double km and height | 72 * Parameter constructor with primitive double km and height |
75 */ | 73 */ |
76 public InfrastructureValue(final Infrastructure infrastructure, final double km, final Attribute attribute, final double height) { | 74 public InfrastructureValue(final Infrastructure infrastructure, final double km, final Attribute attribute, final double height) { |
77 this(infrastructure, Double.valueOf(km), attribute, Double.valueOf(height)); | 75 this(infrastructure, Double.valueOf(km), attribute, Double.valueOf(height)); |
78 } | 76 } |
79 | |
80 | 77 |
81 /***** METHODS *****/ | 78 /***** METHODS *****/ |
82 | 79 |
83 @Id | 80 @Id |
84 @SequenceGenerator(name = "SEQUENCE_INFRASTRUCTURE_VALUE_ID_SEQ", sequenceName = "INFRASTRUCTURE_VALUES_ID_SEQ", allocationSize = 1) | 81 @SequenceGenerator(name = "SEQUENCE_INFRASTRUCTURE_VALUE_ID_SEQ", sequenceName = "INFRASTRUCTURE_VALUES_ID_SEQ", allocationSize = 1) |
138 /** | 135 /** |
139 * Selects from the database the infrastructure values of a data series in a km range | 136 * Selects from the database the infrastructure values of a data series in a km range |
140 */ | 137 */ |
141 public static List<InfrastructureValue> getValues(final Infrastructure parent, final double kmLo, final double kmHi) { | 138 public static List<InfrastructureValue> getValues(final Infrastructure parent, final double kmLo, final double kmHi) { |
142 final Session session = SessionHolder.HOLDER.get(); | 139 final Session session = SessionHolder.HOLDER.get(); |
143 final Query query = session.createQuery("FROM InfrastructureValue WHERE (infrastructure=:parent)" | 140 final Query query = session |
144 + " AND (station >= :kmLo - 0.0001) AND (station <= :kmHi + 0.0001)"); | 141 .createQuery("FROM InfrastructureValue WHERE (infrastructure=:parent)" + " AND (station >= :kmLo - 0.0001) AND (station <= :kmHi + 0.0001)"); |
145 query.setParameter("parent", parent); | 142 query.setParameter("parent", parent); |
146 query.setParameter("kmLo", new Double(kmLo)); | 143 query.setParameter("kmLo", new Double(kmLo)); |
147 query.setParameter("kmHi", new Double(kmHi)); | 144 query.setParameter("kmHi", new Double(kmHi)); |
148 return query.list(); | 145 return query.list(); |
149 } | 146 } |
152 * Selects from the database the infrastructure values of a km range of a river and a group/type/river-side selection | 149 * Selects from the database the infrastructure values of a km range of a river and a group/type/river-side selection |
153 */ | 150 */ |
154 public static List<InfrastructureValue> getValues(final River river, final double kmLo, final double kmHi, final AttributeKey riverside, | 151 public static List<InfrastructureValue> getValues(final River river, final double kmLo, final double kmHi, final AttributeKey riverside, |
155 final Set<String> groupTypes) { | 152 final Set<String> groupTypes) { |
156 final Session session = SessionHolder.HOLDER.get(); | 153 final Session session = SessionHolder.HOLDER.get(); |
157 final Query query = session.createQuery("FROM InfrastructureValue" | 154 final Query query = session |
158 + " WHERE (infrastructure.river=:river)" | 155 .createQuery("FROM InfrastructureValue" + " WHERE (infrastructure.river=:river)" + " AND (station BETWEEN :kmLo - 0.0001 AND :kmHi + 0.0001)" |
159 + " AND (station BETWEEN :kmLo - 0.0001 AND :kmHi + 0.0001)" | 156 + getRiversideClause(riverside, "", "attr_id") + getGroupTypeClause(groupTypes, "") + " ORDER BY station, attribute.id"); |
160 + getRiversideClause(riverside, "", "attr_id") | |
161 + getGroupTypeClause(groupTypes, "") | |
162 + " ORDER BY station, attribute.id"); | |
163 query.setParameter("river", river); | 157 query.setParameter("river", river); |
164 query.setParameter("kmLo", new Double(kmLo)); | 158 query.setParameter("kmLo", new Double(kmLo)); |
165 query.setParameter("kmHi", new Double(kmHi)); | 159 query.setParameter("kmHi", new Double(kmHi)); |
166 if (!getRiversideClause(riverside, "", "attr_id").isEmpty()) | 160 if (!getRiversideClause(riverside, "", "attr_id").isEmpty()) |
167 query.setParameter("attr_id", riverside.getId()); | 161 query.setParameter("attr_id", riverside.getId()); |
175 if (groupTypes.size() == 0) | 169 if (groupTypes.size() == 0) |
176 return ""; | 170 return ""; |
177 String clause = " AND ("; | 171 String clause = " AND ("; |
178 String sep = ""; | 172 String sep = ""; |
179 for (final String groupType : groupTypes) { | 173 for (final String groupType : groupTypes) { |
180 clause += sep + "(" + tableprefix + "infrastructure.group.name='" + groupType.split("\t")[0] + "'" | 174 clause += sep + "(" + tableprefix + "infrastructure.group.name='" + groupType.split("\t")[0] + "'" + " AND " + tableprefix |
181 + " AND " + tableprefix + "infrastructure.type.name='" + groupType.split("\t")[1] + "')"; | 175 + "infrastructure.type.name='" + groupType.split("\t")[1] + "')"; |
182 sep = " OR "; | 176 sep = " OR "; |
183 } | 177 } |
184 if (sep.length() >= 1) | 178 if (sep.length() >= 1) |
185 clause += ")"; | 179 clause += ")"; |
186 return clause; | 180 return clause; |