Mercurial > dive4elements > river
annotate flys-backend/src/main/java/de/intevation/flys/importer/ImportWaterlevelDifferenceColumn.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 | ed13816047b3 |
children | 8320427ecd5c |
rev | line source |
---|---|
2850
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.importer; |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.util.ArrayList; |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 import java.util.List; |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 import org.apache.log4j.Logger; |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 import org.hibernate.Session; |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import org.hibernate.Query; |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import de.intevation.flys.model.WaterlevelDifference; |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 import de.intevation.flys.model.WaterlevelDifferenceColumn; |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 public class ImportWaterlevelDifferenceColumn { |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 private static final Logger log = |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 Logger.getLogger(ImportWaterlevelDifferenceColumn.class); |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 private String description; |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 private List<ImportWaterlevelDifferenceValue> values; |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 private WaterlevelDifferenceColumn peer; |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 public ImportWaterlevelDifferenceColumn(String description) { |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 this.values = new ArrayList<ImportWaterlevelDifferenceValue>(); |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 this.description = description; |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 } |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 public void addValue(ImportWaterlevelDifferenceValue value) { |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 this.values.add(value); |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 } |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 public void storeDependencies(WaterlevelDifference difference) { |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 log.info("store dependencies"); |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 WaterlevelDifferenceColumn peer = getPeer(difference); |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 int i = 0; |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 for (ImportWaterlevelDifferenceValue value: values) { |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 value.storeDependencies(peer); |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 i++; |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 } |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 log.info("stored " + i + " waterlevel difference values"); |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 } |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 public WaterlevelDifferenceColumn getPeer(WaterlevelDifference diff) { |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 if (peer == null) { |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 Session session = ImporterSession.getInstance().getDatabaseSession(); |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 Query query = session.createQuery( |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 "from WaterlevelDifferenceColumn where " + |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 " difference=:difference and " + |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 " description=:description" |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 ); |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 query.setParameter("difference", diff); |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 query.setParameter("description", description); |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 List<WaterlevelDifferenceColumn> cols = query.list(); |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 if (cols.isEmpty()) { |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 peer = new WaterlevelDifferenceColumn(diff, description); |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 session.save(peer); |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 } |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 else { |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 peer = cols.get(0); |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 } |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 } |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 return peer; |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 } |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 } |
a1402c16152f
Added a parser and importer classes used to import waterlevel differences.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |