comparison backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightValue.java @ 8559:6d8d7425a6b5

Bed heights are just bed heights since a while ('single' is obsolete).
author "Tom Gottfried <tom@intevation.de>"
date Mon, 16 Feb 2015 11:08:33 +0100
parents
children 19c38a47a276
comparison
equal deleted inserted replaced
8558:d0ea092a32f5 8559:6d8d7425a6b5
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU AGPL (>=v3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
6 * documentation coming with Dive4Elements River for details.
7 */
8
9 package org.dive4elements.river.importer;
10
11 import java.util.List;
12
13 import org.apache.log4j.Logger;
14
15 import org.hibernate.Session;
16 import org.hibernate.Query;
17
18 import org.dive4elements.river.model.BedHeight;
19 import org.dive4elements.river.model.BedHeightValue;
20
21
22 public class ImportBedHeightValue {
23
24 private static final Logger log =
25 Logger.getLogger(ImportBedHeightValue.class);
26
27
28 protected ImportBedHeight bedHeight;
29
30 protected Double station;
31 protected Double height;
32 protected Double uncertainty;
33 protected Double dataGap;
34 protected Double soundingWidth;
35
36 protected BedHeightValue peer;
37
38
39 public ImportBedHeightValue(
40 ImportBedHeight bedHeight,
41 Double station,
42 Double height,
43 Double uncertainty,
44 Double dataGap,
45 Double soundingWidth
46 ) {
47 this.bedHeight = bedHeight;
48 this.station = station;
49 this.height = height;
50 this.uncertainty = uncertainty;
51 this.dataGap = dataGap;
52 this.soundingWidth = soundingWidth;
53 }
54
55
56 public void storeDependencies(BedHeight bedHeight) {
57 getPeer(bedHeight);
58 }
59
60
61 /**
62 * Add this value to database or return database bound Value, assuring
63 * that the BedHeight exists in db already.
64 */
65 public BedHeightValue getPeer(BedHeight bedHeight) {
66 if (peer == null) {
67 Session session = ImporterSession.getInstance().getDatabaseSession();
68
69 Query query = session.createQuery(
70 "from BedHeightValue where " +
71 " bedHeight=:bedHeight and " +
72 " station=:station and " +
73 " height=:height and " +
74 " uncertainty=:uncertainty and " +
75 " dataGap=:dataGap and " +
76 " soundingWidth=:soundingWidth");
77
78 query.setParameter("bedHeight", bedHeight);
79 query.setParameter("station", station);
80 query.setParameter("height", height);
81 query.setParameter("uncertainty", uncertainty);
82 query.setParameter("dataGap", dataGap);
83 query.setParameter("soundingWidth", soundingWidth);
84
85 List<BedHeightValue> values = query.list();
86 if (values.isEmpty()) {
87 peer = new BedHeightValue(
88 bedHeight,
89 station,
90 height,
91 uncertainty,
92 dataGap,
93 soundingWidth
94 );
95 session.save(peer);
96 }
97 else {
98 peer = values.get(0);
99 }
100 }
101
102 return peer;
103 }
104 }
105 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org