comparison backend/src/main/java/org/dive4elements/river/importer/ImportSedimentLoadValue.java @ 8028:aa054f72e887

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

http://dive4elements.wald.intevation.org