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 |
|
|
* Release: @release@
|
8 |
|
|
*
|
9 |
|
|
* '$Author$'
|
10 |
|
|
* '$Date$'
|
11 |
|
|
* '$Revision$'
|
12 |
|
|
*
|
13 |
|
|
* This program is free software; you can redistribute it and/or modify
|
14 |
|
|
* it under the terms of the GNU General Public License as published by
|
15 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
16 |
|
|
* (at your option) any later version.
|
17 |
|
|
*
|
18 |
|
|
* This program is distributed in the hope that it will be useful,
|
19 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
|
|
* GNU General Public License for more details.
|
22 |
|
|
*
|
23 |
|
|
* You should have received a copy of the GNU General Public License
|
24 |
|
|
* along with this program; if not, write to the Free Software
|
25 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
26 |
|
|
*/
|
27 |
|
|
|
28 |
|
|
package edu.ucsb.nceas.metacat;
|
29 |
|
|
|
30 |
|
|
import java.sql.PreparedStatement;
|
31 |
|
|
import java.sql.ResultSet;
|
32 |
|
|
import java.sql.SQLException;
|
33 |
|
|
import java.util.TimerTask;
|
34 |
|
|
|
35 |
|
|
import edu.ucsb.nceas.metacat.MetaCatUtil;
|
36 |
|
|
import org.apache.log4j.Logger;
|
37 |
|
|
|
38 |
|
|
public class IndexingTimerTask extends TimerTask{
|
39 |
|
|
|
40 |
|
|
private Logger logMetacat = Logger.getLogger(IndexingTimerTask.class);
|
41 |
|
|
|
42 |
|
|
int count = 0;
|
43 |
|
|
|
44 |
|
|
/*
|
45 |
|
|
* Run a separate thread to build the XML index for this document. This
|
46 |
|
|
* thread is run asynchronously in order to more quickly return control to
|
47 |
|
|
* the submitting user. The run method checks to see if the document has
|
48 |
|
|
* been fully inserted before trying to update the xml_index table.
|
49 |
|
|
*/
|
50 |
|
|
public void run()
|
51 |
|
|
{
|
52 |
|
|
DBConnection dbConn = null;
|
53 |
|
|
int serialNumber = 0;
|
54 |
|
|
try{
|
55 |
|
|
logMetacat.warn("Running indexing timer task");
|
56 |
|
|
|
57 |
|
|
dbConn = DBConnectionPool.getDBConnection("IndexingThread.run");
|
58 |
|
|
serialNumber = dbConn.getCheckOutSerialNumber();
|
59 |
|
|
String xmlDocumentsCheck =
|
60 |
|
|
MetaCatUtil.dbAdapter.getLeftJoinQuery("a.docid, a.rev", "xml_documents",
|
61 |
|
|
"xml_index", "a.docid = b.docid", "b.docid is NULL AND "
|
62 |
|
|
+ "(a.doctype like 'eml://ecoinformatics.org/eml-2.0.0' "
|
63 |
|
|
+ "or a.doctype like 'eml://ecoinformatics.org/eml-2.0.1')");
|
64 |
|
|
|
65 |
|
|
PreparedStatement xmlDocCheck = dbConn
|
66 |
|
|
.prepareStatement(xmlDocumentsCheck);
|
67 |
|
|
|
68 |
|
|
// Increase usage count
|
69 |
|
|
dbConn.increaseUsageCount(1);
|
70 |
|
|
xmlDocCheck.execute();
|
71 |
|
|
ResultSet rs = xmlDocCheck.getResultSet();
|
72 |
|
|
|
73 |
|
|
boolean tableHasRows = rs.next();
|
74 |
|
|
while (tableHasRows) {
|
75 |
|
|
String docid = rs.getString(1);
|
76 |
|
|
String rev = rs.getString(2);
|
77 |
|
|
|
78 |
|
|
IndexingQueue.getInstance().add(docid + "." + rev);
|
79 |
|
|
|
80 |
|
|
tableHasRows = rs.next();
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
rs.close();
|
84 |
|
|
xmlDocCheck.close();
|
85 |
|
|
|
86 |
|
|
} catch (SQLException se){
|
87 |
|
|
se.printStackTrace();
|
88 |
|
|
|
89 |
|
|
} catch (Exception e){
|
90 |
|
|
e.printStackTrace();
|
91 |
|
|
|
92 |
|
|
}finally {
|
93 |
|
|
DBConnectionPool.returnDBConnection(dbConn, serialNumber);
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
logMetacat.warn("Indexing timer task returning");
|
97 |
|
|
count++;
|
98 |
|
|
}
|
99 |
|
|
}
|