Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportAnnotation.java @ 763:8076f6a689d0
First part of flys/issue18
flys-backend/trunk@2124 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 15 Jun 2011 09:22:00 +0000 |
parents | 3170fe2e7661 |
children |
comparison
equal
deleted
inserted
replaced
762:23fe9ac1c3b4 | 763:8076f6a689d0 |
---|---|
1 package de.intevation.flys.importer; | 1 package de.intevation.flys.importer; |
2 | 2 |
3 import de.intevation.flys.model.Annotation; | 3 import de.intevation.flys.model.Annotation; |
4 import de.intevation.flys.model.AnnotationType; | |
4 import de.intevation.flys.model.Range; | 5 import de.intevation.flys.model.Range; |
5 import de.intevation.flys.model.Position; | 6 import de.intevation.flys.model.Position; |
6 import de.intevation.flys.model.Attribute; | 7 import de.intevation.flys.model.Attribute; |
7 import de.intevation.flys.model.River; | 8 import de.intevation.flys.model.River; |
8 import de.intevation.flys.model.Edge; | 9 import de.intevation.flys.model.Edge; |
13 import java.util.List; | 14 import java.util.List; |
14 | 15 |
15 public class ImportAnnotation | 16 public class ImportAnnotation |
16 implements Comparable<ImportAnnotation> | 17 implements Comparable<ImportAnnotation> |
17 { | 18 { |
18 protected ImportAttribute attribute; | 19 protected ImportAttribute attribute; |
19 protected ImportPosition position; | 20 protected ImportPosition position; |
20 protected ImportRange range; | 21 protected ImportRange range; |
21 protected ImportEdge edge; | 22 protected ImportEdge edge; |
23 protected ImportAnnotationType type; | |
22 | 24 |
23 protected Annotation peer; | 25 protected Annotation peer; |
24 | 26 |
25 public ImportAnnotation() { | 27 public ImportAnnotation() { |
26 } | 28 } |
27 | 29 |
28 public ImportAnnotation( | 30 public ImportAnnotation( |
29 ImportAttribute attribute, | 31 ImportAttribute attribute, |
30 ImportPosition position, | 32 ImportPosition position, |
31 ImportRange range, | 33 ImportRange range, |
32 ImportEdge edge | 34 ImportEdge edge, |
35 ImportAnnotationType type | |
33 ) { | 36 ) { |
34 this.attribute = attribute; | 37 this.attribute = attribute; |
35 this.position = position; | 38 this.position = position; |
36 this.range = range; | 39 this.range = range; |
37 this.edge = edge; | 40 this.edge = edge; |
41 this.type = type; | |
38 } | 42 } |
39 | 43 |
40 public int compareTo(ImportAnnotation other) { | 44 public int compareTo(ImportAnnotation other) { |
41 int d = attribute.compareTo(other.attribute); | 45 int d = attribute.compareTo(other.attribute); |
42 if (d != 0) { | 46 if (d != 0) { |
53 | 57 |
54 if (edge == null && other.edge != null) return -1; | 58 if (edge == null && other.edge != null) return -1; |
55 if (edge != null && other.edge == null) return +1; | 59 if (edge != null && other.edge == null) return +1; |
56 if (edge == null && other.edge == null) return 0; | 60 if (edge == null && other.edge == null) return 0; |
57 | 61 |
58 return edge.compareTo(other.edge); | 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); | |
59 } | 71 } |
60 | 72 |
61 public ImportAttribute getAttribute() { | 73 public ImportAttribute getAttribute() { |
62 return attribute; | 74 return attribute; |
63 } | 75 } |
80 | 92 |
81 public void setRange(ImportRange range) { | 93 public void setRange(ImportRange range) { |
82 this.range = range; | 94 this.range = range; |
83 } | 95 } |
84 | 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 | |
85 public Annotation getPeer(River river) { | 113 public Annotation getPeer(River river) { |
86 if (peer == null) { | 114 if (peer == null) { |
87 Range r = range.getPeer(river); | 115 Range r = range.getPeer(river); |
88 Attribute a = attribute.getPeer(); | 116 Attribute a = attribute.getPeer(); |
89 Position p = position.getPeer(); | 117 Position p = position.getPeer(); |
90 Edge e = edge != null ? edge.getPeer() : null; | 118 Edge e = edge != null ? edge.getPeer() : null; |
119 AnnotationType t = type != null ? type.getPeer() : null; | |
120 | |
91 Session session = ImporterSession.getInstance().getDatabaseSession(); | 121 Session session = ImporterSession.getInstance().getDatabaseSession(); |
92 Query query = session.createQuery( | 122 Query query = session.createQuery( |
93 "from Annotation where " + | 123 "from Annotation where " + |
94 "range=:range and " + | 124 "range=:range and " + |
95 "attribute=:attribute and " + | 125 "attribute=:attribute and " + |
96 "position=:position and " + | 126 "position=:position and " + |
97 "edge=:edge"); | 127 "edge=:edge and " + |
128 "type=:type"); | |
98 query.setParameter("range", r); | 129 query.setParameter("range", r); |
99 query.setParameter("attribute", a); | 130 query.setParameter("attribute", a); |
100 query.setParameter("position", p); | 131 query.setParameter("position", p); |
101 query.setParameter("edge", e); | 132 query.setParameter("edge", e); |
133 query.setParameter("type", t); | |
102 List<Annotation> annotations = query.list(); | 134 List<Annotation> annotations = query.list(); |
103 if (annotations.isEmpty()) { | 135 if (annotations.isEmpty()) { |
104 peer = new Annotation(r, a, p, e); | 136 peer = new Annotation(r, a, p, e, t); |
105 session.save(peer); | 137 session.save(peer); |
106 } | 138 } |
107 else { | 139 else { |
108 peer = annotations.get(0); | 140 peer = annotations.get(0); |
109 } | 141 } |