[metacat-cvs] metacat/src/edu/ucsb/nceas/metacat DBSAXHandler.java
Saurabh Garg
sgarg at ecoinformatics.org
Thu Nov 10 13:38:52 PST 2005
sgarg 05/11/10 13:38:52
Modified: src/edu/ucsb/nceas/metacat DBSAXHandler.java
Log:
removed the indexing code from DBSAXHandler
Revision Changes Path
1.104 +4 -117 metacat/src/edu/ucsb/nceas/metacat/DBSAXHandler.java
Index: DBSAXHandler.java
===================================================================
RCS file: /cvs/metacat/src/edu/ucsb/nceas/metacat/DBSAXHandler.java,v
retrieving revision 1.103
retrieving revision 1.104
diff -u -r1.103 -r1.104
--- DBSAXHandler.java 2 Nov 2005 18:31:32 -0000 1.103
+++ DBSAXHandler.java 10 Nov 2005 21:38:52 -0000 1.104
@@ -8,8 +8,8 @@
* Release: @release@
*
* '$Author: sgarg $'
- * '$Date: 2005/11/02 18:31:32 $'
- * '$Revision: 1.103 $'
+ * '$Date: 2005/11/10 21:38:52 $'
+ * '$Revision: 1.104 $'
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -54,7 +54,7 @@
* call when processing the XML stream and generating events.
*/
public class DBSAXHandler extends DefaultHandler implements LexicalHandler,
- DeclHandler, Runnable
+ DeclHandler
{
protected boolean atFirstElement;
@@ -97,8 +97,6 @@
protected String pub = null;
- protected Thread xmlIndex;
-
private boolean endDocument = false;
protected int serverCode = 1;
@@ -116,7 +114,6 @@
protected static final int MAXDATACHARS = 4000;
//protected static final int MAXDATACHARS = 50;
- protected static final long INDEXDELAY = 10000;
// methods writeChildNodeToDB, setAttribute, setNamespace,
// writeTextForDBSAXNode will increase endNodeId.
@@ -215,7 +212,6 @@
this.groups = groups;
this.pub = pub;
this.serverCode = serverCode;
- this.xmlIndex = new Thread(this);
}
/** SAX Handler that receives notification of beginning of the document */
@@ -440,116 +436,7 @@
hasTriple = true;
currentTriple = new Triple();
}
- }
-
- public void runIndexingThread(){
-
- boolean useXMLIndex =
- (new Boolean(MetaCatUtil.getOption("usexmlindex"))).booleanValue();
- if (useXMLIndex && !isRevisionDoc) {
- try {
- xmlIndex.start();
- } catch (NullPointerException e) {
- xmlIndex = null;
- logMetacat.error("Error in DBSAXHandler.runIndexingThread() "
- + e.getMessage());
- }
- }
- }
-
- /*
- * Run a separate thread to build the XML index for this document. This
- * thread is run asynchronously in order to more quickly return control to
- * the submitting user. The run method checks to see if the document has
- * been fully inserted before trying to update the xml_index table.
- */
- public void run()
- {
- try {
- if (!isRevisionDoc)
- {
- // stop 5 second
- Thread.sleep(5000);
- //make sure record is done
- checkDocumentTable();
- // Build the index for this document
- currentDocument.buildIndex();
- }
- } catch (Exception e) {
- logMetacat.error("Error in DBSAXHandler.run "
- + e.getMessage());
- }
- }
-
- /*
- * method to make sure insert is finished before create index table If new
- * version of record is in xml_documents every thing will be fine
- */
- private void checkDocumentTable() throws Exception
- {
-
- DBConnection dbConn = null;
- int serialNumber = -1;
-
- try {
- // Opening separate db connection for writing XML Index
- dbConn = DBConnectionPool
- .getDBConnection("DBSAXHandler.checkDocumentTable");
- serialNumber = dbConn.getCheckOutSerialNumber();
-
- // the following while loop construct checks to make sure that
- // the docid of the document that we are trying to index is already
- // in the xml_documents table. if this is not the case, the foreign
- // key relationship between xml_documents and xml_index is
- // temporarily broken causing multiple problems.
- boolean inxmldoc = false;
- long startTime = System.currentTimeMillis();
- while (!inxmldoc) {
- String xmlDocumentsCheck = "select distinct docid from xml_documents"
- + " where docid ='"
- + docid
- + "' and "
- + " rev ='"
- + revision + "'";
-
- PreparedStatement xmlDocCheck = dbConn
- .prepareStatement(xmlDocumentsCheck);
- // Increase usage count
- dbConn.increaseUsageCount(1);
- xmlDocCheck.execute();
- ResultSet doccheckRS = xmlDocCheck.getResultSet();
- boolean tableHasRows = doccheckRS.next();
- if (tableHasRows) {
- logMetacat.info(
- "=========== found the correct document");
- inxmldoc = true;
- }
- doccheckRS.close();
- xmlDocCheck.close();
- // make sure the while loop will be ended in reseaonable time
- long stopTime = System.currentTimeMillis();
- if ((stopTime - startTime) > INDEXDELAY) {
- logMetacat.warn("Couldn't find the docid for index build in "
- + "reseaonable time!");
- throw new Exception(
- "Couldn't find the docid for index build in "
- + "reseaonable time!");
- }
- }//while
- } catch (Exception e) {
- try {
- dbConn.rollback();
- //dbconn.close();
- } catch (SQLException sqle) {
- }
- logMetacat.error("Error in DBSAXHandler.checkDocumentTable "
- + e.getMessage());
-
- } finally {
- DBConnectionPool.returnDBConnection(dbConn, serialNumber);
- }//finally
-
- }
+ }
/** SAX Handler that is called for each XML text node */
public void characters(char[] cbuf, int start, int len) throws SAXException
More information about the Metacat-cvs
mailing list