Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModel.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.sql.SQLException; | |
4 import java.util.List; | |
5 | |
6 import org.apache.log4j.Logger; | |
7 | |
8 import org.hibernate.Session; | |
9 import org.hibernate.Query; | |
10 import org.hibernate.exception.ConstraintViolationException; | |
11 | |
12 import de.intevation.flys.model.DischargeZone; | |
13 import de.intevation.flys.model.FlowVelocityModel; | |
14 import de.intevation.flys.model.River; | |
15 | |
16 | |
17 public class ImportFlowVelocityModel { | |
18 | |
19 private static final Logger log = | |
20 Logger.getLogger(ImportFlowVelocityModel.class); | |
21 | |
22 | |
23 private String description; | |
24 | |
25 private ImportDischargeZone dischargeZone; | |
26 | |
27 private List<ImportFlowVelocityModelValue> values; | |
28 | |
29 private FlowVelocityModel peer; | |
30 | |
31 | |
32 public ImportFlowVelocityModel( | |
33 ImportDischargeZone dischargeZone, | |
34 String description | |
35 ) { | |
36 this.dischargeZone = dischargeZone; | |
37 this.description = description; | |
38 } | |
39 | |
40 | |
41 public void storeDependencies(River river) | |
42 throws SQLException, ConstraintViolationException | |
43 { | |
44 log.debug("store dependencies"); | |
45 | |
46 dischargeZone.storeDependencies(river); | |
47 | |
48 FlowVelocityModel peer = getPeer(river); | |
49 | |
50 for (ImportFlowVelocityModelValue value: values) { | |
51 value.storeDependencies(peer); | |
52 } | |
53 } | |
54 | |
55 | |
56 public FlowVelocityModel getPeer(River river) { | |
57 if (peer == null) { | |
58 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
59 | |
60 DischargeZone zone = dischargeZone.getPeer(river); | |
61 | |
62 Query query = session.createQuery( | |
63 "from FlowVelocityModel where " + | |
64 " river:=river and " + | |
65 " dischargeZone=:dischargeZone" | |
66 ); | |
67 | |
68 query.setParameter("river", river); | |
69 query.setParameter("dischargeZone", zone); | |
70 | |
71 List<FlowVelocityModel> model = query.list(); | |
72 | |
73 if (model.isEmpty()) { | |
74 peer = new FlowVelocityModel(river, zone); | |
75 session.save(peer); | |
76 } | |
77 else { | |
78 peer = model.get(0); | |
79 } | |
80 } | |
81 | |
82 return peer; | |
83 } | |
84 } | |
85 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |