[metacat-cvs] metacat/src/edu/ucsb/nceas/metacat IndexingQueue.java
Saurabh Garg
sgarg at ecoinformatics.org
Fri Nov 18 13:17:18 PST 2005
sgarg 05/11/18 13:17:18
Modified: src/edu/ucsb/nceas/metacat IndexingQueue.java
Log:
Modified the way checkDocumentTable is accessed. Also removed the while loop from the checkDocumentTable. Now if the document is not found, the thread goes to sleep - instead of checking again. (In hope of a more bugfree code)
Revision Changes Path
1.3 +37 -50 metacat/src/edu/ucsb/nceas/metacat/IndexingQueue.java
Index: IndexingQueue.java
===================================================================
RCS file: /cvs/metacat/src/edu/ucsb/nceas/metacat/IndexingQueue.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- IndexingQueue.java 11 Nov 2005 18:00:54 -0000 1.2
+++ IndexingQueue.java 18 Nov 2005 21:17:18 -0000 1.3
@@ -7,8 +7,8 @@
* Release: @release@
*
* '$Author: sgarg $'
- * '$Date: 2005/11/11 18:00:54 $'
- * '$Revision: 1.2 $'
+ * '$Date: 2005/11/18 21:17:18 $'
+ * '$Revision: 1.3 $'
*
* 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
@@ -121,10 +121,17 @@
IndexingQueue.getInstance().
currentDocidsBeingIndexed.add(returnVal.getDocid());
String docid = returnVal.getDocid() + "." + returnVal.getRev();
- checkDocumentTable(docid, "xml_documents");
- DocumentImpl doc = new DocumentImpl(docid, false);
- logMetacat.warn("Calling buildIndex for " + docid);
- doc.buildIndex();
+ if(checkDocumentTable(docid, "xml_documents")){
+ logMetacat.warn("Calling buildIndex for " + docid);
+ DocumentImpl doc = new DocumentImpl(docid, false);
+ doc.buildIndex();
+ } else {
+ logMetacat.warn("Couldn't find the docid:" + docid
+ + " in xml_documents table");
+ sleep(MAXIMUMINDEXDELAY);
+ throw(new Exception("Couldn't find the docid:" + docid
+ + " in xml_documents table"));
+ }
} catch (Exception e) {
logMetacat.warn("Exception: " + e);
e.printStackTrace();
@@ -150,15 +157,16 @@
}
}
- private void checkDocumentTable(String docid, String tablename) throws Exception{
+ private boolean checkDocumentTable(String docid, String tablename) throws Exception{
DBConnection dbConn = null;
int serialNumber = -1;
-
+ boolean inxmldoc = false;
+
String revision = docid.substring(docid.lastIndexOf(".")+1,docid.length());
docid = docid.substring(0,docid.lastIndexOf("."));
- logMetacat.warn("docid is " + docid
- + " and revision is " + revision);
+ logMetacat.info("Checking if document exsists in xml_documents: docid is "
+ + docid + " and revision is " + revision);
try {
// Opening separate db connection for writing XML Index
@@ -166,51 +174,30 @@
.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 " + tablename
- + " 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) {
- inxmldoc = true;
- }
- doccheckRS.close();
- xmlDocCheck.close();
- // make sure the while loop will be ended in reseaonable time
- long stopTime = System.currentTimeMillis();
- if ((stopTime - startTime) > MAXIMUMINDEXDELAY) {
- logMetacat.warn("Couldn't find the docid:" + docid
- + " for indexing in "
- + "reseaonable time!");
- throw new Exception(
- "Couldn't find the docid for index build in "
- + "reseaonable time!");
- }
- }//while
+ String xmlDocumentsCheck = "SELECT distinct docid FROM " + tablename
+ + " 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) {
+ inxmldoc = true;
+ }
+ doccheckRS.close();
+ xmlDocCheck.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBConnectionPool.returnDBConnection(dbConn, serialNumber);
}//finally
-
- }
+
+ return inxmldoc;
+ }
}
class IndexingQueueObject implements Comparable{
More information about the Metacat-cvs
mailing list