Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportFlowVelocityMeasurement.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-backend/src/main/java/org/dive4elements/river/importer/ImportFlowVelocityMeasurement.java@18619c1e7c2a |
children | 4dd33b86dc61 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.importer; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import org.apache.log4j.Logger; | |
7 | |
8 import org.hibernate.Session; | |
9 import org.hibernate.Query; | |
10 | |
11 import org.dive4elements.river.model.FlowVelocityMeasurement; | |
12 import org.dive4elements.river.model.River; | |
13 | |
14 | |
15 public class ImportFlowVelocityMeasurement { | |
16 | |
17 private static final Logger log = Logger | |
18 .getLogger(ImportFlowVelocityMeasurement.class); | |
19 | |
20 private String description; | |
21 | |
22 private List<ImportFlowVelocityMeasurementValue> values; | |
23 | |
24 private FlowVelocityMeasurement peer; | |
25 | |
26 public ImportFlowVelocityMeasurement() { | |
27 this(null); | |
28 } | |
29 | |
30 public ImportFlowVelocityMeasurement(String description) { | |
31 this.description = description; | |
32 this.values = new ArrayList<ImportFlowVelocityMeasurementValue>(); | |
33 } | |
34 | |
35 public void setDescription(String description) { | |
36 this.description = description; | |
37 } | |
38 | |
39 public void addValue(ImportFlowVelocityMeasurementValue value) { | |
40 this.values.add(value); | |
41 } | |
42 | |
43 public void storeDependencies(River river) { | |
44 log.debug("store dependencies"); | |
45 | |
46 FlowVelocityMeasurement peer = getPeer(river); | |
47 | |
48 if (peer != null) { | |
49 for (ImportFlowVelocityMeasurementValue value : values) { | |
50 value.storeDependencies(peer); | |
51 } | |
52 } | |
53 } | |
54 | |
55 public FlowVelocityMeasurement getPeer(River river) { | |
56 if (peer == null) { | |
57 Session session = ImporterSession.getInstance() | |
58 .getDatabaseSession(); | |
59 | |
60 Query query = session | |
61 .createQuery("from FlowVelocityMeasurement where " | |
62 + " river=:river and " + " description=:description"); | |
63 | |
64 query.setParameter("river", river); | |
65 query.setParameter("description", description); | |
66 | |
67 List<FlowVelocityMeasurement> measurement = query.list(); | |
68 | |
69 if (measurement.isEmpty()) { | |
70 peer = new FlowVelocityMeasurement(river, description); | |
71 | |
72 session.save(peer); | |
73 } | |
74 else { | |
75 peer = measurement.get(0); | |
76 } | |
77 } | |
78 | |
79 return peer; | |
80 } | |
81 } | |
82 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |