Mercurial > dive4elements > river
annotate flys-backend/src/main/java/de/intevation/flys/model/FastAnnotations.java @ 4820:26c849cf54e7
Merged
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Mon, 21 Jan 2013 12:49:44 +0100 |
parents | 20d249e1589f |
children |
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 } |
3653
20d249e1589f
Added FastAnnotation.Annotation.toString()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3334
diff
changeset
|
137 |
20d249e1589f
Added FastAnnotation.Annotation.toString()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3334
diff
changeset
|
138 @Override |
20d249e1589f
Added FastAnnotation.Annotation.toString()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3334
diff
changeset
|
139 public String toString() { |
20d249e1589f
Added FastAnnotation.Annotation.toString()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3334
diff
changeset
|
140 return "[a=" + a + ";b=" + b + |
20d249e1589f
Added FastAnnotation.Annotation.toString()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3334
diff
changeset
|
141 ";pos=" + position + ";attr=" + attribute + |
20d249e1589f
Added FastAnnotation.Annotation.toString()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3334
diff
changeset
|
142 ";name=" + name + ";top=" + top + |
20d249e1589f
Added FastAnnotation.Annotation.toString()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3334
diff
changeset
|
143 ";bot=" + bottom + "]"; |
20d249e1589f
Added FastAnnotation.Annotation.toString()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3334
diff
changeset
|
144 } |
3323
07c96cd39360
Fix comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2382
diff
changeset
|
145 } // class Annotation |
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
|
146 |
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 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
|
148 |
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 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
|
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 } // 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
|
152 |
3325
96bd63281af7
Added Override annotation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3324
diff
changeset
|
153 public static class NameFilter implements Filter { |
3324
290189f07809
Added filter for annotation names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3323
diff
changeset
|
154 |
290189f07809
Added filter for annotation names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3323
diff
changeset
|
155 private String name; |
290189f07809
Added filter for annotation names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3323
diff
changeset
|
156 |
3325
96bd63281af7
Added Override annotation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3324
diff
changeset
|
157 public NameFilter(String name) { |
3324
290189f07809
Added filter for annotation names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3323
diff
changeset
|
158 this.name = name; |
290189f07809
Added filter for annotation names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3323
diff
changeset
|
159 } |
290189f07809
Added filter for annotation names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3323
diff
changeset
|
160 |
3325
96bd63281af7
Added Override annotation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3324
diff
changeset
|
161 @Override |
96bd63281af7
Added Override annotation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3324
diff
changeset
|
162 public boolean accept(Annotation annotation) { |
3324
290189f07809
Added filter for annotation names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3323
diff
changeset
|
163 return annotation.getName().contains(name); |
290189f07809
Added filter for annotation names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3323
diff
changeset
|
164 } |
3325
96bd63281af7
Added Override annotation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3324
diff
changeset
|
165 } // class NameFilter |
3324
290189f07809
Added filter for annotation names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3323
diff
changeset
|
166 |
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
|
167 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
|
168 @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
|
169 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
|
170 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
|
171 } |
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 }; |
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 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
|
175 @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
|
176 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
|
177 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
|
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 }; |
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 |
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 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
|
182 @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
|
183 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
|
184 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
|
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 |
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 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
|
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 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
|
191 } |
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 |
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 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
|
194 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
|
195 } |
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 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
|
198 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
|
199 } |
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 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
|
202 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
|
203 } |
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 |
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 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
|
206 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
|
207 } |
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 |
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 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
|
210 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
|
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 |
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 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
|
214 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
|
215 |
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 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
|
217 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
|
218 |
3334
2ae732e2c65c
FLYS backend: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3325
diff
changeset
|
219 @Override |
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
|
220 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
|
221 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
|
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 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
|
226 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
|
227 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
|
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 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
|
230 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
|
231 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
|
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 |
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 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
|
235 |
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 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
|
237 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
|
238 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
|
239 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
|
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 |
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 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
|
244 } |
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 |
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 @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
|
247 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
|
248 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
|
249 } |
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 } |
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 |
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 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
|
254 |
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 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
|
256 |
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 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
|
258 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
|
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 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
|
262 } |
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 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
|
265 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
|
266 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
|
267 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
|
268 } |
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 |
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 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
|
271 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
|
272 |
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 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
|
274 .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
|
275 .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
|
276 .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
|
277 .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
|
278 .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
|
279 .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
|
280 .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
|
281 } |
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 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
|
284 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
|
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 // 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
|
287 // 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
|
288 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
|
289 |
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 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
|
291 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
|
292 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
|
293 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 |
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 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
|
301 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
|
302 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
|
303 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
|
304 } |
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 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
|
306 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
|
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 } |
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 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
|
311 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
|
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 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
314 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
|
315 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
316 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
317 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
|
318 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
319 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
|
320 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
321 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
|
322 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
323 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
|
324 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
325 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
326 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
|
327 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
328 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
|
329 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
330 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
|
331 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
332 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
|
333 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
334 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
335 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |