Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModel.java @ 3943:a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
flys-backend/trunk@5520 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 19 Sep 2012 10:05:36 +0000 |
parents | 5b54a648f702 |
children | c7ce7c9e405e |
comparison
equal
deleted
inserted
replaced
3942:43aa1ac8614b | 3943:a5b003595d6c |
---|---|
15 import de.intevation.flys.model.River; | 15 import de.intevation.flys.model.River; |
16 | 16 |
17 | 17 |
18 public class ImportFlowVelocityModel { | 18 public class ImportFlowVelocityModel { |
19 | 19 |
20 private static final Logger log = | 20 private static final Logger log = Logger |
21 Logger.getLogger(ImportFlowVelocityModel.class); | 21 .getLogger(ImportFlowVelocityModel.class); |
22 | |
23 | 22 |
24 private String description; | 23 private String description; |
25 | 24 |
26 private ImportDischargeZone dischargeZone; | 25 private ImportDischargeZone dischargeZone; |
27 | 26 |
28 private List<ImportFlowVelocityModelValue> values; | 27 private List<ImportFlowVelocityModelValue> values; |
29 | 28 |
30 private FlowVelocityModel peer; | 29 private FlowVelocityModel peer; |
31 | 30 |
32 | |
33 public ImportFlowVelocityModel() { | 31 public ImportFlowVelocityModel() { |
34 values = new ArrayList<ImportFlowVelocityModelValue>(); | 32 values = new ArrayList<ImportFlowVelocityModelValue>(); |
35 } | 33 } |
36 | 34 |
37 | 35 public ImportFlowVelocityModel(ImportDischargeZone dischargeZone, |
38 public ImportFlowVelocityModel( | 36 String description) { |
39 ImportDischargeZone dischargeZone, | |
40 String description | |
41 ) { | |
42 this(); | 37 this(); |
43 | 38 |
44 this.dischargeZone = dischargeZone; | 39 this.dischargeZone = dischargeZone; |
45 this.description = description; | 40 this.description = description; |
46 } | 41 } |
47 | |
48 | 42 |
49 public void setDischargeZone(ImportDischargeZone dischargeZone) { | 43 public void setDischargeZone(ImportDischargeZone dischargeZone) { |
50 this.dischargeZone = dischargeZone; | 44 this.dischargeZone = dischargeZone; |
51 } | 45 } |
52 | 46 |
53 | |
54 public void setDescription(String description) { | 47 public void setDescription(String description) { |
55 this.description = description; | 48 this.description = description; |
56 } | 49 } |
57 | |
58 | 50 |
59 public void addValue(ImportFlowVelocityModelValue value) { | 51 public void addValue(ImportFlowVelocityModelValue value) { |
60 this.values.add(value); | 52 this.values.add(value); |
61 } | 53 } |
62 | 54 |
63 | 55 public void storeDependencies(River river) throws SQLException, |
64 public void storeDependencies(River river) | 56 ConstraintViolationException { |
65 throws SQLException, ConstraintViolationException | |
66 { | |
67 log.debug("store dependencies"); | 57 log.debug("store dependencies"); |
68 | 58 |
69 if (dischargeZone == null) { | 59 if (dischargeZone == null) { |
70 log.warn("skip flow velocity model: No discharge zone specified."); | 60 log.warn("skip flow velocity model: No discharge zone specified."); |
71 return; | 61 return; |
73 | 63 |
74 dischargeZone.storeDependencies(river); | 64 dischargeZone.storeDependencies(river); |
75 | 65 |
76 FlowVelocityModel peer = getPeer(river); | 66 FlowVelocityModel peer = getPeer(river); |
77 | 67 |
78 int i = 0; | 68 if (peer != null) { |
69 int i = 0; | |
79 | 70 |
80 for (ImportFlowVelocityModelValue value: values) { | 71 for (ImportFlowVelocityModelValue value : values) { |
81 value.storeDependencies(peer); | 72 value.storeDependencies(peer); |
82 i++; | 73 i++; |
74 } | |
75 | |
76 log.info("stored " + i + " flow velocity model values."); | |
83 } | 77 } |
84 | |
85 log.info("stored " + i + " flow velocity model values."); | |
86 } | 78 } |
87 | |
88 | 79 |
89 public FlowVelocityModel getPeer(River river) { | 80 public FlowVelocityModel getPeer(River river) { |
90 if (peer == null) { | 81 if (peer == null) { |
91 Session session = ImporterSession.getInstance().getDatabaseSession(); | 82 Session session = ImporterSession.getInstance() |
83 .getDatabaseSession(); | |
92 | 84 |
93 DischargeZone zone = dischargeZone.getPeer(river); | 85 DischargeZone zone = dischargeZone.getPeer(river); |
94 | 86 |
95 Query query = session.createQuery( | 87 Query query = session.createQuery("from FlowVelocityModel where " |
96 "from FlowVelocityModel where " + | 88 + " river=:river and " + " dischargeZone=:dischargeZone"); |
97 " river=:river and " + | |
98 " dischargeZone=:dischargeZone" | |
99 ); | |
100 | 89 |
101 query.setParameter("river", river); | 90 query.setParameter("river", river); |
102 query.setParameter("dischargeZone", zone); | 91 query.setParameter("dischargeZone", zone); |
103 | 92 |
104 List<FlowVelocityModel> model = query.list(); | 93 List<FlowVelocityModel> model = query.list(); |