Revision 579
Added by berkley about 24 years ago
src/edu/ucsb/nceas/metacat/ReplicationHandler.java | ||
---|---|---|
122 | 122 |
//System.out.println("get responses"); |
123 | 123 |
server = (String)(keys.nextElement()); |
124 | 124 |
u = new URL("http://" + server + "?action=update"); |
125 |
//System.out.println(u.toString()); |
|
125 | 126 |
String result = MetacatReplication.getURLContent(u); |
126 | 127 |
//System.out.println(result); |
127 | 128 |
responses.add(result); |
... | ... | |
180 | 181 |
{ //if the document needs to be updated or inserted, this is executed |
181 | 182 |
u = new URL("http://" + docServer + "?action=read&docid=" + |
182 | 183 |
docid); |
184 |
//System.out.println(u.toString()); |
|
183 | 185 |
String newxmldoc = MetacatReplication.getURLContent(u); |
184 | 186 |
DocInfoHandler dih = new DocInfoHandler(); |
185 | 187 |
XMLReader docinfoParser = initParser(dih); |
186 | 188 |
URL docinfoUrl = new URL("http://" + docServer + |
187 | 189 |
"?action=getdocumentinfo&docid=" + |
188 | 190 |
docid); |
191 |
//System.out.println(docinfoUrl.toString()); |
|
189 | 192 |
String docInfoStr = MetacatReplication.getURLContent(docinfoUrl); |
190 | 193 |
docinfoParser.parse(new InputSource(new StringReader(docInfoStr))); |
191 | 194 |
Hashtable docinfoHash = dih.getDocInfo(); |
... | ... | |
207 | 210 |
{ //delete the deleted documents; |
208 | 211 |
Vector w = new Vector((Vector)d.elementAt(k)); |
209 | 212 |
String docid = (String)w.elementAt(0); |
210 |
|
|
211 |
DocumentImpl.delete(conn, docid, null, null); |
|
212 |
System.out.println("Document " + docid + " deleted."); |
|
213 |
if(!alreadyDeleted(docid, conn)) |
|
214 |
{ |
|
215 |
DocumentImpl.delete(conn, docid, null, null); |
|
216 |
System.out.println("Document " + docid + " deleted."); |
|
217 |
} |
|
213 | 218 |
} |
214 | 219 |
|
215 | 220 |
keys = serverList.keys(); |
... | ... | |
240 | 245 |
} |
241 | 246 |
|
242 | 247 |
/** |
248 |
* Method that returns true if docid has already been "deleted" from metacat. |
|
249 |
*/ |
|
250 |
private static boolean alreadyDeleted(String docid, Connection conn) |
|
251 |
{ |
|
252 |
try |
|
253 |
{ |
|
254 |
StringBuffer sb = new StringBuffer(); |
|
255 |
sb.append("select docid from xml_revisions where docid not in "); |
|
256 |
sb.append("(select docid from xml_documents) and docid like '"); |
|
257 |
sb.append(docid).append("'"); |
|
258 |
PreparedStatement pstmt = conn.prepareStatement(sb.toString()); |
|
259 |
pstmt.execute(); |
|
260 |
ResultSet rs = pstmt.getResultSet(); |
|
261 |
boolean tablehasrows = rs.next(); |
|
262 |
if(tablehasrows) |
|
263 |
{ |
|
264 |
return true; |
|
265 |
} |
|
266 |
return false; |
|
267 |
} |
|
268 |
catch(Exception e) |
|
269 |
{ |
|
270 |
System.out.println("error in alreadyDeleted: " + e.getMessage()); |
|
271 |
e.printStackTrace(System.out); |
|
272 |
} |
|
273 |
return false; |
|
274 |
} |
|
275 |
|
|
276 |
/** |
|
243 | 277 |
* Method to check each server in the servetList for updates |
244 | 278 |
*/ |
245 | 279 |
private void update(Hashtable serverList, Connection conn) |
Also available in: Unified diff
fixed typo, removed extra print statements