annotate flys-artifacts/src/main/java/org/dive4elements/river/artifacts/model/AnnotationsFactory.java @ 5831:bd047b71ab37

Repaired internal references
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:06:39 +0200
parents flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/AnnotationsFactory.java@6ed8ebd48d6e
children
rev   line source
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4048
diff changeset
1 package org.dive4elements.river.artifacts.model;
301
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;
1924
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
7 import java.util.Collections;
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4048
diff changeset
9 import org.dive4elements.river.backend.SessionHolder;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4048
diff changeset
10 import org.dive4elements.river.model.Annotation;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4048
diff changeset
11 import org.dive4elements.river.model.River;
301
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
1031
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
21 /**
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
22 * 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
23 *
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
24 * @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
25 *
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
26 * @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
27 * 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 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
30 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
31
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
32 Query query = session.createQuery(
1925
01f2473e362d Fixed flys/411 (Oracle max expressions for annotations query).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1924
diff changeset
33 "from Annotation as an " +
01f2473e362d Fixed flys/411 (Oracle max expressions for annotations query).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1924
diff changeset
34 "where an.range.b = null and an.range.river.name=:name " +
01f2473e362d Fixed flys/411 (Oracle max expressions for annotations query).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1924
diff changeset
35 "order by range.a");
01f2473e362d Fixed flys/411 (Oracle max expressions for annotations query).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1924
diff changeset
36 query.setParameter("name", river);
1031
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
37 return query.list();
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
38 }
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
39
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
40
1924
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
41 public static List<Annotation> getAnnotations(River river) {
311
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
42 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
43
311
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
44 Query query = session.createQuery(
1924
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
45 "from Annotation as an where an.range.river = :river" +
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
46 " order by an.range.a");
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
47 query.setParameter("river", river);
311
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
48 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
49 }
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 332
diff changeset
50
2063
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1925
diff changeset
51
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1925
diff changeset
52 public static Annotation getAnnotation(String river, double km) {
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1925
diff changeset
53 Session session = SessionHolder.HOLDER.get();
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1925
diff changeset
54
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1925
diff changeset
55 Query query = session.createQuery(
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1925
diff changeset
56 "from Annotation as a " +
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1925
diff changeset
57 "where a.range.river.name = :river AND a.range.a = :km");
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1925
diff changeset
58
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1925
diff changeset
59 query.setParameter("river", river);
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1925
diff changeset
60 query.setParameter("km", BigDecimal.valueOf(km));
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1925
diff changeset
61
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1925
diff changeset
62 List<Annotation> result = query.list();
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1925
diff changeset
63
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1925
diff changeset
64 return result != null && result.size() > 0 ? result.get(0) : null;
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1925
diff changeset
65 }
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1925
diff changeset
66
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1925
diff changeset
67
1031
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
68 /**
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
69 * 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
70 * 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
71 *
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
72 * @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
73 *
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
74 * @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
75 * 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
76 */
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
77 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
78 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
79
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
80 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
81 "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
82 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
83
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
84 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
85 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
86 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
87 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
88 return minAmaxB;
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
89 }
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
90
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
91
1924
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
92 public static Iterator<Annotation> getAnnotationsIterator(
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
93 String riverName
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
94 ) {
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 332
diff changeset
95 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
96
1924
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
97 Query riverQuery = session.createQuery(
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
98 "from River where name = :name");
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
99 riverQuery.setParameter("name", riverName);
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
100 List<River> rivers = riverQuery.list();
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
101 if (rivers.isEmpty()) {
3785
a5f65e8983be Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2063
diff changeset
102 return Collections.<Annotation>emptyList().iterator();
1924
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
103 }
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 332
diff changeset
104
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 332
diff changeset
105 Query query = session.createQuery(
1924
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
106 "from Annotation as an" +
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
107 " where an.range.river = :river order by an.range.a");
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
108 query.setParameter("river", rivers.get(0));
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
109
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 332
diff changeset
110 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
111 }
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112 }
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org