Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensity.java @ 2817:8979f2294af9
Finished parsing MINFO specific sediment density.
flys-backend/trunk@4234 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 13 Apr 2012 11:45:29 +0000 |
parents | 70b4a31a3306 |
children | aed7aba93718 |
comparison
equal
deleted
inserted
replaced
2816:70b4a31a3306 | 2817:8979f2294af9 |
---|---|
1 package de.intevation.flys.importer; | 1 package de.intevation.flys.importer; |
2 | |
3 import java.sql.SQLException; | |
2 | 4 |
3 import java.util.ArrayList; | 5 import java.util.ArrayList; |
4 import java.util.List; | 6 import java.util.List; |
5 | 7 |
6 import org.apache.log4j.Logger; | 8 import org.apache.log4j.Logger; |
9 | |
10 import org.hibernate.Session; | |
11 import org.hibernate.Query; | |
12 import org.hibernate.exception.ConstraintViolationException; | |
7 | 13 |
8 import de.intevation.flys.model.River; | 14 import de.intevation.flys.model.River; |
9 import de.intevation.flys.model.SedimentDensity; | 15 import de.intevation.flys.model.SedimentDensity; |
10 | 16 |
11 | 17 |
18 | 24 |
19 protected ImportDepth depth; | 25 protected ImportDepth depth; |
20 | 26 |
21 protected ImportUnit unit; | 27 protected ImportUnit unit; |
22 | 28 |
29 protected String description; | |
30 | |
23 protected List<ImportSedimentDensityValue> values; | 31 protected List<ImportSedimentDensityValue> values; |
24 | 32 |
25 | 33 |
26 public ImportSedimentDensity() { | 34 public ImportSedimentDensity(String description) { |
27 values = new ArrayList<ImportSedimentDensityValue>(); | 35 this.description = description; |
36 this.values = new ArrayList<ImportSedimentDensityValue>(); | |
37 } | |
38 | |
39 | |
40 public String getDescription() { | |
41 return description; | |
28 } | 42 } |
29 | 43 |
30 | 44 |
31 public void setDepth(ImportDepth depth) { | 45 public void setDepth(ImportDepth depth) { |
32 this.depth = depth; | 46 this.depth = depth; |
41 public void addValue(ImportSedimentDensityValue value) { | 55 public void addValue(ImportSedimentDensityValue value) { |
42 values.add(value); | 56 values.add(value); |
43 } | 57 } |
44 | 58 |
45 | 59 |
46 public void storeDependencies(River river) { | 60 public void storeDependencies(River river) |
61 throws SQLException, ConstraintViolationException | |
62 { | |
47 log.info("store dependencies"); | 63 log.info("store dependencies"); |
64 | |
65 if (depth != null) { | |
66 depth.storeDependencies(); | |
67 } | |
68 | |
69 log.info("store sediment density values."); | |
70 | |
71 SedimentDensity peer = getPeer(river); | |
72 | |
73 for (ImportSedimentDensityValue value: values) { | |
74 value.storeDependencies(peer); | |
75 } | |
48 } | 76 } |
49 | 77 |
50 | 78 |
51 public SedimentDensity getPeer(River river) { | 79 public SedimentDensity getPeer(River river) { |
52 log.info("get peer"); | 80 log.info("get peer"); |
53 | 81 |
54 return null; | 82 if (peer == null) { |
83 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
84 | |
85 Query query = session.createQuery( | |
86 "from SedimentDensity where " + | |
87 " river=:river and " + | |
88 " depth=:depth and " + | |
89 " unit=:unit"); | |
90 | |
91 query.setParameter("river", river); | |
92 query.setParameter("depth", depth.getPeer()); | |
93 query.setParameter("unit", unit.getPeer()); | |
94 | |
95 List<SedimentDensity> density = query.list(); | |
96 | |
97 if (density.isEmpty()) { | |
98 log.debug("Create new SedimentDensity DB instance."); | |
99 | |
100 peer = new SedimentDensity( | |
101 river, | |
102 depth.getPeer(), | |
103 unit.getPeer(), | |
104 description); | |
105 | |
106 session.save(peer); | |
107 } | |
108 else { | |
109 peer = density.get(0); | |
110 } | |
111 } | |
112 | |
113 return peer; | |
55 } | 114 } |
56 } | 115 } |
57 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 116 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |