1
|
/**
|
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: tao $'
|
9
|
* '$Date: 2013-08-26 16:30:00 -0700 (Mon, 26 Aug 2013) $'
|
10
|
* '$Revision: 8164 $'
|
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
|
import java.util.Vector;
|
34
|
import java.util.Iterator;
|
35
|
|
36
|
import edu.ucsb.nceas.metacat.common.query.EnabledQueryEngines;
|
37
|
import edu.ucsb.nceas.metacat.database.DBConnection;
|
38
|
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
|
39
|
import edu.ucsb.nceas.metacat.database.DatabaseService;
|
40
|
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
41
|
import edu.ucsb.nceas.metacat.util.MetacatUtil;
|
42
|
|
43
|
import org.apache.log4j.Logger;
|
44
|
|
45
|
public class IndexingTimerTask extends TimerTask{
|
46
|
|
47
|
private Logger logMetacat = Logger.getLogger(IndexingTimerTask.class);
|
48
|
|
49
|
int count = 0;
|
50
|
|
51
|
/*
|
52
|
* Run a separate thread to build the XML index for this document. This
|
53
|
* thread is run asynchronously in order to more quickly return control to
|
54
|
* the submitting user. The run method checks to see if the document has
|
55
|
* been fully inserted before trying to update the xml_index table.
|
56
|
*/
|
57
|
public void run()
|
58
|
{
|
59
|
if(!EnabledQueryEngines.getInstance().isEnabled(EnabledQueryEngines.PATHQUERYENGINE)) {
|
60
|
return;
|
61
|
}
|
62
|
DBConnection dbConn = null;
|
63
|
int serialNumber = 0;
|
64
|
try{
|
65
|
logMetacat.warn("Running indexing timer task");
|
66
|
|
67
|
dbConn = DBConnectionPool.getDBConnection("IndexingThread");
|
68
|
serialNumber = dbConn.getCheckOutSerialNumber();
|
69
|
Vector indexNamespaces = MetacatUtil.getOptionList(PropertyService.getProperty("xml.indexNamespaces"));
|
70
|
String nonJoinCriteria = "b.docid is NULL";
|
71
|
boolean first = true;
|
72
|
|
73
|
if(indexNamespaces != null && !indexNamespaces.isEmpty()){
|
74
|
Iterator it = indexNamespaces.iterator();
|
75
|
while(it.hasNext()){
|
76
|
if(first){
|
77
|
nonJoinCriteria = nonJoinCriteria + " AND (";
|
78
|
nonJoinCriteria = nonJoinCriteria
|
79
|
+ " a.doctype like '"
|
80
|
+ it.next()
|
81
|
+ "'";
|
82
|
|
83
|
first = false;
|
84
|
} else {
|
85
|
nonJoinCriteria = nonJoinCriteria + " OR ";
|
86
|
nonJoinCriteria = nonJoinCriteria
|
87
|
+ " a.doctype like '"
|
88
|
+ it.next()
|
89
|
+ "'";
|
90
|
}
|
91
|
}
|
92
|
nonJoinCriteria = nonJoinCriteria + ")";
|
93
|
} else {
|
94
|
// if no namespaces are defined in metacat.properties then return
|
95
|
return;
|
96
|
}
|
97
|
|
98
|
String xmlDocumentsCheck =
|
99
|
DatabaseService.getInstance().getDBAdapter().getLeftJoinQuery("a.docid, a.rev", "xml_documents",
|
100
|
"xml_index", "a.docid = b.docid", nonJoinCriteria);
|
101
|
|
102
|
PreparedStatement xmlDocCheck = dbConn.prepareStatement(xmlDocumentsCheck);
|
103
|
|
104
|
// Increase usage count
|
105
|
dbConn.increaseUsageCount(1);
|
106
|
xmlDocCheck.execute();
|
107
|
ResultSet rs = xmlDocCheck.getResultSet();
|
108
|
|
109
|
boolean tableHasRows = rs.next();
|
110
|
while (tableHasRows) {
|
111
|
String docid = rs.getString(1);
|
112
|
String rev = rs.getString(2);
|
113
|
|
114
|
IndexingQueue.getInstance().add(docid, rev);
|
115
|
|
116
|
tableHasRows = rs.next();
|
117
|
}
|
118
|
|
119
|
rs.close();
|
120
|
xmlDocCheck.close();
|
121
|
|
122
|
} catch (SQLException se){
|
123
|
se.printStackTrace();
|
124
|
|
125
|
} catch (Exception e){
|
126
|
e.printStackTrace();
|
127
|
|
128
|
}finally {
|
129
|
DBConnectionPool.returnDBConnection(dbConn, serialNumber);
|
130
|
}
|
131
|
|
132
|
logMetacat.warn("Indexing timer task returning");
|
133
|
count++;
|
134
|
}
|
135
|
}
|