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