Revision 2307
Added by Matt Jones over 20 years ago
src/edu/ucsb/nceas/metacat/DBSAXHandler.java | ||
---|---|---|
427 | 427 |
} |
428 | 428 |
} |
429 | 429 |
|
430 |
/* The run method of xmlIndex thread. It writes XML Index for the document. */ |
|
430 |
/* |
|
431 |
* Run a separate thread to build the XML index for this document. This |
|
432 |
* thread is run asynchronously in order to more quickly return control to |
|
433 |
* the submitting user. The run method checks to see if the document has |
|
434 |
* been fully inserted before trying to update the xml_index table. |
|
435 |
*/ |
|
431 | 436 |
public void run() |
432 | 437 |
{ |
433 |
DBSAXNode currNode = null; |
|
434 |
DBSAXNode prevNode = null; |
|
435 |
DBConnection dbConn = null; |
|
436 |
int serialNumber = -1; |
|
437 |
String doctype = currentDocument.getDoctype(); |
|
438 |
int step = 0; |
|
439 |
int counter = 0; |
|
440 |
|
|
441 | 438 |
try { |
442 | 439 |
// stop 5 second |
443 | 440 |
Thread.sleep(5000); |
444 |
// Opening separate db connection for writing XML Index |
|
445 |
dbConn = DBConnectionPool.getDBConnection("DBSAXHandler.run"); |
|
446 |
serialNumber = dbConn.getCheckOutSerialNumber(); |
|
447 |
dbConn.setAutoCommit(false); |
|
448 | 441 |
//make sure record is done |
449 | 442 |
checkDocumentTable(); |
450 |
// Going through the elements of the document and writing its Index |
|
451 |
Enumeration nodes = nodeIndex.elements(); |
|
452 |
while (nodes.hasMoreElements()) { |
|
453 |
currNode = (DBSAXNode) nodes.nextElement(); |
|
454 |
currNode.updateNodeIndex(dbConn, docid, doctype); |
|
455 |
} |
|
456 |
dbConn.commit(); |
|
457 |
|
|
443 |
// Build the index for this document |
|
444 |
currentDocument.buildIndex(); |
|
458 | 445 |
} catch (Exception e) { |
459 |
try { |
|
460 |
dbConn.rollback(); |
|
461 |
//dbconn.close(); |
|
462 |
} catch (SQLException sqle) { |
|
463 |
} |
|
464 | 446 |
MetaCatUtil.debugMessage("Error in DBSAXHandler.run " |
465 | 447 |
+ e.getMessage(), 30); |
466 |
|
|
467 |
} finally { |
|
468 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
|
469 |
}//finally |
|
448 |
} |
|
470 | 449 |
} |
471 | 450 |
|
472 | 451 |
/* |
Also available in: Unified diff
Changed DBSAXHandler.run() to now use the new DocumentImpl.buildIndex() method
for populating the xml_index table. The new method uses a jdbc ResultSet
for populating the index rather than doing it with the DBSAXNode, so it is
faster and can be run at any time on any document. This will allow us to
rebuild the index for any given document, or for all of the documents.