annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java @ 326:07eba6d3b4a5

Fetches w/q value tables from the backend. flys-artifacts/trunk@1722 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 18 Apr 2011 14:40:35 +0000
parents
children e09634fbf6bc
rev   line source
326
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.model;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import java.io.Serializable;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 import de.intevation.flys.model.River;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import de.intevation.flys.model.Wst;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 import de.intevation.flys.model.WstColumn;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 import de.intevation.flys.backend.SessionHolder;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 import java.util.ArrayList;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 import java.util.Comparator;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 import java.util.List;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 import java.util.Collections;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 import java.util.Iterator;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 import org.hibernate.Session;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 import org.hibernate.Query;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 import org.hibernate.SQLQuery;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 import org.hibernate.type.StandardBasicTypes;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 public class WstValueTable
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 implements Serializable
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 // TODO: put this into a property file
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 public static final String SQL_POS_WQ =
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 "SELECT wcv.position AS position," +
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 " w," +
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 " (SELECT q" +
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 " FROM wst_column_q_ranges wcqr" +
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 " JOIN wst_q_ranges wqr" +
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 " ON wcqr.wst_q_range_id = wqr.id" +
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 " JOIN ranges r" +
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 " ON r.id = wqr.range_id" +
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 " WHERE wcqr.wst_column_id = wc.id" +
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 " AND wcv.position BETWEEN r.a AND r.b) AS q," +
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 " wc.position AS column_pos " +
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 "FROM wst_column_values wcv" +
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 " JOIN wst_columns wc" +
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 " ON wcv.wst_column_id = wc.id" +
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 " JOIN wsts w" +
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 " ON wc.wst_id = w.id " +
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 "WHERE w.id = :wst_id" +
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 "ORDER BY wcv.position ASC," +
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 " wc.position DESC";
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 public static class Column
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 implements Serializable
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 protected String name;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 public Column() {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 public Column(String name) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 this.name = name;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 public String getName() {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 return name;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 public void setName(String name) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 this.name = name;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 // class Column
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 public static class Row
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 implements Serializable
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 double km;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 double [] wq;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 public Row() {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 public Row(double km, double [] wq) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 this.km = km;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 this.wq = wq;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 // class Row
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 protected List<Row> rows;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 protected Column [] columns;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 public WstValueTable() {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 rows = new ArrayList<Row>();
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 public WstValueTable(Column [] columns) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 this();
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 this.columns = columns;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 public static WstValueTable getTable(River river) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 return getTable(river, 0);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 public static WstValueTable getTable(River river, int kind) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 Session session = SessionHolder.HOLDER.get();
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 Query query = session.createQuery(
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 "from Wst where river=:river and kind=:kind");
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 query.setParameter("river", river);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 query.setInteger("kind", kind);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113 List<Wst> wsts = query.list();
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
115 if (wsts.isEmpty()) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
116 return null;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
118
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
119 Wst wst = wsts.get(0);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
121 // TODO: Do this sorting at database level
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
122 List<WstColumn> wstColumns = new ArrayList(wst.getColumns());
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
123 Collections.sort(wstColumns, new Comparator<WstColumn>() {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
124 public int compare(WstColumn a, WstColumn b) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
125 int pa = a.getPosition();
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
126 int pb = b.getPosition();
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
127 if (pa < pb) return -1;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
128 if (pa > pb) return +1;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129 return 0;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
130 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
131 });
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
132
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
133 Column [] columns = new Column[wstColumns.size()];
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
134 for (int i = 0; i < columns.length; ++i) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
135 columns[i] = new Column(wstColumns.get(i).getName());
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
136 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
137
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
138 // using native SQL here to avoid myriad of small objects.
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
139 SQLQuery sqlQuery = session.createSQLQuery(SQL_POS_WQ)
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
140 .addScalar("position", StandardBasicTypes.DOUBLE)
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
141 .addScalar("w", StandardBasicTypes.DOUBLE)
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
142 .addScalar("q", StandardBasicTypes.DOUBLE)
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
143 .addScalar("column_pos", StandardBasicTypes.INTEGER);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
144
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
145 sqlQuery.setInteger("wst_id", wst.getId());
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
146
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
147 WstValueTable valueTable = new WstValueTable(columns);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
148
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
149 int lastColumnNo = -1;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
150 Row row = null;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
152 for (Iterator<Object []> iter = sqlQuery.iterate(); iter.hasNext();) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
153 Object [] result = iter.next();
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
154 double km = (Double) result[0];
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
155 Double w = (Double) result[1];
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
156 Double q = (Double) result[2];
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 int columnNo = (Integer)result[3];
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159 if (columnNo > lastColumnNo) { // new row
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 if (row != null) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 valueTable.rows.add(row);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163 row = new Row(km, new double[(columnNo+1) << 1]);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165 int idx = columnNo << 1;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
166
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
167 row.wq[idx ] = w != null ? w : Double.NaN;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
168 row.wq[idx+1] = q != null ? q : Double.NaN;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
169
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170 lastColumnNo = columnNo;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
171 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
172
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
173 if (row != null) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
174 valueTable.rows.add(row);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
175 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
176
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
177 return valueTable;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
178 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
179 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
180 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org