Revision 2640
Added by Jing Tao about 19 years ago
src/edu/ucsb/nceas/metacat/DeletedDocumentImpl.java | ||
---|---|---|
1 |
/** |
|
2 |
* '$RCSfile$' |
|
3 |
* |
|
4 |
* '$Author$' |
|
5 |
* '$Date$' |
|
6 |
* '$Revision$' |
|
7 |
* |
|
8 |
* For Details: http://kepler.ecoinformatics.org |
|
9 |
* |
|
10 |
* Copyright (c) 2003 The Regents of the University of California. |
|
11 |
* All rights reserved. |
|
12 |
* |
|
13 |
* Permission is hereby granted, without written agreement and without |
|
14 |
* license or royalty fees, to use, copy, modify, and distribute this |
|
15 |
* software and its documentation for any purpose, provided that the |
|
16 |
* above copyright notice and the following two paragraphs appear in |
|
17 |
* all copies of this software. |
|
18 |
* |
|
19 |
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY |
|
20 |
* FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
|
21 |
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
|
22 |
* IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY |
|
23 |
* OF SUCH DAMAGE. |
|
24 |
* |
|
25 |
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, |
|
26 |
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
27 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE |
|
28 |
* PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY |
|
29 |
* OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, |
|
30 |
* UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
|
31 |
*/ |
|
32 |
package edu.ucsb.nceas.metacat; |
|
33 |
|
|
34 |
import java.sql.PreparedStatement; |
|
35 |
import java.sql.SQLException; |
|
36 |
|
|
37 |
/** |
|
38 |
* @author tao |
|
39 |
* This class represents a deleted document. It will be used when timed replication |
|
40 |
* try to insert a deleted document into metacat. The document will be insert into |
|
41 |
* xml_revisions table rather than xml_documents table. |
|
42 |
*/ |
|
43 |
public class DeletedDocumentImpl extends DocumentImpl |
|
44 |
{ |
|
45 |
|
|
46 |
/** |
|
47 |
* Contructor of this class. |
|
48 |
* @param conn |
|
49 |
* @param rootNodeId |
|
50 |
* @param docName |
|
51 |
* @param docType |
|
52 |
* @param docId |
|
53 |
* @param newRevision |
|
54 |
* @param action |
|
55 |
* @param user |
|
56 |
* @param pub |
|
57 |
* @param catalogId |
|
58 |
* @param serverCode |
|
59 |
* @throws Exception |
|
60 |
*/ |
|
61 |
public DeletedDocumentImpl(DBConnection conn, long rootNodeId, String docName, |
|
62 |
String docType, String docId, String newRevision, String action, |
|
63 |
String user, String pub, String catalogId, int serverCode) |
|
64 |
throws Exception |
|
65 |
{ |
|
66 |
this.connection = conn; |
|
67 |
this.rootnodeid = rootNodeId; |
|
68 |
this.docname = docName; |
|
69 |
this.doctype = docType; |
|
70 |
this.docid = docId; |
|
71 |
this.updatedVersion = newRevision; |
|
72 |
String sysdate = dbAdapter.getDateTimeFunction(); |
|
73 |
writeDocumentToRevisionTable(connection, docid, updatedVersion, doctype, |
|
74 |
docname,user, pub, catalogId, serverCode, rootnodeid, sysdate); |
|
75 |
} |
|
76 |
|
|
77 |
/* |
|
78 |
* This method will write a record to revision table base on given |
|
79 |
* info. The create date and update will be current time. |
|
80 |
* If rootNodeId < 0, this means it has not rootid |
|
81 |
*/ |
|
82 |
private static void writeDocumentToRevisionTable(DBConnection con, String docId, |
|
83 |
String rev, String docType, String docName, String user, String pub, |
|
84 |
String catalogid, int serverCode, long rootNodeId, String sysdate) throws SQLException, Exception |
|
85 |
{ |
|
86 |
|
|
87 |
try |
|
88 |
{ |
|
89 |
PreparedStatement pstmt = null; |
|
90 |
pstmt = con.prepareStatement("INSERT INTO xml_revisions " |
|
91 |
+ "(docid, rootnodeid, docname, doctype, user_owner, " |
|
92 |
+ "user_updated, date_created, date_updated, " |
|
93 |
+ "public_access, catalog_id, server_location, rev) " |
|
94 |
+ "VALUES (?, ?, ?, ?, ?, ?, " + sysdate + ", " |
|
95 |
+ sysdate + ", ?, ?, ?, ?)"); |
|
96 |
// Increase dbconnection usage count |
|
97 |
con.increaseUsageCount(1); |
|
98 |
|
|
99 |
// Bind the values to the query |
|
100 |
pstmt.setString(1, docId); |
|
101 |
if (rootNodeId >0 ) |
|
102 |
{ |
|
103 |
pstmt.setLong(2, rootNodeId); |
|
104 |
} |
|
105 |
pstmt.setString(3, docName); |
|
106 |
pstmt.setString(4, docType); |
|
107 |
pstmt.setString(5, user); |
|
108 |
pstmt.setString(6, user); |
|
109 |
pstmt.setString(7, null); |
|
110 |
pstmt.setString(8, catalogid); |
|
111 |
pstmt.setInt(9, serverCode); |
|
112 |
pstmt.setInt(10, Integer.parseInt(rev)); |
|
113 |
|
|
114 |
// Do the insertion |
|
115 |
pstmt.execute(); |
|
116 |
pstmt.close(); |
|
117 |
|
|
118 |
|
|
119 |
} |
|
120 |
catch (SQLException sqle) |
|
121 |
{ |
|
122 |
throw sqle; |
|
123 |
} |
|
124 |
catch (Exception e) |
|
125 |
{ |
|
126 |
throw e; |
|
127 |
} |
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* This method will generate record in xml_revision table for a data file |
|
132 |
* The reason why we need this method is because data file would be parsed by |
|
133 |
* xml parser. So the constructor would be called for data file and this |
|
134 |
* method will replace the function |
|
135 |
*/ |
|
136 |
static public void registerDeletedDataFile(String docname, |
|
137 |
String doctype, String accnum, String user, int serverCode) throws Exception |
|
138 |
{ |
|
139 |
DBConnection dbconn = null; |
|
140 |
int serialNumber = -1; |
|
141 |
//MetaCatUtil util = new MetaCatUtil(); |
|
142 |
AccessionNumber ac; |
|
143 |
PreparedStatement pstmt = null; |
|
144 |
String action = null; |
|
145 |
String sysdate = dbAdapter.getDateTimeFunction(); |
|
146 |
try |
|
147 |
{ |
|
148 |
//dbconn = util.openDBConnection(); |
|
149 |
dbconn = DBConnectionPool.getDBConnection( |
|
150 |
"DeletedDocumentImpl.registerDeletedDataFile"); |
|
151 |
serialNumber = dbconn.getCheckOutSerialNumber(); |
|
152 |
String docIdWithoutRev = MetaCatUtil |
|
153 |
.getDocIdFromAccessionNumber(accnum); |
|
154 |
String rev = MetaCatUtil.getRevisionStringFromString(accnum); |
|
155 |
writeDocumentToRevisionTable(dbconn, docIdWithoutRev, |
|
156 |
rev, doctype, docname, user, null, |
|
157 |
null, serverCode, -1, sysdate); |
|
158 |
dbconn.close(); |
|
159 |
} |
|
160 |
finally |
|
161 |
{ |
|
162 |
|
|
163 |
DBConnectionPool.returnDBConnection(dbconn, serialNumber); |
|
164 |
} |
|
165 |
} |
|
166 |
} |
|
167 | 0 |
Also available in: Unified diff
Remove this file.