Revision 697
Added by bojilova almost 24 years ago
src/edu/ucsb/nceas/metacat/DBSAXHandler.java | ||
---|---|---|
186 | 186 |
} |
187 | 187 |
rootNode.writeNodename(docname); |
188 | 188 |
try { |
189 |
// for validated XML Documents store a reference to XML DB Catalog |
|
190 |
String catalogid = null; |
|
191 |
if ( systemid != null ) { |
|
192 |
Statement stmt = conn.createStatement(); |
|
193 |
ResultSet rs = stmt.executeQuery( |
|
194 |
"SELECT catalog_id FROM xml_catalog " + |
|
195 |
"WHERE entry_type = 'DTD' " + |
|
196 |
"AND public_id = '" + doctype + "'"); |
|
197 |
boolean hasRow = rs.next(); |
|
198 |
if ( hasRow ) { |
|
199 |
catalogid = rs.getString(1); |
|
200 |
} |
|
201 |
stmt.close(); |
|
202 |
} |
|
189 | 203 |
currentDocument = new DocumentImpl(conn, rootNode.getNodeID(), |
190 |
docname, doctype, docid, action, user, this.pub,
|
|
191 |
this.serverCode); |
|
204 |
docname, doctype, docid, action, user, |
|
205 |
this.pub, catalogid, this.serverCode);
|
|
192 | 206 |
} catch (Exception ane) { |
193 | 207 |
throw (new SAXException("Error in DBSaxHandler.startElement " + |
194 | 208 |
action, ane)); |
195 | 209 |
} |
196 |
// not needed any more |
|
197 |
//rootNode.writeDocID(currentDocument.getDocID()); |
|
198 | 210 |
} |
199 | 211 |
|
200 | 212 |
// Create the current node representation |
... | ... | |
386 | 398 |
doctype = publicId; |
387 | 399 |
systemid = systemId; |
388 | 400 |
|
401 |
//System.out.println("Start DTD"); |
|
402 |
//System.out.println("DOCNAME: " + docname); |
|
403 |
//System.out.println("DOCTYPE: " + doctype); |
|
404 |
//System.out.println(" SYSID: " + systemid); |
|
405 |
|
|
389 | 406 |
MetaCatUtil.debugMessage("Start DTD"); |
390 | 407 |
MetaCatUtil.debugMessage("DOCNAME: " + docname); |
391 | 408 |
MetaCatUtil.debugMessage("DOCTYPE: " + doctype); |
... | ... | |
396 | 413 |
* SAX Handler that receives notification of end of DTD |
397 | 414 |
*/ |
398 | 415 |
public void endDTD() throws SAXException { |
416 |
|
|
417 |
//System.out.println("end DTD"); |
|
399 | 418 |
MetaCatUtil.debugMessage("end DTD"); |
400 | 419 |
} |
401 | 420 |
|
... | ... | |
429 | 448 |
*/ |
430 | 449 |
public void startEntity(String name) throws SAXException { |
431 | 450 |
MetaCatUtil.debugMessage("start ENTITY: " + name); |
451 |
//System.out.println("start ENTITY: " + name); |
|
432 | 452 |
if (name.equals("[dtd]")) { |
433 | 453 |
processingDTD = true; |
434 | 454 |
} |
... | ... | |
439 | 459 |
*/ |
440 | 460 |
public void endEntity(String name) throws SAXException { |
441 | 461 |
MetaCatUtil.debugMessage("end ENTITY: " + name); |
462 |
//System.out.println("end ENTITY: " + name); |
|
442 | 463 |
if (name.equals("[dtd]")) { |
443 | 464 |
processingDTD = false; |
444 | 465 |
} |
... | ... | |
449 | 470 |
*/ |
450 | 471 |
public void elementDecl(String name, String model) |
451 | 472 |
throws org.xml.sax.SAXException { |
473 |
//System.out.println("ELEMENTDECL: " + name + " " + model); |
|
452 | 474 |
MetaCatUtil.debugMessage("ELEMENTDECL: " + name + " " + model); |
453 | 475 |
} |
454 | 476 |
|
... | ... | |
458 | 480 |
public void attributeDecl(String eName, String aName, |
459 | 481 |
String type, String valueDefault, String value) |
460 | 482 |
throws org.xml.sax.SAXException { |
483 |
//System.out.println("ATTRIBUTEDECL: " + eName + " " |
|
484 |
// + aName + " " + type + " " + valueDefault + " " |
|
485 |
// + value); |
|
461 | 486 |
MetaCatUtil.debugMessage("ATTRIBUTEDECL: " + eName + " " |
462 | 487 |
+ aName + " " + type + " " + valueDefault + " " |
463 | 488 |
+ value); |
... | ... | |
468 | 493 |
*/ |
469 | 494 |
public void internalEntityDecl(String name, String value) |
470 | 495 |
throws org.xml.sax.SAXException { |
496 |
//System.out.println("INTERNENTITYDECL: " + name + " " + value); |
|
471 | 497 |
MetaCatUtil.debugMessage("INTERNENTITYDECL: " + name + " " + value); |
472 | 498 |
} |
473 | 499 |
|
... | ... | |
477 | 503 |
public void externalEntityDecl(String name, String publicId, |
478 | 504 |
String systemId) |
479 | 505 |
throws org.xml.sax.SAXException { |
506 |
//System.out.println("EXTERNENTITYDECL: " + name + " " + publicId |
|
507 |
// + " " + systemId); |
|
480 | 508 |
MetaCatUtil.debugMessage("EXTERNENTITYDECL: " + name + " " + publicId |
481 | 509 |
+ " " + systemId); |
482 | 510 |
} |
src/edu/ucsb/nceas/metacat/DocumentImpl.java | ||
---|---|---|
79 | 79 |
private String userupdated = null; |
80 | 80 |
private int rev; |
81 | 81 |
private int serverlocation; |
82 |
private int publicaccess;
|
|
82 |
private String publicaccess;
|
|
83 | 83 |
private long rootnodeid; |
84 | 84 |
private ElementNode rootNode = null; |
85 | 85 |
private TreeSet nodeRecordList = null; |
... | ... | |
143 | 143 |
*/ |
144 | 144 |
public DocumentImpl(Connection conn, long rootnodeid, String docname, |
145 | 145 |
String doctype, String docid, String action, String user, |
146 |
String pub, int serverCode) |
|
146 |
String pub, String catalogid, int serverCode)
|
|
147 | 147 |
throws SQLException, Exception |
148 | 148 |
{ |
149 | 149 |
this.conn = conn; |
... | ... | |
151 | 151 |
this.docname = docname; |
152 | 152 |
this.doctype = doctype; |
153 | 153 |
this.docid = docid; |
154 |
writeDocumentToDB(action, user, pub, serverCode); |
|
154 |
writeDocumentToDB(action, user, pub, catalogid, serverCode);
|
|
155 | 155 |
} |
156 | 156 |
|
157 | 157 |
// NOT USED ANY MORE |
... | ... | |
236 | 236 |
return serverlocation; |
237 | 237 |
} |
238 | 238 |
|
239 |
public int getPublicaccess() {
|
|
239 |
public String getPublicaccess() {
|
|
240 | 240 |
return publicaccess; |
241 | 241 |
} |
242 | 242 |
|
... | ... | |
502 | 502 |
// DOCTITLE attr cleared from the db |
503 | 503 |
// sql.append("SELECT docname, doctype, rootnodeid, doctitle, "); |
504 | 504 |
sql.append("SELECT docname, doctype, rootnodeid, "); |
505 |
sql.append("date_created, date_updated, "); |
|
506 |
sql.append("user_owner, user_updated, server_location, ");
|
|
507 |
sql.append("rev FROM ").append(table);
|
|
505 |
sql.append("date_created, date_updated, user_owner, user_updated, ");
|
|
506 |
sql.append("server_location, public_access, rev");
|
|
507 |
sql.append(" FROM ").append(table); |
|
508 | 508 |
sql.append(" WHERE docid LIKE '").append(docid.getIdentifier()); |
509 | 509 |
sql.append("' and rev like '").append(docid.getRev()).append("'"); |
510 | 510 |
//System.out.println(sql.toString()); |
... | ... | |
528 | 528 |
this.userowner = rs.getString(6); |
529 | 529 |
this.userupdated = rs.getString(7); |
530 | 530 |
this.serverlocation = rs.getInt(8); |
531 |
this.rev = rs.getInt(9); |
|
531 |
this.publicaccess = rs.getString(9); |
|
532 |
this.rev = rs.getInt(10); |
|
532 | 533 |
} |
533 | 534 |
|
534 | 535 |
if (this.doctype != null) { |
... | ... | |
623 | 624 |
} |
624 | 625 |
} |
625 | 626 |
|
626 |
/** creates SQL code and inserts new document into DB connection |
|
627 |
default serverCode of 1*/ |
|
628 |
private void writeDocumentToDB(String action, String user) |
|
629 |
throws SQLException, Exception |
|
630 |
{ |
|
631 |
writeDocumentToDB(action, user, null, 1); |
|
632 |
} |
|
627 |
// NOT USED ANY MORE |
|
628 |
// /** creates SQL code and inserts new document into DB connection |
|
629 |
// default serverCode of 1*/ |
|
630 |
// private void writeDocumentToDB(String action, String user) |
|
631 |
// throws SQLException, Exception |
|
632 |
// { |
|
633 |
// writeDocumentToDB(action, user, null, 1); |
|
634 |
// } |
|
633 | 635 |
|
634 | 636 |
/** creates SQL code and inserts new document into DB connection */ |
635 | 637 |
private void writeDocumentToDB(String action, String user, String pub, |
636 |
int serverCode) |
|
638 |
String catalogid, int serverCode)
|
|
637 | 639 |
throws SQLException, Exception { |
638 | 640 |
try { |
639 | 641 |
PreparedStatement pstmt = null; |
... | ... | |
642 | 644 |
//AccessionNumber ac = new AccessionNumber(); |
643 | 645 |
//this.docid = ac.generate(docid, "INSERT"); |
644 | 646 |
pstmt = conn.prepareStatement( |
645 |
"INSERT INTO xml_documents " + |
|
646 |
"(docid, rootnodeid, docname, doctype, user_owner, user_updated, " + |
|
647 |
"date_created, date_updated, public_access, server_location) " + |
|
648 |
"VALUES (?, ?, ?, ?, ?, ?, sysdate, sysdate, ?, ?)"); |
|
647 |
"INSERT INTO xml_documents " + |
|
648 |
"(docid, rootnodeid, docname, doctype, " + |
|
649 |
"user_owner, user_updated, date_created, date_updated, " + |
|
650 |
"public_access, catalog_id, server_location) " + |
|
651 |
"VALUES (?, ?, ?, ?, ?, ?, sysdate, sysdate, ?, ?, ?)"); |
|
649 | 652 |
//note that the server_location is set to 1. |
650 | 653 |
//this means that "localhost" in the xml_replication table must |
651 | 654 |
//always be the first entry!!!!! |
... | ... | |
659 | 662 |
pstmt.setString(6, user); |
660 | 663 |
if ( pub == null ) { |
661 | 664 |
pstmt.setString(7, null); |
662 |
} else if ( pub.toUpperCase().equals("YES") ) { |
|
665 |
} else if ( pub.toUpperCase().equals("YES") || pub.equals("1") ) {
|
|
663 | 666 |
pstmt.setInt(7, 1); |
664 |
} else if ( pub.toUpperCase().equals("NO") ) { |
|
667 |
} else if ( pub.toUpperCase().equals("NO") || pub.equals("0") ) {
|
|
665 | 668 |
pstmt.setInt(7, 0); |
666 | 669 |
} |
667 |
pstmt.setInt(8, serverCode); |
|
670 |
pstmt.setString(8, catalogid); |
|
671 |
pstmt.setInt(9, serverCode); |
|
668 | 672 |
} else if (action.equals("UPDATE")) { |
669 | 673 |
|
670 | 674 |
// Save the old document entry in a backup table |
... | ... | |
684 | 688 |
"UPDATE xml_documents " + |
685 | 689 |
"SET rootnodeid = ?, docname = ?, doctype = ?, " + |
686 | 690 |
"user_updated = ?, date_updated = sysdate, " + |
687 |
"server_location = ?, rev = ?, public_access = ? " + |
|
691 |
"server_location = ?, rev = ?, public_access = ?, catalog_id = ? " +
|
|
688 | 692 |
"WHERE docid LIKE ?"); |
689 | 693 |
// Bind the values to the query |
690 | 694 |
pstmt.setLong(1, rootnodeid); |
... | ... | |
695 | 699 |
pstmt.setInt(6, thisrev); |
696 | 700 |
if ( pub == null ) { |
697 | 701 |
pstmt.setString(7, null); |
698 |
} else if ( pub.toUpperCase().equals("YES") ) { |
|
702 |
} else if ( pub.toUpperCase().equals("YES") || pub.equals("1") ) {
|
|
699 | 703 |
pstmt .setInt(7, 1); |
700 |
} else if ( pub.toUpperCase().equals("NO") ) { |
|
704 |
} else if ( pub.toUpperCase().equals("NO") || pub.equals("0") ) {
|
|
701 | 705 |
pstmt.setInt(7, 0); |
702 | 706 |
} |
703 |
pstmt.setString(8, this.docid); |
|
707 |
pstmt.setString(8, catalogid); |
|
708 |
pstmt.setString(9, this.docid); |
|
704 | 709 |
|
705 | 710 |
} else { |
706 | 711 |
System.err.println("Action not supported: " + action); |
... | ... | |
1114 | 1119 |
PreparedStatement pstmt = conn.prepareStatement( |
1115 | 1120 |
"INSERT INTO xml_revisions " + |
1116 | 1121 |
"(revisionid, docid, rootnodeid, docname, doctype, " + |
1117 |
"user_owner, user_updated, date_created, date_updated, server_location, " +
|
|
1118 |
"rev)" +
|
|
1122 |
"user_owner, user_updated, date_created, date_updated, " + |
|
1123 |
"server_location, rev, public_access, catalog_id) " +
|
|
1119 | 1124 |
"SELECT null, ?, rootnodeid, docname, doctype, " + |
1120 |
"user_owner, ?, sysdate, sysdate, server_location, rev "+ |
|
1125 |
"user_owner, ?, sysdate, sysdate, server_location, rev, " + |
|
1126 |
"public_access, catalog_id " + |
|
1121 | 1127 |
"FROM xml_documents " + |
1122 | 1128 |
"WHERE docid = ?"); |
1123 | 1129 |
// Bind the values to the query and execute it |
src/edu/ucsb/nceas/metacat/ReplicationHandler.java | ||
---|---|---|
108 | 108 |
} |
109 | 109 |
} |
110 | 110 |
serverList = buildServerList(conn); |
111 |
updateCatalog(serverList); |
|
111 | 112 |
update(serverList); |
112 |
updateCatalog(serverList); |
|
113 | 113 |
conn.close(); |
114 | 114 |
} |
115 | 115 |
catch (Exception e) |
... | ... | |
272 | 272 |
{ |
273 | 273 |
String newDocid = DocumentImpl.write(conn, |
274 | 274 |
new StringReader(newxmldoc), |
275 |
null, |
|
275 |
(String)docinfoHash.get("public_access"), |
|
276 |
null, /* the dtd text */ |
|
276 | 277 |
action, |
277 | 278 |
docid, |
278 | 279 |
(String)docinfoHash.get("user_owner"), |
279 | 280 |
(String)docinfoHash.get("user_owner"), |
280 | 281 |
serverCode, |
281 |
true); |
|
282 |
true, /* override */ |
|
283 |
false /* validate */); |
|
282 | 284 |
MetacatReplication.replLog("wrote doc " + docid + " from " + |
283 | 285 |
docServer); |
284 | 286 |
System.out.println("wrote doc " + docid + " from " + |
Also available in: Unified diff
- fixed missing replication of public_access
- new attribute catalog_id added in xml_documents and xml_revisions
as a FK to xml_catalog; catalog_id is replicated also