annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java @ 327:e09634fbf6bc

Moved the query complexity of creating a w/q value table into view 'wst_value_table' and used this instead. flys-artifacts/trunk@1724 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 18 Apr 2011 16:01:23 +0000
parents 07eba6d3b4a5
children 64cfbd631f29
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 =
327
e09634fbf6bc Moved the query complexity of creating a w/q value table into view
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 326
diff changeset
29 "SELECT position, w, q, column_pos" +
e09634fbf6bc Moved the query complexity of creating a w/q value table into view
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 326
diff changeset
30 " FROM wst_value_table" +
e09634fbf6bc Moved the query complexity of creating a w/q value table into view
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 326
diff changeset
31 " WHERE wst_id = :wst_id";
326
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 public static class Column
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 implements Serializable
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 protected String name;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 public Column() {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 public Column(String name) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 this.name = name;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 public String getName() {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 return name;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 }
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 void setName(String name) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 this.name = name;
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 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 // class Column
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 public static class Row
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 implements Serializable
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 double km;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 double [] wq;
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 Row() {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 }
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 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
65 this.km = km;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 this.wq = wq;
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 Row
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 protected List<Row> rows;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 protected Column [] columns;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 public WstValueTable() {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76 rows = new ArrayList<Row>();
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 }
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 public WstValueTable(Column [] columns) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 this();
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 this.columns = columns;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 }
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 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
85 return getTable(river, 0);
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
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 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
89
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 Session session = SessionHolder.HOLDER.get();
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 Query query = session.createQuery(
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 "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
94 query.setParameter("river", river);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 query.setInteger("kind", kind);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 List<Wst> wsts = query.list();
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 if (wsts.isEmpty()) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 return null;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 }
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 Wst wst = wsts.get(0);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 // 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
106 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
107 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
108 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
109 int pa = a.getPosition();
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 int pb = b.getPosition();
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 if (pa < pb) return -1;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112 if (pa > pb) return +1;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113 return 0;
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 });
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
116
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117 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
118 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
119 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
120 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
121
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
122 // 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
123 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
124 .addScalar("position", StandardBasicTypes.DOUBLE)
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
125 .addScalar("w", StandardBasicTypes.DOUBLE)
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
126 .addScalar("q", StandardBasicTypes.DOUBLE)
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
127 .addScalar("column_pos", StandardBasicTypes.INTEGER);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
128
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129 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
130
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
131 WstValueTable valueTable = new WstValueTable(columns);
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 int lastColumnNo = -1;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
134 Row row = null;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
135
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
136 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
137 Object [] result = iter.next();
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
138 double km = (Double) result[0];
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
139 Double w = (Double) result[1];
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
140 Double q = (Double) result[2];
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
141 int columnNo = (Integer)result[3];
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
142
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
143 if (columnNo > lastColumnNo) { // new row
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
144 if (row != null) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
145 valueTable.rows.add(row);
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 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
148 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
149 int idx = columnNo << 1;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
150
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151 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
152 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
153
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
154 lastColumnNo = columnNo;
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
155 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
156
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 if (row != null) {
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 valueTable.rows.add(row);
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 return valueTable;
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 }
07eba6d3b4a5 Fetches w/q value tables from the backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org