1 |
2732
|
sgarg
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
|
|
* Purpose: A Class that tracks sessions for MetaCatServlet users.
|
4 |
|
|
* Copyright: 2000 Regents of the University of California and the
|
5 |
|
|
* National Center for Ecological Analysis and Synthesis
|
6 |
|
|
* Authors: Matt Jones
|
7 |
|
|
*
|
8 |
|
|
* '$Author$'
|
9 |
|
|
* '$Date$'
|
10 |
|
|
* '$Revision$'
|
11 |
|
|
*
|
12 |
|
|
* This program is free software; you can redistribute it and/or modify
|
13 |
|
|
* it under the terms of the GNU General Public License as published by
|
14 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
15 |
|
|
* (at your option) any later version.
|
16 |
|
|
*
|
17 |
|
|
* This program is distributed in the hope that it will be useful,
|
18 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20 |
|
|
* GNU General Public License for more details.
|
21 |
|
|
*
|
22 |
|
|
* You should have received a copy of the GNU General Public License
|
23 |
|
|
* along with this program; if not, write to the Free Software
|
24 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
25 |
|
|
*/
|
26 |
|
|
|
27 |
|
|
package edu.ucsb.nceas.metacat;
|
28 |
|
|
|
29 |
|
|
import java.sql.PreparedStatement;
|
30 |
|
|
import java.sql.ResultSet;
|
31 |
|
|
import java.sql.SQLException;
|
32 |
|
|
import java.util.TimerTask;
|
33 |
2758
|
sgarg
|
import java.util.Vector;
|
34 |
|
|
import java.util.Iterator;
|
35 |
2732
|
sgarg
|
|
36 |
5015
|
daigle
|
import edu.ucsb.nceas.metacat.database.DBConnection;
|
37 |
|
|
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
|
38 |
|
|
import edu.ucsb.nceas.metacat.database.DatabaseService;
|
39 |
5030
|
daigle
|
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
40 |
4698
|
daigle
|
import edu.ucsb.nceas.metacat.util.MetacatUtil;
|
41 |
4080
|
daigle
|
|
42 |
2732
|
sgarg
|
import org.apache.log4j.Logger;
|
43 |
|
|
|
44 |
|
|
public class IndexingTimerTask extends TimerTask{
|
45 |
|
|
|
46 |
|
|
private Logger logMetacat = Logger.getLogger(IndexingTimerTask.class);
|
47 |
|
|
|
48 |
|
|
int count = 0;
|
49 |
|
|
|
50 |
|
|
/*
|
51 |
|
|
* Run a separate thread to build the XML index for this document. This
|
52 |
|
|
* thread is run asynchronously in order to more quickly return control to
|
53 |
|
|
* the submitting user. The run method checks to see if the document has
|
54 |
|
|
* been fully inserted before trying to update the xml_index table.
|
55 |
|
|
*/
|
56 |
|
|
public void run()
|
57 |
|
|
{
|
58 |
|
|
DBConnection dbConn = null;
|
59 |
|
|
int serialNumber = 0;
|
60 |
|
|
try{
|
61 |
|
|
logMetacat.warn("Running indexing timer task");
|
62 |
|
|
|
63 |
2759
|
sgarg
|
dbConn = DBConnectionPool.getDBConnection("IndexingThread");
|
64 |
2732
|
sgarg
|
serialNumber = dbConn.getCheckOutSerialNumber();
|
65 |
4698
|
daigle
|
Vector indexNamespaces = MetacatUtil.getOptionList(PropertyService.getProperty("xml.indexNamespaces"));
|
66 |
2758
|
sgarg
|
String nonJoinCriteria = "b.docid is NULL";
|
67 |
|
|
boolean first = true;
|
68 |
|
|
|
69 |
|
|
if(indexNamespaces != null && !indexNamespaces.isEmpty()){
|
70 |
|
|
Iterator it = indexNamespaces.iterator();
|
71 |
|
|
while(it.hasNext()){
|
72 |
|
|
if(first){
|
73 |
|
|
nonJoinCriteria = nonJoinCriteria + " AND (";
|
74 |
|
|
nonJoinCriteria = nonJoinCriteria
|
75 |
|
|
+ " a.doctype like '"
|
76 |
|
|
+ it.next()
|
77 |
|
|
+ "'";
|
78 |
|
|
|
79 |
|
|
first = false;
|
80 |
|
|
} else {
|
81 |
|
|
nonJoinCriteria = nonJoinCriteria + " OR ";
|
82 |
|
|
nonJoinCriteria = nonJoinCriteria
|
83 |
|
|
+ " a.doctype like '"
|
84 |
|
|
+ it.next()
|
85 |
|
|
+ "'";
|
86 |
|
|
}
|
87 |
|
|
}
|
88 |
|
|
nonJoinCriteria = nonJoinCriteria + ")";
|
89 |
|
|
} else {
|
90 |
|
|
// if no namespaces are defined in metacat.properties then return
|
91 |
|
|
return;
|
92 |
|
|
}
|
93 |
|
|
|
94 |
2732
|
sgarg
|
String xmlDocumentsCheck =
|
95 |
5319
|
jones
|
DatabaseService.getInstance().getDBAdapter().getLeftJoinQuery("a.docid, a.rev", "xml_documents",
|
96 |
2780
|
sgarg
|
"xml_index", "a.docid = b.docid", nonJoinCriteria);
|
97 |
2758
|
sgarg
|
|
98 |
|
|
PreparedStatement xmlDocCheck = dbConn.prepareStatement(xmlDocumentsCheck);
|
99 |
2732
|
sgarg
|
|
100 |
|
|
// Increase usage count
|
101 |
|
|
dbConn.increaseUsageCount(1);
|
102 |
|
|
xmlDocCheck.execute();
|
103 |
|
|
ResultSet rs = xmlDocCheck.getResultSet();
|
104 |
|
|
|
105 |
|
|
boolean tableHasRows = rs.next();
|
106 |
|
|
while (tableHasRows) {
|
107 |
|
|
String docid = rs.getString(1);
|
108 |
|
|
String rev = rs.getString(2);
|
109 |
|
|
|
110 |
2734
|
sgarg
|
IndexingQueue.getInstance().add(docid, rev);
|
111 |
2732
|
sgarg
|
|
112 |
|
|
tableHasRows = rs.next();
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
rs.close();
|
116 |
|
|
xmlDocCheck.close();
|
117 |
|
|
|
118 |
|
|
} catch (SQLException se){
|
119 |
|
|
se.printStackTrace();
|
120 |
|
|
|
121 |
|
|
} catch (Exception e){
|
122 |
|
|
e.printStackTrace();
|
123 |
|
|
|
124 |
|
|
}finally {
|
125 |
|
|
DBConnectionPool.returnDBConnection(dbConn, serialNumber);
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
logMetacat.warn("Indexing timer task returning");
|
129 |
|
|
count++;
|
130 |
|
|
}
|
131 |
|
|
}
|