Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightEpochValue.java @ 2810:04eeb45df27b
Implemented model classes and importer classes for bed height epochs.
flys-backend/trunk@4222 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 12 Apr 2012 12:50:49 +0000 |
parents | |
children | 8926571e47fb |
comparison
equal
deleted
inserted
replaced
2809:f283212966e8 | 2810:04eeb45df27b |
---|---|
1 package de.intevation.flys.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 de.intevation.flys.model.BedHeightEpoch; | |
13 import de.intevation.flys.model.BedHeightEpochValue; | |
14 | |
15 | |
16 public class ImportBedHeightEpochValue { | |
17 | |
18 private static final Logger log = | |
19 Logger.getLogger(ImportBedHeightEpochValue.class); | |
20 | |
21 | |
22 private BigDecimal station; | |
23 private BigDecimal height; | |
24 | |
25 private BedHeightEpochValue peer; | |
26 | |
27 | |
28 public ImportBedHeightEpochValue() { | |
29 } | |
30 | |
31 | |
32 public ImportBedHeightEpochValue(BigDecimal station, BigDecimal height) { | |
33 this.station = station; | |
34 this.height = height; | |
35 } | |
36 | |
37 | |
38 public void storeDependencies(BedHeightEpoch bedHeight) { | |
39 getPeer(bedHeight); | |
40 } | |
41 | |
42 | |
43 public BedHeightEpochValue getPeer(BedHeightEpoch bedHeight) { | |
44 if (peer == null) { | |
45 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
46 | |
47 Query query = session.createQuery( | |
48 "from BedHeightEpochValue where " + | |
49 " bedHeight=:bedHeight and " + | |
50 " station=:station and " + | |
51 " height=:height"); | |
52 | |
53 query.setParameter("bedHeight", bedHeight); | |
54 query.setParameter("station", station); | |
55 query.setParameter("height", height); | |
56 | |
57 List<BedHeightEpochValue> values = query.list(); | |
58 | |
59 if (values.isEmpty()) { | |
60 peer = new BedHeightEpochValue( | |
61 bedHeight, | |
62 station, | |
63 height | |
64 ); | |
65 session.save(peer); | |
66 } | |
67 else { | |
68 peer = values.get(0); | |
69 } | |
70 } | |
71 | |
72 return peer; | |
73 } | |
74 } | |
75 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |