Revision 2764
Added by sgarg about 19 years ago
src/edu/ucsb/nceas/metacat/IndexingQueue.java | ||
---|---|---|
121 | 121 |
IndexingQueue.getInstance(). |
122 | 122 |
currentDocidsBeingIndexed.add(returnVal.getDocid()); |
123 | 123 |
String docid = returnVal.getDocid() + "." + returnVal.getRev(); |
124 |
checkDocumentTable(docid, "xml_documents"); |
|
125 |
DocumentImpl doc = new DocumentImpl(docid, false); |
|
126 |
logMetacat.warn("Calling buildIndex for " + docid); |
|
127 |
doc.buildIndex(); |
|
124 |
if(checkDocumentTable(docid, "xml_documents")){ |
|
125 |
logMetacat.warn("Calling buildIndex for " + docid); |
|
126 |
DocumentImpl doc = new DocumentImpl(docid, false); |
|
127 |
doc.buildIndex(); |
|
128 |
} else { |
|
129 |
logMetacat.warn("Couldn't find the docid:" + docid |
|
130 |
+ " in xml_documents table"); |
|
131 |
sleep(MAXIMUMINDEXDELAY); |
|
132 |
throw(new Exception("Couldn't find the docid:" + docid |
|
133 |
+ " in xml_documents table")); |
|
134 |
} |
|
128 | 135 |
} catch (Exception e) { |
129 | 136 |
logMetacat.warn("Exception: " + e); |
130 | 137 |
e.printStackTrace(); |
... | ... | |
150 | 157 |
} |
151 | 158 |
} |
152 | 159 |
|
153 |
private void checkDocumentTable(String docid, String tablename) throws Exception{
|
|
160 |
private boolean checkDocumentTable(String docid, String tablename) throws Exception{
|
|
154 | 161 |
DBConnection dbConn = null; |
155 | 162 |
int serialNumber = -1; |
156 |
|
|
163 |
boolean inxmldoc = false; |
|
164 |
|
|
157 | 165 |
String revision = docid.substring(docid.lastIndexOf(".")+1,docid.length()); |
158 | 166 |
docid = docid.substring(0,docid.lastIndexOf(".")); |
159 | 167 |
|
160 |
logMetacat.warn("docid is " + docid
|
|
161 |
+ " and revision is " + revision); |
|
168 |
logMetacat.info("Checking if document exsists in xml_documents: docid is "
|
|
169 |
+ docid + " and revision is " + revision);
|
|
162 | 170 |
|
163 | 171 |
try { |
164 | 172 |
// Opening separate db connection for writing XML Index |
... | ... | |
166 | 174 |
.getDBConnection("DBSAXHandler.checkDocumentTable"); |
167 | 175 |
serialNumber = dbConn.getCheckOutSerialNumber(); |
168 | 176 |
|
169 |
// the following while loop construct checks to make sure that |
|
170 |
// the docid of the document that we are trying to index is already |
|
171 |
// in the xml_documents table. if this is not the case, the foreign |
|
172 |
// key relationship between xml_documents and xml_index is |
|
173 |
// temporarily broken causing multiple problems. |
|
174 |
boolean inxmldoc = false; |
|
175 |
long startTime = System.currentTimeMillis(); |
|
176 |
while (!inxmldoc) { |
|
177 |
String xmlDocumentsCheck = "select distinct docid from " + tablename |
|
178 |
+ " where docid ='" |
|
179 |
+ docid |
|
180 |
+ "' and " |
|
181 |
+ " rev ='" |
|
182 |
+ revision + "'"; |
|
177 |
String xmlDocumentsCheck = "SELECT distinct docid FROM " + tablename |
|
178 |
+ " WHERE docid ='" + docid |
|
179 |
+ "' AND rev ='" + revision + "'"; |
|
183 | 180 |
|
184 |
PreparedStatement xmlDocCheck = dbConn |
|
185 |
.prepareStatement(xmlDocumentsCheck); |
|
186 |
// Increase usage count |
|
187 |
dbConn.increaseUsageCount(1); |
|
188 |
xmlDocCheck.execute(); |
|
189 |
ResultSet doccheckRS = xmlDocCheck.getResultSet(); |
|
190 |
boolean tableHasRows = doccheckRS.next(); |
|
191 |
if (tableHasRows) { |
|
192 |
inxmldoc = true; |
|
193 |
} |
|
194 |
doccheckRS.close(); |
|
195 |
xmlDocCheck.close(); |
|
196 |
// make sure the while loop will be ended in reseaonable time |
|
197 |
long stopTime = System.currentTimeMillis(); |
|
198 |
if ((stopTime - startTime) > MAXIMUMINDEXDELAY) { |
|
199 |
logMetacat.warn("Couldn't find the docid:" + docid |
|
200 |
+ " for indexing in " |
|
201 |
+ "reseaonable time!"); |
|
202 |
throw new Exception( |
|
203 |
"Couldn't find the docid for index build in " |
|
204 |
+ "reseaonable time!"); |
|
205 |
} |
|
206 |
}//while |
|
181 |
PreparedStatement xmlDocCheck = dbConn.prepareStatement(xmlDocumentsCheck); |
|
182 |
// Increase usage count |
|
183 |
|
|
184 |
dbConn.increaseUsageCount(1); |
|
185 |
xmlDocCheck.execute(); |
|
186 |
ResultSet doccheckRS = xmlDocCheck.getResultSet(); |
|
187 |
boolean tableHasRows = doccheckRS.next(); |
|
188 |
if (tableHasRows) { |
|
189 |
inxmldoc = true; |
|
190 |
} |
|
191 |
doccheckRS.close(); |
|
192 |
xmlDocCheck.close(); |
|
207 | 193 |
} catch (SQLException e) { |
208 | 194 |
e.printStackTrace(); |
209 | 195 |
} finally { |
210 | 196 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
211 | 197 |
}//finally |
212 |
|
|
213 |
} |
|
198 |
|
|
199 |
return inxmldoc; |
|
200 |
} |
|
214 | 201 |
} |
215 | 202 |
|
216 | 203 |
class IndexingQueueObject implements Comparable{ |
Also available in: Unified diff
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)