Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportCrossSection.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/ImportCrossSection.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.River; | |
4 import org.dive4elements.river.model.CrossSection; | |
5 import org.dive4elements.river.model.TimeInterval; | |
6 | |
7 import org.hibernate.Session; | |
8 import org.hibernate.Query; | |
9 | |
10 import java.util.List; | |
11 | |
12 import org.apache.log4j.Logger; | |
13 | |
14 /** CrossSection to be imported, holds list of ImportCrossSectionLines. */ | |
15 public class ImportCrossSection | |
16 { | |
17 private static Logger log = Logger.getLogger(ImportRiver.class); | |
18 | |
19 protected ImportRiver river; | |
20 protected String description; | |
21 protected ImportTimeInterval timeInterval; | |
22 protected List<ImportCrossSectionLine> lines; | |
23 | |
24 protected CrossSection peer; | |
25 | |
26 public ImportCrossSection() { | |
27 } | |
28 | |
29 public ImportCrossSection( | |
30 ImportRiver river, | |
31 String description, | |
32 ImportTimeInterval timeInterval, | |
33 List<ImportCrossSectionLine> lines | |
34 ) { | |
35 this.river = river; | |
36 this.description = description; | |
37 this.timeInterval = timeInterval; | |
38 this.lines = lines; | |
39 wireWithLines(); | |
40 } | |
41 | |
42 public void wireWithLines() { | |
43 for (ImportCrossSectionLine line: lines) { | |
44 line.setCrossSection(this); | |
45 } | |
46 } | |
47 | |
48 public ImportRiver getRiver() { | |
49 return river; | |
50 } | |
51 | |
52 public void setRiver(ImportRiver river) { | |
53 this.river = river; | |
54 } | |
55 | |
56 public String getDescription() { | |
57 return description; | |
58 } | |
59 | |
60 public void setDescription(String description) { | |
61 this.description = description; | |
62 } | |
63 | |
64 public ImportTimeInterval getTimeInterval() { | |
65 return timeInterval; | |
66 } | |
67 | |
68 public void setTimeInterval(ImportTimeInterval timeInterval) { | |
69 this.timeInterval = timeInterval; | |
70 } | |
71 | |
72 public void storeDependencies() { | |
73 | |
74 log.info("store cross section '" + description + "'"); | |
75 | |
76 getPeer(); | |
77 | |
78 int i = 1, N = lines.size(); | |
79 | |
80 for (ImportCrossSectionLine line: lines) { | |
81 line.storeDependencies(); | |
82 log.info(" stored " + i + " lines. remaining: " + (N-i)); | |
83 ++i; | |
84 } | |
85 } | |
86 | |
87 public CrossSection getPeer() { | |
88 | |
89 if (peer == null) { | |
90 River r = river.getPeer(); | |
91 TimeInterval t = timeInterval != null | |
92 ? timeInterval.getPeer() | |
93 : null; | |
94 | |
95 Session session = | |
96 ImporterSession.getInstance().getDatabaseSession(); | |
97 | |
98 Query query = session.createQuery( | |
99 "from CrossSection where " + | |
100 "river=:r and " + | |
101 "timeInterval=:t and " + | |
102 "description=:d"); | |
103 | |
104 query.setParameter("r", r); | |
105 query.setParameter("t", t); | |
106 query.setParameter("d", description); | |
107 | |
108 List<CrossSection> crossSections = query.list(); | |
109 if (crossSections.isEmpty()) { | |
110 peer = new CrossSection(r, t, description); | |
111 session.save(peer); | |
112 } | |
113 else { | |
114 peer = crossSections.get(0); | |
115 } | |
116 } | |
117 return peer; | |
118 } | |
119 } | |
120 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |