comparison backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightSingleValue.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightSingleValue.java@18619c1e7c2a
children 4dd33b86dc61
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 package org.dive4elements.river.importer;
2
3 import java.util.List;
4
5 import java.math.BigDecimal;
6
7 import org.apache.log4j.Logger;
8
9 import org.hibernate.Session;
10 import org.hibernate.Query;
11
12 import org.dive4elements.river.model.BedHeightSingle;
13 import org.dive4elements.river.model.BedHeightSingleValue;
14
15
16 public class ImportBedHeightSingleValue implements ImportBedHeightValue {
17
18 private static final Logger log =
19 Logger.getLogger(ImportBedHeightSingleValue.class);
20
21
22 protected ImportBedHeightSingle bedHeight;
23
24 protected BigDecimal station;
25 protected BigDecimal height;
26 protected BigDecimal uncertainty;
27 protected BigDecimal dataGap;
28 protected BigDecimal soundingWidth;
29 protected BigDecimal width;
30
31 protected BedHeightSingleValue peer;
32
33
34 public ImportBedHeightSingleValue(
35 ImportBedHeightSingle bedHeight,
36 BigDecimal station,
37 BigDecimal height,
38 BigDecimal uncertainty,
39 BigDecimal dataGap,
40 BigDecimal soundingWidth,
41 BigDecimal width
42 ) {
43 this.bedHeight = bedHeight;
44 this.station = station;
45 this.height = height;
46 this.uncertainty = uncertainty;
47 this.dataGap = dataGap;
48 this.soundingWidth = soundingWidth;
49 this.width = width;
50 }
51
52
53 public void storeDependencies(BedHeightSingle bedHeight) {
54 getPeer(bedHeight);
55 }
56
57
58 /**
59 * Add this value to database or return database bound Value, assuring
60 * that the BedHeightSingle exists in db already.
61 */
62 public BedHeightSingleValue getPeer(BedHeightSingle bedHeight) {
63 if (peer == null) {
64 Session session = ImporterSession.getInstance().getDatabaseSession();
65
66 Query query = session.createQuery(
67 "from BedHeightSingleValue where " +
68 " bedHeight=:bedHeight and " +
69 " station=:station and " +
70 " height=:height and " +
71 " uncertainty=:uncertainty and " +
72 " dataGap=:dataGap and " +
73 " soundingWidth=:soundingWidth and " +
74 " width=:width");
75
76 query.setParameter("bedHeight", bedHeight);
77 query.setParameter("station", station);
78 query.setParameter("height", height);
79 query.setParameter("uncertainty", uncertainty);
80 query.setParameter("dataGap", dataGap);
81 query.setParameter("soundingWidth", soundingWidth);
82 query.setParameter("width", width);
83
84 List<BedHeightSingleValue> values = query.list();
85 if (values.isEmpty()) {
86 peer = new BedHeightSingleValue(
87 bedHeight,
88 station,
89 height,
90 uncertainty,
91 dataGap,
92 soundingWidth,
93 width
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