Mercurial > dive4elements > river
annotate flys-backend/src/main/java/de/intevation/flys/model/FastAnnotations.java @ 2849:c36106f15ac9
Added missing constraint to relation 'waterlevel_difference'.
flys-backend/trunk@4303 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 26 Apr 2012 09:44:39 +0000 |
parents | c5791de0c495 |
children | 07c96cd39360 |
rev | line source |
---|---|
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.model; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.util.Comparator; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 import java.util.ArrayList; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import java.util.List; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 import java.util.Arrays; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import java.util.HashMap; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 import java.util.Iterator; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 import java.util.NoSuchElementException; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import java.io.Serializable; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 import org.hibernate.Session; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 import org.hibernate.SQLQuery; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import org.hibernate.type.StandardBasicTypes; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 import de.intevation.flys.backend.SessionHolder; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 public class FastAnnotations |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 implements Serializable |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 public static final String SQL_BY_RIVER_NAME = |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 "SELECT r.a AS a, r.b AS b, p.value AS position, " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 "at.value AS attribute, ant.name AS name, " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 "e.top AS top, e.bottom AS bottom " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 "FROM annotations an " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 "JOIN ranges r " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 "ON an.range_id = r.id " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 "JOIN attributes at " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 "ON an.attribute_id = at.id " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 "JOIN positions p " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 "ON an.position_id = p.id " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 "JOIN rivers riv " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 "ON r.river_id = riv.id " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 "LEFT JOIN annotation_types ant " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 "ON an.type_id = ant.id " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 "LEFT JOIN edges e " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 "ON an.edge_id = e.id " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 "WHERE riv.name = :river_name " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 "ORDER BY r.a"; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 public static final String SQL_BY_RIVER_ID = |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 "SELECT r.a AS a, r.b AS b, p.value AS position, " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 "at.value AS attribute, ant.name AS name, " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 "e.top AS top, e.bottom AS bottom " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 "FROM annotations an " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 "JOIN ranges r " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 "ON an.range_id = r.id " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 "JOIN attributes at " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 "ON an.attribute_id = at.id " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 "JOIN positions p " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 "ON an.position_id = p.id " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 "LEFT JOIN annotation_types ant " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 "ON an.type_id = ant.id " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 "LEFT JOIN edges e " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 "ON an.edge_id = e.id " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 "WHERE r.id = :river_id " + |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 "ORDER BY r.a"; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 public static final double EPSILON = 1e-5; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 public static final Comparator<Annotation> KM_CMP = |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 new Comparator<Annotation>() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 @Override |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 public int compare(Annotation a, Annotation b) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 double diff = a.a - b.a; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 if (diff < -EPSILON) return -1; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 if (diff > +EPSILON) return +1; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 return 0; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 }; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 public static final class Annotation |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 implements Serializable |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 private double a; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 private double b; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 private String position; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 private String attribute; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 private String name; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 private double top; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 private double bottom; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 public Annotation() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 public Annotation(double a) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 this.a = a; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 public Annotation( |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 double a, |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 double b, |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 String position, |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 String attribute, |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 String name, |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 double top, |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 double bottom |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 ) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 this.a = a; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 this.b = b; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 this.position = position; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 this.attribute = attribute; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 this.name = name; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 this.top = top; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 this.bottom = bottom; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 public double getA() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 return a; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 public double getB() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 return b; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 public String getPosition() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 return position; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 public String getAttribute() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 return attribute; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 public String getName() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 return name; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 public double getTop() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 return top; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 public double getBottom() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 return bottom; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 } // class Serializable |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 public interface Filter { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 boolean accept(Annotation annotation); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 } // interface Filter |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 public static final Filter ALL = new Filter() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 @Override |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 public boolean accept(Annotation annotation) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 return true; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 }; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 public static final Filter IS_POINT = new Filter() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 @Override |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 public boolean accept(Annotation annotation) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 return Double.isNaN(annotation.getB()); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 }; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 public static final Filter IS_RANGE = new Filter() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 @Override |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 public boolean accept(Annotation annotation) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 return !Double.isNaN(annotation.getB()); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 }; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 private Annotation [] annotations; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 public FastAnnotations() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 public FastAnnotations(Annotation [] annotations) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 this.annotations = annotations; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 public FastAnnotations(String riverName) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 this(loadByRiverName(riverName)); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 public FastAnnotations(int riverId) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 this(loadByRiverId(riverId)); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 public FastAnnotations(Iterator<Annotation> iter) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 this(toArray(iter)); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 public int size() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 return annotations.length; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 public Iterator<Annotation> filter(final Filter filter) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 return new Iterator<Annotation>() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 private int idx; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 private Annotation current = findNext(); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 @Override |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 public boolean hasNext() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 return current != null; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
200 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 @Override |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 public Annotation next() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
204 if (current == null) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 throw new NoSuchElementException(); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
206 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 Annotation result = current; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
208 current = findNext(); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
209 return result; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
210 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 private Annotation findNext() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
213 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
214 while (idx < annotations.length) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 Annotation annotation = annotations[idx++]; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
216 if (filter.accept(annotation)) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
217 return annotation; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
219 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
220 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
221 return null; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
222 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
223 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
224 @Override |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
225 public void remove() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
226 throw new UnsupportedOperationException(); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
227 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
228 }; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
229 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
230 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
231 public static Annotation [] toArray(Iterator<Annotation> iter) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
232 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
233 ArrayList<Annotation> list = new ArrayList<Annotation>(); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
234 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
235 while (iter.hasNext()) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
236 list.add(iter.next()); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
237 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
238 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
239 return list.toArray(new Annotation[list.size()]); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
240 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
241 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
242 public Annotation findByKm(double km) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
243 Annotation key = new Annotation(km); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
244 int idx = Arrays.binarySearch(annotations, key, KM_CMP); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
245 return idx < 0 ? null : annotations[idx]; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
247 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
248 private static SQLQuery createQuery(String query) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
249 Session session = SessionHolder.HOLDER.get(); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
250 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
251 return session.createSQLQuery(query) |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
252 .addScalar("a", StandardBasicTypes.DOUBLE) |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
253 .addScalar("b", StandardBasicTypes.DOUBLE) |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
254 .addScalar("position", StandardBasicTypes.STRING) |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
255 .addScalar("attribute", StandardBasicTypes.STRING) |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
256 .addScalar("name", StandardBasicTypes.STRING) |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
257 .addScalar("top", StandardBasicTypes.DOUBLE) |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
258 .addScalar("bottom", StandardBasicTypes.DOUBLE); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
259 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
260 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
261 private static Annotation [] buildAnnotations(List<Object []> list) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
262 Annotation [] anns = new Annotation[list.size()]; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
263 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
264 // Names are likely the same because they are a type |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
265 // like 'Pegel' or 'Hafen'. |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
266 HashMap<String, String> names = new HashMap<String, String>(); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
267 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
268 for (int i = 0; i < anns.length; ++i) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
269 Object [] data = list.get(i); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
270 double a = ((Double)data[0]); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
271 double b = data[1] != null ? (Double)data[1] : Double.NaN; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
272 String position = (String)data[2]; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
273 String attribute = (String)data[3]; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
274 String name = (String)data[4]; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
275 double top = data[5] != null ? (Double)data[5] : Double.NaN; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
276 double bottom = data[6] != null ? (Double)data[6] : Double.NaN; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
277 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
278 if (name != null) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
279 String old = names.get(name); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
280 if (old != null) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
281 name = old; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
282 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
283 else { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
284 names.put(name, name); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
285 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
286 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
287 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
288 anns[i] = new Annotation( |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
289 a, b, position, attribute, name, top, bottom); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
290 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
291 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
292 return anns; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
293 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
294 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
295 public static Annotation [] loadByRiverName(String riverName) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
296 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
297 SQLQuery query = createQuery(SQL_BY_RIVER_NAME); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
298 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
299 query.setString("river_name", riverName); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
300 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
301 return buildAnnotations(query.list()); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
302 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
303 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
304 public static Annotation [] loadByRiverId(int riverId) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
305 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
306 SQLQuery query = createQuery(SQL_BY_RIVER_ID); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
307 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
308 query.setInteger("river_id", riverId); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
309 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
310 return buildAnnotations(query.list()); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
311 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
312 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
313 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |