comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportCrossSection.java @ 1204:22858e7cca79

Integrated PRF parsing into importer. Needs testing! flys-backend/trunk@2309 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 07 Jul 2011 22:25:38 +0000
parents
children 5f1506fc7636
comparison
equal deleted inserted replaced
1203:3c01bef43a98 1204:22858e7cca79
1 package de.intevation.flys.importer;
2
3 import de.intevation.flys.model.River;
4 import de.intevation.flys.model.CrossSection;
5 import de.intevation.flys.model.TimeInterval;
6
7 import org.hibernate.Session;
8 import org.hibernate.Query;
9
10 import java.util.List;
11
12 public class ImportCrossSection
13 {
14 protected ImportRiver river;
15 protected String description;
16 protected ImportTimeInterval timeInterval;
17 protected List<ImportCrossSectionLine> lines;
18
19 protected CrossSection peer;
20
21 public ImportCrossSection() {
22 }
23
24 public ImportCrossSection(
25 ImportRiver river,
26 String description,
27 ImportTimeInterval timeInterval,
28 List<ImportCrossSectionLine> lines
29 ) {
30 this.river = river;
31 this.description = description;
32 this.timeInterval = timeInterval;
33 this.lines = lines;
34 wireWithLines();
35 }
36
37 public void wireWithLines() {
38 for (ImportCrossSectionLine line: lines) {
39 line.setCrossSection(this);
40 }
41 }
42
43 public ImportRiver getRiver() {
44 return river;
45 }
46
47 public void setRiver(ImportRiver river) {
48 this.river = river;
49 }
50
51 public String getDescription() {
52 return description;
53 }
54
55 public void setDescription(String description) {
56 this.description = description;
57 }
58
59 public ImportTimeInterval getTimeInterval() {
60 return timeInterval;
61 }
62
63 public void setTimeInterval(ImportTimeInterval timeInterval) {
64 this.timeInterval = timeInterval;
65 }
66
67 public void storeDependencies() {
68
69 getPeer();
70
71 for (ImportCrossSectionLine line: lines) {
72 line.storeDependencies();
73 }
74 }
75
76 public CrossSection getPeer() {
77
78 if (peer == null) {
79 River r = river.getPeer();
80 TimeInterval t = timeInterval != null
81 ? timeInterval.getPeer()
82 : null;
83
84 Session session =
85 ImporterSession.getInstance().getDatabaseSession();
86
87 Query query = session.createQuery(
88 "from CrossSection where " +
89 "river=:r and " +
90 "timeInterval=:t and " +
91 "description=:d");
92
93 query.setParameter("r", r);
94 query.setParameter("t", t);
95 query.setParameter("d", description);
96
97 List<CrossSection> crossSections = query.list();
98 if (crossSections.isEmpty()) {
99 peer = new CrossSection(r, t, description);
100 session.save(peer);
101 }
102 else {
103 peer = crossSections.get(0);
104 }
105 }
106 return peer;
107 }
108 }
109 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org