Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModelValue.java @ 2827:85b25e74594f
Added temp classes used during the import process of flow velocity data.
flys-backend/trunk@4244 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 17 Apr 2012 08:50:15 +0000 |
parents | |
children | ac13e466a55e |
comparison
equal
deleted
inserted
replaced
2826:c3f8cf0cdf69 | 2827:85b25e74594f |
---|---|
1 package de.intevation.flys.importer; | |
2 | |
3 import java.math.BigDecimal; | |
4 import java.sql.SQLException; | |
5 import java.util.List; | |
6 | |
7 import org.hibernate.Session; | |
8 import org.hibernate.Query; | |
9 import org.hibernate.exception.ConstraintViolationException; | |
10 | |
11 import de.intevation.flys.model.FlowVelocityModel; | |
12 import de.intevation.flys.model.FlowVelocityModelValue; | |
13 | |
14 | |
15 public class ImportFlowVelocityModelValue { | |
16 | |
17 private BigDecimal station; | |
18 private BigDecimal totalChannel; | |
19 private BigDecimal mainChannel; | |
20 private BigDecimal shearStress; | |
21 | |
22 private FlowVelocityModelValue peer; | |
23 | |
24 | |
25 public ImportFlowVelocityModelValue( | |
26 BigDecimal station, | |
27 BigDecimal totalChannel, | |
28 BigDecimal mainChannel, | |
29 BigDecimal shearStress | |
30 ) { | |
31 this.station = station; | |
32 this.totalChannel = totalChannel; | |
33 this.mainChannel = mainChannel; | |
34 this.shearStress = shearStress; | |
35 } | |
36 | |
37 | |
38 public void storeDependencies(FlowVelocityModel model) | |
39 throws SQLException, ConstraintViolationException | |
40 { | |
41 getPeer(model); | |
42 } | |
43 | |
44 | |
45 public FlowVelocityModelValue getPeer(FlowVelocityModel model) { | |
46 if (peer == null) { | |
47 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
48 | |
49 Query query = session.createQuery( | |
50 "from FlowVelocityModelValue where " + | |
51 " model:=model and " + | |
52 " station=:station" | |
53 ); | |
54 | |
55 query.setParameter("model", model); | |
56 query.setParameter("station", station); | |
57 | |
58 List<FlowVelocityModelValue> values = query.list(); | |
59 | |
60 if (values.isEmpty()) { | |
61 peer = new FlowVelocityModelValue( | |
62 model, station, totalChannel, mainChannel, shearStress); | |
63 | |
64 session.save(peer); | |
65 } | |
66 else { | |
67 peer = values.get(0); | |
68 } | |
69 } | |
70 | |
71 return peer; | |
72 } | |
73 } | |
74 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |