Revision 2521
Added by sgarg over 18 years ago
MetaCatServlet.java | ||
---|---|---|
210 | 210 |
+ pse.getMessage(), 20); |
211 | 211 |
} |
212 | 212 |
|
213 |
// Index the paths specified in the metacat.properties |
|
214 |
checkIndexPaths(); |
|
215 |
|
|
213 | 216 |
System.out.println("Metacat (" + Version.getVersion() |
214 |
+ ") initialized."); |
|
217 |
+ ") initialized."); |
|
218 |
|
|
215 | 219 |
} catch (ServletException ex) { |
216 | 220 |
throw ex; |
217 | 221 |
} catch (SQLException e) { |
... | ... | |
220 | 224 |
} |
221 | 225 |
} |
222 | 226 |
|
227 |
|
|
223 | 228 |
/** |
229 |
* Index the paths specified in the metacat.properties |
|
230 |
*/ |
|
231 |
void checkIndexPaths(){ |
|
232 |
MetaCatUtil.pathsForIndexing |
|
233 |
= MetaCatUtil.getOptionList(MetaCatUtil.getOption("indexed_paths")); |
|
234 |
|
|
235 |
if (MetaCatUtil.pathsForIndexing != null) { |
|
236 |
|
|
237 |
MetaCatUtil.debugMessage("Indexing paths....", 20); |
|
238 |
|
|
239 |
DBConnection conn = null; |
|
240 |
int serialNumber = -1; |
|
241 |
PreparedStatement pstmt = null; |
|
242 |
PreparedStatement pstmt1 = null; |
|
243 |
ResultSet rs = null; |
|
244 |
|
|
245 |
for (int i = 0; i < MetaCatUtil.pathsForIndexing.size(); i++) { |
|
246 |
MetaCatUtil.formattedDebugMessage("Checking if '" |
|
247 |
+ (String) MetaCatUtil.pathsForIndexing.elementAt(i) |
|
248 |
+ "' is indexed.... ",30, false, true); |
|
249 |
|
|
250 |
try { |
|
251 |
//check out DBConnection |
|
252 |
conn = DBConnectionPool. |
|
253 |
getDBConnection("MetaCatServlet.checkIndexPaths"); |
|
254 |
serialNumber = conn.getCheckOutSerialNumber(); |
|
255 |
|
|
256 |
pstmt = conn.prepareStatement( |
|
257 |
"SELECT * FROM xml_path_index " + "WHERE path = ?"); |
|
258 |
pstmt.setString(1, (String) MetaCatUtil.pathsForIndexing |
|
259 |
.elementAt(i)); |
|
260 |
|
|
261 |
pstmt.execute(); |
|
262 |
rs = pstmt.getResultSet(); |
|
263 |
|
|
264 |
if (!rs.next()) { |
|
265 |
MetaCatUtil.formattedDebugMessage("not indexed yet.", 30, |
|
266 |
true, false); |
|
267 |
rs.close(); |
|
268 |
pstmt.close(); |
|
269 |
conn.increaseUsageCount(1); |
|
270 |
|
|
271 |
MetaCatUtil.debugMessage( |
|
272 |
"Inserting following path in xml_path_index: " |
|
273 |
+ (String)MetaCatUtil.pathsForIndexing |
|
274 |
.elementAt(i), 60); |
|
275 |
|
|
276 |
pstmt = conn.prepareStatement("SELECT DISTINCT n.docid, " |
|
277 |
+ "n.nodedata, n.nodedatanumerical, n.parentnodeid" |
|
278 |
+ " FROM xml_nodes n, xml_index i WHERE" |
|
279 |
+ " i.path = ? and n.parentnodeid=i.nodeid and" |
|
280 |
+ " n.nodetype LIKE 'TEXT'"); |
|
281 |
pstmt.setString(1, (String) MetaCatUtil. |
|
282 |
pathsForIndexing.elementAt(i)); |
|
283 |
pstmt.execute(); |
|
284 |
rs = pstmt.getResultSet(); |
|
285 |
|
|
286 |
int count = 0; |
|
287 |
MetaCatUtil.debugMessage( |
|
288 |
"Executed the select statement for: " |
|
289 |
+ (String) MetaCatUtil.pathsForIndexing |
|
290 |
.elementAt(i), 60); |
|
291 |
|
|
292 |
try { |
|
293 |
while (rs.next()) { |
|
294 |
|
|
295 |
String docid = rs.getString(1); |
|
296 |
String nodedata = rs.getString(2); |
|
297 |
float nodedatanumerical = rs.getFloat(3); |
|
298 |
int parentnodeid = rs.getInt(4); |
|
299 |
|
|
300 |
if (!nodedata.trim().equals("")) { |
|
301 |
pstmt1 = conn.prepareStatement( |
|
302 |
"INSERT INTO xml_path_index" |
|
303 |
+ " (docid, path, nodedata, " |
|
304 |
+ "nodedatanumerical, parentnodeid)" |
|
305 |
+ " VALUES (?, ?, ?, ?, ?)"); |
|
306 |
|
|
307 |
pstmt1.setString(1, docid); |
|
308 |
pstmt1.setString(2, (String) MetaCatUtil. |
|
309 |
pathsForIndexing.elementAt(i)); |
|
310 |
pstmt1.setString(3, nodedata); |
|
311 |
pstmt1.setFloat(4, nodedatanumerical); |
|
312 |
pstmt1.setFloat(5, parentnodeid); |
|
313 |
|
|
314 |
pstmt1.execute(); |
|
315 |
pstmt1.close(); |
|
316 |
|
|
317 |
count++; |
|
318 |
|
|
319 |
} |
|
320 |
} |
|
321 |
} |
|
322 |
catch (Exception e) { |
|
323 |
System.out.println("Exception:" + e.getMessage()); |
|
324 |
e.printStackTrace(); |
|
325 |
} |
|
326 |
|
|
327 |
rs.close(); |
|
328 |
pstmt.close(); |
|
329 |
conn.increaseUsageCount(1); |
|
330 |
|
|
331 |
MetaCatUtil.debugMessage("Indexed " + count |
|
332 |
+ " records from xml_nodes for '" |
|
333 |
+ (String) MetaCatUtil.pathsForIndexing.elementAt(i) |
|
334 |
+ "'", 20); |
|
335 |
|
|
336 |
} else { |
|
337 |
MetaCatUtil.formattedDebugMessage("already indexed.", 30, |
|
338 |
true, false); |
|
339 |
} |
|
340 |
|
|
341 |
rs.close(); |
|
342 |
pstmt.close(); |
|
343 |
conn.increaseUsageCount(1); |
|
344 |
|
|
345 |
} catch (Exception e) { |
|
346 |
MetaCatUtil.debugMessage("error in DocumentImpl.delete: " |
|
347 |
+ e.getMessage(), 30); |
|
348 |
}finally { |
|
349 |
//check in DBonnection |
|
350 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
351 |
} |
|
352 |
|
|
353 |
|
|
354 |
} |
|
355 |
|
|
356 |
MetaCatUtil.debugMessage("Path Indexing Completed", 20); |
|
357 |
} |
|
358 |
} |
|
359 |
/** |
|
224 | 360 |
* Close all db connections from the pool |
225 | 361 |
*/ |
226 | 362 |
public void destroy() |
Also available in: Unified diff
Adding a new method to MetaCatServlet for getting the value of paths to be indexed from metacat.properties file and indexing those paths in xml_path_index