Revision 6595
Added by ben leinfelder about 13 years ago
test/MaxmumDBConnection.java | ||
---|---|---|
140 | 140 |
DBConnection conn = null; |
141 | 141 |
PreparedStatement pStmt = null; |
142 | 142 |
ResultSet rs = null; |
143 |
String sql = "select docid from xml_documents where docid like'%jing%'";
|
|
143 |
String sql = "select docid from xml_documents where docid like ?";
|
|
144 | 144 |
|
145 | 145 |
try |
146 | 146 |
{ |
... | ... | |
148 | 148 |
serialNumber = conn.getCheckOutSerialNumber(); |
149 | 149 |
System.out.println("serialNumber: "+serialNumber); |
150 | 150 |
pStmt = conn.prepareStatement(sql); |
151 |
pStmt.setString(1, "%jing%"); |
|
151 | 152 |
pStmt.execute(); |
152 | 153 |
rs = pStmt.getResultSet(); |
153 | 154 |
if (rs.next()) |
src/edu/ucsb/nceas/metacat/IndexingQueue.java | ||
---|---|---|
216 | 216 |
boolean inxmldoc = false; |
217 | 217 |
|
218 | 218 |
String revision = docid.substring(docid.lastIndexOf(".")+1,docid.length()); |
219 |
int rev = Integer.parseInt(revision); |
|
219 | 220 |
docid = docid.substring(0,docid.lastIndexOf(".")); |
220 | 221 |
|
221 | 222 |
logMetacat.info("Checking if document exists in xml_documents: docid is " |
... | ... | |
228 | 229 |
serialNumber = dbConn.getCheckOutSerialNumber(); |
229 | 230 |
|
230 | 231 |
String xmlDocumentsCheck = "SELECT distinct docid FROM " + tablename |
231 |
+ " WHERE docid ='" + docid
|
|
232 |
+ "' AND rev ='" + revision + "'";
|
|
232 |
+ " WHERE docid = ? "
|
|
233 |
+ " AND rev = ?";
|
|
233 | 234 |
|
234 | 235 |
PreparedStatement xmlDocCheck = dbConn.prepareStatement(xmlDocumentsCheck); |
236 |
xmlDocCheck.setString(1, docid); |
|
237 |
xmlDocCheck.setInt(2, rev); |
|
235 | 238 |
// Increase usage count |
236 |
|
|
237 | 239 |
dbConn.increaseUsageCount(1); |
238 | 240 |
xmlDocCheck.execute(); |
239 | 241 |
ResultSet doccheckRS = xmlDocCheck.getResultSet(); |
src/edu/ucsb/nceas/metacat/spatial/SpatialDocument.java | ||
---|---|---|
92 | 92 |
* Determine the docname/schema and decide how to proceed with spatial |
93 | 93 |
* harvest |
94 | 94 |
*/ |
95 |
String query = "SELECT docname FROM xml_documents WHERE docid='" + docid.trim() |
|
96 |
+ "';"; |
|
95 |
String query = "SELECT docname FROM xml_documents WHERE docid = ?"; |
|
97 | 96 |
String docname = ""; |
98 | 97 |
try { |
99 | 98 |
pstmt = dbconn.prepareStatement(query); |
99 |
pstmt.setString(1, docid.trim()); |
|
100 | 100 |
pstmt.execute(); |
101 | 101 |
rs = pstmt.getResultSet(); |
102 | 102 |
while (rs.next()) { |
... | ... | |
146 | 146 |
* Get the bounding coordinates |
147 | 147 |
*/ |
148 | 148 |
query = "SELECT path, nodedatanumerical, parentnodeid FROM xml_path_index" |
149 |
+ " WHERE docid = '" |
|
150 |
+ docid.trim() |
|
151 |
+ "'" |
|
152 |
+ " AND docid IN (SELECT distinct docid FROM xml_access WHERE docid = '" |
|
153 |
+ docid.trim() |
|
154 |
+ "' AND principal_name = 'public' AND perm_type = 'allow')" |
|
149 |
+ " WHERE docid = ?" |
|
150 |
+ " AND docid IN (SELECT distinct docid FROM xml_access WHERE docid = ?" |
|
151 |
+ " AND principal_name = 'public' AND perm_type = 'allow')" |
|
155 | 152 |
+ " AND (path = '" + westPath + "'" + " OR path = '" + southPath |
156 | 153 |
+ "'" + " OR path = '" + eastPath + "'" + " OR path = '" |
157 | 154 |
+ northPath + "'" + " ) ORDER BY parentnodeid;"; |
158 | 155 |
|
159 | 156 |
try { |
160 | 157 |
pstmt = dbconn.prepareStatement(query); |
158 |
pstmt.setString(1, docid.trim()); |
|
159 |
pstmt.setString(2, docid.trim()); |
|
161 | 160 |
pstmt.execute(); |
162 | 161 |
rs = pstmt.getResultSet(); |
163 | 162 |
while (rs.next()) { |
... | ... | |
187 | 186 |
try { |
188 | 187 |
|
189 | 188 |
String docTitlePath = PropertyService.getProperty("spatial.docTitle"); |
190 |
query = "select nodedata from xml_path_index where path = '"
|
|
191 |
+ docTitlePath.trim() + "' and docid = '" + docid.trim() + "'";
|
|
189 |
query = "select nodedata from xml_path_index where path = ?"
|
|
190 |
+ " and docid = ?";
|
|
192 | 191 |
pstmt = dbconn.prepareStatement(query); |
192 |
pstmt.setString(1, docTitlePath.trim()); |
|
193 |
pstmt.setString(2, docid.trim()); |
|
193 | 194 |
pstmt.execute(); |
194 | 195 |
rs = pstmt.getResultSet(); |
195 | 196 |
if (rs.next()) |
src/edu/ucsb/nceas/metacat/EventLog.java | ||
---|---|---|
27 | 27 |
import java.sql.ResultSet; |
28 | 28 |
import java.sql.SQLException; |
29 | 29 |
import java.sql.Timestamp; |
30 |
import java.util.ArrayList; |
|
30 | 31 |
import java.util.Date; |
32 |
import java.util.List; |
|
31 | 33 |
|
32 | 34 |
import org.apache.log4j.Logger; |
33 | 35 |
|
... | ... | |
112 | 114 |
String insertString = "insert into access_log" |
113 | 115 |
+ "(ip_address, user_agent, principal, docid, " |
114 | 116 |
+ "event, date_logged) " |
115 |
+ "values (" |
|
116 |
+ "'" + logData.getIpAddress() + "', " |
|
117 |
+ "'" + logData.getUserAgent() + "', " |
|
118 |
+ "'" + logData.getPrincipal() + "', " |
|
119 |
+ "'" + logData.getDocid() + "', " |
|
120 |
+ "'" + logData.getEvent() + "', " |
|
121 |
+ " ? " + ")"; |
|
122 |
|
|
117 |
+ "values ( ?, ?, ?, ?, ?, ? )"; |
|
118 |
|
|
123 | 119 |
DBConnection dbConn = null; |
124 | 120 |
int serialNumber = -1; |
125 | 121 |
try { |
... | ... | |
129 | 125 |
|
130 | 126 |
// Execute the insert statement |
131 | 127 |
PreparedStatement stmt = dbConn.prepareStatement(insertString); |
132 |
stmt.setTimestamp(1, new Timestamp(new Date().getTime())); |
|
128 |
|
|
129 |
stmt.setString(1, logData.getIpAddress()); |
|
130 |
stmt.setString(2, logData.getUserAgent()); |
|
131 |
stmt.setString(3, logData.getPrincipal()); |
|
132 |
stmt.setString(4, logData.getDocid()); |
|
133 |
stmt.setString(5, logData.getEvent()); |
|
134 |
stmt.setTimestamp(6, new Timestamp(new Date().getTime())); |
|
133 | 135 |
stmt.executeUpdate(); |
134 | 136 |
stmt.close(); |
135 | 137 |
} catch (SQLException e) { |
... | ... | |
175 | 177 |
int startIndex = 0; |
176 | 178 |
int endIndex = 0; |
177 | 179 |
|
180 |
List<String> paramValues = new ArrayList<String>(); |
|
178 | 181 |
if (ipAddress != null) { |
179 |
query.append(generateSqlClause(clauseAdded, "ip_address", ipAddress)); |
|
182 |
query.append("ip_address in ("); |
|
183 |
for (int i = 0; i < ipAddress.length; i++) { |
|
184 |
if (i > 0) { |
|
185 |
query.append(", "); |
|
186 |
} |
|
187 |
query.append("?"); |
|
188 |
paramValues.add(ipAddress[i]); |
|
189 |
} |
|
190 |
query.append(") "); |
|
180 | 191 |
clauseAdded = true; |
181 | 192 |
} |
182 | 193 |
if (principal != null) { |
183 |
query.append(generateSqlClause(clauseAdded, "principal", principal)); |
|
194 |
query.append("principal in ("); |
|
195 |
for (int i = 0; i < principal.length; i++) { |
|
196 |
if (i > 0) { |
|
197 |
query.append(", "); |
|
198 |
} |
|
199 |
query.append("?"); |
|
200 |
paramValues.add(principal[i]); |
|
201 |
} |
|
202 |
query.append(") "); |
|
184 | 203 |
clauseAdded = true; |
185 | 204 |
} |
186 | 205 |
if (docid != null) { |
187 |
query.append(generateSqlClause(clauseAdded, "docid", docid)); |
|
206 |
query.append("docid in ("); |
|
207 |
for (int i = 0; i < docid.length; i++) { |
|
208 |
if (i > 0) { |
|
209 |
query.append(", "); |
|
210 |
} |
|
211 |
query.append("?"); |
|
212 |
paramValues.add(docid[i]); |
|
213 |
} |
|
214 |
query.append(") "); |
|
188 | 215 |
clauseAdded = true; |
189 | 216 |
} |
190 | 217 |
if (event != null) { |
191 |
query.append(generateSqlClause(clauseAdded, "event", event)); |
|
218 |
query.append("event in ("); |
|
219 |
for (int i = 0; i < event.length; i++) { |
|
220 |
if (i > 0) { |
|
221 |
query.append(", "); |
|
222 |
} |
|
223 |
query.append("?"); |
|
224 |
paramValues.add(event[i]); |
|
225 |
} |
|
226 |
query.append(") "); |
|
192 | 227 |
clauseAdded = true; |
193 | 228 |
} |
194 | 229 |
if (startDate != null) { |
... | ... | |
216 | 251 |
|
217 | 252 |
// Execute the query statement |
218 | 253 |
PreparedStatement stmt = dbConn.prepareStatement(query.toString()); |
254 |
//set the param values |
|
255 |
int parameterIndex = 1; |
|
256 |
for (String val: paramValues) { |
|
257 |
stmt.setString(parameterIndex, val); |
|
258 |
} |
|
219 | 259 |
if (startIndex > 0) { |
220 |
stmt.setTimestamp(startIndex, startDate); |
|
260 |
stmt.setTimestamp(parameterIndex + startIndex, startDate);
|
|
221 | 261 |
} |
222 | 262 |
if (endIndex > 0) { |
223 |
stmt.setTimestamp(endIndex, endDate); |
|
263 |
stmt.setTimestamp(parameterIndex + endIndex, endDate);
|
|
224 | 264 |
} |
225 | 265 |
stmt.execute(); |
226 | 266 |
ResultSet rs = stmt.getResultSet(); |
... | ... | |
251 | 291 |
} |
252 | 292 |
|
253 | 293 |
/** |
254 |
* Utility method to help build a SQL query from an array of values. For each |
|
255 |
* value in the array an 'OR' clause is constructed. |
|
256 |
* |
|
257 |
* @param addOperator a flag indicating whether to add an 'AND' operator |
|
258 |
* to the clause |
|
259 |
* @param column the name of the column to filter against |
|
260 |
* @param values the values to match in the SQL query |
|
261 |
* @return a String representation of the SQL query clause |
|
262 |
*/ |
|
263 |
private String generateSqlClause(boolean addOperator, String column, |
|
264 |
String[] values) |
|
265 |
{ |
|
266 |
StringBuffer clause = new StringBuffer(); |
|
267 |
if (addOperator) { |
|
268 |
clause.append(" and "); |
|
269 |
} |
|
270 |
clause.append("("); |
|
271 |
for (int i = 0; i < values.length; i++) { |
|
272 |
if (i > 0) { |
|
273 |
clause.append(" or "); |
|
274 |
} |
|
275 |
clause.append(column); |
|
276 |
clause.append(" like '"); |
|
277 |
clause.append(values[i]); |
|
278 |
clause.append("'"); |
|
279 |
} |
|
280 |
clause.append(")"); |
|
281 |
return clause.toString(); |
|
282 |
} |
|
283 |
|
|
284 |
/** |
|
285 | 294 |
* Format each returned log record as an XML structure. |
286 | 295 |
* |
287 | 296 |
* @param entryId the identifier of the log entry |
src/edu/ucsb/nceas/metacat/ContentTypeProvider.java | ||
---|---|---|
475 | 475 |
return docId; |
476 | 476 |
} |
477 | 477 |
// get sql command |
478 |
String sql = "SELECT doctype, docid from xml_documents where docid in ("; |
|
478 |
String sql = "SELECT doctype, docid from xml_documents where docid in ( ";
|
|
479 | 479 |
// the first element |
480 |
sql = sql + "'"+(String)list.elementAt(0) + "'"; |
|
481 |
for (int i=1; i<list.size(); i++) |
|
482 |
{ |
|
483 |
String docid = (String) list.elementAt(i); |
|
484 |
sql = sql + ", '" + docid + "'"; |
|
485 |
}//for |
|
486 |
// add parensis |
|
480 |
sql = sql + "?"; |
|
481 |
// remaining values |
|
482 |
for (int i = 1; i < list.size(); i++) { |
|
483 |
sql = sql + ", ?"; |
|
484 |
} |
|
485 |
// add parentheses |
|
487 | 486 |
sql = sql + ")"; |
488 | 487 |
logMetacat.info("SQL for select doctype: "+ sql); |
489 | 488 |
ResultSet rs = null; |
... | ... | |
497 | 496 |
("ContentTypeProvider.setPhycialDocIdForBeta"); |
498 | 497 |
serialNumber=conn.getCheckOutSerialNumber(); |
499 | 498 |
pStmt = conn.prepareStatement(sql); |
499 |
// set the parameter values |
|
500 |
for (int i = 0; i < list.size(); i++) { |
|
501 |
String docid = (String) list.elementAt(i); |
|
502 |
pStmt.setString(i+1, docid); |
|
503 |
} |
|
500 | 504 |
//execute query |
501 | 505 |
pStmt.execute(); |
502 | 506 |
rs = pStmt.getResultSet(); |
src/edu/ucsb/nceas/metacat/PermissionController.java | ||
---|---|---|
459 | 459 |
// check out DBConnection |
460 | 460 |
conn = DBConnectionPool.getDBConnection("PermissionControl.isAccessDoc"); |
461 | 461 |
serialNumber = conn.getCheckOutSerialNumber(); |
462 |
pStmt = conn.prepareStatement("select doctype from xml_documents where "
|
|
463 |
+ "docid like '" + docId + "'");
|
|
462 |
pStmt = conn.prepareStatement("select doctype from xml_documents where docid like ? ");
|
|
463 |
pStmt.setString(1, docId);
|
|
464 | 464 |
pStmt.execute(); |
465 | 465 |
ResultSet rs = pStmt.getResultSet(); |
466 | 466 |
boolean hasRow = rs.next(); |
src/edu/ucsb/nceas/metacat/DocumentImpl.java | ||
---|---|---|
46 | 46 |
import java.sql.Statement; |
47 | 47 |
import java.sql.Timestamp; |
48 | 48 |
import java.util.Calendar; |
49 |
import java.util.Date; |
|
49 | 50 |
import java.util.Hashtable; |
50 | 51 |
import java.util.HashMap; |
51 | 52 |
import java.util.Iterator; |
... | ... | |
165 | 166 |
protected String docname = null; |
166 | 167 |
protected String doctype = null; |
167 | 168 |
private String validateType = null; //base on dtd or schema |
168 |
private String createdate = null;
|
|
169 |
private String updatedate = null;
|
|
169 |
private Date createdate = null;
|
|
170 |
private Date updatedate = null;
|
|
170 | 171 |
private String system_id = null; |
171 | 172 |
private String userowner = null; |
172 | 173 |
private String userupdated = null; |
... | ... | |
291 | 292 |
public DocumentImpl(DBConnection conn, long rootNodeId, String docName, |
292 | 293 |
String docType, String docId, String newRevision, String action, |
293 | 294 |
String user, String pub, String catalogId, int serverCode, |
294 |
String createDate, String updateDate)
|
|
295 |
Date createDate, Date updateDate)
|
|
295 | 296 |
throws SQLException, Exception |
296 | 297 |
{ |
297 | 298 |
this.connection = conn; |
... | ... | |
434 | 435 |
*/ |
435 | 436 |
public static void registerDocumentInReplication(String docname, |
436 | 437 |
String doctype, String accnum, String user, int serverCode, |
437 |
String tableName, String createDate, String updateDate)
|
|
438 |
String tableName, Date createDate, Date updateDate)
|
|
438 | 439 |
throws SQLException, AccessionNumberException, Exception |
439 | 440 |
{ |
440 | 441 |
DBConnection conn = null; |
... | ... | |
492 | 493 |
*/ |
493 | 494 |
private static void modifyRecordsInGivenTable(String tableName, String action, |
494 | 495 |
String docid, String doctype, String docname, String user, |
495 |
String rev, int serverCode, String createDate, String updateDate,
|
|
496 |
String rev, int serverCode, Date createDate, Date updateDate,
|
|
496 | 497 |
DBConnection dbconn) throws Exception |
497 | 498 |
{ |
498 | 499 |
|
499 | 500 |
PreparedStatement pstmt = null; |
500 | 501 |
int revision = (new Integer(rev)).intValue(); |
501 | 502 |
String sqlDateString = DatabaseService.getInstance().getDBAdapter().getDateTimeFunction(); |
502 |
if (createDate == null) |
|
503 |
{ |
|
504 |
createDate = sqlDateString; |
|
503 |
Date today = new Date(Calendar.getInstance().getTimeInMillis()); |
|
504 |
|
|
505 |
if (createDate == null){ |
|
506 |
createDate = today; |
|
505 | 507 |
} |
506 |
else |
|
507 |
{ |
|
508 |
createDate = DatabaseService.getInstance().getDBAdapter().toDate(createDate, "YYYY-MM-DD HH24:MI:SS");
|
|
508 |
|
|
509 |
if (updateDate == null) {
|
|
510 |
updateDate = today;
|
|
509 | 511 |
} |
510 | 512 |
|
511 |
if (updateDate == null) |
|
512 |
{ |
|
513 |
updateDate = sqlDateString; |
|
514 |
} |
|
515 |
else |
|
516 |
{ |
|
517 |
updateDate = DatabaseService.getInstance().getDBAdapter().toDate(updateDate, "YYYY-MM-DD HH24:MI:SS"); |
|
518 |
} |
|
519 |
try |
|
520 |
{ |
|
513 |
try { |
|
521 | 514 |
|
522 | 515 |
StringBuffer sql = new StringBuffer(); |
523 | 516 |
if (action != null && action.equals("INSERT")) { |
524 | 517 |
|
525 | 518 |
sql.append("insert into "); |
526 | 519 |
sql.append(tableName); |
527 |
sql.append(" (docid, docname, " + |
|
528 |
"doctype, "); |
|
529 |
sql.append("user_owner, user_updated, server_location, " + |
|
530 |
"rev,date_created"); |
|
531 |
sql.append(", date_updated, public_access) values ('"); |
|
532 |
sql.append(docid).append("','"); |
|
533 |
sql.append(docname).append("','"); |
|
534 |
sql.append(doctype).append("','"); |
|
535 |
sql.append(user).append("','"); |
|
536 |
sql.append(user).append("','"); |
|
537 |
sql.append(serverCode).append("',"); |
|
538 |
sql.append(revision).append(","); |
|
539 |
sql.append(createDate).append(","); |
|
540 |
sql.append(updateDate).append(","); |
|
520 |
sql.append(" (docid, docname, doctype, "); |
|
521 |
sql.append("user_owner, user_updated, server_location, rev, date_created, "); |
|
522 |
sql.append("date_updated, public_access) values ("); |
|
523 |
sql.append("?, "); |
|
524 |
sql.append("?, "); |
|
525 |
sql.append("?, "); |
|
526 |
sql.append("?, "); |
|
527 |
sql.append("?, "); |
|
528 |
sql.append("?, "); |
|
529 |
sql.append("?, "); |
|
530 |
sql.append("?, "); |
|
531 |
sql.append("?, "); |
|
541 | 532 |
sql.append("'0')"); |
533 |
// set the values |
|
534 |
pstmt = dbconn.prepareStatement(sql.toString()); |
|
535 |
pstmt.setString(1, docid); |
|
536 |
pstmt.setString(2, docname); |
|
537 |
pstmt.setString(3, doctype); |
|
538 |
pstmt.setString(4, user); |
|
539 |
pstmt.setString(5, user); |
|
540 |
pstmt.setInt(6, serverCode); |
|
541 |
pstmt.setInt(7, revision); |
|
542 |
pstmt.setTimestamp(8, new Timestamp(createDate.getTime())); |
|
543 |
pstmt.setTimestamp(9, new Timestamp(updateDate.getTime())); |
|
544 |
|
|
542 | 545 |
} else if (action != null && action.equals("UPDATE")) { |
543 | 546 |
|
544 |
sql.append("update xml_documents set docname ='"); |
|
545 |
sql.append(docname).append("', "); |
|
546 |
sql.append("user_updated='"); |
|
547 |
sql.append(user).append("', "); |
|
548 |
sql.append("server_location='"); |
|
549 |
sql.append(serverCode).append("',"); |
|
550 |
sql.append("rev="); |
|
551 |
sql.append(revision).append(","); |
|
552 |
sql.append("date_updated="); |
|
553 |
sql.append(updateDate); |
|
554 |
sql.append(" where docid='"); |
|
555 |
sql.append(docid).append("'"); |
|
547 |
sql.append("update xml_documents set docname = ?,"); |
|
548 |
sql.append("user_updated = ?, "); |
|
549 |
sql.append("server_location= ?, "); |
|
550 |
sql.append("rev = ?, "); |
|
551 |
sql.append("date_updated = ?"); |
|
552 |
sql.append(" where docid = ? "); |
|
553 |
// set the values |
|
554 |
pstmt = dbconn.prepareStatement(sql.toString()); |
|
555 |
pstmt.setString(1, docname); |
|
556 |
pstmt.setString(2, user); |
|
557 |
pstmt.setInt(3, serverCode); |
|
558 |
pstmt.setInt(4, revision); |
|
559 |
pstmt.setTimestamp(5, new Timestamp(updateDate.getTime())); |
|
560 |
pstmt.setString(6, docid); |
|
556 | 561 |
} |
557 |
pstmt = dbconn.prepareStatement(sql.toString()); |
|
558 | 562 |
logMetacat.debug("DocumentImpl.modifyRecordsInGivenTable - executing SQL: " + pstmt.toString()); |
559 | 563 |
pstmt.execute(); |
560 | 564 |
pstmt.close(); |
... | ... | |
599 | 603 |
public static void writeDataFileInReplication(InputStream input, |
600 | 604 |
String filePath, String docname, String doctype, String accnum, |
601 | 605 |
String user, String docHomeServer, String notificationServer, |
602 |
String tableName, boolean timedReplication, String createDate, String updateDate)
|
|
606 |
String tableName, boolean timedReplication, Date createDate, Date updateDate)
|
|
603 | 607 |
throws SQLException, AccessionNumberException, Exception |
604 | 608 |
{ |
605 | 609 |
int serverCode = -2; |
... | ... | |
880 | 884 |
/** |
881 | 885 |
* get the creation date |
882 | 886 |
*/ |
883 |
public String getCreateDate()
|
|
887 |
public Date getCreateDate()
|
|
884 | 888 |
{ |
885 | 889 |
return createdate; |
886 | 890 |
} |
... | ... | |
888 | 892 |
/** |
889 | 893 |
* get the update date |
890 | 894 |
*/ |
891 |
public String getUpdateDate()
|
|
895 |
public Date getUpdateDate()
|
|
892 | 896 |
{ |
893 | 897 |
return updatedate; |
894 | 898 |
} |
... | ... | |
2029 | 2033 |
.getDBConnection("DocumentImpl.isRevisionOnly"); |
2030 | 2034 |
serialNumber = dbconn.getCheckOutSerialNumber(); |
2031 | 2035 |
pstmt = dbconn.prepareStatement("select rev from xml_documents " |
2032 |
+ "where docid like '" + newid + "'"); |
|
2036 |
+ "where docid like ?"); |
|
2037 |
pstmt.setString(1, newid); |
|
2033 | 2038 |
logMetacat.debug("DocumentImpl.isRevisionOnly - executing SQL: " + pstmt.toString()); |
2034 | 2039 |
pstmt.execute(); |
2035 | 2040 |
ResultSet rs = pstmt.getResultSet(); |
... | ... | |
2135 | 2140 |
sql.append("date_created, date_updated, user_owner, user_updated,"); |
2136 | 2141 |
sql.append(" server_location, public_access, rev"); |
2137 | 2142 |
sql.append(" FROM ").append(table); |
2138 |
sql.append(" WHERE docid LIKE '").append(docid);
|
|
2139 |
sql.append("' and rev = ").append(revision);
|
|
2143 |
sql.append(" WHERE docid LIKE ? ");
|
|
2144 |
sql.append(" and rev = ? ");
|
|
2140 | 2145 |
|
2141 | 2146 |
pstmt = dbconn.prepareStatement(sql.toString()); |
2147 |
pstmt.setString(1, docid); |
|
2148 |
pstmt.setInt(2, revision); |
|
2142 | 2149 |
|
2143 | 2150 |
logMetacat.debug("DocumentImpl.getDocumentInfo - executing SQL: " + pstmt.toString()); |
2144 | 2151 |
pstmt.execute(); |
... | ... | |
2148 | 2155 |
this.docname = rs.getString(1); |
2149 | 2156 |
this.doctype = rs.getString(2); |
2150 | 2157 |
this.rootnodeid = rs.getLong(3); |
2151 |
this.createdate = rs.getString(4);
|
|
2152 |
this.updatedate = rs.getString(5);
|
|
2158 |
this.createdate = rs.getTimestamp(4);
|
|
2159 |
this.updatedate = rs.getTimestamp(5);
|
|
2153 | 2160 |
this.userowner = rs.getString(6); |
2154 | 2161 |
this.userupdated = rs.getString(7); |
2155 | 2162 |
this.serverlocation = rs.getInt(8); |
... | ... | |
2335 | 2342 |
|
2336 | 2343 |
/** creates SQL code and inserts new document into DB connection */ |
2337 | 2344 |
private void writeDocumentToDB(String action, String user, String pub, |
2338 |
String catalogid, int serverCode, String createDate, String updateDate) throws SQLException, Exception
|
|
2345 |
String catalogid, int serverCode, Date createDate, Date updateDate) throws SQLException, Exception
|
|
2339 | 2346 |
{ |
2340 | 2347 |
//System.out.println("!!!!!!!!1write document to db " +docid +"."+rev); |
2341 | 2348 |
String sysdate = DatabaseService.getInstance().getDBAdapter().getDateTimeFunction(); |
2342 |
if (createDate == null)
|
|
2343 |
{ |
|
2344 |
createDate = sysdate;
|
|
2349 |
Date today = Calendar.getInstance().getTime();
|
|
2350 |
if (createDate == null) {
|
|
2351 |
createDate = today;
|
|
2345 | 2352 |
} |
2346 |
else |
|
2347 |
{ |
|
2348 |
createDate = DatabaseService.getInstance().getDBAdapter().toDate(createDate, "YYYY-MM-DD HH24:MI:SS"); |
|
2353 |
if (updateDate == null) { |
|
2354 |
updateDate = today; |
|
2349 | 2355 |
} |
2350 |
if (updateDate == null) |
|
2351 |
{ |
|
2352 |
updateDate = sysdate; |
|
2353 |
} |
|
2354 |
else |
|
2355 |
{ |
|
2356 |
updateDate = DatabaseService.getInstance().getDBAdapter().toDate(updateDate, "YYYY-MM-DD HH24:MI:SS"); |
|
2357 |
} |
|
2358 | 2356 |
DocumentImpl thisdoc = null; |
2359 | 2357 |
|
2360 | 2358 |
try { |
... | ... | |
2370 | 2368 |
+ "(docid, rootnodeid, docname, doctype, user_owner, " |
2371 | 2369 |
+ "user_updated, date_created, date_updated, " |
2372 | 2370 |
+ "public_access, server_location, rev, catalog_id) " |
2373 |
+ "VALUES (?, ?, ?, ?, ?, ?, " + createDate + ", "
|
|
2374 |
+ updateDate + ", ?, ?, ?, ?)";
|
|
2371 |
+ "VALUES (?, ?, ?, ?, ?, ?, ?, "
|
|
2372 |
+ "?, ?, ?, ?, ?)";
|
|
2375 | 2373 |
} |
2376 | 2374 |
else |
2377 | 2375 |
{ |
... | ... | |
2379 | 2377 |
+ "(docid, rootnodeid, docname, doctype, user_owner, " |
2380 | 2378 |
+ "user_updated, date_created, date_updated, " |
2381 | 2379 |
+ "public_access, server_location, rev) " |
2382 |
+ "VALUES (?, ?, ?, ?, ?, ?, " + createDate + ", "
|
|
2383 |
+ updateDate + ", ?, ?, ?)";
|
|
2380 |
+ "VALUES (?, ?, ?, ?, ?, ?, ?, "
|
|
2381 |
+ "?, ?, ?, ?)";
|
|
2384 | 2382 |
} |
2385 | 2383 |
/*pstmt = connection |
2386 | 2384 |
.prepareStatement("INSERT INTO xml_documents " |
... | ... | |
2404 | 2402 |
pstmt.setString(4, doctype); |
2405 | 2403 |
pstmt.setString(5, user); |
2406 | 2404 |
pstmt.setString(6, user); |
2405 |
// dates |
|
2406 |
pstmt.setTimestamp(7, new Timestamp(createDate.getTime())); |
|
2407 |
pstmt.setTimestamp(8, new Timestamp(updateDate.getTime())); |
|
2407 | 2408 |
//public access is usefulless, so set it to null |
2408 |
pstmt.setInt(7, 0);
|
|
2409 |
pstmt.setInt(9, 0);
|
|
2409 | 2410 |
/* |
2410 | 2411 |
* if ( pub == null ) { pstmt.setString(7, null); } else if ( |
2411 | 2412 |
* pub.toUpperCase().equals("YES") || pub.equals("1") ) { |
... | ... | |
2413 | 2414 |
* pub.toUpperCase().equals("NO") || pub.equals("0") ) { |
2414 | 2415 |
* pstmt.setInt(7, 0); } |
2415 | 2416 |
*/ |
2416 |
pstmt.setInt(8, serverCode);
|
|
2417 |
pstmt.setInt(9, rev);
|
|
2417 |
pstmt.setInt(10, serverCode);
|
|
2418 |
pstmt.setInt(11, rev);
|
|
2418 | 2419 |
|
2419 | 2420 |
if (catalogid != null) |
2420 | 2421 |
{ |
2421 |
pstmt.setInt(10, (new Integer(catalogid)).intValue());
|
|
2422 |
pstmt.setInt(12, (new Integer(catalogid)).intValue());
|
|
2422 | 2423 |
} |
2423 | 2424 |
|
2424 | 2425 |
|
... | ... | |
2466 | 2467 |
{ |
2467 | 2468 |
updateSql = "UPDATE xml_documents " |
2468 | 2469 |
+ "SET rootnodeid = ?, docname = ?, doctype = ?, " |
2469 |
+ "user_updated = ?, date_updated = " |
|
2470 |
+ updateDate |
|
2471 |
+ ", " |
|
2470 |
+ "user_updated = ?, date_updated = ?, " |
|
2472 | 2471 |
+ "server_location = ?, rev = ?, public_access = ?, " |
2473 | 2472 |
+ "catalog_id = ? " |
2474 | 2473 |
+ "WHERE docid = ?"; |
... | ... | |
2477 | 2476 |
{ |
2478 | 2477 |
updateSql = "UPDATE xml_documents " |
2479 | 2478 |
+ "SET rootnodeid = ?, docname = ?, doctype = ?, " |
2480 |
+ "user_updated = ?, date_updated = " |
|
2481 |
+ updateDate |
|
2482 |
+ ", " |
|
2479 |
+ "user_updated = ?, date_updated = ?, " |
|
2483 | 2480 |
+ "server_location = ?, rev = ?, public_access = ? " |
2484 | 2481 |
+ "WHERE docid = ?"; |
2485 | 2482 |
} |
2486 |
/*pstmt = connection |
|
2487 |
.prepareStatement("UPDATE xml_documents " |
|
2488 |
+ "SET rootnodeid = ?, docname = ?, doctype = ?, " |
|
2489 |
+ "user_updated = ?, date_updated = " |
|
2490 |
+ updateDate |
|
2491 |
+ ", " |
|
2492 |
+ "server_location = ?, rev = ?, public_access = ?, " |
|
2493 |
+ "catalog_id = ? " |
|
2494 |
+ "WHERE docid = ?");*/ |
|
2495 | 2483 |
// Increase dbconnection usage count |
2496 | 2484 |
pstmt = connection.prepareStatement(updateSql); |
2497 | 2485 |
connection.increaseUsageCount(1); |
... | ... | |
2500 | 2488 |
pstmt.setString(2, docname); |
2501 | 2489 |
pstmt.setString(3, doctype); |
2502 | 2490 |
pstmt.setString(4, user); |
2503 |
pstmt.setInt(5, serverCode); |
|
2504 |
pstmt.setInt(6, thisrev); |
|
2505 |
pstmt.setInt(7, 0); |
|
2491 |
pstmt.setTimestamp(5, new Timestamp(updateDate.getTime())); |
|
2492 |
pstmt.setInt(6, serverCode); |
|
2493 |
pstmt.setInt(7, thisrev); |
|
2494 |
pstmt.setInt(8, 0); |
|
2506 | 2495 |
/* |
2507 | 2496 |
* if ( pub == null ) { pstmt.setString(7, null); } else if ( |
2508 | 2497 |
* pub.toUpperCase().equals("YES") || pub.equals("1") ) { pstmt |
... | ... | |
2511 | 2500 |
*/ |
2512 | 2501 |
if (catalogid != null) |
2513 | 2502 |
{ |
2514 |
pstmt.setInt(8, (new Integer(catalogid)).intValue());
|
|
2515 |
pstmt.setString(9, this.docid);
|
|
2503 |
pstmt.setInt(9, (new Integer(catalogid)).intValue());
|
|
2504 |
pstmt.setString(10, this.docid);
|
|
2516 | 2505 |
} |
2517 | 2506 |
else |
2518 | 2507 |
{ |
2519 |
pstmt.setString(8, this.docid);
|
|
2508 |
pstmt.setString(9, this.docid);
|
|
2520 | 2509 |
} |
2521 | 2510 |
|
2522 | 2511 |
} else { |
... | ... | |
2907 | 2896 |
String pub, Reader dtd, String action, String accnum, String user, |
2908 | 2897 |
String[] groups, String homeServer, String notifyServer, |
2909 | 2898 |
String ruleBase, boolean needValidation, String tableName, |
2910 |
boolean timedReplication, String createDate, String updateDate) throws Exception
|
|
2899 |
boolean timedReplication, Date createDate, Date updateDate) throws Exception
|
|
2911 | 2900 |
{ |
2912 | 2901 |
// Get the xml as a string so we can write to file later |
2913 | 2902 |
StringReader xmlReader = new StringReader(xmlString); |
... | ... | |
3495 | 3484 |
String action, String docid, Reader xml, String rev, String user, |
3496 | 3485 |
String[] groups, String pub, int serverCode, Reader dtd, |
3497 | 3486 |
String ruleBase, boolean needValidation, boolean isRevision, |
3498 |
String createDate, String updateDate, String encoding) throws Exception
|
|
3487 |
Date createDate, Date updateDate, String encoding) throws Exception
|
|
3499 | 3488 |
{ |
3500 | 3489 |
XMLReader parser = null; |
3501 | 3490 |
try { |
... | ... | |
3880 | 3869 |
serialNumber = conn.getCheckOutSerialNumber(); |
3881 | 3870 |
//delete a record |
3882 | 3871 |
pStmt = conn.prepareStatement( |
3883 |
"DELETE FROM xml_documents WHERE docid = '" + docId + "'"); |
|
3872 |
"DELETE FROM xml_documents WHERE docid = ? "); |
|
3873 |
pStmt.setString(1, docId); |
|
3884 | 3874 |
logMetacat.debug("DocumentImpl.deleteXMLDocuments - executing SQL: " + pStmt.toString()); |
3885 | 3875 |
pStmt.execute(); |
3886 | 3876 |
} finally { |
... | ... | |
3921 | 3911 |
serialNumber = conn.getCheckOutSerialNumber(); |
3922 | 3912 |
|
3923 | 3913 |
pStmt = conn |
3924 |
.prepareStatement("SELECT server_location FROM xml_documents WHERE docid='"
|
|
3925 |
+ docId + "'");
|
|
3914 |
.prepareStatement("SELECT server_location FROM xml_documents WHERE docid = ?");
|
|
3915 |
pStmt.setString(1, docId);
|
|
3926 | 3916 |
pStmt.execute(); |
3927 | 3917 |
|
3928 | 3918 |
ResultSet rs = pStmt.getResultSet(); |
... | ... | |
3982 | 3972 |
.getDBConnection("DocumentImpl.getServerCode"); |
3983 | 3973 |
serialNumber = dbConn.getCheckOutSerialNumber(); |
3984 | 3974 |
pStmt = dbConn |
3985 |
.prepareStatement("SELECT serverid FROM xml_replication WHERE server='"
|
|
3986 |
+ serverName + "'");
|
|
3975 |
.prepareStatement("SELECT serverid FROM xml_replication WHERE server = ?");
|
|
3976 |
pStmt.setString(1, serverName);
|
|
3987 | 3977 |
pStmt.execute(); |
3988 | 3978 |
|
3989 | 3979 |
ResultSet rs = pStmt.getResultSet(); |
... | ... | |
4040 | 4030 |
|
4041 | 4031 |
// Compare the server to dabase |
4042 | 4032 |
pStmt = dbConn |
4043 |
.prepareStatement("SELECT serverid FROM xml_replication WHERE server='"
|
|
4044 |
+ server + "'");
|
|
4033 |
.prepareStatement("SELECT serverid FROM xml_replication WHERE server = ?");
|
|
4034 |
pStmt.setString(1, server);
|
|
4045 | 4035 |
pStmt.execute(); |
4046 | 4036 |
ResultSet rs = pStmt.getResultSet(); |
4047 | 4037 |
boolean hasRow = rs.next(); |
... | ... | |
4063 | 4053 |
* 'MM/DD/YY'), '" + replicate +"', '"+dataReplicate+"','"+ hub + |
4064 | 4054 |
* "')"); |
4065 | 4055 |
*/ |
4056 |
|
|
4057 |
Calendar cal = Calendar.getInstance(); |
|
4058 |
cal.set(1980, 1, 1); |
|
4066 | 4059 |
pStmt = dbConn |
4067 | 4060 |
.prepareStatement("INSERT INTO xml_replication " |
4068 | 4061 |
+ "(server, last_checked, replicate, datareplicate, hub) " |
4069 |
+ "VALUES ('" + server + "', " |
|
4070 |
+ DatabaseService.getInstance().getDBAdapter().toDate("01/01/1980", "MM/DD/YYYY") |
|
4071 |
+ ", '" + replicate + "', '" + dataReplicate |
|
4072 |
+ "','" + hub + "')"); |
|
4062 |
+ "VALUES (?, ?, ?, ?, ?)"); |
|
4063 |
pStmt.setString(1, server); |
|
4064 |
pStmt.setTimestamp(2, new Timestamp(cal.getTimeInMillis()) ); |
|
4065 |
pStmt.setInt(3, replicate); |
|
4066 |
pStmt.setInt(4, dataReplicate); |
|
4067 |
pStmt.setInt(5, hub); |
|
4073 | 4068 |
|
4074 | 4069 |
logMetacat.debug("DocumentImpl.insertServerIntoReplicationTable - executing SQL: " + pStmt.toString()); |
4075 | 4070 |
pStmt.execute(); |
... | ... | |
4255 | 4250 |
*/ |
4256 | 4251 |
private static void writeDocumentToRevisionTable(DBConnection con, String docId, |
4257 | 4252 |
String rev, String docType, String docName, String user, |
4258 |
String catalogid, int serverCode, long rootNodeId, String createDate, String updateDate) throws SQLException, Exception
|
|
4253 |
String catalogid, int serverCode, long rootNodeId, Date createDate, Date updateDate) throws SQLException, Exception
|
|
4259 | 4254 |
{ |
4260 | 4255 |
|
4261 | 4256 |
try |
4262 | 4257 |
{ |
4258 |
Date today = Calendar.getInstance().getTime(); |
|
4259 |
if (createDate == null){ |
|
4260 |
createDate = today; |
|
4261 |
} |
|
4263 | 4262 |
|
4264 |
if (createDate == null) |
|
4265 |
{ |
|
4266 |
createDate = DatabaseService.getInstance().getDBAdapter().getDateTimeFunction(); |
|
4267 |
} |
|
4268 |
else |
|
4269 |
{ |
|
4270 |
createDate = DatabaseService.getInstance().getDBAdapter().toDate(createDate, "YYYY-MM-DD HH24:MI:SS"); |
|
4271 |
} |
|
4272 | 4263 |
logMetacat.debug("DocumentImpl.writeDocumentToRevisionTable - the create date is "+createDate); |
4273 |
if (updateDate == null) |
|
4274 |
{ |
|
4275 |
updateDate = DatabaseService.getInstance().getDBAdapter().getDateTimeFunction(); |
|
4264 |
if (updateDate == null){ |
|
4265 |
updateDate = today; |
|
4276 | 4266 |
} |
4277 |
else |
|
4278 |
{ |
|
4279 |
updateDate = DatabaseService.getInstance().getDBAdapter().toDate(updateDate, "YYYY-MM-DD HH24:MI:SS"); |
|
4280 |
} |
|
4281 | 4267 |
logMetacat.debug("DocumentImpl.writeDocumentToRevisionTable - the update date is "+updateDate); |
4282 | 4268 |
PreparedStatement pstmt = null; |
4283 | 4269 |
String sql = null; |
... | ... | |
4289 | 4275 |
+ "(docid, docname, doctype, user_owner, " |
4290 | 4276 |
+ "user_updated, date_created, date_updated, " |
4291 | 4277 |
+ "public_access, server_location, rev) " |
4292 |
+ "VALUES (?, ?, ?, ?, ?, " + createDate + ", "
|
|
4293 |
+ updateDate + ", ?, ?, ?)";
|
|
4278 |
+ "VALUES (?, ?, ?, ?, ?, ?,"
|
|
4279 |
+ " ?, ?, ?, ?)";
|
|
4294 | 4280 |
} |
4295 | 4281 |
else |
4296 | 4282 |
{ |
... | ... | |
4300 | 4286 |
+ "(docid, docname, doctype, user_owner, " |
4301 | 4287 |
+ "user_updated, date_created, date_updated, " |
4302 | 4288 |
+ "public_access, server_location, rev, catalog_id, rootnodeid ) " |
4303 |
+ "VALUES (?, ?, ?, ?, ?, " + createDate + ", "
|
|
4304 |
+ updateDate + ", ?, ?, ?, ?, ?)";
|
|
4289 |
+ "VALUES (?, ?, ?, ?, ?, ?, "
|
|
4290 |
+ "?, ?, ?, ?, ?)";
|
|
4305 | 4291 |
} |
4306 | 4292 |
else |
4307 | 4293 |
{ |
... | ... | |
4309 | 4295 |
+ "(docid, docname, doctype, user_owner, " |
4310 | 4296 |
+ "user_updated, date_created, date_updated, " |
4311 | 4297 |
+ "public_access, server_location, rev, rootnodeid ) " |
4312 |
+ "VALUES (?, ?, ?, ?, ?, " + createDate + ", "
|
|
4313 |
+ updateDate + ", ?, ?, ?, ?)";
|
|
4298 |
+ "VALUES (?, ?, ?, ?, ?, ?, "
|
|
4299 |
+ "?, ?, ?, ?, ?)";
|
|
4314 | 4300 |
} |
4315 | 4301 |
} |
4316 | 4302 |
pstmt = con.prepareStatement(sql); |
... | ... | |
4328 | 4314 |
logMetacat.debug("DocumentImpl.writeDocumentToRevisionTable - onwer is "+user); |
4329 | 4315 |
pstmt.setString(5, user); |
4330 | 4316 |
logMetacat.debug("DocumentImpl.writeDocumentToRevisionTable - update user is "+user); |
4331 |
pstmt.setInt(6, 0); |
|
4317 |
pstmt.setTimestamp(6, new Timestamp(createDate.getTime())); |
|
4318 |
pstmt.setTimestamp(7, new Timestamp(updateDate.getTime())); |
|
4332 | 4319 |
|
4333 |
pstmt.setInt(7, serverCode); |
|
4320 |
pstmt.setInt(8, 0); |
|
4321 |
|
|
4322 |
pstmt.setInt(9, serverCode); |
|
4334 | 4323 |
logMetacat.debug("DocumentImpl.writeDocumentToRevisionTable - server code is "+serverCode); |
4335 |
pstmt.setInt(8, Integer.parseInt(rev));
|
|
4324 |
pstmt.setInt(10, Integer.parseInt(rev));
|
|
4336 | 4325 |
logMetacat.debug("DocumentImpl.writeDocumentToRevisionTable - rev is "+rev); |
4337 | 4326 |
|
4338 |
if (rootNodeId >0 ) |
|
4327 |
if (rootNodeId > 0 )
|
|
4339 | 4328 |
{ |
4340 | 4329 |
if (catalogid != null) |
4341 | 4330 |
{ |
4342 |
pstmt.setInt(9, (new Integer(catalogid)).intValue());
|
|
4331 |
pstmt.setInt(11, (new Integer(catalogid)).intValue());
|
|
4343 | 4332 |
logMetacat.debug("DocumentImpl.writeDocumentToRevisionTable - catalog id is "+catalogid); |
4344 |
pstmt.setLong(10, rootNodeId);
|
|
4333 |
pstmt.setLong(12, rootNodeId);
|
|
4345 | 4334 |
logMetacat.debug("DocumentImpl.writeDocumentToRevisionTable - root id is "+rootNodeId); |
4346 | 4335 |
} |
4347 | 4336 |
else |
4348 | 4337 |
{ |
4349 |
pstmt.setLong(9, rootNodeId);
|
|
4338 |
pstmt.setLong(11, rootNodeId);
|
|
4350 | 4339 |
logMetacat.debug("DocumentImpl.writeDocumentToRevisionTable - root id is "+rootNodeId); |
4351 | 4340 |
} |
4352 | 4341 |
} |
... | ... | |
4379 | 4368 |
*/ |
4380 | 4369 |
static private void registerDeletedDataFile(String docname, |
4381 | 4370 |
String doctype, String accnum, String user, int serverCode, |
4382 |
String createDate, String updateDate) throws Exception
|
|
4371 |
Date createDate, Date updateDate) throws Exception
|
|
4383 | 4372 |
{ |
4384 | 4373 |
DBConnection dbconn = null; |
4385 | 4374 |
int serialNumber = -1; |
... | ... | |
4421 | 4410 |
logMetacat.debug("DocumentImpl.deleteXMLNodes - for root Id: " + rootId); |
4422 | 4411 |
PreparedStatement pstmt = null; |
4423 | 4412 |
double start = System.currentTimeMillis()/1000; |
4424 |
String sql = "DELETE FROM xml_nodes WHERE rootnodeid ="+ rootId;
|
|
4413 |
String sql = "DELETE FROM xml_nodes WHERE rootnodeid = ? ";
|
|
4425 | 4414 |
pstmt = dbconn.prepareStatement(sql); |
4415 |
pstmt.setLong(1, rootId); |
|
4426 | 4416 |
// Increase dbconnection usage count |
4427 | 4417 |
dbconn.increaseUsageCount(1); |
4428 | 4418 |
logMetacat.debug("DocumentImpl.deleteXMLNodes - executing SQL: " + pstmt.toString()); |
src/edu/ucsb/nceas/metacat/DocumentImplWrapper.java | ||
---|---|---|
28 | 28 |
package edu.ucsb.nceas.metacat; |
29 | 29 |
|
30 | 30 |
import java.io.Reader; |
31 |
import java.util.Date; |
|
31 | 32 |
|
32 | 33 |
import edu.ucsb.nceas.metacat.database.DBConnection; |
33 | 34 |
|
... | ... | |
63 | 64 |
|
64 | 65 |
public String writeReplication(DBConnection conn, String xml, String pub, Reader dtd, |
65 | 66 |
String action, String accnum, String user, String[] groups, |
66 |
String homeServer, String notifyServer, String createDate, String updateDate)
|
|
67 |
String homeServer, String notifyServer, Date createDate, Date updateDate)
|
|
67 | 68 |
throws Exception { |
68 | 69 |
//we don't need to check validation in replication |
69 | 70 |
// so rule base is null and need validation is false (first false) |
... | ... | |
96 | 97 |
public String writeReplication(DBConnection conn, String xml, String pub, Reader dtd, |
97 | 98 |
String action, String accnum, String user, String[] groups, |
98 | 99 |
String homeServer, String notifyServer, String tableName, |
99 |
boolean timedReplication, String createDate, String updateDate)
|
|
100 |
boolean timedReplication, Date createDate, Date updateDate)
|
|
100 | 101 |
throws Exception { |
101 | 102 |
//we don't need to check validation in replication |
102 | 103 |
// so rule base is null and need validation is false |
src/edu/ucsb/nceas/metacat/RelationHandler.java | ||
---|---|---|
163 | 163 |
try { |
164 | 164 |
PreparedStatement pstmt = connection.prepareStatement( |
165 | 165 |
"DELETE FROM xml_relation " + |
166 |
"WHERE docid = '" + docid + "'"); |
|
166 |
"WHERE docid = ?"); |
|
167 |
pstmt.setString(1, docid); |
|
167 | 168 |
//increase usage count |
168 | 169 |
connection.increaseUsageCount(1); |
169 | 170 |
pstmt.execute(); |
... | ... | |
191 | 192 |
StringBuffer sql = new StringBuffer(); |
192 | 193 |
sql |
193 | 194 |
.append("SELECT docid, rev FROM xml_documents WHERE docid in (SELECT subject "); |
194 |
sql.append("FROM xml_relation WHERE docid='").append(docid);
|
|
195 |
sql.append("' AND (");
|
|
195 |
sql.append("FROM xml_relation WHERE docid = ? ");
|
|
196 |
sql.append(" AND ("); |
|
196 | 197 |
Vector accessdoctypes; |
197 | 198 |
try { |
198 | 199 |
accessdoctypes = MetacatUtil.getOptionList(PropertyService |
... | ... | |
214 | 215 |
dbConn = DBConnectionPool.getDBConnection("RelationHandler.getAccessFileID"); |
215 | 216 |
serialNumber = dbConn.getCheckOutSerialNumber(); |
216 | 217 |
pstmt = dbConn.prepareStatement(sql.toString()); |
218 |
pstmt.setString(1, docid); |
|
217 | 219 |
pstmt.execute(); |
218 | 220 |
ResultSet rs = pstmt.getResultSet(); |
219 | 221 |
boolean hasRow = rs.next(); |
src/edu/ucsb/nceas/metacat/AccessionNumber.java | ||
---|---|---|
265 | 265 |
conn=DBConnectionPool.getDBConnection("AccessionNumber.getLastRevision"); |
266 | 266 |
serialNumber=conn.getCheckOutSerialNumber(); |
267 | 267 |
pstmt = conn.prepareStatement |
268 |
("SELECT rev FROM xml_documents WHERE docid='" + docid + "'"); |
|
268 |
("SELECT rev FROM xml_documents WHERE docid = ?"); |
|
269 |
pstmt.setString(1, docid); |
|
269 | 270 |
pstmt.execute(); |
270 | 271 |
|
271 | 272 |
ResultSet rs = pstmt.getResultSet(); |
... | ... | |
303 | 304 |
serialNumber=conn.getCheckOutSerialNumber(); |
304 | 305 |
|
305 | 306 |
pStmt = conn.prepareStatement |
306 |
("SELECT rev FROM xml_documents WHERE docid='" + docId + "'"); |
|
307 |
("SELECT rev FROM xml_documents WHERE docid = ? "); |
|
308 |
pStmt.setString(1, docId); |
|
307 | 309 |
pStmt.execute(); |
308 | 310 |
|
309 | 311 |
ResultSet rs = pStmt.getResultSet(); |
src/edu/ucsb/nceas/metacat/DBUtil.java | ||
---|---|---|
867 | 867 |
serialNumber = dbConn.getCheckOutSerialNumber(); |
868 | 868 |
|
869 | 869 |
pStmt = dbConn |
870 |
.prepareStatement("SELECT rev FROM xml_revisions WHERE docid='"
|
|
871 |
+ docIdWithoutRev + "'");
|
|
870 |
.prepareStatement("SELECT rev FROM xml_revisions WHERE docid = ?");
|
|
871 |
pStmt.setString(1, docIdWithoutRev);
|
|
872 | 872 |
pStmt.execute(); |
873 | 873 |
|
874 | 874 |
ResultSet rs = pStmt.getResultSet(); |
... | ... | |
918 | 918 |
serialNumber = dbConn.getCheckOutSerialNumber(); |
919 | 919 |
|
920 | 920 |
pStmt = dbConn |
921 |
.prepareStatement("SELECT rev FROM xml_documents WHERE docid='"
|
|
922 |
+ docIdWithoutRev + "'");
|
|
921 |
.prepareStatement("SELECT rev FROM xml_documents WHERE docid = ?");
|
|
922 |
pStmt.setString(1, docIdWithoutRev);
|
|
923 | 923 |
pStmt.execute(); |
924 | 924 |
|
925 | 925 |
ResultSet rs = pStmt.getResultSet(); |
src/edu/ucsb/nceas/metacat/DBSAXHandler.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
import java.sql.ResultSet; |
31 | 31 |
import java.sql.Statement; |
32 |
import java.util.Date; |
|
32 | 33 |
import java.util.EmptyStackException; |
33 | 34 |
import java.util.Enumeration; |
34 | 35 |
import java.util.Hashtable; |
... | ... | |
83 | 84 |
|
84 | 85 |
protected DocumentImpl currentDocument; |
85 | 86 |
|
86 |
protected String createDate = null;
|
|
87 |
protected Date createDate = null;
|
|
87 | 88 |
|
88 |
protected String updateDate = null;
|
|
89 |
protected Date updateDate = null;
|
|
89 | 90 |
|
90 | 91 |
protected DBSAXNode rootNode; |
91 | 92 |
|
... | ... | |
149 | 150 |
* |
150 | 151 |
* @param conn the JDBC connection to which information is written |
151 | 152 |
*/ |
152 |
private DBSAXHandler(DBConnection conn, String createDate, String updateDate)
|
|
153 |
private DBSAXHandler(DBConnection conn, Date createDate, Date updateDate)
|
|
153 | 154 |
{ |
154 | 155 |
this.connection = conn; |
155 | 156 |
this.atFirstElement = true; |
... | ... | |
210 | 211 |
*/ |
211 | 212 |
public DBSAXHandler(DBConnection conn, String action, String docid, |
212 | 213 |
String revision, String user, String[] groups, String pub, |
213 |
int serverCode, String createDate, String updateDate)
|
|
214 |
int serverCode, Date createDate, Date updateDate)
|
|
214 | 215 |
{ |
215 | 216 |
this(conn, createDate, updateDate); |
216 | 217 |
this.action = action; |
src/edu/ucsb/nceas/metacat/Sitemap.java | ||
---|---|---|
122 | 122 |
serialNumber = dbConn.getCheckOutSerialNumber(); |
123 | 123 |
|
124 | 124 |
// Execute the query statement |
125 |
PreparedStatement stmt = dbConn.prepareStatement(query |
|
126 |
.toString()); |
|
125 |
PreparedStatement stmt = dbConn.prepareStatement(query.toString()); |
|
127 | 126 |
stmt.execute(); |
128 | 127 |
ResultSet rs = stmt.getResultSet(); |
129 | 128 |
|
src/edu/ucsb/nceas/metacat/Eml200SAXHandler.java | ||
---|---|---|
42 | 42 |
import java.sql.ResultSet; |
43 | 43 |
import java.sql.SQLException; |
44 | 44 |
import java.sql.Statement; |
45 |
import java.util.Date; |
|
45 | 46 |
import java.util.EmptyStackException; |
46 | 47 |
import java.util.Enumeration; |
47 | 48 |
import java.util.Hashtable; |
... | ... | |
330 | 331 |
*/ |
331 | 332 |
public Eml200SAXHandler(DBConnection conn, String action, String docid, |
332 | 333 |
String revision, String user, String[] groups, String pub, |
333 |
int serverCode, String createDate, String updateDate) throws SAXException
|
|
334 |
int serverCode, Date createDate, Date updateDate) throws SAXException
|
|
334 | 335 |
{ |
335 | 336 |
super(conn, action, docid, revision, user, groups, pub, |
336 | 337 |
serverCode, createDate, updateDate); |
src/edu/ucsb/nceas/metacat/Eml210SAXHandler.java | ||
---|---|---|
36 | 36 |
import java.sql.ResultSet; |
37 | 37 |
import java.sql.SQLException; |
38 | 38 |
import java.sql.Statement; |
39 |
import java.util.Date; |
|
39 | 40 |
import java.util.EmptyStackException; |
40 | 41 |
import java.util.Enumeration; |
41 | 42 |
import java.util.Hashtable; |
... | ... | |
190 | 191 |
*/ |
191 | 192 |
public Eml210SAXHandler(DBConnection conn, String action, String docid, |
192 | 193 |
String revision, String user, String[] groups, String pub, int serverCode, |
193 |
String createDate, String updateDate) throws SAXException {
|
|
194 |
Date createDate, Date updateDate) throws SAXException {
|
|
194 | 195 |
super(conn, action, docid, revision, user, groups, pub, serverCode, createDate, |
195 | 196 |
updateDate); |
196 | 197 |
// Get the unchangeable subtrees (user doesn't have write permission) |
src/edu/ucsb/nceas/metacat/IdentifierManager.java | ||
---|---|---|
486 | 486 |
Hashtable<String, Object> h = new Hashtable<String, Object>(); |
487 | 487 |
String sql = "select docname, doctype, user_owner, user_updated, " + |
488 | 488 |
"server_location, rev, date_created, date_updated from " + |
489 |
"xml_documents where docid like '" + localId + "'";
|
|
489 |
"xml_documents where docid like ?";
|
|
490 | 490 |
DBConnection dbConn = null; |
491 | 491 |
int serialNumber = -1; |
492 | 492 |
try |
... | ... | |
497 | 497 |
|
498 | 498 |
// Execute the insert statement |
499 | 499 |
PreparedStatement stmt = dbConn.prepareStatement(sql); |
500 |
stmt.setString(1, localId); |
|
500 | 501 |
ResultSet rs = stmt.executeQuery(); |
501 | 502 |
if (rs.next()) |
502 | 503 |
{ |
... | ... | |
581 | 582 |
//do nothing. just try the localId as it is |
582 | 583 |
} |
583 | 584 |
int rev = 0; |
584 |
String sql = "select rev from xml_documents where docid like '" + localId + "'";
|
|
585 |
String sql = "select rev from xml_documents where docid like ? ";
|
|
585 | 586 |
DBConnection dbConn = null; |
586 | 587 |
int serialNumber = -1; |
587 | 588 |
try |
... | ... | |
592 | 593 |
|
593 | 594 |
// Execute the insert statement |
594 | 595 |
PreparedStatement stmt = dbConn.prepareStatement(sql); |
596 |
stmt.setString(1, localId); |
|
595 | 597 |
ResultSet rs = stmt.executeQuery(); |
596 | 598 |
if (rs.next()) |
597 | 599 |
{ |
... | ... | |
1042 | 1044 |
serialNumber = dbConn.getCheckOutSerialNumber(); |
1043 | 1045 |
|
1044 | 1046 |
// Execute the update statement |
1045 |
String query = "update " + TYPE_IDENTIFIER + " set (docid, rev) = (?, ?) where guid='" + guid + "'";
|
|
1047 |
String query = "update " + TYPE_IDENTIFIER + " set (docid, rev) = (?, ?) where guid = ?";
|
|
1046 | 1048 |
PreparedStatement stmt = dbConn.prepareStatement(query); |
1047 | 1049 |
stmt.setString(1, docid); |
1048 | 1050 |
stmt.setInt(2, rev); |
1051 |
stmt.setString(3, guid); |
|
1049 | 1052 |
int rows = stmt.executeUpdate(); |
1050 | 1053 |
|
1051 | 1054 |
stmt.close(); |
src/edu/ucsb/nceas/metacat/DocumentIdentifier.java | ||
---|---|---|
154 | 154 |
dbConn=DBConnectionPool. |
155 | 155 |
getDBConnection("DocumentIdentifier.getNewestRev"); |
156 | 156 |
serialNumber=dbConn.getCheckOutSerialNumber(); |
157 |
pstmt = dbConn.prepareStatement("select rev from xml_documents where " +
|
|
158 |
"docid like '" + docid + "'");
|
|
157 |
pstmt = dbConn.prepareStatement("select rev from xml_documents where docid like ? ");
|
|
158 |
pstmt.setString(1, docid);
|
|
159 | 159 |
pstmt.execute(); |
160 | 160 |
ResultSet rs = pstmt.getResultSet(); |
161 | 161 |
boolean tablehasrows = rs.next(); |
src/edu/ucsb/nceas/metacat/replication/ReplicationHandler.java | ||
---|---|---|
35 | 35 |
import java.sql.PreparedStatement; |
36 | 36 |
import java.sql.ResultSet; |
37 | 37 |
import java.sql.SQLException; |
38 |
import java.sql.Timestamp; |
|
38 | 39 |
import java.text.DateFormat; |
39 | 40 |
import java.text.ParseException; |
41 |
import java.util.Calendar; |
|
40 | 42 |
import java.util.Date; |
41 | 43 |
import java.util.Hashtable; |
42 | 44 |
import java.util.TimerTask; |
43 | 45 |
import java.util.Vector; |
44 | 46 |
|
47 |
import javax.xml.bind.DatatypeConverter; |
|
48 |
|
|
45 | 49 |
import org.apache.log4j.Logger; |
46 | 50 |
import org.dataone.service.types.v1.SystemMetadata; |
47 | 51 |
import org.dataone.service.util.TypeMarshaller; |
... | ... | |
391 | 395 |
// Get home server of the docid |
392 | 396 |
String docHomeServer = docinfoHash.get("home_server"); |
393 | 397 |
logReplication.info("ReplicationHandler.handleSingleXMLDocument - doc home server in repl: "+docHomeServer); |
394 |
String createdDate = docinfoHash.get("date_created"); |
|
395 |
String updatedDate = docinfoHash.get("date_updated"); |
|
398 |
|
|
399 |
// dates |
|
400 |
String createdDateString = docinfoHash.get("date_created"); |
|
401 |
String updatedDateString = docinfoHash.get("date_updated"); |
|
402 |
Date createdDate = DatatypeConverter.parseDateTime(createdDateString).getTime(); |
|
403 |
Date updatedDate = DatatypeConverter.parseDateTime(updatedDateString).getTime(); |
|
404 |
|
|
396 | 405 |
//docid should include rev number too |
397 | 406 |
/*String accnum=docId+util.getProperty("document.accNumSeparator")+ |
398 | 407 |
(String)docinfoHash.get("rev");*/ |
... | ... | |
553 | 562 |
// Get docid home sever. it might be different to remoteserver |
554 | 563 |
// because of hub feature |
555 | 564 |
String docHomeServer = docinfoHash.get("home_server"); |
556 |
String createdDate = docinfoHash.get("date_created"); |
|
557 |
String updatedDate = docinfoHash.get("date_updated"); |
|
565 |
String createdDateString = docinfoHash.get("date_created"); |
|
566 |
String updatedDateString = docinfoHash.get("date_updated"); |
|
567 |
Date createdDate = DatatypeConverter.parseDateTime(createdDateString).getTime(); |
|
568 |
Date updatedDate = DatatypeConverter.parseDateTime(updatedDateString).getTime(); |
|
558 | 569 |
//docid should include rev number too |
559 | 570 |
/*String accnum=docId+util.getProperty("document.accNumSeparator")+ |
560 | 571 |
(String)docinfoHash.get("rev");*/ |
... | ... | |
762 | 773 |
MetacatUtil.getLocalReplicationServerName()+"&action=gettime"); |
763 | 774 |
String datexml = ReplicationService.getURLContent(dateurl); |
764 | 775 |
logReplication.info("ReplicationHandler.updateLastCheckTimeForSingleServer - datexml: "+datexml); |
765 |
if (datexml!=null && !datexml.equals("")) |
|
766 |
{ |
|
776 |
if (datexml != null && !datexml.equals("")) { |
|
777 |
|
|
778 |
// parse the ISO datetime |
|
767 | 779 |
String datestr = datexml.substring(11, datexml.indexOf('<', 11)); |
780 |
Calendar updated = DatatypeConverter.parseDateTime(datestr); |
|
781 |
|
|
768 | 782 |
StringBuffer sql = new StringBuffer(); |
769 |
/*sql.append("update xml_replication set last_checked = to_date('"); |
|
770 |
sql.append(datestr).append("', 'YY-MM-DD HH24:MI:SS') where "); |
|
771 |
sql.append("server like '").append(server).append("'");*/ |
|
772 |
sql.append("update xml_replication set last_checked = "); |
|
773 |
sql.append(DatabaseService.getInstance().getDBAdapter().toDate(datestr, "MM/DD/YY HH24:MI:SS")); |
|
774 |
sql.append(" where server like '").append(server).append("'"); |
|
783 |
sql.append("update xml_replication set last_checked = ? "); |
|
784 |
sql.append(" where server like ? "); |
|
775 | 785 |
pstmt = dbConn.prepareStatement(sql.toString()); |
776 |
|
|
786 |
pstmt.setTimestamp(1, new Timestamp(updated.getTimeInMillis())); |
|
787 |
pstmt.setString(2, server); |
|
788 |
|
|
777 | 789 |
pstmt.executeUpdate(); |
778 | 790 |
dbConn.commit(); |
779 | 791 |
pstmt.close(); |
... | ... | |
1013 | 1025 |
boolean xml_revs = false; |
1014 | 1026 |
|
1015 | 1027 |
StringBuffer sb = new StringBuffer(); |
1016 |
sb.append("select docid from xml_revisions where docid like '"); |
|
1017 |
sb.append(docid).append("'"); |
|
1028 |
sb.append("select docid from xml_revisions where docid like ? "); |
|
1018 | 1029 |
pstmt = dbConn.prepareStatement(sb.toString()); |
1030 |
pstmt.setString(1, docid); |
|
1019 | 1031 |
pstmt.execute(); |
1020 | 1032 |
ResultSet rs = pstmt.getResultSet(); |
1021 | 1033 |
boolean tablehasrows = rs.next(); |
src/edu/ucsb/nceas/metacat/replication/ReplicationService.java | ||
---|---|---|
47 | 47 |
import java.sql.PreparedStatement; |
48 | 48 |
import java.sql.ResultSet; |
49 | 49 |
import java.sql.SQLException; |
50 |
import java.sql.Timestamp; |
|
50 | 51 |
import java.text.SimpleDateFormat; |
52 |
import java.util.Calendar; |
|
51 | 53 |
import java.util.Date; |
52 | 54 |
import java.util.Hashtable; |
53 | 55 |
import java.util.List; |
... | ... | |
56 | 58 |
|
57 | 59 |
import javax.servlet.http.HttpServletRequest; |
58 | 60 |
import javax.servlet.http.HttpServletResponse; |
61 |
import javax.xml.bind.DatatypeConverter; |
|
59 | 62 |
|
60 | 63 |
import org.apache.http.HttpResponse; |
61 | 64 |
import org.apache.http.conn.scheme.Scheme; |
... | ... | |
323 | 326 |
//Get hub value |
324 | 327 |
hub = ((String[]) params.get("hub"))[0]; |
325 | 328 |
|
326 |
String toDateSql = DatabaseService.getInstance().getDBAdapter().toDate("01/01/1980","MM/DD/YYYY"); |
|
329 |
Calendar cal = Calendar.getInstance(); |
|
330 |
cal.set(1980, 1, 1); |
|
327 | 331 |
String sql = "INSERT INTO xml_replication " |
328 | 332 |
+ "(server, last_checked, replicate, datareplicate, systemmetadatareplicate, hub) " |
329 |
+ "VALUES (?," + toDateSql + ",?,?,?,?)";
|
|
333 |
+ "VALUES (?,?,?,?,?,?)";
|
|
330 | 334 |
|
331 | 335 |
pstmt = dbConn.prepareStatement(sql); |
332 | 336 |
|
333 | 337 |
pstmt.setString(1, server); |
334 |
pstmt.setInt(2, Integer.parseInt(replicate)); |
|
335 |
pstmt.setInt(3, Integer.parseInt(dataReplicate)); |
|
336 |
pstmt.setInt(4, Integer.parseInt(systemMetadataReplicate)); |
|
337 |
pstmt.setInt(5, Integer.parseInt(hub)); |
|
338 |
pstmt.setTimestamp(2, new Timestamp(cal.getTimeInMillis())); |
|
339 |
pstmt.setInt(3, Integer.parseInt(replicate)); |
|
340 |
pstmt.setInt(4, Integer.parseInt(dataReplicate)); |
|
341 |
pstmt.setInt(5, Integer.parseInt(systemMetadataReplicate)); |
|
342 |
pstmt.setInt(6, Integer.parseInt(hub)); |
|
338 | 343 |
|
339 | 344 |
String sqlReport = "XMLAccessAccess.getXMLAccessForDoc - SQL: " + sql; |
340 | 345 |
sqlReport += " [" + server + "," + replicate + |
... | ... | |
384 | 389 |
} else if (subaction.equals("delete")) { |
385 | 390 |
server = ((String[]) params.get("server"))[0]; |
386 | 391 |
pstmt = dbConn.prepareStatement("DELETE FROM xml_replication " |
387 |
+ "WHERE server LIKE '" + server + "'"); |
|
392 |
+ "WHERE server LIKE ?"); |
|
393 |
pstmt.setString(1, server); |
|
388 | 394 |
pstmt.execute(); |
389 | 395 |
pstmt.close(); |
390 | 396 |
dbConn.commit(); |
... | ... | |
601 | 607 |
IdentifierManager.getInstance().createMapping(sysMeta.getIdentifier().getValue(), docid); |
602 | 608 |
} |
603 | 609 |
|
604 |
// replicate doc contents |
|
605 |
String createdDate = (String) docinfoHash.get("date_created"); |
|
606 |
String updatedDate = (String) docinfoHash.get("date_updated"); |
|
610 |
// dates |
|
611 |
String createdDateString = docinfoHash.get("date_created"); |
|
612 |
String updatedDateString = docinfoHash.get("date_updated"); |
|
613 |
Date createdDate = DatatypeConverter.parseDateTime(createdDateString).getTime(); |
|
614 |
Date updatedDate = DatatypeConverter.parseDateTime(updatedDateString).getTime(); |
|
615 |
|
|
607 | 616 |
logReplication.info("ReplicationService.handleForceReplicateRequest - homeServer: " + homeServer); |
608 | 617 |
// Get Document type |
609 | 618 |
String docType = (String) docinfoHash.get("doctype"); |
... | ... | |
811 | 820 |
String docType = (String) docinfoHash.get("doctype"); |
812 | 821 |
|
813 | 822 |
String docHomeServer = (String) docinfoHash.get("home_server"); |
814 |
|
|
815 |
String createdDate = (String) docinfoHash.get("date_created"); |
|
816 |
|
|
817 |
String updatedDate = (String) docinfoHash.get("date_updated"); |
|
823 |
|
|
824 |
String createdDateString = docinfoHash.get("date_created"); |
|
825 |
String updatedDateString = docinfoHash.get("date_updated"); |
|
826 |
|
|
827 |
Date createdDate = DatatypeConverter.parseDateTime(createdDateString).getTime(); |
|
828 |
Date updatedDate = DatatypeConverter.parseDateTime(updatedDateString).getTime(); |
|
829 |
|
|
818 | 830 |
logReplication.info("ReplicationService.handleForceReplicateDataFileRequest - docHomeServer of datafile: " + docHomeServer); |
819 | 831 |
|
820 | 832 |
if (dbaction.equals("insert") || dbaction.equals("update")) { |
... | ... | |
972 | 984 |
} catch(McdbDocNotFoundException e) { |
973 | 985 |
logMetacat.warn("No SystemMetadata found for: " + docid); |
974 | 986 |
} |
987 |
|
|
988 |
Calendar created = Calendar.getInstance(); |
|
989 |
created.setTime(doc.getCreateDate()); |
|
990 |
Calendar updated = Calendar.getInstance(); |
|
991 |
updated.setTime(doc.getUpdateDate()); |
|
992 |
|
|
975 | 993 |
sb.append("<docname>").append(doc.getDocname()); |
976 | 994 |
sb.append("</docname><doctype>").append(doc.getDoctype()); |
977 | 995 |
sb.append("</doctype>"); |
... | ... | |
979 | 997 |
sb.append("</user_owner><user_updated>").append(doc.getUserupdated()); |
980 | 998 |
sb.append("</user_updated>"); |
981 | 999 |
sb.append("<date_created>"); |
982 |
sb.append(doc.getCreateDate());
|
|
1000 |
sb.append(DatatypeConverter.printDateTime(created));
|
|
983 | 1001 |
sb.append("</date_created>"); |
984 | 1002 |
sb.append("<date_updated>"); |
985 |
sb.append(doc.getUpdateDate());
|
|
1003 |
sb.append(DatatypeConverter.printDateTime(updated));
|
|
986 | 1004 |
sb.append("</date_updated>"); |
987 | 1005 |
sb.append("<home_server>"); |
988 | 1006 |
sb.append(doc.getDocHomeServer()); |
... | ... | |
1739 | 1757 |
*/ |
1740 | 1758 |
protected static void handleGetTimeRequest( |
1741 | 1759 |
Hashtable<String, String[]> params, HttpServletResponse response) { |
1742 |
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yy HH:mm:ss"); |
|
1743 |
java.util.Date localtime = new java.util.Date(); |
|
1744 |
String dateString = formatter.format(localtime); |
|
1745 | 1760 |
|
1761 |
// use standard ISO format -- the receiving end wants this too |
|
1762 |
String dateString = DatatypeConverter.printDateTime(Calendar.getInstance()); |
|
1763 |
|
|
1746 | 1764 |
// get a writer for sending back to response |
1747 | 1765 |
response.setContentType("text/xml"); |
1748 | 1766 |
Writer out = null; |
... | ... | |
1795 | 1813 |
dbConn = DBConnectionPool.getDBConnection("MetacatReplication.getServer"); |
1796 | 1814 |
serialNumber = dbConn.getCheckOutSerialNumber(); |
1797 | 1815 |
String sql = new String("select server from " |
1798 |
+ "xml_replication where serverid = " + serverCode);
|
|
1816 |
+ "xml_replication where serverid = ?");
|
|
1799 | 1817 |
pstmt = dbConn.prepareStatement(sql); |
1818 |
pstmt.setInt(1, serverCode); |
|
1800 | 1819 |
//System.out.println("getserver sql: " + sql); |
1801 | 1820 |
pstmt.execute(); |
1802 | 1821 |
ResultSet rs = pstmt.getResultSet(); |
... | ... | |
1846 | 1865 |
dbConn = DBConnectionPool.getDBConnection("MetacatReplication.getServerCode"); |
1847 | 1866 |
serialNumber = dbConn.getCheckOutSerialNumber(); |
1848 | 1867 |
pstmt = dbConn.prepareStatement("SELECT serverid FROM xml_replication " |
1849 |
+ "WHERE server LIKE '" + server + "'"); |
|
1868 |
+ "WHERE server LIKE ?"); |
|
1869 |
pstmt.setString(1, server); |
|
1850 | 1870 |
pstmt.execute(); |
1851 | 1871 |
ResultSet rs = pstmt.getResultSet(); |
1852 | 1872 |
boolean tablehasrows = rs.next(); |
... | ... | |
1971 | 1991 |
.getDBConnection("ReplicationHandler.getServerLocation"); |
1972 | 1992 |
serialNumber = dbConn.getCheckOutSerialNumber(); |
1973 | 1993 |
pstmt = dbConn.prepareStatement("SELECT server_location FROM xml_documents " |
1974 |
+ "WHERE docid LIKE '" + docId + "'"); |
|
1994 |
+ "WHERE docid LIKE ? "); |
|
1995 |
pstmt.setString(1, docId); |
|
1975 | 1996 |
pstmt.execute(); |
1976 | 1997 |
ResultSet rs = pstmt.getResultSet(); |
1977 | 1998 |
boolean tablehasrows = rs.next(); |
... | ... | |
2142 | 2163 |
dbConn = DBConnectionPool.getDBConnection("MetacatReplication.repltoServer"); |
2143 | 2164 |
serialNumber = dbConn.getCheckOutSerialNumber(); |
2144 | 2165 |
pstmt = dbConn.prepareStatement("select replicate from " |
2145 |
+ "xml_replication where server like '" + server + "'"); |
|
2166 |
+ "xml_replication where server like ? "); |
|
2167 |
pstmt.setString(1, server); |
|
2146 | 2168 |
pstmt.execute(); |
2147 | 2169 |
ResultSet rs = pstmt.getResultSet(); |
2148 | 2170 |
boolean tablehasrows = rs.next(); |
src/edu/ucsb/nceas/metacat/replication/ReplicationServerList.java | ||
---|---|---|
30 | 30 |
import java.sql.PreparedStatement; |
31 | 31 |
import java.sql.ResultSet; |
32 | 32 |
import java.sql.SQLException; |
33 |
import java.sql.Timestamp; |
|
34 |
import java.util.Calendar; |
|
33 | 35 |
import java.util.Date; |
34 | 36 |
import java.util.Vector; |
35 | 37 |
|
... | ... | |
478 | 480 |
// Add this server to xml_table too |
479 | 481 |
try |
480 | 482 |
{ |
483 |
Calendar cal = Calendar.getInstance(); |
|
484 |
cal.set(1980, 1, 1); |
|
481 | 485 |
// Checkout DBConnection |
482 | 486 |
dbConn=DBConnectionPool. |
483 | 487 |
getDBConnection("ReplicationSErverList.addToServerListIfItIsNot"); |
... | ... | |
490 | 494 |
replicate +"', '"+dataReplicate+"','"+ hub + "')");*/ |
491 | 495 |
pStmt = dbConn.prepareStatement("INSERT INTO xml_replication " + |
492 | 496 |
"(server, last_checked, replicate, datareplicate, hub) "+ |
493 |
"VALUES ('" + givenServerName + "', "+ |
|
494 |
DatabaseService.getInstance().getDBAdapter().toDate("01/01/1980","MM/DD/YYYY") + ", '" + |
|
495 |
replicate +"', '"+dataReplicate+"','"+ hub + "')"); |
|
497 |
"VALUES (?, ?, ?, ?, ?, ?)"); |
|
498 |
pStmt.setString(1, givenServerName); |
|
499 |
pStmt.setTimestamp(2, new Timestamp(cal.getTimeInMillis()) ); |
|
500 |
pStmt.setInt(3, replicate); |
|
501 |
pStmt.setInt(4, dataReplicate); |
|
502 |
pStmt.setInt(5, hub); |
|
503 |
|
|
496 | 504 |
pStmt.execute(); |
497 | 505 |
|
498 | 506 |
pStmt.close(); |
Also available in: Unified diff
http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5527