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