Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportHYKEntry.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-backend/src/main/java/org/dive4elements/river/importer/ImportHYKEntry.java@18619c1e7c2a |
children | 4dd33b86dc61 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.importer; | |
2 | |
3 import org.dive4elements.river.model.HYKEntry; | |
4 import org.dive4elements.river.model.HYK; | |
5 | |
6 import java.util.Date; | |
7 import java.util.List; | |
8 import java.util.ArrayList; | |
9 | |
10 import java.math.BigDecimal; | |
11 | |
12 import org.hibernate.Session; | |
13 import org.hibernate.Query; | |
14 | |
15 public class ImportHYKEntry | |
16 { | |
17 protected ImportHYK hyk; | |
18 protected BigDecimal km; | |
19 protected Date measure; | |
20 | |
21 protected List<ImportHYKFormation> formations; | |
22 | |
23 protected HYKEntry peer; | |
24 | |
25 public ImportHYKEntry() { | |
26 formations = new ArrayList<ImportHYKFormation>(); | |
27 } | |
28 | |
29 public ImportHYKEntry( | |
30 ImportHYK hyk, | |
31 BigDecimal km, | |
32 Date measure | |
33 ) { | |
34 this(); | |
35 this.hyk = hyk; | |
36 this.km = km; | |
37 this.measure = measure; | |
38 } | |
39 | |
40 public ImportHYK getHYK() { | |
41 return hyk; | |
42 } | |
43 | |
44 public void setHYK(ImportHYK hyk) { | |
45 this.hyk = hyk; | |
46 } | |
47 | |
48 public BigDecimal getKm() { | |
49 return km; | |
50 } | |
51 | |
52 public void setKm(BigDecimal km) { | |
53 this.km = km; | |
54 } | |
55 | |
56 public void addFormation(ImportHYKFormation formation) { | |
57 int numFormation = formations.size(); | |
58 formations.add(formation); | |
59 formation.setFormationNum(numFormation); | |
60 formation.setEntry(this); | |
61 } | |
62 | |
63 public void storeDependencies() { | |
64 getPeer(); | |
65 for (ImportHYKFormation formation: formations) { | |
66 formation.storeDependencies(); | |
67 } | |
68 } | |
69 | |
70 public HYKEntry getPeer() { | |
71 if (peer == null) { | |
72 HYK h = hyk.getPeer(); | |
73 Session session = ImporterSession.getInstance() | |
74 .getDatabaseSession(); | |
75 Query query = session.createQuery( | |
76 "from HYKEntry where HYK=:hyk " + | |
77 "and km=:km and measure=:measure"); | |
78 query.setParameter("hyk", h); | |
79 query.setParameter("km", km); | |
80 query.setParameter("measure", measure); | |
81 List<HYKEntry> entries = query.list(); | |
82 if (entries.isEmpty()) { | |
83 peer = new HYKEntry(h, km, measure); | |
84 session.save(peer); | |
85 } | |
86 else { | |
87 peer = entries.get(0); | |
88 } | |
89 } | |
90 return peer; | |
91 } | |
92 } | |
93 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |