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