Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightSingleValue.java @ 7730:e1b831fe435a slt-simplify-cross-sections
Merged default into slt-simplify-cross-sections branch and updated package and class names.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Mon, 20 Jan 2014 14:04:20 +0100 |
parents | e2eb1a110b44 |
children | 3a0522f1a532 |
comparison
equal
deleted
inserted
replaced
5084:ca45dd039b54 | 7730:e1b831fe435a |
---|---|
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.BedHeightSingle; | |
19 import org.dive4elements.river.model.BedHeightSingleValue; | |
20 | |
21 | |
22 public class ImportBedHeightSingleValue implements ImportBedHeightValue { | |
23 | |
24 private static final Logger log = | |
25 Logger.getLogger(ImportBedHeightSingleValue.class); | |
26 | |
27 | |
28 protected ImportBedHeightSingle bedHeight; | |
29 | |
30 protected Double station; | |
31 protected Double height; | |
32 protected Double uncertainty; | |
33 protected Double dataGap; | |
34 protected Double soundingWidth; | |
35 protected Double width; | |
36 | |
37 protected BedHeightSingleValue peer; | |
38 | |
39 | |
40 public ImportBedHeightSingleValue( | |
41 ImportBedHeightSingle bedHeight, | |
42 Double station, | |
43 Double height, | |
44 Double uncertainty, | |
45 Double dataGap, | |
46 Double soundingWidth, | |
47 Double width | |
48 ) { | |
49 this.bedHeight = bedHeight; | |
50 this.station = station; | |
51 this.height = height; | |
52 this.uncertainty = uncertainty; | |
53 this.dataGap = dataGap; | |
54 this.soundingWidth = soundingWidth; | |
55 this.width = width; | |
56 } | |
57 | |
58 | |
59 public void storeDependencies(BedHeightSingle bedHeight) { | |
60 getPeer(bedHeight); | |
61 } | |
62 | |
63 | |
64 /** | |
65 * Add this value to database or return database bound Value, assuring | |
66 * that the BedHeightSingle exists in db already. | |
67 */ | |
68 public BedHeightSingleValue getPeer(BedHeightSingle bedHeight) { | |
69 if (peer == null) { | |
70 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
71 | |
72 Query query = session.createQuery( | |
73 "from BedHeightSingleValue where " + | |
74 " bedHeight=:bedHeight and " + | |
75 " station=:station and " + | |
76 " height=:height and " + | |
77 " uncertainty=:uncertainty and " + | |
78 " dataGap=:dataGap and " + | |
79 " soundingWidth=:soundingWidth and " + | |
80 " width=:width"); | |
81 | |
82 query.setParameter("bedHeight", bedHeight); | |
83 query.setParameter("station", station); | |
84 query.setParameter("height", height); | |
85 query.setParameter("uncertainty", uncertainty); | |
86 query.setParameter("dataGap", dataGap); | |
87 query.setParameter("soundingWidth", soundingWidth); | |
88 query.setParameter("width", width); | |
89 | |
90 List<BedHeightSingleValue> values = query.list(); | |
91 if (values.isEmpty()) { | |
92 peer = new BedHeightSingleValue( | |
93 bedHeight, | |
94 station, | |
95 height, | |
96 uncertainty, | |
97 dataGap, | |
98 soundingWidth, | |
99 width | |
100 ); | |
101 session.save(peer); | |
102 } | |
103 else { | |
104 peer = values.get(0); | |
105 } | |
106 } | |
107 | |
108 return peer; | |
109 } | |
110 } | |
111 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |