Revision 471
Added by bojilova over 23 years ago
DBSAXNode.java | ||
---|---|---|
60 | 60 |
this.conn = conn; |
61 | 61 |
this.parentNode = parentNode; |
62 | 62 |
writeChildNodeToDB("ELEMENT", getTagName(), null, docid); |
63 |
updateNodeIndex(docid, doctype); |
|
63 |
//No writing XML Index from here. New Thread used instead. |
|
64 |
//updateNodeIndex(docid, doctype); |
|
64 | 65 |
} |
65 | 66 |
|
66 | 67 |
/** creates SQL code and inserts new node into DB connection */ |
... | ... | |
159 | 160 |
} |
160 | 161 |
} |
161 | 162 |
|
162 |
/** |
|
163 |
* creates SQL code to put doc ID for the document node and for |
|
164 |
* comment/PI nodes under document node into DB connection |
|
165 |
*/ |
|
166 |
/* |
|
167 |
public void writeDocID(String doc_id) { |
|
168 |
try { |
|
169 |
PreparedStatement pstmt; |
|
170 |
pstmt = conn.prepareStatement( |
|
171 |
"UPDATE xml_nodes set docid = ? " + |
|
172 |
"WHERE nodeid = ?"); |
|
173 |
|
|
174 |
// Bind the values to the query |
|
175 |
pstmt.setString(1, doc_id); |
|
176 |
pstmt.setLong(2, getNodeID()); |
|
177 |
// Do the insertion |
|
178 |
pstmt.execute(); |
|
179 |
pstmt.close(); |
|
180 |
|
|
181 |
// for comments and PI on the top |
|
182 |
pstmt = conn.prepareStatement( |
|
183 |
"UPDATE xml_nodes set docid = ? " + |
|
184 |
"WHERE parentnodeid = ?"); |
|
185 |
// Bind the values to the query |
|
186 |
pstmt.setString(1, doc_id); |
|
187 |
pstmt.setLong(2, getNodeID()); |
|
188 |
// Do the insertion |
|
189 |
pstmt.execute(); |
|
190 |
pstmt.close(); |
|
191 |
} catch (SQLException e) { |
|
192 |
System.out.println(e.getMessage()); |
|
193 |
} |
|
194 |
} |
|
195 |
*/ |
|
196 | 163 |
/** get next node id from DB connection */ |
197 | 164 |
private long generateNodeID() throws SAXException { |
198 | 165 |
long nid=0; |
... | ... | |
230 | 197 |
} |
231 | 198 |
|
232 | 199 |
/** |
200 |
* NOT USED |
|
233 | 201 |
* Update the node index (xml_index) for this node by generating |
234 | 202 |
* test strings that represent all of the relative and absolute |
235 | 203 |
* paths through the XML tree from document root to this node |
... | ... | |
285 | 253 |
pstmt.setLong(5, getParentID()); |
286 | 254 |
|
287 | 255 |
// Step through the hashtable and insert each of the path values |
256 |
Enumeration en = pathlist.keys(); |
|
257 |
while (en.hasMoreElements()) { |
|
258 |
String path = (String)en.nextElement(); |
|
259 |
Long nodeid = (Long)pathlist.get(path); |
|
260 |
pstmt.setLong(1, nodeid.longValue()); |
|
261 |
pstmt.setString(2, path); |
|
262 |
pstmt.executeUpdate(); |
|
263 |
|
|
264 |
//System.out.println(nodeid + " ==> " + path); |
|
265 |
} |
|
266 |
|
|
267 |
// Close the database statement |
|
268 |
pstmt.close(); |
|
269 |
} catch (SQLException sqe) { |
|
270 |
System.err.println("SQL Exception while inserting path to index."); |
|
271 |
System.err.println(sqe.getMessage()); |
|
272 |
throw new SAXException(sqe.getMessage()); |
|
273 |
} |
|
274 |
} |
|
275 |
|
|
276 |
/** |
|
277 |
* USED FROM SEPARATE THREAD RUNNED from DBSAXHandler on endDocument() |
|
278 |
* Update the node index (xml_index) for this node by generating |
|
279 |
* test strings that represent all of the relative and absolute |
|
280 |
* paths through the XML tree from document root to this node |
|
281 |
*/ |
|
282 |
public void updateNodeIndex(Connection conn, String docid, String doctype) |
|
283 |
throws SAXException |
|
284 |
{ |
|
285 |
Hashtable pathlist = new Hashtable(); |
|
286 |
boolean atStartingNode = true; |
|
287 |
boolean atRootDocumentNode = false; |
|
288 |
DBSAXNode nodePointer = this; |
|
289 |
StringBuffer currentPath = new StringBuffer(); |
|
290 |
int counter = 0; |
|
291 |
|
|
292 |
// Create a Hashtable of all of the paths to reach this node |
|
293 |
// including absolute paths and relative paths |
|
294 |
while (!atRootDocumentNode) { |
|
295 |
if (atStartingNode) { |
|
296 |
currentPath.insert(0, nodePointer.getTagName()); |
|
297 |
pathlist.put(currentPath.toString(), new Long(getNodeID())); |
|
298 |
counter++; |
|
299 |
atStartingNode = false; |
|
300 |
} else { |
|
301 |
currentPath.insert(0, "/"); |
|
302 |
currentPath.insert(0, nodePointer.getTagName()); |
|
303 |
pathlist.put(currentPath.toString(), new Long(getNodeID())); |
|
304 |
counter++; |
|
305 |
} |
|
306 |
|
|
307 |
// advance to the next parent node |
|
308 |
nodePointer = nodePointer.getParentNode(); |
|
309 |
|
|
310 |
// If we're at the DOCUMENT node (root of DOM tree), add |
|
311 |
// the root "/" to make the absolute path |
|
312 |
if (nodePointer.getNodeType().equals("DOCUMENT")) { |
|
313 |
currentPath.insert(0, "/"); |
|
314 |
pathlist.put(currentPath.toString(), new Long(getNodeID())); |
|
315 |
counter++; |
|
316 |
atRootDocumentNode = true; |
|
317 |
} |
|
318 |
} |
|
319 |
|
|
320 |
try { |
|
321 |
// Create an insert statement to reuse for all of the path insertions |
|
322 |
PreparedStatement pstmt = conn.prepareStatement( |
|
323 |
"INSERT INTO xml_index (nodeid, path, docid, doctype, " + |
|
324 |
"parentnodeid) " + |
|
325 |
"VALUES (?, ?, ?, ?, ?)"); |
|
326 |
((OraclePreparedStatement)pstmt).setExecuteBatch(counter); |
|
327 |
|
|
328 |
pstmt.setString(3, docid); |
|
329 |
pstmt.setString(4, doctype); |
|
330 |
pstmt.setLong(5, getParentID()); |
|
331 |
|
|
332 |
// Step through the hashtable and insert each of the path values |
|
288 | 333 |
Enumeration en = pathlist.keys(); |
289 | 334 |
while (en.hasMoreElements()) { |
290 | 335 |
String path = (String)en.nextElement(); |
Also available in: Unified diff
Separate thread used for writing into xml_index table.
This cut the time of the response on insert almost in half.
The tread is started afterwards
(on end of document parsing and inserting into xml_nodes) from
DBSAXHandler and uses new(separate) db connection.
But I did not find a good way to show the work done of that thread.