Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java @ 1818:e3eb1ea885a7
Simplified code in Datacage builder by using the new pair.
flys-artifacts/trunk@3147 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 03 Nov 2011 09:58:04 +0000 |
parents | 3ca999f507b7 |
children | 755d9763928f |
comparison
equal
deleted
inserted
replaced
1817:595c404523a6 | 1818:e3eb1ea885a7 |
---|---|
23 | 23 |
24 import java.sql.SQLException; | 24 import java.sql.SQLException; |
25 import java.sql.Connection; | 25 import java.sql.Connection; |
26 | 26 |
27 import de.intevation.artifacts.common.utils.XMLUtils; | 27 import de.intevation.artifacts.common.utils.XMLUtils; |
28 | |
29 import de.intevation.flys.utils.Pair; | |
28 | 30 |
29 import org.apache.log4j.Logger; | 31 import org.apache.log4j.Logger; |
30 | 32 |
31 public class Builder | 33 public class Builder |
32 { | 34 { |
80 } // class NamedConnection | 82 } // class NamedConnection |
81 | 83 |
82 | 84 |
83 public class BuildHelper | 85 public class BuildHelper |
84 { | 86 { |
85 protected Node output; | 87 protected Node output; |
86 protected Document owner; | 88 protected Document owner; |
87 protected StackFrames frames; | 89 protected StackFrames frames; |
88 protected List<NamedConnection> connections; | 90 protected List<NamedConnection> connections; |
89 protected Map<String, CompiledStatement.Instance> statements; | 91 protected Map<String, CompiledStatement.Instance> statements; |
90 protected Deque<NamedConnection> connectionsStack; | 92 protected Deque<Pair<NamedConnection, ResultData>> connectionsStack; |
91 protected Deque<ResultData> resultsStack; | |
92 | 93 |
93 public BuildHelper( | 94 public BuildHelper( |
94 Node output, | 95 Node output, |
95 List<NamedConnection> connections, | 96 List<NamedConnection> connections, |
96 Map<String, Object> parameters | 97 Map<String, Object> parameters |
98 if (connections.isEmpty()) { | 99 if (connections.isEmpty()) { |
99 throw new IllegalArgumentException("no connections given."); | 100 throw new IllegalArgumentException("no connections given."); |
100 } | 101 } |
101 | 102 |
102 this.connections = connections; | 103 this.connections = connections; |
103 connectionsStack = new ArrayDeque<NamedConnection>(); | 104 connectionsStack = |
104 resultsStack = new ArrayDeque<ResultData>(); | 105 new ArrayDeque<Pair<NamedConnection, ResultData>>(); |
105 this.output = output; | 106 this.output = output; |
106 frames = new StackFrames(parameters); | 107 frames = new StackFrames(parameters); |
107 owner = getOwnerDocument(output); | 108 owner = getOwnerDocument(output); |
108 statements = | 109 statements = |
109 new HashMap<String, CompiledStatement.Instance>(); | 110 new HashMap<String, CompiledStatement.Instance>(); |
170 statements.put(key, csi); | 171 statements.put(key, csi); |
171 } | 172 } |
172 | 173 |
173 NamedConnection connection = connectionsStack.isEmpty() | 174 NamedConnection connection = connectionsStack.isEmpty() |
174 ? connections.get(0) | 175 ? connections.get(0) |
175 : connectionsStack.peek(); | 176 : connectionsStack.peek().getA(); |
176 | 177 |
177 if (con.length() > 0) { | 178 if (con.length() > 0) { |
178 for (NamedConnection nc: connections) { | 179 for (NamedConnection nc: connections) { |
179 if (con.equals(nc.name)) { | 180 if (con.equals(nc.name)) { |
180 connection = nc; | 181 connection = nc; |
188 frames, | 189 frames, |
189 connection.cached); | 190 connection.cached); |
190 | 191 |
191 // only descent if there are results | 192 // only descent if there are results |
192 if (!rd.isEmpty()) { | 193 if (!rd.isEmpty()) { |
193 resultsStack.push(rd); | 194 connectionsStack.push(new Pair(connection, rd)); |
194 connectionsStack.push(connection); | |
195 try { | 195 try { |
196 for (int i = 0; i < S; ++i) { | 196 for (int i = 0; i < S; ++i) { |
197 build(parent, subs.item(i)); | 197 build(parent, subs.item(i)); |
198 } | 198 } |
199 } | 199 } |
200 finally { | 200 finally { |
201 connectionsStack.pop(); | 201 connectionsStack.pop(); |
202 resultsStack.pop(); | |
203 } | 202 } |
204 } | 203 } |
205 } | 204 } |
206 | 205 |
207 protected void elements(Node parent, Element current) | 206 protected void elements(Node parent, Element current) |
208 throws SQLException | 207 throws SQLException |
209 { | 208 { |
210 log.debug("dc:elements"); | 209 log.debug("dc:elements"); |
211 | 210 |
212 if (resultsStack.isEmpty()) { | 211 if (connectionsStack.isEmpty()) { |
213 log.warn("dc:elements without having results"); | 212 log.warn("dc:elements without having results"); |
214 return; | 213 return; |
215 } | 214 } |
216 | 215 |
217 NodeList subs = current.getChildNodes(); | 216 NodeList subs = current.getChildNodes(); |
220 if (S == 0) { | 219 if (S == 0) { |
221 log.debug("dc:elements has no children"); | 220 log.debug("dc:elements has no children"); |
222 return; | 221 return; |
223 } | 222 } |
224 | 223 |
225 ResultData rd = resultsStack.peek(); | 224 ResultData rd = connectionsStack.peek().getB(); |
226 | 225 |
227 String [] columns = rd.getColumnLabels(); | 226 String [] columns = rd.getColumnLabels(); |
228 | 227 |
229 //if (log.isDebugEnabled()) { | 228 //if (log.isDebugEnabled()) { |
230 // log.debug("pushing vars: " | 229 // log.debug("pushing vars: " |