Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/AnnotationsFactory.java @ 1127:6b9877a9f6c1
Added infrastructure to start WSPLGEN calculations - the FloodMapState already start such calculations.
flys-artifacts/trunk@2639 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 02 Sep 2011 13:12:05 +0000 |
parents | bcef54a563ea |
children | 57b03b3ab15c |
rev | line source |
---|---|
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
1031
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
3 import java.math.BigDecimal; |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
4 |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 import java.util.List; |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
332
diff
changeset
|
6 import java.util.Iterator; |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 |
315
94c176fdcb89
Removed the SessionHolder and adapted imports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
8 import de.intevation.flys.backend.SessionHolder; |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import de.intevation.flys.model.Annotation; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import de.intevation.flys.model.Range; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import de.intevation.flys.model.River; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 import org.hibernate.Session; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 import org.hibernate.Query; |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 /** |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 */ |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 public class AnnotationsFactory { |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 public static List<Annotation> getAnnotations(River river) { |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 return getAnnotations(river.getName()); |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 } |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 |
1031
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
26 /** |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
27 * Get Annotations which do not have a "b" ("to")-value set. |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
28 * |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
29 * @param river name of the river of interest. |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
30 * |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
31 * @return List of Annotations for river which have only "a" ("from") |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
32 * value set. |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
33 */ |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
34 public static List<Annotation> getPointAnnotations(String river) { |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
35 Session session = SessionHolder.HOLDER.get(); |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
36 |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
37 Query rangesQuery = session.createQuery( |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
38 "from Range where river.name=:name and b = null"); |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
39 rangesQuery.setParameter("name", river); |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
40 List<Range> ranges = rangesQuery.list(); |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
41 |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
42 Query query = session.createQuery( |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
43 "from Annotation where range in (:ranges) order by range.a"); |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
44 query.setParameterList("ranges", ranges); |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
45 return query.list(); |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
46 } |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
47 |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
48 |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 public static List<Annotation> getAnnotations(String river) { |
311
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
50 Session session = SessionHolder.HOLDER.get(); |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 |
311
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
52 Query rangesQuery = session.createQuery( |
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
53 "from Range where river.name=:name"); |
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
54 rangesQuery.setParameter("name", river); |
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
55 List<Range> ranges = rangesQuery.list(); |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 |
311
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
57 Query query = session.createQuery( |
332
bf4e12f1d025
The list of annotations returned by the AnnotationFactory is ordered by its range.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
315
diff
changeset
|
58 "from Annotation where range in (:ranges) order by range.a"); |
311
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
59 query.setParameterList("ranges", ranges); |
ea3a438a7021
Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
301
diff
changeset
|
60 return query.list(); |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 } |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
332
diff
changeset
|
62 |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
332
diff
changeset
|
63 |
1031
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
64 /** |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
65 * Get minimal "a" ("from") and maximal "b" ("to") value of annotations' |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
66 * ranges of a river. |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
67 * |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
68 * @param river name of the river of interest. |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
69 * |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
70 * @return Array containing minimal "a" and max "b" value of any |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
71 * annotation stored for the given river. |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
72 */ |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
73 public static double[] getAnnotationsBreadth(String river) { |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
74 Session session = SessionHolder.HOLDER.get(); |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
75 |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
76 Query minAQuery = session.createQuery( |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
77 "select min(a), max(b) from Range where river.name=:name"); |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
78 minAQuery.setParameter("name", river); |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
79 |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
80 double[] minAmaxB = {0.0f, 0.0f}; |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
81 Object[] row = (Object[]) minAQuery.list().iterator().next(); |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
82 minAmaxB[0] = ((BigDecimal) row[0]).doubleValue(); |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
83 minAmaxB[1] = ((BigDecimal) row[1]).doubleValue(); |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
84 return minAmaxB; |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
85 } |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
86 |
bcef54a563ea
Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
644
diff
changeset
|
87 |
644
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
332
diff
changeset
|
88 public static Iterator<Annotation> getAnnotationsIterator(String river) { |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
332
diff
changeset
|
89 Session session = SessionHolder.HOLDER.get(); |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
332
diff
changeset
|
90 |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
332
diff
changeset
|
91 Query rangesQuery = session.createQuery( |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
332
diff
changeset
|
92 "from Range where river.name=:name"); |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
332
diff
changeset
|
93 rangesQuery.setParameter("name", river); |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
332
diff
changeset
|
94 List<Range> ranges = rangesQuery.list(); |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
332
diff
changeset
|
95 |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
332
diff
changeset
|
96 Query query = session.createQuery( |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
332
diff
changeset
|
97 "from Annotation where range in (:ranges) order by range.a"); |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
332
diff
changeset
|
98 query.setParameterList("ranges", ranges); |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
332
diff
changeset
|
99 return (Iterator<Annotation>)query.iterate(); |
02c0cce0e469
Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
332
diff
changeset
|
100 } |
301
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 } |
1a00cb4998a8
Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
102 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |