comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportAnnotation.java @ 759:9f2204ed79ed

Import edges to database. flys-backend/trunk@2107 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 14 Jun 2011 13:13:58 +0000
parents 67fd63e4ef66
children 3170fe2e7661
comparison
equal deleted inserted replaced
758:bf16268629d9 759:9f2204ed79ed
3 import de.intevation.flys.model.Annotation; 3 import de.intevation.flys.model.Annotation;
4 import de.intevation.flys.model.Range; 4 import de.intevation.flys.model.Range;
5 import de.intevation.flys.model.Position; 5 import de.intevation.flys.model.Position;
6 import de.intevation.flys.model.Attribute; 6 import de.intevation.flys.model.Attribute;
7 import de.intevation.flys.model.River; 7 import de.intevation.flys.model.River;
8 import de.intevation.flys.model.Edge;
8 9
9 import org.hibernate.Session; 10 import org.hibernate.Session;
10 import org.hibernate.Query; 11 import org.hibernate.Query;
11 12
12 import java.util.List; 13 import java.util.List;
15 implements Comparable<ImportAnnotation> 16 implements Comparable<ImportAnnotation>
16 { 17 {
17 protected ImportAttribute attribute; 18 protected ImportAttribute attribute;
18 protected ImportPosition position; 19 protected ImportPosition position;
19 protected ImportRange range; 20 protected ImportRange range;
21 protected ImportEdge edge;
20 22
21 protected Annotation peer; 23 protected Annotation peer;
22 24
23 public ImportAnnotation() { 25 public ImportAnnotation() {
24 } 26 }
25 27
26 public ImportAnnotation( 28 public ImportAnnotation(
27 ImportAttribute attribute, 29 ImportAttribute attribute,
28 ImportPosition position, 30 ImportPosition position,
29 ImportRange range 31 ImportRange range,
32 ImportEdge edge
30 ) { 33 ) {
31 this.attribute = attribute; 34 this.attribute = attribute;
32 this.position = position; 35 this.position = position;
33 this.range = range; 36 this.range = range;
37 this.edge = edge;
34 } 38 }
35 39
36 public int compareTo(ImportAnnotation other) { 40 public int compareTo(ImportAnnotation other) {
37 int d = attribute.compareTo(other.attribute); 41 int d = attribute.compareTo(other.attribute);
38 if (d != 0) { 42 if (d != 0) {
45 49
46 if ((d = range.compareTo(other.range)) != 0) { 50 if ((d = range.compareTo(other.range)) != 0) {
47 return d; 51 return d;
48 } 52 }
49 53
50 return 0; 54 if (edge == null && other.edge != null) return -1;
55 if (edge != null && other.edge == null) return +1;
56 if (edge == null && other.edge == null) return 0;
57
58 return edge.compareTo(other.edge);
51 } 59 }
52 60
53 public ImportAttribute getAttribute() { 61 public ImportAttribute getAttribute() {
54 return attribute; 62 return attribute;
55 } 63 }
77 public Annotation getPeer(River river) { 85 public Annotation getPeer(River river) {
78 if (peer == null) { 86 if (peer == null) {
79 Range r = range.getPeer(river); 87 Range r = range.getPeer(river);
80 Attribute a = attribute.getPeer(); 88 Attribute a = attribute.getPeer();
81 Position p = position.getPeer(); 89 Position p = position.getPeer();
90 Edge e = edge != null ? edge.getPeer() : null;
82 Session session = ImporterSession.getInstance().getDatabaseSession(); 91 Session session = ImporterSession.getInstance().getDatabaseSession();
83 Query query = session.createQuery( 92 Query query = session.createQuery(
84 "from Annotation where " + 93 "from Annotation where " +
85 "range=:range and attribute=:attribute and position=:position"); 94 "range=:range and " +
95 "attribute=:attribute and " +
96 "position=:position and " +
97 "edge=:edge");
86 query.setParameter("range", r); 98 query.setParameter("range", r);
87 query.setParameter("attribute", a); 99 query.setParameter("attribute", a);
88 query.setParameter("position", p); 100 query.setParameter("position", p);
101 query.setParameter("edge", e);
89 List<Annotation> annotations = query.list(); 102 List<Annotation> annotations = query.list();
90 if (annotations.isEmpty()) { 103 if (annotations.isEmpty()) {
91 peer = new Annotation(r, a, p); 104 peer = new Annotation(r, a, p);
92 session.save(peer); 105 session.save(peer);
93 } 106 }

http://dive4elements.wald.intevation.org