Mercurial > dive4elements > river
annotate flys-backend/src/main/java/de/intevation/flys/importer/ImportEdge.java @ 4447:a5993b69439b
Add processor to be able to generate curves for WKms values
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Wed, 07 Nov 2012 15:52:25 +0100 |
parents | 9f2204ed79ed |
children |
rev | line source |
---|---|
759
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.importer; |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import de.intevation.flys.model.Edge; |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import org.hibernate.Session; |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 import org.hibernate.Query; |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 import java.util.List; |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 import java.math.BigDecimal; |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 public class ImportEdge |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 implements Comparable<ImportEdge> |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 { |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 protected BigDecimal top; |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 protected BigDecimal bottom; |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 protected Edge peer; |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 public ImportEdge() { |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 } |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 public ImportEdge(BigDecimal top, BigDecimal bottom) { |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 this.top = top; |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 this.bottom = bottom; |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 } |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 public BigDecimal getTop() { |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 return top; |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 } |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 public void setTop(BigDecimal top) { |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 this.top = top; |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 } |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 public BigDecimal getBottom() { |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 return bottom; |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 } |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 public void setBottom(BigDecimal bottom) { |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 this.bottom = bottom; |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 } |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 private static final int compare(BigDecimal a, BigDecimal b) { |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 if (a == null && b != null) return -1; |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 if (a != null && b == null) return +1; |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 if (a == null && b == null) return 0; |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 return a.compareTo(b); |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 } |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 public int compareTo(ImportEdge other) { |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 int cmp = compare(top, other.top); |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 return cmp != 0 ? cmp : compare(bottom, other.bottom); |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 } |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 public Edge getPeer() { |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 if (peer == null) { |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 Session session = ImporterSession.getInstance().getDatabaseSession(); |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 Query query = session.createQuery( |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 "from Edge where top=:top and bottom=:bottom"); |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 query.setParameter("top", top); |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 query.setParameter("bottom", bottom); |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 List<Edge> edges = query.list(); |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 if (edges.isEmpty()) { |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 peer = new Edge(top, bottom); |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 session.save(peer); |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 } |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 else { |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 peer = edges.get(0); |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 } |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 } |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 return peer; |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 } |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 } |
9f2204ed79ed
Import edges to database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |