Revision 457
Added by bojilova over 23 years ago
DocumentImpl.java | ||
---|---|---|
107 | 107 |
*/ |
108 | 108 |
public DocumentImpl(Connection conn, long rootnodeid, String docname, |
109 | 109 |
String doctype, String docid, String action, String user) |
110 |
throws AccessionNumberException
|
|
110 |
throws SQLException, Exception
|
|
111 | 111 |
{ |
112 | 112 |
this.conn = conn; |
113 | 113 |
this.rootnodeid = rootnodeid; |
... | ... | |
451 | 451 |
*/ |
452 | 452 |
public static String write( Connection conn, String filename, String action, |
453 | 453 |
String docid, String user, String group ) |
454 |
throws IOException, SQLException, ClassNotFoundException, |
|
455 |
SAXException, SAXParseException, Exception { |
|
454 |
throws Exception { |
|
456 | 455 |
|
457 | 456 |
return write(conn, new FileReader(new File(filename).toString()), |
458 | 457 |
action, docid, user, group); |
... | ... | |
468 | 467 |
*/ |
469 | 468 |
public static String write( Connection conn, Reader xml, String action, |
470 | 469 |
String docid, String user, String group ) |
471 |
throws IOException, SQLException, ClassNotFoundException, |
|
472 |
SAXException, SAXParseException, Exception { |
|
470 |
throws Exception { |
|
473 | 471 |
|
472 |
// Determine if the docid is OK for INSERT or UPDATE |
|
473 |
AccessionNumber ac = new AccessionNumber(); |
|
474 |
String newdocid = ac.generate(docid, action); |
|
475 |
|
|
474 | 476 |
if ( action.equals("UPDATE") ) { |
475 |
// Determine if the docid is OK for UPDATE |
|
476 |
AccessionNumber ac = new AccessionNumber(); |
|
477 |
String newdocid = ac.generate(docid, "UPDATE"); |
|
478 |
|
|
479 | 477 |
// check for 'write' permission for 'user' to update this document |
480 | 478 |
if ( !hasWritePermission(conn, docid, user, group) ) { |
481 | 479 |
throw new Exception("User " + user + |
... | ... | |
484 | 482 |
} |
485 | 483 |
|
486 | 484 |
try { |
487 |
XMLReader parser = initializeParser(conn, action, docid, user); |
|
485 |
XMLReader parser = initializeParser(conn, action, newdocid, user);
|
|
488 | 486 |
conn.setAutoCommit(false); |
489 | 487 |
parser.parse(new InputSource(xml)); |
490 | 488 |
conn.commit(); |
491 | 489 |
conn.setAutoCommit(true); |
492 |
return docid;
|
|
490 |
//return newdocid;
|
|
493 | 491 |
} catch (SAXParseException e) { |
494 | 492 |
conn.rollback(); |
493 |
conn.setAutoCommit(true); |
|
495 | 494 |
throw e; |
496 | 495 |
} catch (SAXException e) { |
497 |
|
|
496 |
conn.rollback(); |
|
497 |
conn.setAutoCommit(true); |
|
498 |
throw e; |
|
499 |
/* |
|
498 | 500 |
// If its a problem with the accession number its ok, just the |
499 | 501 |
// accession number was regenerated |
500 | 502 |
AccessionNumberGeneratedException ang = null; |
... | ... | |
515 | 517 |
conn.rollback(); |
516 | 518 |
throw e; |
517 | 519 |
} |
520 |
*/ |
|
518 | 521 |
} catch (Exception e) { |
519 | 522 |
conn.rollback(); |
523 |
conn.setAutoCommit(true); |
|
520 | 524 |
throw e; |
521 | 525 |
} |
526 |
|
|
527 |
if ( (docid != null) && !(newdocid.equals(docid)) ) { |
|
528 |
return new String("New document ID generated:" + newdocid); |
|
529 |
} else { |
|
530 |
return newdocid; |
|
531 |
} |
|
522 | 532 |
} |
523 | 533 |
|
524 | 534 |
/** |
... | ... | |
529 | 539 |
*/ |
530 | 540 |
public static void delete( Connection conn, String docid, |
531 | 541 |
String user, String group ) |
532 |
throws IOException, SQLException, ClassNotFoundException, |
|
533 |
AccessionNumberException, Exception { |
|
542 |
throws Exception { |
|
534 | 543 |
|
535 | 544 |
// Determine if the docid is OK for DELETE |
536 | 545 |
AccessionNumber ac = new AccessionNumber(); |
... | ... | |
552 | 561 |
stmt.execute("DELETE FROM xml_documents WHERE docid = '" + docid + "'"); |
553 | 562 |
stmt.close(); |
554 | 563 |
conn.commit(); |
564 |
conn.setAutoCommit(true); |
|
555 | 565 |
} |
556 | 566 |
|
557 | 567 |
/** Check for "write" permissions from DB connection */ |
... | ... | |
632 | 642 |
|
633 | 643 |
/** creates SQL code and inserts new document into DB connection */ |
634 | 644 |
private void writeDocumentToDB(String action, String user) |
635 |
throws AccessionNumberException {
|
|
645 |
throws SQLException, Exception {
|
|
636 | 646 |
try { |
637 | 647 |
PreparedStatement pstmt = null; |
638 | 648 |
|
639 | 649 |
if (action.equals("INSERT")) { |
640 |
AccessionNumber ac = new AccessionNumber(); |
|
641 |
this.docid = ac.generate(docid, "INSERT"); |
|
650 |
//AccessionNumber ac = new AccessionNumber();
|
|
651 |
//this.docid = ac.generate(docid, "INSERT");
|
|
642 | 652 |
pstmt = conn.prepareStatement( |
643 | 653 |
"INSERT INTO xml_documents " + |
644 | 654 |
"(docid, rootnodeid, docname, doctype, " + |
... | ... | |
682 | 692 |
pstmt.execute(); |
683 | 693 |
pstmt.close(); |
684 | 694 |
|
685 |
} catch (SQLException e) { |
|
686 |
System.out.println(e.getMessage());
|
|
687 |
} catch (AccessionNumberException ane) { |
|
688 |
MetaCatUtil.debugMessage("Invalid accession number."); |
|
689 |
MetaCatUtil.debugMessage(ane.getMessage()); |
|
690 |
throw ane; |
|
695 |
} catch (SQLException sqle) {
|
|
696 |
throw sqle;
|
|
697 |
// } catch (AccessionNumberException ane) {
|
|
698 |
// MetaCatUtil.debugMessage("Invalid accession number.");
|
|
699 |
// MetaCatUtil.debugMessage(ane.getMessage());
|
|
700 |
// throw ane;
|
|
691 | 701 |
} catch (Exception e) { |
692 |
System.out.println(e.getMessage());
|
|
702 |
throw e;
|
|
693 | 703 |
} |
694 | 704 |
} |
695 | 705 |
|
... | ... | |
804 | 814 |
|
805 | 815 |
} |
806 | 816 |
|
807 |
/** Save a document entry in the xml_revisions table */ |
|
808 |
/* |
|
809 |
private static void archiveDocRevision(Connection conn, String docid, |
|
810 |
String user) throws SQLException { |
|
811 |
// First get all of the values we need |
|
812 |
long rnodeid = -1; |
|
813 |
String docname = null; |
|
814 |
String doctype = null; |
|
815 |
String doctitle = null; |
|
816 |
String user_owner = null; |
|
817 |
Date date_created = null; |
|
818 |
PreparedStatement pstmt = conn.prepareStatement( |
|
819 |
"SELECT rootnodeid,docname,doctype,doctitle,user_owner,date_created " + |
|
820 |
"FROM xml_documents " + |
|
821 |
"WHERE docid = ?"); |
|
822 |
// Bind the values to the query and execute it |
|
823 |
pstmt.setString(1, docid); |
|
824 |
pstmt.execute(); |
|
825 |
|
|
826 |
ResultSet rs = pstmt.getResultSet(); |
|
827 |
boolean tableHasRows = rs.next(); |
|
828 |
if (tableHasRows) { |
|
829 |
rnodeid = rs.getLong(1); |
|
830 |
docname = rs.getString(2); |
|
831 |
doctype = rs.getString(3); |
|
832 |
doctitle = rs.getString(4); |
|
833 |
user_owner = rs.getString(5); |
|
834 |
date_created = rs.getDate(6); |
|
835 |
} |
|
836 |
pstmt.close(); |
|
837 |
|
|
838 |
MetaCatUtil.debugMessage(new Long(rnodeid).toString()); |
|
839 |
MetaCatUtil.debugMessage(docname); |
|
840 |
MetaCatUtil.debugMessage(doctitle); |
|
841 |
//MetaCatUtil.debugMessage(date_created.toString()); |
|
842 |
|
|
843 |
// Next create the new record in the other table using the values selected |
|
844 |
pstmt = conn.prepareStatement( |
|
845 |
"INSERT INTO xml_revisions " + |
|
846 |
"(revisionid, docid, rootnodeid, docname, doctype, doctitle, " + |
|
847 |
"user_owner, user_updated, date_created, date_updated) " + |
|
848 |
"VALUES (null, ?, ?, ?, ?, ?, ?, ?, sysdate, sysdate)"); |
|
849 |
// Bind the values to the query and execute it |
|
850 |
pstmt.setString(1, docid); |
|
851 |
pstmt.setLong(2, rnodeid); |
|
852 |
pstmt.setString(3, docname); |
|
853 |
pstmt.setString(4, doctype); |
|
854 |
pstmt.setString(5, doctitle); |
|
855 |
pstmt.setString(6, user_owner); |
|
856 |
pstmt.setString(7, user); |
|
857 |
//pstmt.setDate(6, date_created); |
|
858 |
pstmt.execute(); |
|
859 |
pstmt.close(); |
|
860 |
} |
|
861 |
*/ |
|
862 | 817 |
/** |
863 | 818 |
* Set up the parser handlers for writing the document to the database |
864 | 819 |
*/ |
865 | 820 |
private static XMLReader initializeParser(Connection conn, |
866 |
String action, String docid, String user) { |
|
821 |
String action, String docid, String user) |
|
822 |
throws Exception { |
|
867 | 823 |
XMLReader parser = null; |
868 | 824 |
// |
869 | 825 |
// Set up the SAX document handlers for parsing |
... | ... | |
893 | 849 |
parser.setErrorHandler((ErrorHandler)chandler); |
894 | 850 |
|
895 | 851 |
} catch (Exception e) { |
896 |
System.err.println(e.toString());
|
|
852 |
throw e;
|
|
897 | 853 |
} |
898 | 854 |
|
899 | 855 |
return parser; |
Also available in: Unified diff
changes related to decrease the time of INSERT of document.
With these changes I inserted 200KB file for 3 minutes, 50KB for 50sec.
This is mainly simplifing the DBSAXNode class and
using batching feature of Oracle JDBC driver.