Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportSedimentDensityValue.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/ImportSedimentDensityValue.java@18619c1e7c2a |
children | 4dd33b86dc61 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.importer; | |
2 | |
3 import java.math.BigDecimal; | |
4 | |
5 import java.util.List; | |
6 | |
7 import org.apache.log4j.Logger; | |
8 | |
9 import org.hibernate.Session; | |
10 import org.hibernate.Query; | |
11 | |
12 import org.dive4elements.river.model.SedimentDensity; | |
13 import org.dive4elements.river.model.SedimentDensityValue; | |
14 | |
15 | |
16 public class ImportSedimentDensityValue { | |
17 | |
18 private static final Logger log = | |
19 Logger.getLogger(ImportSedimentDensityValue.class); | |
20 | |
21 | |
22 protected SedimentDensityValue peer; | |
23 | |
24 protected BigDecimal station; | |
25 | |
26 protected BigDecimal shoreOffset; | |
27 | |
28 protected BigDecimal density; | |
29 | |
30 private BigDecimal year; | |
31 | |
32 protected String description; | |
33 | |
34 | |
35 public ImportSedimentDensityValue( | |
36 BigDecimal station, | |
37 BigDecimal shoreOffset, | |
38 BigDecimal density, | |
39 BigDecimal year, | |
40 String description | |
41 ) { | |
42 this.station = station; | |
43 this.shoreOffset = shoreOffset; | |
44 this.density = density; | |
45 this.year = year; | |
46 this.description = description; | |
47 } | |
48 | |
49 | |
50 public void storeDependencies(SedimentDensity sedimentDensity) { | |
51 log.info("store dependencies"); | |
52 | |
53 getPeer(sedimentDensity); | |
54 } | |
55 | |
56 | |
57 public SedimentDensityValue getPeer(SedimentDensity sedimentDensity) { | |
58 log.info("get peer"); | |
59 | |
60 if (peer == null) { | |
61 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
62 | |
63 Query query = session.createQuery( | |
64 "from SedimentDensityValue where " + | |
65 " sedimentDensity=:sedimentDensity and " + | |
66 " station=:station and " + | |
67 " shoreOffset=:shoreOffset and " + | |
68 " density=:density and " + | |
69 " year=:year and " + | |
70 " description=:description"); | |
71 | |
72 query.setParameter("sedimentDensity", sedimentDensity); | |
73 query.setParameter("station", station); | |
74 query.setParameter("shoreOffset", shoreOffset); | |
75 query.setParameter("density", density); | |
76 query.setParameter("year", year); | |
77 query.setParameter("description", description); | |
78 | |
79 List<SedimentDensityValue> values = query.list(); | |
80 if (values.isEmpty()) { | |
81 log.debug("Create new SedimentDensityValue DB instance."); | |
82 | |
83 peer = new SedimentDensityValue( | |
84 sedimentDensity, | |
85 station, | |
86 shoreOffset, | |
87 density, | |
88 year, | |
89 description); | |
90 | |
91 session.save(peer); | |
92 } | |
93 else { | |
94 peer = values.get(0); | |
95 } | |
96 } | |
97 | |
98 return peer; | |
99 } | |
100 } | |
101 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |