comparison backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightEpochValue.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 4c3ccf2b0304
children
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 java.math.BigDecimal;
14
15 import org.apache.log4j.Logger;
16
17 import org.hibernate.Session;
18 import org.hibernate.Query;
19
20 import org.dive4elements.river.model.BedHeightEpoch;
21 import org.dive4elements.river.model.BedHeightEpochValue;
22
23
24 public class ImportBedHeightEpochValue implements ImportBedHeightValue {
25
26 private static final Logger log =
27 Logger.getLogger(ImportBedHeightEpochValue.class);
28
29
30 private BigDecimal station;
31 private BigDecimal height;
32
33 private BedHeightEpochValue peer;
34
35
36 public ImportBedHeightEpochValue() {
37 }
38
39
40 public ImportBedHeightEpochValue(BigDecimal station, BigDecimal height) {
41 this.station = station;
42 this.height = height;
43 }
44
45
46 public void storeDependencies(BedHeightEpoch bedHeight) {
47 getPeer(bedHeight);
48 }
49
50
51 public BedHeightEpochValue getPeer(BedHeightEpoch bedHeight) {
52 if (peer == null) {
53 Session session = ImporterSession.getInstance().getDatabaseSession();
54
55 Query query = session.createQuery(
56 "from BedHeightEpochValue where " +
57 " bedHeight=:bedHeight and " +
58 " station=:station and " +
59 " height=:height");
60
61 query.setParameter("bedHeight", bedHeight);
62 query.setParameter("station", station);
63 query.setParameter("height", height);
64
65 List<BedHeightEpochValue> values = query.list();
66
67 if (values.isEmpty()) {
68 peer = new BedHeightEpochValue(
69 bedHeight,
70 station,
71 height
72 );
73 session.save(peer);
74 }
75 else {
76 peer = values.get(0);
77 }
78 }
79
80 return peer;
81 }
82 }
83 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org