annotate backend/src/main/java/org/dive4elements/river/model/Wst.java @ 8973:35afa0349782

New field wsts.sinfo_selection
author mschaefer
date Tue, 03 Apr 2018 10:29:57 +0200
parents 5e38e2924c07
children
rev   line source
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5992
4c3ccf2b0304 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5850
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5992
4c3ccf2b0304 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5850
diff changeset
6 * documentation coming with Dive4Elements River for details.
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
9 package org.dive4elements.river.model;
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 import java.io.Serializable;
468
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
12 import java.math.BigDecimal;
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
13 import java.util.List;
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14
171
4a83e14f40f9 Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
15 import javax.persistence.Column;
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
16 import javax.persistence.Entity;
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
17 import javax.persistence.GeneratedValue;
171
4a83e14f40f9 Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
18 import javax.persistence.GenerationType;
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
19 import javax.persistence.Id;
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 172
diff changeset
20 import javax.persistence.JoinColumn;
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
21 import javax.persistence.OneToMany;
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 172
diff changeset
22 import javax.persistence.OneToOne;
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
23 import javax.persistence.SequenceGenerator;
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
24 import javax.persistence.Table;
171
4a83e14f40f9 Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
25
468
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
26 import org.apache.log4j.Logger;
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
27 import org.dive4elements.river.backend.SessionHolder;
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
28 import org.hibernate.Query;
2374
ab1e642e7c85 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2372
diff changeset
29 import org.hibernate.SQLQuery;
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
30 import org.hibernate.Session;
2374
ab1e642e7c85 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2372
diff changeset
31 import org.hibernate.type.StandardBasicTypes;
468
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
32
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
33
6555
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5992
diff changeset
34 /** DB-mapped WST. */
171
4a83e14f40f9 Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
35 @Entity
4a83e14f40f9 Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
36 @Table(name = "wsts")
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 public class Wst
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 implements Serializable
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 {
8200
9d2e69f971f5 sed -i src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6555
diff changeset
40 private static Logger log = Logger.getLogger(Wst.class);
468
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
41
171
4a83e14f40f9 Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
42 private Integer id;
4a83e14f40f9 Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
43 private River river;
4a83e14f40f9 Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
44 private String description;
467
c8c09e31cdb8 Added new column 'kind' in discharge tables and wst to distinguish between different types.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 201
diff changeset
45 private Integer kind;
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
46 private String sinfo_selection;
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47
475
9aa0eddc5221 Add forgotten one to many relation Wst -> WstColumn.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 469
diff changeset
48 private List<WstColumn> columns;
9aa0eddc5221 Add forgotten one to many relation Wst -> WstColumn.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 469
diff changeset
49
2374
ab1e642e7c85 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2372
diff changeset
50
ab1e642e7c85 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2372
diff changeset
51 public static final String SQL_SELECT_MINMAX =
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
52 "select min(q) as minQ, max(q) as maxQ from wst_q_values " +
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
53 "where wst_id = :wst and not (a > :km or b < :km)";
2374
ab1e642e7c85 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2372
diff changeset
54
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 public Wst() {
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 }
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
58 public Wst(final River river, final String description) {
2347
0acf28a3d28a Removed the Unit from Wsts - added a WstUnit column to rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2346
diff changeset
59 this(river, description, 0);
467
c8c09e31cdb8 Added new column 'kind' in discharge tables and wst to distinguish between different types.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 201
diff changeset
60 }
c8c09e31cdb8 Added new column 'kind' in discharge tables and wst to distinguish between different types.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 201
diff changeset
61
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
62 public Wst(final River river, final String description, final Integer kind) {
201
3169b559ca3c Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
63 this.river = river;
3169b559ca3c Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
64 this.description = description;
467
c8c09e31cdb8 Added new column 'kind' in discharge tables and wst to distinguish between different types.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 201
diff changeset
65 this.kind = kind;
201
3169b559ca3c Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
66 }
3169b559ca3c Build models for wsts, wst columns and q ranges and store them in the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
67
171
4a83e14f40f9 Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
68 @Id
4a83e14f40f9 Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
69 @SequenceGenerator(
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
70 name = "SEQUENCE_WSTS_ID_SEQ",
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
71 sequenceName = "WSTS_ID_SEQ",
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
72 allocationSize = 1)
171
4a83e14f40f9 Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
73 @GeneratedValue(
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
74 strategy = GenerationType.SEQUENCE,
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
75 generator = "SEQUENCE_WSTS_ID_SEQ")
171
4a83e14f40f9 Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
76 @Column(name = "id")
4a83e14f40f9 Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
77 public Integer getId() {
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
78 return this.id;
171
4a83e14f40f9 Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
79 }
4a83e14f40f9 Added entity and id annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
80
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
81 public void setId(final Integer id) {
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 this.id = id;
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83 }
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 172
diff changeset
85 @OneToOne
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 172
diff changeset
86 @JoinColumn(name = "river_id" )
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 172
diff changeset
87 public River getRiver() {
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
88 return this.river;
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 172
diff changeset
89 }
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 172
diff changeset
90
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
91 public void setRiver(final River river) {
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 this.river = river;
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 }
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94
172
605320b7df94 Added column annotations for simple fields. TODO: foreign keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
95 @Column(name = "description")
605320b7df94 Added column annotations for simple fields. TODO: foreign keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
96 public String getDescription() {
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
97 return this.description;
172
605320b7df94 Added column annotations for simple fields. TODO: foreign keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
98 }
605320b7df94 Added column annotations for simple fields. TODO: foreign keys.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
99
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
100 public void setDescription(final String description) {
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 this.description = description;
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 }
467
c8c09e31cdb8 Added new column 'kind' in discharge tables and wst to distinguish between different types.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 201
diff changeset
103
c8c09e31cdb8 Added new column 'kind' in discharge tables and wst to distinguish between different types.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 201
diff changeset
104 @Column(name = "kind")
c8c09e31cdb8 Added new column 'kind' in discharge tables and wst to distinguish between different types.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 201
diff changeset
105 public Integer getKind() {
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
106 return this.kind;
467
c8c09e31cdb8 Added new column 'kind' in discharge tables and wst to distinguish between different types.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 201
diff changeset
107 }
c8c09e31cdb8 Added new column 'kind' in discharge tables and wst to distinguish between different types.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 201
diff changeset
108
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
109 public void setKind(final Integer kind) {
467
c8c09e31cdb8 Added new column 'kind' in discharge tables and wst to distinguish between different types.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 201
diff changeset
110 this.kind = kind;
c8c09e31cdb8 Added new column 'kind' in discharge tables and wst to distinguish between different types.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 201
diff changeset
111 }
468
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
112
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
113 @Column(name = "sinfo_selection")
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
114 public String getSInfoSelection() {
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
115 return this.sinfo_selection;
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
116 }
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
117
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
118 public void setSInfoSelection(final String sinfoSelection) {
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
119 this.sinfo_selection = sinfoSelection;
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
120 }
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
121
475
9aa0eddc5221 Add forgotten one to many relation Wst -> WstColumn.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 469
diff changeset
122 @OneToMany
9aa0eddc5221 Add forgotten one to many relation Wst -> WstColumn.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 469
diff changeset
123 @JoinColumn(name="wst_id")
9aa0eddc5221 Add forgotten one to many relation Wst -> WstColumn.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 469
diff changeset
124 public List<WstColumn> getColumns() {
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
125 return this.columns;
475
9aa0eddc5221 Add forgotten one to many relation Wst -> WstColumn.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 469
diff changeset
126 }
9aa0eddc5221 Add forgotten one to many relation Wst -> WstColumn.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 469
diff changeset
127
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
128 public void setColumns(final List<WstColumn> columns) {
475
9aa0eddc5221 Add forgotten one to many relation Wst -> WstColumn.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 469
diff changeset
129 this.columns = columns;
9aa0eddc5221 Add forgotten one to many relation Wst -> WstColumn.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 469
diff changeset
130 }
468
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
131
2346
f834b411ca57 Added db table, model class and importer stuff for units.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 475
diff changeset
132
468
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
133 /**
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
134 * Determines the min and max Q values of this WST. The min value is placed
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
135 * in the first field of the resulting array - the max value is placed in
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
136 * the second field.
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
137 *
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
138 * @return the min and max Q values of this WST.
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
139 */
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
140 public double[] determineMinMaxQ() {
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
141 final double[] ab = this.river.determineMinMaxDistance();
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
142 return determineMinMaxQ(new Range(ab[0], ab[1], this.river));
468
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
143 }
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
144
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
145
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
146 /**
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
147 * Determines the min and max Q values of this WST in the given range. The
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
148 * min value is placed in the first field of the resulting array - the max
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
149 * value is placed in the second field.
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
150 *
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
151 * @param range The range used for querying the Q values.
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
152 *
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
153 * @return the min and max Q values of this WST.
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
154 */
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
155 public double[] determineMinMaxQ(final Range range) {
2372
027736510a30 Added a new method Wst.determineMinMaxQ(double,double).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2347
diff changeset
156 if (range != null) {
027736510a30 Added a new method Wst.determineMinMaxQ(double,double).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2347
diff changeset
157 return determineMinMaxQ(
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
158 range.getA().doubleValue(),
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
159 range.getB().doubleValue());
2372
027736510a30 Added a new method Wst.determineMinMaxQ(double,double).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2347
diff changeset
160 }
027736510a30 Added a new method Wst.determineMinMaxQ(double,double).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2347
diff changeset
161
027736510a30 Added a new method Wst.determineMinMaxQ(double,double).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2347
diff changeset
162 return null;
027736510a30 Added a new method Wst.determineMinMaxQ(double,double).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2347
diff changeset
163 }
027736510a30 Added a new method Wst.determineMinMaxQ(double,double).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2347
diff changeset
164
027736510a30 Added a new method Wst.determineMinMaxQ(double,double).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2347
diff changeset
165
027736510a30 Added a new method Wst.determineMinMaxQ(double,double).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2347
diff changeset
166 /**
027736510a30 Added a new method Wst.determineMinMaxQ(double,double).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2347
diff changeset
167 * Determines the min and max Q values of this WST in the given range. The
027736510a30 Added a new method Wst.determineMinMaxQ(double,double).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2347
diff changeset
168 * min value is placed in the first field of the resulting array - the max
027736510a30 Added a new method Wst.determineMinMaxQ(double,double).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2347
diff changeset
169 * value is placed in the second field.
027736510a30 Added a new method Wst.determineMinMaxQ(double,double).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2347
diff changeset
170 *
027736510a30 Added a new method Wst.determineMinMaxQ(double,double).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2347
diff changeset
171 * @param fromKm the lower km value.
027736510a30 Added a new method Wst.determineMinMaxQ(double,double).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2347
diff changeset
172 * @param toKm the upper km value.
027736510a30 Added a new method Wst.determineMinMaxQ(double,double).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2347
diff changeset
173 *
027736510a30 Added a new method Wst.determineMinMaxQ(double,double).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2347
diff changeset
174 * @return the min and max Q values of this WST.
027736510a30 Added a new method Wst.determineMinMaxQ(double,double).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2347
diff changeset
175 */
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
176 public double[] determineMinMaxQ(final double fromKm, final double toKm) {
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
177 final Session session = SessionHolder.HOLDER.get();
468
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
178
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
179 final Query query = session.createQuery(
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
180 "select min(q), max(q) from WstQRange where "
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
181 + "id in "
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
182 + " (select wstQRange.id from WstColumnQRange where "
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
183 + " wstColumn.id in (select id from WstColumn where wst.id = :wst)) "
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
184 + "and range.id in "
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
185 + " (select id from Range where not (a > :end or b < :start))");
468
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
186
469
b5ca22aae092 Fixed index problem when an empty list is returned.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 468
diff changeset
187 query.setParameter("wst", getId());
2372
027736510a30 Added a new method Wst.determineMinMaxQ(double,double).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2347
diff changeset
188 query.setParameter("start", new BigDecimal(fromKm));
027736510a30 Added a new method Wst.determineMinMaxQ(double,double).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2347
diff changeset
189 query.setParameter("end", new BigDecimal(toKm));
468
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
190
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
191 final List<Object []> results = query.list();
468
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
192
469
b5ca22aae092 Fixed index problem when an empty list is returned.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 468
diff changeset
193 if (results.isEmpty()) {
b5ca22aae092 Fixed index problem when an empty list is returned.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 468
diff changeset
194 return null;
b5ca22aae092 Fixed index problem when an empty list is returned.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 468
diff changeset
195 }
b5ca22aae092 Fixed index problem when an empty list is returned.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 468
diff changeset
196
5850
df5d29987df8 Wst: Avoid NPE.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5844
diff changeset
197 if (results.get(0)[0] == null || results.get(0)[1] == null) {
8200
9d2e69f971f5 sed -i src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6555
diff changeset
198 log.warn("Could not process result from min/maxQ query.");
5850
df5d29987df8 Wst: Avoid NPE.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5844
diff changeset
199 return null;
df5d29987df8 Wst: Avoid NPE.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5844
diff changeset
200 }
df5d29987df8 Wst: Avoid NPE.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5844
diff changeset
201
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
202 final Object [] result = results.get(0);
469
b5ca22aae092 Fixed index problem when an empty list is returned.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 468
diff changeset
203
b5ca22aae092 Fixed index problem when an empty list is returned.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 468
diff changeset
204 return new double [] {
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
205 ((BigDecimal)result[0]).doubleValue(),
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
206 ((BigDecimal)result[1]).doubleValue() };
468
8d76556c9616 Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 467
diff changeset
207 }
2374
ab1e642e7c85 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2372
diff changeset
208
ab1e642e7c85 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2372
diff changeset
209
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
210 public double[] determineMinMaxQFree(final double km) {
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
211 final Session session = SessionHolder.HOLDER.get();
2374
ab1e642e7c85 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2372
diff changeset
212
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
213 final SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_MINMAX)
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
214 .addScalar("minQ", StandardBasicTypes.DOUBLE)
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
215 .addScalar("maxQ", StandardBasicTypes.DOUBLE);
2374
ab1e642e7c85 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2372
diff changeset
216
ab1e642e7c85 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2372
diff changeset
217 sqlQuery.setInteger("wst", getId());
ab1e642e7c85 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2372
diff changeset
218 sqlQuery.setDouble("km", km);
ab1e642e7c85 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2372
diff changeset
219
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
220 final List<Object[]> minmaxQ = sqlQuery.list();
2374
ab1e642e7c85 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2372
diff changeset
221
2794
3c26e16ae6c2 Fix or workaround flys/issue632, avoid NPE.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2374
diff changeset
222
2374
ab1e642e7c85 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2372
diff changeset
223 if (minmaxQ.isEmpty()) {
ab1e642e7c85 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2372
diff changeset
224 return null;
ab1e642e7c85 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2372
diff changeset
225 }
ab1e642e7c85 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2372
diff changeset
226
8973
35afa0349782 New field wsts.sinfo_selection
mschaefer
parents: 8856
diff changeset
227 final Object[] mm = minmaxQ.get(0);
2374
ab1e642e7c85 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2372
diff changeset
228
2794
3c26e16ae6c2 Fix or workaround flys/issue632, avoid NPE.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2374
diff changeset
229 if (mm[0] == null || mm[1] == null) {
8842
ff27548d078c Whitespace cosmetics.
Tom Gottfried <tom@intevation.de>
parents: 8200
diff changeset
230 log.warn("No min/max Q for km " + km + " found.");
2794
3c26e16ae6c2 Fix or workaround flys/issue632, avoid NPE.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2374
diff changeset
231 return null;
3c26e16ae6c2 Fix or workaround flys/issue632, avoid NPE.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2374
diff changeset
232 }
3c26e16ae6c2 Fix or workaround flys/issue632, avoid NPE.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2374
diff changeset
233
2374
ab1e642e7c85 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2372
diff changeset
234 return new double[] { (Double) mm[0], (Double) mm[1] };
ab1e642e7c85 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2372
diff changeset
235 }
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
236 }
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
237 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org