Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportMorphWidth.java @ 7730:e1b831fe435a slt-simplify-cross-sections
Merged default into slt-simplify-cross-sections branch and updated package and class names.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Mon, 20 Jan 2014 14:04:20 +0100 |
parents | 4c3ccf2b0304 |
children | 0a5239a1e46e |
comparison
equal
deleted
inserted
replaced
5084:ca45dd039b54 | 7730:e1b831fe435a |
---|---|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.importer; | |
10 | |
11 import org.dive4elements.river.model.MorphologicalWidth; | |
12 import org.dive4elements.river.model.River; | |
13 | |
14 import java.util.ArrayList; | |
15 import java.util.List; | |
16 | |
17 import org.apache.log4j.Logger; | |
18 | |
19 import org.hibernate.Query; | |
20 import org.hibernate.Session; | |
21 | |
22 | |
23 public class ImportMorphWidth { | |
24 | |
25 private static Logger log = Logger.getLogger(ImportMorphWidth.class); | |
26 | |
27 protected MorphologicalWidth peer; | |
28 | |
29 protected ImportUnit unit; | |
30 | |
31 protected List<ImportMorphWidthValue> values; | |
32 | |
33 public ImportMorphWidth() { | |
34 this.values = new ArrayList<ImportMorphWidthValue>(); | |
35 } | |
36 | |
37 public void addValue(ImportMorphWidthValue value) { | |
38 this.values.add(value); | |
39 } | |
40 | |
41 public void setUnit(ImportUnit unit) { | |
42 this.unit = unit; | |
43 } | |
44 | |
45 public void storeDependencies(River river) { | |
46 log.info("store dependencies"); | |
47 | |
48 MorphologicalWidth peer = getPeer(river); | |
49 | |
50 if (peer != null) { | |
51 log.info("store morphological width values"); | |
52 | |
53 for (ImportMorphWidthValue value : values) { | |
54 value.storeDependencies(peer); | |
55 } | |
56 } | |
57 } | |
58 | |
59 public MorphologicalWidth getPeer(River river) { | |
60 log.info("get peer"); | |
61 | |
62 if (peer == null) { | |
63 Session session = ImporterSession.getInstance() | |
64 .getDatabaseSession(); | |
65 | |
66 Query query = session.createQuery("from MorphologicalWidth where " | |
67 + " river=:river and " + " unit=:unit"); | |
68 | |
69 query.setParameter("river", river); | |
70 query.setParameter("unit", unit.getPeer()); | |
71 | |
72 List<MorphologicalWidth> widths = query.list(); | |
73 | |
74 if (widths.isEmpty()) { | |
75 log.debug("Create new MorphologicalWidth DB instance."); | |
76 | |
77 peer = new MorphologicalWidth(river, unit.getPeer()); | |
78 | |
79 session.save(peer); | |
80 } | |
81 else { | |
82 peer = widths.get(0); | |
83 } | |
84 } | |
85 | |
86 return peer; | |
87 } | |
88 } | |
89 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |