Revision 554
Added by berkley about 24 years ago
src/edu/ucsb/nceas/metacat/MetacatReplication.java | ||
---|---|---|
89 | 89 |
{ //stop the replication server |
90 | 90 |
replicationDaemon.cancel(); |
91 | 91 |
out.println("Replication Handler Stopped"); |
92 |
System.out.println("Replication Handler Stopped"); |
|
92 | 93 |
} |
93 | 94 |
else if(((String[])params.get("action"))[0].equals("start")) |
94 | 95 |
{ //start the replication server |
... | ... | |
182 | 183 |
sql.append("to_date('").append(dateString).append("','YY-MM-DD HH24:MI:SS')"); |
183 | 184 |
//System.out.println("sql: " + sql.toString()); |
184 | 185 |
|
186 |
//get any recently deleted documents |
|
187 |
StringBuffer delsql = new StringBuffer(); |
|
188 |
delsql.append("select docid, date_created, server_location from "); |
|
189 |
delsql.append("xml_revisions where docid not in (select docid from "); |
|
190 |
delsql.append("xml_documents) and date_created > to_date('"); |
|
191 |
delsql.append(dateString).append("','YY-MM-DD HH24:MI:SS')"); |
|
192 |
|
|
185 | 193 |
try |
186 | 194 |
{ |
187 | 195 |
Connection conn = util.openDBConnection(); |
... | ... | |
210 | 218 |
} |
211 | 219 |
tablehasrows = rs.next(); |
212 | 220 |
} |
221 |
|
|
222 |
pstmt = conn.prepareStatement(delsql.toString()); |
|
223 |
pstmt.execute(); |
|
224 |
rs = pstmt.getResultSet(); |
|
225 |
tablehasrows = rs.next(); |
|
226 |
while(tablehasrows) |
|
227 |
{ //handle the deleted documents |
|
228 |
String docid = rs.getString(1); |
|
229 |
String dateUpdated = rs.getString(2); |
|
230 |
int serverCode = rs.getInt(3); |
|
231 |
if(serverCode == 1) |
|
232 |
{ |
|
233 |
returnXML.append("<deletedDocument><docid>").append(docid); |
|
234 |
returnXML.append("</docid><date_updated>").append(dateUpdated); |
|
235 |
returnXML.append("</date_updated></deletedDocument>"); |
|
236 |
} |
|
237 |
tablehasrows = rs.next(); |
|
238 |
} |
|
239 |
|
|
213 | 240 |
returnXML.append("</updates></replication>"); |
214 | 241 |
conn.close(); |
215 | 242 |
//System.out.println(returnXML.toString()); |
src/edu/ucsb/nceas/metacat/ReplMessageHandler.java | ||
---|---|---|
34 | 34 |
{ |
35 | 35 |
private Vector updates = new Vector(); |
36 | 36 |
private Vector indivUpdate = new Vector(); |
37 |
private Vector indivDelete = new Vector(); |
|
38 |
private Vector deletes = new Vector(); |
|
37 | 39 |
private String server; |
40 |
private boolean update = false; |
|
41 |
private boolean delete = false; |
|
38 | 42 |
String currentTag = new String(); |
39 | 43 |
|
40 | 44 |
public ReplMessageHandler() |
... | ... | |
51 | 55 |
if(localName.equals("updatedDocument")) |
52 | 56 |
{ |
53 | 57 |
indivUpdate = new Vector(); |
58 |
update = true; |
|
54 | 59 |
} |
60 |
else if(localName.equals("deletedDocument")) |
|
61 |
{ |
|
62 |
indivDelete = new Vector(); |
|
63 |
delete = true; |
|
64 |
} |
|
55 | 65 |
} |
56 | 66 |
|
57 | 67 |
/** |
... | ... | |
63 | 73 |
if(localName.equals("updatedDocument")) |
64 | 74 |
{ |
65 | 75 |
updates.add(new Vector(indivUpdate)); |
76 |
update = false; |
|
66 | 77 |
} |
78 |
else if(localName.equals("deletedDocument")) |
|
79 |
{ |
|
80 |
deletes.add(new Vector(indivDelete)); |
|
81 |
delete = false; |
|
82 |
} |
|
67 | 83 |
} |
68 | 84 |
|
69 | 85 |
/** |
... | ... | |
71 | 87 |
*/ |
72 | 88 |
public void characters(char[] ch, int start, int length) throws SAXException |
73 | 89 |
{ |
74 |
if(currentTag.equals("docid")) |
|
90 |
if(currentTag.equals("docid") && update)
|
|
75 | 91 |
{ |
76 | 92 |
indivUpdate.add(new String(ch, start, length)); |
77 | 93 |
} |
78 |
if(currentTag.equals("date_updated"))
|
|
94 |
else if(currentTag.equals("docid") && delete)
|
|
79 | 95 |
{ |
96 |
indivDelete.add(new String(ch, start, length)); |
|
97 |
} |
|
98 |
|
|
99 |
if(currentTag.equals("date_updated") && update) |
|
100 |
{ |
|
80 | 101 |
indivUpdate.add(new String(ch, start, length)); |
81 | 102 |
indivUpdate.add(server); |
82 | 103 |
} |
104 |
else if(currentTag.equals("date_updated") && delete) |
|
105 |
{ |
|
106 |
indivDelete.add(new String(ch, start, length)); |
|
107 |
indivDelete.add(server); |
|
108 |
} |
|
109 |
|
|
83 | 110 |
if(currentTag.equals("server")) |
84 | 111 |
{ |
85 | 112 |
server = new String(ch, start, length); |
86 | 113 |
} |
87 | 114 |
} |
88 | 115 |
|
89 |
public Vector getResultVect()
|
|
116 |
public Vector getUpdatesVect()
|
|
90 | 117 |
{ |
91 | 118 |
return updates; |
92 | 119 |
} |
93 | 120 |
|
121 |
public Vector getDeletesVect() |
|
122 |
{ |
|
123 |
return deletes; |
|
124 |
} |
|
125 |
|
|
94 | 126 |
} |
src/edu/ucsb/nceas/metacat/ReplicationHandler.java | ||
---|---|---|
132 | 132 |
parser.parse(new InputSource( |
133 | 133 |
new StringReader( |
134 | 134 |
(String)(responses.elementAt(i))))); |
135 |
Vector v = new Vector(message.getResultVect()); |
|
135 |
Vector v = new Vector(message.getUpdatesVect()); |
|
136 |
Vector d = new Vector(message.getDeletesVect()); |
|
136 | 137 |
for(int j=0; j<v.size(); j++) |
137 | 138 |
{ //go through each update vector and update or insert |
138 | 139 |
//a new document |
... | ... | |
193 | 194 |
System.out.println("newDocid: " + newDocid + " " + action + "ED"); |
194 | 195 |
} |
195 | 196 |
} |
197 |
|
|
198 |
for(int k=0; k<d.size(); k++) |
|
199 |
{ |
|
200 |
Vector w = new Vector((Vector)d.elementAt(k)); |
|
201 |
String docid = (String)w.elementAt(0); |
|
202 |
|
|
203 |
DocumentImpl.delete(conn, docid, null, null); |
|
204 |
} |
|
196 | 205 |
} |
197 | 206 |
|
198 | 207 |
//update the last_update field for each server to the current date/time |
Also available in: Unified diff
added delete functionality