Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportHYKEntry.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 | 392bbcd8a88b |
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.HYKEntry; | |
12 import org.dive4elements.river.model.HYK; | |
13 | |
14 import java.util.Date; | |
15 import java.util.List; | |
16 import java.util.ArrayList; | |
17 | |
18 import java.math.BigDecimal; | |
19 | |
20 import org.hibernate.Session; | |
21 import org.hibernate.Query; | |
22 | |
23 public class ImportHYKEntry | |
24 { | |
25 protected ImportHYK hyk; | |
26 protected BigDecimal km; | |
27 protected Date measure; | |
28 | |
29 protected List<ImportHYKFormation> formations; | |
30 | |
31 protected HYKEntry peer; | |
32 | |
33 public ImportHYKEntry() { | |
34 formations = new ArrayList<ImportHYKFormation>(); | |
35 } | |
36 | |
37 public ImportHYKEntry( | |
38 ImportHYK hyk, | |
39 BigDecimal km, | |
40 Date measure | |
41 ) { | |
42 this(); | |
43 this.hyk = hyk; | |
44 this.km = km; | |
45 this.measure = measure; | |
46 } | |
47 | |
48 public ImportHYK getHYK() { | |
49 return hyk; | |
50 } | |
51 | |
52 public void setHYK(ImportHYK hyk) { | |
53 this.hyk = hyk; | |
54 } | |
55 | |
56 public BigDecimal getKm() { | |
57 return km; | |
58 } | |
59 | |
60 public void setKm(BigDecimal km) { | |
61 this.km = km; | |
62 } | |
63 | |
64 public void addFormation(ImportHYKFormation formation) { | |
65 int numFormation = formations.size(); | |
66 formations.add(formation); | |
67 formation.setFormationNum(numFormation); | |
68 formation.setEntry(this); | |
69 } | |
70 | |
71 public void storeDependencies() { | |
72 getPeer(); | |
73 for (ImportHYKFormation formation: formations) { | |
74 formation.storeDependencies(); | |
75 } | |
76 } | |
77 | |
78 public HYKEntry getPeer() { | |
79 if (peer == null) { | |
80 HYK h = hyk.getPeer(); | |
81 Session session = ImporterSession.getInstance() | |
82 .getDatabaseSession(); | |
83 Query query = session.createQuery( | |
84 "from HYKEntry where HYK=:hyk " + | |
85 "and km=:km and measure=:measure"); | |
86 query.setParameter("hyk", h); | |
87 query.setParameter("km", km); | |
88 query.setParameter("measure", measure); | |
89 List<HYKEntry> entries = query.list(); | |
90 if (entries.isEmpty()) { | |
91 peer = new HYKEntry(h, km, measure); | |
92 session.save(peer); | |
93 } | |
94 else { | |
95 peer = entries.get(0); | |
96 } | |
97 } | |
98 return peer; | |
99 } | |
100 } | |
101 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |