Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityMeasurement.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 | ac5bd90697c1 |
children | 4ee97d914501 |
comparison
equal
deleted
inserted
replaced
3942:43aa1ac8614b | 3943:a5b003595d6c |
---|---|
14 import de.intevation.flys.model.River; | 14 import de.intevation.flys.model.River; |
15 | 15 |
16 | 16 |
17 public class ImportFlowVelocityMeasurement { | 17 public class ImportFlowVelocityMeasurement { |
18 | 18 |
19 private static final Logger log = | 19 private static final Logger log = Logger |
20 Logger.getLogger(ImportFlowVelocityMeasurement.class); | 20 .getLogger(ImportFlowVelocityMeasurement.class); |
21 | |
22 | 21 |
23 private String description; | 22 private String description; |
24 | 23 |
25 private List<ImportFlowVelocityMeasurementValue> values; | 24 private List<ImportFlowVelocityMeasurementValue> values; |
26 | 25 |
27 private FlowVelocityMeasurement peer; | 26 private FlowVelocityMeasurement peer; |
28 | 27 |
29 | |
30 public ImportFlowVelocityMeasurement() { | 28 public ImportFlowVelocityMeasurement() { |
31 this(null); | 29 this(null); |
32 } | 30 } |
33 | 31 |
34 | |
35 public ImportFlowVelocityMeasurement(String description) { | 32 public ImportFlowVelocityMeasurement(String description) { |
36 this.description = description; | 33 this.description = description; |
37 this.values = new ArrayList<ImportFlowVelocityMeasurementValue>(); | 34 this.values = new ArrayList<ImportFlowVelocityMeasurementValue>(); |
38 } | 35 } |
39 | |
40 | 36 |
41 public void setDescription(String description) { | 37 public void setDescription(String description) { |
42 this.description = description; | 38 this.description = description; |
43 } | 39 } |
44 | 40 |
45 | |
46 public void addValue(ImportFlowVelocityMeasurementValue value) { | 41 public void addValue(ImportFlowVelocityMeasurementValue value) { |
47 this.values.add(value); | 42 this.values.add(value); |
48 } | 43 } |
49 | 44 |
50 | 45 public void storeDependencies(River river) throws SQLException, |
51 public void storeDependencies(River river) | 46 ConstraintViolationException { |
52 throws SQLException, ConstraintViolationException | |
53 { | |
54 log.debug("store dependencies"); | 47 log.debug("store dependencies"); |
55 | 48 |
56 FlowVelocityMeasurement peer = getPeer(river); | 49 FlowVelocityMeasurement peer = getPeer(river); |
57 | 50 |
58 for (ImportFlowVelocityMeasurementValue value: values) { | 51 if (peer != null) { |
59 value.storeDependencies(peer); | 52 for (ImportFlowVelocityMeasurementValue value : values) { |
53 value.storeDependencies(peer); | |
54 } | |
60 } | 55 } |
61 } | 56 } |
62 | 57 |
63 | |
64 public FlowVelocityMeasurement getPeer(River river) { | 58 public FlowVelocityMeasurement getPeer(River river) { |
65 if (peer == null) { | 59 if (peer == null) { |
66 Session session = ImporterSession.getInstance().getDatabaseSession(); | 60 Session session = ImporterSession.getInstance() |
61 .getDatabaseSession(); | |
67 | 62 |
68 Query query = session.createQuery( | 63 Query query = session |
69 "from FlowVelocityMeasurement where " + | 64 .createQuery("from FlowVelocityMeasurement where " |
70 " river=:river and " + | 65 + " river=:river and " + " description=:description"); |
71 " description=:description" | |
72 ); | |
73 | 66 |
74 query.setParameter("river", river); | 67 query.setParameter("river", river); |
75 query.setParameter("description", description); | 68 query.setParameter("description", description); |
76 | 69 |
77 List<FlowVelocityMeasurement> measurement = query.list(); | 70 List<FlowVelocityMeasurement> measurement = query.list(); |