Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
5830:160f53ee0870 | 5831:bd047b71ab37 |
---|---|
1 package org.dive4elements.river.artifacts.model; | |
2 | |
3 import java.math.BigDecimal; | |
4 | |
5 import java.util.List; | |
6 import java.util.Iterator; | |
7 import java.util.Collections; | |
8 | |
9 import org.dive4elements.river.backend.SessionHolder; | |
10 import org.dive4elements.river.model.Annotation; | |
11 import org.dive4elements.river.model.River; | |
12 | |
13 import org.hibernate.Session; | |
14 import org.hibernate.Query; | |
15 | |
16 /** | |
17 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
18 */ | |
19 public class AnnotationsFactory { | |
20 | |
21 /** | |
22 * Get Annotations which do not have a "b" ("to")-value set. | |
23 * | |
24 * @param river name of the river of interest. | |
25 * | |
26 * @return List of Annotations for river which have only "a" ("from") | |
27 * value set. | |
28 */ | |
29 public static List<Annotation> getPointAnnotations(String river) { | |
30 Session session = SessionHolder.HOLDER.get(); | |
31 | |
32 Query query = session.createQuery( | |
33 "from Annotation as an " + | |
34 "where an.range.b = null and an.range.river.name=:name " + | |
35 "order by range.a"); | |
36 query.setParameter("name", river); | |
37 return query.list(); | |
38 } | |
39 | |
40 | |
41 public static List<Annotation> getAnnotations(River river) { | |
42 Session session = SessionHolder.HOLDER.get(); | |
43 | |
44 Query query = session.createQuery( | |
45 "from Annotation as an where an.range.river = :river" + | |
46 " order by an.range.a"); | |
47 query.setParameter("river", river); | |
48 return query.list(); | |
49 } | |
50 | |
51 | |
52 public static Annotation getAnnotation(String river, double km) { | |
53 Session session = SessionHolder.HOLDER.get(); | |
54 | |
55 Query query = session.createQuery( | |
56 "from Annotation as a " + | |
57 "where a.range.river.name = :river AND a.range.a = :km"); | |
58 | |
59 query.setParameter("river", river); | |
60 query.setParameter("km", BigDecimal.valueOf(km)); | |
61 | |
62 List<Annotation> result = query.list(); | |
63 | |
64 return result != null && result.size() > 0 ? result.get(0) : null; | |
65 } | |
66 | |
67 | |
68 /** | |
69 * Get minimal "a" ("from") and maximal "b" ("to") value of annotations' | |
70 * ranges of a river. | |
71 * | |
72 * @param river name of the river of interest. | |
73 * | |
74 * @return Array containing minimal "a" and max "b" value of any | |
75 * annotation stored for the given river. | |
76 */ | |
77 public static double[] getAnnotationsBreadth(String river) { | |
78 Session session = SessionHolder.HOLDER.get(); | |
79 | |
80 Query minAQuery = session.createQuery( | |
81 "select min(a), max(b) from Range where river.name=:name"); | |
82 minAQuery.setParameter("name", river); | |
83 | |
84 double[] minAmaxB = {0.0f, 0.0f}; | |
85 Object[] row = (Object[]) minAQuery.list().iterator().next(); | |
86 minAmaxB[0] = ((BigDecimal) row[0]).doubleValue(); | |
87 minAmaxB[1] = ((BigDecimal) row[1]).doubleValue(); | |
88 return minAmaxB; | |
89 } | |
90 | |
91 | |
92 public static Iterator<Annotation> getAnnotationsIterator( | |
93 String riverName | |
94 ) { | |
95 Session session = SessionHolder.HOLDER.get(); | |
96 | |
97 Query riverQuery = session.createQuery( | |
98 "from River where name = :name"); | |
99 riverQuery.setParameter("name", riverName); | |
100 List<River> rivers = riverQuery.list(); | |
101 if (rivers.isEmpty()) { | |
102 return Collections.<Annotation>emptyList().iterator(); | |
103 } | |
104 | |
105 Query query = session.createQuery( | |
106 "from Annotation as an" + | |
107 " where an.range.river = :river order by an.range.a"); | |
108 query.setParameter("river", rivers.get(0)); | |
109 | |
110 return (Iterator<Annotation>)query.iterate(); | |
111 } | |
112 } | |
113 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |