1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Purpose: A Class that manages database access of xml access
|
4
|
* information.
|
5
|
* Copyright: 2009 Regents of the University of California and the
|
6
|
* National Center for Ecological Analysis and Synthesis
|
7
|
* Authors: Michael Daigle
|
8
|
*
|
9
|
* '$Author: daigle $'
|
10
|
* '$Date: 2009-03-23 13:56:56 -0800 (Mon, 23 Mar 2009) $'
|
11
|
* '$Revision: 4854 $'
|
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
|
|
34
|
import org.apache.log4j.Logger;
|
35
|
|
36
|
import edu.ucsb.nceas.metacat.database.DBConnection;
|
37
|
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
|
38
|
import edu.ucsb.nceas.metacat.shared.AccessException;
|
39
|
import edu.ucsb.nceas.metacat.shared.BaseAccess;
|
40
|
import edu.ucsb.nceas.metacat.shared.BaseDAO;
|
41
|
|
42
|
public class XMLQueryresultAccess extends BaseAccess {
|
43
|
|
44
|
private Logger logMetacat = Logger.getLogger(XMLQueryresultAccess.class);
|
45
|
|
46
|
// Constructor
|
47
|
public XMLQueryresultAccess() throws AccessException {}
|
48
|
|
49
|
/**
|
50
|
* Delete xml access. This removes all access records from the database for a given document
|
51
|
*
|
52
|
* @param docId
|
53
|
* document id
|
54
|
*/
|
55
|
public void deleteXMLQueryresulForDoc(String docId) throws AccessException {
|
56
|
if (docId == null) {
|
57
|
throw new AccessException("XMLQueryresultAccess.deleteXMLQueryresulForDoc - docid is required when " +
|
58
|
"deleting XML access record");
|
59
|
}
|
60
|
|
61
|
PreparedStatement pstmt = null;
|
62
|
DBConnection conn = null;
|
63
|
int serialNumber = -1;
|
64
|
try {
|
65
|
// check out DBConnection
|
66
|
conn = DBConnectionPool.getDBConnection("XMLQueryresultAccess.deleteXMLQueryresulForDoc");
|
67
|
serialNumber = conn.getCheckOutSerialNumber();
|
68
|
|
69
|
String sql = "DELETE FROM xml_queryresult WHERE docid = ?";
|
70
|
pstmt = conn.prepareStatement(sql);
|
71
|
|
72
|
// Bind the values to the query
|
73
|
pstmt.setString(1, docId);
|
74
|
|
75
|
String sqlReport = "XMLQueryresultAccess.deleteXMLQueryresulForDoc - SQL: " + sql;
|
76
|
sqlReport += " [" + docId + "]";
|
77
|
|
78
|
logMetacat.info(sqlReport);
|
79
|
|
80
|
pstmt.execute();
|
81
|
} catch (SQLException sqle) {
|
82
|
throw new AccessException("XMLQueryresultAccess.deleteXMLQueryresulForDoc - SQL error when deleting"
|
83
|
+ "xml query result for doc id: " + docId + ":" + sqle.getMessage());
|
84
|
} finally {
|
85
|
closeDBObjects(pstmt, conn, serialNumber, logMetacat);
|
86
|
}
|
87
|
}
|
88
|
|
89
|
/**
|
90
|
* Populate a job data object with the current row in a resultset
|
91
|
*
|
92
|
* @param resultSet
|
93
|
* the result set which is already pointing to the desired row.
|
94
|
* @return a scheduled job data object
|
95
|
*/
|
96
|
protected BaseDAO populateDAO(ResultSet resultSet) throws SQLException {
|
97
|
|
98
|
// XMLAccessDAO xmlAccessDAO = new XMLAccessDAO();
|
99
|
// xmlAccessDAO.setDocId(resultSet.getString("docid"));
|
100
|
// xmlAccessDAO.setAccessFileId(resultSet.getString("accessfileid"));
|
101
|
// xmlAccessDAO.setPrincipalName(resultSet.getString("principal_name"));
|
102
|
// xmlAccessDAO.setPermission(resultSet.getLong("permission"));
|
103
|
// xmlAccessDAO.setPermType(resultSet.getString("perm_type"));
|
104
|
// xmlAccessDAO.setPermOrder(resultSet.getString("perm_order"));
|
105
|
// xmlAccessDAO.setBeginTime(resultSet.getDate("begin_time"));
|
106
|
// xmlAccessDAO.setEndTime(resultSet.getDate("end_time"));
|
107
|
// xmlAccessDAO.setTicketCount(resultSet.getLong("ticket_count"));
|
108
|
// xmlAccessDAO.setSubTreeId(resultSet.getString("subtreeid"));
|
109
|
// xmlAccessDAO.setStartNodeId(resultSet.getString("startnodeid"));
|
110
|
// xmlAccessDAO.setEndNodeId(resultSet.getString("endnodeid"));
|
111
|
|
112
|
return null;
|
113
|
}
|
114
|
|
115
|
}
|