Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportSedimentLoadValue.java @ 8056:d86cc6a17b7a
Importer: Import sediment load at measurement stations.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 18 Jul 2014 15:37:26 +0200 |
parents | aa054f72e887 |
children | e8d2042c9639 |
comparison
equal
deleted
inserted
replaced
8055:cd35b76f1ef8 | 8056:d86cc6a17b7a |
---|---|
1 package org.dive4elements.river.importer; | 1 package org.dive4elements.river.importer; |
2 | 2 |
3 import java.util.List; | 3 import java.util.List; |
4 | 4 |
5 import org.dive4elements.river.model.MeasurementStation; | 5 import org.dive4elements.river.model.MeasurementStation; |
6 import org.dive4elements.river.model.River; | |
7 import org.dive4elements.river.model.SedimentLoad; | 6 import org.dive4elements.river.model.SedimentLoad; |
8 import org.dive4elements.river.model.SedimentLoadValue; | 7 import org.dive4elements.river.model.SedimentLoadValue; |
9 import org.hibernate.Query; | 8 import org.hibernate.Query; |
10 import org.hibernate.Session; | 9 import org.hibernate.Session; |
11 | 10 |
12 public class ImportSedimentLoadValue { | 11 public class ImportSedimentLoadValue { |
13 | 12 |
14 private SedimentLoadValue peer; | 13 private SedimentLoadValue peer; |
15 | 14 |
16 private ImportMeasurementStation station; | 15 private MeasurementStation station; |
17 private ImportSedimentLoad sedimentLoad; | 16 private Double value; |
18 private Double value; | |
19 | 17 |
20 public ImportSedimentLoadValue() { | 18 public ImportSedimentLoadValue() { |
21 } | 19 } |
22 | 20 |
23 public ImportSedimentLoadValue( | 21 public ImportSedimentLoadValue( |
24 ImportMeasurementStation station, | 22 MeasurementStation station, |
25 ImportSedimentLoad sedimentLoad, | 23 Double value |
26 Double value | |
27 ) { | 24 ) { |
28 this.station = station; | 25 this.station = station; |
29 this.sedimentLoad = sedimentLoad; | |
30 this.value = value; | 26 this.value = value; |
31 } | 27 } |
32 | 28 |
33 protected SedimentLoadValue getPeer(River river) { | 29 protected SedimentLoadValue getPeer(SedimentLoad sedimentLoad) { |
34 | 30 |
35 if (peer == null) { | 31 if (peer == null) { |
36 Session session = ImporterSession.getInstance().getDatabaseSession(); | 32 Session session = ImporterSession.getInstance().getDatabaseSession(); |
37 Query query = session.createQuery( | 33 Query query = session.createQuery( |
38 "from SedimentLoadValue where " + | 34 "from SedimentLoadValue where " + |
39 " station = :station and " + | 35 " measurementStation = :station and " + |
40 " sedimentLoad = :sedimentLoad and " + | 36 " sedimentLoad = :sedimentLoad and " + |
41 " value = :value"); | 37 " value = :value"); |
42 | 38 |
43 MeasurementStation ms = station.getPeer(river); | 39 query.setParameter("station", station); |
44 SedimentLoad sl = sedimentLoad.getPeer(); | 40 query.setParameter("sedimentLoad", sedimentLoad); |
45 | |
46 query.setParameter("station", ms); | |
47 query.setParameter("sedimentLoad", sl); | |
48 query.setParameter("value", value); | 41 query.setParameter("value", value); |
49 | 42 |
50 List<SedimentLoadValue> values = query.list(); | 43 List<SedimentLoadValue> values = query.list(); |
51 if (values.isEmpty()) { | 44 if (values.isEmpty()) { |
52 peer = new SedimentLoadValue(sl, ms, value); | 45 peer = new SedimentLoadValue(sedimentLoad, station, value); |
53 session.save(peer); | 46 session.save(peer); |
54 } | 47 } |
55 else { | 48 else { |
56 peer = values.get(0); | 49 peer = values.get(0); |
57 } | 50 } |
58 } | 51 } |
59 | 52 |
60 return peer; | 53 return peer; |
61 } | 54 } |
62 | 55 |
63 public void storeDependencies(River river) { | 56 public void storeDependencies(SedimentLoad sedimentLoad) { |
64 station.storeDependencies(river); | 57 getPeer(sedimentLoad); |
65 sedimentLoad.storeDependencies(); | |
66 getPeer(river); | |
67 } | 58 } |
68 } | 59 } |
69 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 60 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |