Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportWstColumn.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/ImportWstColumn.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.Wst; | |
4 import org.dive4elements.river.model.WstColumn; | |
5 import org.dive4elements.river.model.River; | |
6 import org.dive4elements.river.model.TimeInterval; | |
7 | |
8 import org.hibernate.Session; | |
9 import org.hibernate.Query; | |
10 | |
11 import java.util.List; | |
12 import java.util.ArrayList; | |
13 | |
14 import java.math.BigDecimal; | |
15 | |
16 import org.apache.log4j.Logger; | |
17 | |
18 | |
19 /** Unmapped column of a WST. */ | |
20 public class ImportWstColumn | |
21 { | |
22 private static Logger log = Logger.getLogger(ImportWstColumn.class); | |
23 | |
24 protected ImportWst wst; | |
25 protected String name; | |
26 protected String description; | |
27 protected Integer position; | |
28 | |
29 protected ImportTimeInterval timeInterval; | |
30 | |
31 protected List<ImportWstColumnQRange> columnQRanges; | |
32 protected List<ImportWstColumnValue> columnValues; | |
33 | |
34 protected WstColumn peer; | |
35 | |
36 public ImportWstColumn() { | |
37 columnQRanges = new ArrayList<ImportWstColumnQRange>(); | |
38 columnValues = new ArrayList<ImportWstColumnValue>(); | |
39 } | |
40 | |
41 public ImportWstColumn( | |
42 ImportWst wst, | |
43 String name, | |
44 String description, | |
45 Integer position | |
46 ) { | |
47 this(); | |
48 this.wst = wst; | |
49 this.name = name; | |
50 this.description = description; | |
51 this.position = position; | |
52 } | |
53 | |
54 public ImportWst getWst() { | |
55 return wst; | |
56 } | |
57 | |
58 public void setWst(ImportWst wst) { | |
59 this.wst = wst; | |
60 } | |
61 | |
62 public String getName() { | |
63 return name; | |
64 } | |
65 | |
66 public void setName(String name) { | |
67 this.name = name; | |
68 } | |
69 | |
70 public String getDescription() { | |
71 return description; | |
72 } | |
73 | |
74 public void setDescription(String description) { | |
75 this.description = description; | |
76 } | |
77 | |
78 public Integer getPosition() { | |
79 return position; | |
80 } | |
81 | |
82 public void setPosition(Integer position) { | |
83 this.position = position; | |
84 } | |
85 | |
86 public void addColumnValue(BigDecimal position, BigDecimal w) { | |
87 columnValues.add( | |
88 new ImportWstColumnValue(this, position, w)); | |
89 } | |
90 | |
91 public void addColumnQRange(ImportWstQRange columnQRange) { | |
92 columnQRanges.add( | |
93 new ImportWstColumnQRange(this, columnQRange)); | |
94 } | |
95 | |
96 | |
97 /** Get the Column Values stored in this column. */ | |
98 public List<ImportWstColumnValue> getColumnValues() { | |
99 return columnValues; | |
100 } | |
101 | |
102 | |
103 public void storeDependencies(River river) { | |
104 log.info("store column '" + name + "'"); | |
105 WstColumn column = getPeer(river); | |
106 | |
107 for (ImportWstColumnQRange columnQRange: columnQRanges) { | |
108 columnQRange.getPeer(river); | |
109 } | |
110 | |
111 for (ImportWstColumnValue columnValue: columnValues) { | |
112 columnValue.getPeer(river); | |
113 } | |
114 } | |
115 | |
116 public ImportTimeInterval getTimeInterval() { | |
117 return timeInterval; | |
118 } | |
119 | |
120 public void setTimeInterval(ImportTimeInterval timeInterval) { | |
121 this.timeInterval = timeInterval; | |
122 } | |
123 | |
124 /** Get corresponding mapped wst-column (from database). */ | |
125 public WstColumn getPeer(River river) { | |
126 if (peer == null) { | |
127 Wst w = wst.getPeer(river); | |
128 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
129 Query query = session.createQuery( | |
130 "from WstColumn where " + | |
131 "wst=:wst and name=:name and description=:description" + | |
132 " and position=:position"); | |
133 query.setParameter("wst", w); | |
134 query.setParameter("name", name); | |
135 query.setParameter("description", description); | |
136 query.setParameter("position", position); | |
137 | |
138 TimeInterval ti = timeInterval != null | |
139 ? timeInterval.getPeer() | |
140 : null; | |
141 | |
142 List<WstColumn> columns = query.list(); | |
143 if (columns.isEmpty()) { | |
144 peer = new WstColumn(w, name, description, position, ti); | |
145 session.save(peer); | |
146 } | |
147 else { | |
148 peer = columns.get(0); | |
149 } | |
150 } | |
151 return peer; | |
152 } | |
153 | |
154 public void fixRangesOrder() { | |
155 for (ImportWstColumnQRange wcqr: columnQRanges) { | |
156 wcqr.fixRangesOrder(); | |
157 } | |
158 } | |
159 } | |
160 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |