Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportMorphWidthValue.java @ 2819:0c2567626754
Tiny schema modification specific to MINFO morphological width values; added importer classes.
flys-backend/trunk@4236 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 13 Apr 2012 12:53:29 +0000 |
parents | |
children | 212c33c9a5e2 |
comparison
equal
deleted
inserted
replaced
2818:25ed1f18fcc4 | 2819:0c2567626754 |
---|---|
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 log.info("store dependencies"); | |
42 | |
43 getPeer(parent); | |
44 } | |
45 | |
46 | |
47 public MorphologicalWidthValue getPeer(MorphologicalWidth parent) { | |
48 log.info("get peer"); | |
49 | |
50 if (peer == null) { | |
51 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
52 | |
53 Query query = session.createQuery( | |
54 "from MorphologicalWidthValue where " + | |
55 " morphologicalWidth=:morphologicalWidth and " + | |
56 " station=:station and " + | |
57 " width=:width and " + | |
58 " description=:description"); | |
59 | |
60 query.setParameter("morphologicalWidth", parent); | |
61 query.setParameter("station", station); | |
62 query.setParameter("width", width); | |
63 query.setParameter("description", description); | |
64 | |
65 List<MorphologicalWidthValue> values = query.list(); | |
66 | |
67 if (values.isEmpty()) { | |
68 log.debug("Create new MorphologicalWidthValue DB instance."); | |
69 | |
70 peer = new MorphologicalWidthValue( | |
71 parent, | |
72 station, | |
73 width, | |
74 description | |
75 ); | |
76 | |
77 session.save(peer); | |
78 } | |
79 else { | |
80 peer = values.get(0); | |
81 } | |
82 } | |
83 | |
84 return peer; | |
85 } | |
86 } | |
87 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |