Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportMorphWidth.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 | 0a536eb5d668 |
comparison
equal
deleted
inserted
replaced
2818:25ed1f18fcc4 | 2819:0c2567626754 |
---|---|
1 package de.intevation.flys.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 de.intevation.flys.model.MorphologicalWidth; | |
12 import de.intevation.flys.model.River; | |
13 | |
14 | |
15 public class ImportMorphWidth { | |
16 | |
17 private static Logger log = Logger.getLogger(ImportMorphWidth.class); | |
18 | |
19 | |
20 protected MorphologicalWidth peer; | |
21 | |
22 protected ImportUnit unit; | |
23 | |
24 protected List<ImportMorphWidthValue> values; | |
25 | |
26 | |
27 public ImportMorphWidth(ImportUnit unit) { | |
28 this.unit = unit; | |
29 this.values = new ArrayList<ImportMorphWidthValue>(); | |
30 } | |
31 | |
32 | |
33 public void addValue(ImportMorphWidthValue value) { | |
34 this.values.add(value); | |
35 } | |
36 | |
37 | |
38 public void storeDependencies(River river) { | |
39 log.info("store dependencies"); | |
40 | |
41 MorphologicalWidth peer = getPeer(river); | |
42 | |
43 log.info("store morphological width values"); | |
44 | |
45 for (ImportMorphWidthValue value: values) { | |
46 value.storeDependencies(peer); | |
47 } | |
48 } | |
49 | |
50 | |
51 public MorphologicalWidth getPeer(River river) { | |
52 log.info("get peer"); | |
53 | |
54 if (peer == null) { | |
55 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
56 | |
57 Query query = session.createQuery( | |
58 "from MorphologicalWidth where " + | |
59 " river=:river and " + | |
60 " unit=:unit"); | |
61 | |
62 query.setParameter("river", river); | |
63 query.setParameter("unit", unit.getPeer()); | |
64 | |
65 List<MorphologicalWidth> widths = query.list(); | |
66 | |
67 if (widths.isEmpty()) { | |
68 log.debug("Create new MorphologicalWidth DB instance."); | |
69 | |
70 peer = new MorphologicalWidth(river, unit.getPeer()); | |
71 | |
72 session.save(peer); | |
73 } | |
74 else { | |
75 peer = widths.get(0); | |
76 } | |
77 } | |
78 | |
79 return peer; | |
80 } | |
81 } | |
82 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |