Revision 1526
Added by Jing Tao almost 22 years ago
src/edu/ucsb/nceas/metacat/FilteredSubTree.java | ||
---|---|---|
28 | 28 |
|
29 | 29 |
package edu.ucsb.nceas.metacat; |
30 | 30 |
|
31 |
import java.util.Enumeration; |
|
32 |
import java.util.Collections; |
|
31 | 33 |
import java.util.Hashtable; |
32 | 34 |
import java.util.Stack; |
33 | 35 |
import java.util.Vector; |
... | ... | |
49 | 51 |
private String startElementName = null; |
50 | 52 |
private long startNodeId = -1; |
51 | 53 |
private long endNodeId = -1; |
52 |
private Hashtable filteredTree;
|
|
54 |
private Vector sortedFilteredSubTree = new Vector();
|
|
53 | 55 |
|
54 | 56 |
|
55 | 57 |
/** |
... | ... | |
143 | 145 |
} |
144 | 146 |
|
145 | 147 |
/** Set a filtered subtree(subtree should be merger equivlent */ |
146 |
public void setFilteredSubtree(Hashtable tree)
|
|
148 |
public void setFilteredSubTree(Hashtable tree)
|
|
147 | 149 |
{ |
148 |
filteredTree = tree; |
|
150 |
// order the subtree vector by start node id |
|
151 |
// because the subtree is mergeEquivlent, so there is no nested subtree |
|
152 |
Enumeration en = tree.elements(); |
|
153 |
while (en.hasMoreElements()) |
|
154 |
{ |
|
155 |
SubTree sTree = (SubTree) en.nextElement(); |
|
156 |
sortedFilteredSubTree.add(sTree); |
|
157 |
} |
|
158 |
Collections.sort(sortedFilteredSubTree, new SubTree()); |
|
149 | 159 |
} |
150 | 160 |
|
161 |
/** Get the filted subtree vector*/ |
|
162 |
public Vector getFilteredSubTree() |
|
163 |
{ |
|
164 |
return sortedFilteredSubTree; |
|
165 |
} |
|
166 |
|
|
151 | 167 |
/** Get unfiltered subtree node list*/ |
152 | 168 |
public Stack getUnfilteredSubTreeNodeList() throws McdbException |
153 | 169 |
{ |
... | ... | |
163 | 179 |
String nodename = null; |
164 | 180 |
String nodeprefix = null; |
165 | 181 |
String nodedata = null; |
166 |
Vector sorteSubTree = new Vector(); |
|
167 |
// order the subtree vector by start node id |
|
168 |
// because the subtree is mergeEquivlent, so there is no nested subtree |
|
169 | 182 |
String sql = "SELECT nodeid, parentnodeid, nodeindex, " + |
170 | 183 |
"nodetype, nodename, nodeprefix, nodedata " + |
171 |
"FROM xml_nodes WHERE docid = ? AND nodeid >= ? AND " + |
|
172 |
"nodeid <= ? ORDER BY nodeid DESC"; |
|
184 |
"FROM xml_nodes WHERE docid = ? AND ((nodeid >= ? AND "; |
|
185 |
for ( int i =0; i< sortedFilteredSubTree.size(); i++) |
|
186 |
{ |
|
187 |
sql = sql + "nodeid < ? ) OR (nodeid > ? AND "; |
|
188 |
} |
|
189 |
sql = sql + "nodeid <= ? )) ORDER BY nodeid DESC"; |
|
190 |
MetaCatUtil.debugMessage("sql command for selecting filtere subtree is: " |
|
191 |
+sql, 25); |
|
192 |
|
|
173 | 193 |
try |
174 | 194 |
{ |
175 | 195 |
dbconn=DBConnectionPool. |
... | ... | |
180 | 200 |
// Bind the values to the query |
181 | 201 |
pstmt.setString(1, docId); |
182 | 202 |
pstmt.setLong(2, startNodeId); |
183 |
pstmt.setLong(3, endNodeId); |
|
203 |
int i =0; |
|
204 |
boolean inLoop = false; |
|
205 |
for (i=0; i< sortedFilteredSubTree.size(); i++) |
|
206 |
{ |
|
207 |
SubTree tree = (SubTree)sortedFilteredSubTree.elementAt(i); |
|
208 |
long startId = tree.getStartNodeId(); |
|
209 |
long endId = tree.getEndNodeId(); |
|
210 |
pstmt.setLong((2*i+3), startId); |
|
211 |
pstmt.setLong((2*i+4), endId); |
|
212 |
inLoop = true; |
|
213 |
} |
|
214 |
if (inLoop) |
|
215 |
{ |
|
216 |
pstmt.setLong((2*i+5), endNodeId); |
|
217 |
} |
|
218 |
else |
|
219 |
{ |
|
220 |
pstmt.setLong(3, endNodeId); |
|
221 |
} |
|
184 | 222 |
|
185 | 223 |
pstmt.execute(); |
186 | 224 |
ResultSet rs = pstmt.getResultSet(); |
... | ... | |
209 | 247 |
} //try |
210 | 248 |
catch (SQLException e) |
211 | 249 |
{ |
212 |
throw new McdbException("Error in SubTree.getSubTreeNodeList 1 " + |
|
250 |
throw new McdbException("Error in FilteredSubTree.getSubTreeNodeList 1 " +
|
|
213 | 251 |
e.getMessage()); |
214 | 252 |
}//catch |
215 | 253 |
finally |
... | ... | |
220 | 258 |
} |
221 | 259 |
catch (SQLException ee) |
222 | 260 |
{ |
223 |
MetaCatUtil.debugMessage("error in SubTree.getSubTreeNodeList 2: " |
|
261 |
MetaCatUtil.debugMessage("error in FilteredSubTree.getSubTreeNodeList 2: "
|
|
224 | 262 |
+ee.getMessage(), 30); |
225 | 263 |
} |
226 | 264 |
finally |
Also available in: Unified diff
Add code to get filted subtree nodes