annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/AnnotationsFactory.java @ 2063:97a25b54eea3

Part 1 of #125: added a description for a location to the WaterlevelExport. flys-artifacts/trunk@3557 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 02 Jan 2012 08:50:50 +0000
parents 01f2473e362d
children a5f65e8983be
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;
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
315
94c176fdcb89 Removed the SessionHolder and adapted imports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 311
diff changeset
9 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
10 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
11 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
12 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
13
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.Session;
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 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
16
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 /**
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 * @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
19 */
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 public class AnnotationsFactory {
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21
1031
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
22 /**
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
23 * 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
24 *
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
25 * @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
26 *
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
27 * @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
28 * value set.
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
29 */
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
30 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
31 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
32
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
33 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
34 "from Annotation as an " +
01f2473e362d Fixed flys/411 (Oracle max expressions for annotations query).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1924
diff changeset
35 "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
36 "order by range.a");
01f2473e362d Fixed flys/411 (Oracle max expressions for annotations query).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1924
diff changeset
37 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
38 return query.list();
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
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
41
1924
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
42 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
43 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
44
311
ea3a438a7021 Backend access: Static methods are using the SessionHolder, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 301
diff changeset
45 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
46 "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
47 " 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
48 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
49 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
50 }
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 332
diff changeset
51
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
52
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 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
54 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
55
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 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
57 "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
58 "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
59
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("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
61 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
62
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 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
64
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 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
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
97a25b54eea3 Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1925
diff changeset
68
1031
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 * 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
71 * 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
72 *
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
73 * @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
74 *
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
75 * @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
76 * 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
77 */
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
78 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
79 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
80
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
81 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
82 "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
83 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
84
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
85 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
86 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
87 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
88 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
89 return minAmaxB;
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
bcef54a563ea Added functionality to query range and point-annotations only to
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 644
diff changeset
92
1924
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
93 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
94 String riverName
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
95 ) {
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 332
diff changeset
96 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
97
1924
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
98 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
99 "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
100 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
101 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
102 if (rivers.isEmpty()) {
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
103 List<Annotation> list = Collections.emptyList();
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
104 return list.iterator();
57b03b3ab15c Optimize query to fix annotations fetching on oracle, by Sascha Teichmann.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1031
diff changeset
105 }
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 332
diff changeset
106
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 332
diff changeset
107 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
108 "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
109 " 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
110 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
111
644
02c0cce0e469 Introduce a cache for the distance-info service
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 332
diff changeset
112 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
113 }
301
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114 }
1a00cb4998a8 Implemented a service that retrieves distance information for a specific river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org