comparison flys-backend/src/main/java/org/dive4elements/river/importer/ImportMorphWidthValue.java @ 5828:dfb26b03b179

Moved directories to org.dive4elements.river
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 11:53:11 +0200
parents flys-backend/src/main/java/de/intevation/flys/importer/ImportMorphWidthValue.java@212c33c9a5e2
children 18619c1e7c2a
comparison
equal deleted inserted replaced
5827:e308d4ecd35a 5828:dfb26b03b179
1 package de.intevation.flys.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 de.intevation.flys.model.MorphologicalWidth;
13 import de.intevation.flys.model.MorphologicalWidthValue;
14
15
16 public class ImportMorphWidthValue {
17
18 private static Logger log = Logger.getLogger(ImportMorphWidthValue.class);
19
20
21 protected MorphologicalWidthValue peer;
22
23 protected BigDecimal station;
24 protected BigDecimal width;
25
26 protected String description;
27
28
29 public ImportMorphWidthValue(
30 BigDecimal station,
31 BigDecimal width,
32 String description
33 ) {
34 this.station = station;
35 this.width = width;
36 this.description = description;
37 }
38
39
40 public void storeDependencies(MorphologicalWidth parent) {
41 getPeer(parent);
42 }
43
44
45 public MorphologicalWidthValue getPeer(MorphologicalWidth parent) {
46 if (peer == null) {
47 Session session = ImporterSession.getInstance().getDatabaseSession();
48
49 Query query = session.createQuery(
50 "from MorphologicalWidthValue where " +
51 " morphologicalWidth=:morphologicalWidth and " +
52 " station=:station and " +
53 " width=:width and " +
54 " description=:description");
55
56 query.setParameter("morphologicalWidth", parent);
57 query.setParameter("station", station);
58 query.setParameter("width", width);
59 query.setParameter("description", description);
60
61 List<MorphologicalWidthValue> values = query.list();
62
63 if (values.isEmpty()) {
64 peer = new MorphologicalWidthValue(
65 parent,
66 station,
67 width,
68 description
69 );
70
71 session.save(peer);
72 }
73 else {
74 peer = values.get(0);
75 }
76 }
77
78 return peer;
79 }
80 }
81 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org