Mercurial > dive4elements > river
comparison flys-backend/src/main/java/org/dive4elements/river/importer/ImportAnnotation.java @ 5828:dfb26b03b179
Moved directories to org.dive4elements.river
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 11:53:11 +0200 |
parents | flys-backend/src/main/java/de/intevation/flys/importer/ImportAnnotation.java@8076f6a689d0 |
children | 18619c1e7c2a |
comparison
equal
deleted
inserted
replaced
5827:e308d4ecd35a | 5828:dfb26b03b179 |
---|---|
1 package de.intevation.flys.importer; | |
2 | |
3 import de.intevation.flys.model.Annotation; | |
4 import de.intevation.flys.model.AnnotationType; | |
5 import de.intevation.flys.model.Range; | |
6 import de.intevation.flys.model.Position; | |
7 import de.intevation.flys.model.Attribute; | |
8 import de.intevation.flys.model.River; | |
9 import de.intevation.flys.model.Edge; | |
10 | |
11 import org.hibernate.Session; | |
12 import org.hibernate.Query; | |
13 | |
14 import java.util.List; | |
15 | |
16 public class ImportAnnotation | |
17 implements Comparable<ImportAnnotation> | |
18 { | |
19 protected ImportAttribute attribute; | |
20 protected ImportPosition position; | |
21 protected ImportRange range; | |
22 protected ImportEdge edge; | |
23 protected ImportAnnotationType type; | |
24 | |
25 protected Annotation peer; | |
26 | |
27 public ImportAnnotation() { | |
28 } | |
29 | |
30 public ImportAnnotation( | |
31 ImportAttribute attribute, | |
32 ImportPosition position, | |
33 ImportRange range, | |
34 ImportEdge edge, | |
35 ImportAnnotationType type | |
36 ) { | |
37 this.attribute = attribute; | |
38 this.position = position; | |
39 this.range = range; | |
40 this.edge = edge; | |
41 this.type = type; | |
42 } | |
43 | |
44 public int compareTo(ImportAnnotation other) { | |
45 int d = attribute.compareTo(other.attribute); | |
46 if (d != 0) { | |
47 return d; | |
48 } | |
49 | |
50 if ((d = position.compareTo(other.position)) != 0) { | |
51 return d; | |
52 } | |
53 | |
54 if ((d = range.compareTo(other.range)) != 0) { | |
55 return d; | |
56 } | |
57 | |
58 if (edge == null && other.edge != null) return -1; | |
59 if (edge != null && other.edge == null) return +1; | |
60 if (edge == null && other.edge == null) return 0; | |
61 | |
62 if ((d = edge.compareTo(other.edge)) != 0) { | |
63 return d; | |
64 } | |
65 | |
66 if (type == null && other.type != null) return -1; | |
67 if (type != null && other.type == null) return +1; | |
68 if (type == null && other.type == null) return 0; | |
69 | |
70 return type.compareTo(other.type); | |
71 } | |
72 | |
73 public ImportAttribute getAttribute() { | |
74 return attribute; | |
75 } | |
76 | |
77 public void setAttribute(ImportAttribute attribute) { | |
78 this.attribute = attribute; | |
79 } | |
80 | |
81 public ImportPosition getPosition() { | |
82 return position; | |
83 } | |
84 | |
85 public void setPosition(ImportPosition position) { | |
86 this.position = position; | |
87 } | |
88 | |
89 public ImportRange getRange() { | |
90 return range; | |
91 } | |
92 | |
93 public void setRange(ImportRange range) { | |
94 this.range = range; | |
95 } | |
96 | |
97 public ImportEdge getEdge() { | |
98 return edge; | |
99 } | |
100 | |
101 public void setEdge(ImportEdge edge) { | |
102 this.edge = edge; | |
103 } | |
104 | |
105 public ImportAnnotationType getType() { | |
106 return type; | |
107 } | |
108 | |
109 public void setType(ImportAnnotationType type) { | |
110 this.type = type; | |
111 } | |
112 | |
113 public Annotation getPeer(River river) { | |
114 if (peer == null) { | |
115 Range r = range.getPeer(river); | |
116 Attribute a = attribute.getPeer(); | |
117 Position p = position.getPeer(); | |
118 Edge e = edge != null ? edge.getPeer() : null; | |
119 AnnotationType t = type != null ? type.getPeer() : null; | |
120 | |
121 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
122 Query query = session.createQuery( | |
123 "from Annotation where " + | |
124 "range=:range and " + | |
125 "attribute=:attribute and " + | |
126 "position=:position and " + | |
127 "edge=:edge and " + | |
128 "type=:type"); | |
129 query.setParameter("range", r); | |
130 query.setParameter("attribute", a); | |
131 query.setParameter("position", p); | |
132 query.setParameter("edge", e); | |
133 query.setParameter("type", t); | |
134 List<Annotation> annotations = query.list(); | |
135 if (annotations.isEmpty()) { | |
136 peer = new Annotation(r, a, p, e, t); | |
137 session.save(peer); | |
138 } | |
139 else { | |
140 peer = annotations.get(0); | |
141 } | |
142 } | |
143 return peer; | |
144 } | |
145 } | |
146 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |