Project

General

Profile

« Previous | Next » 

Revision 956

Added by Jing Tao over 22 years ago

A constructor for this class was added. In the new constructor, user can specify the revision number he want to update. In method writeDocumentToDB, when a update action happend, the rev number would not automatictlly to add one, but it can go to specified number. This is for bug 417.

View differences:

src/edu/ucsb/nceas/metacat/DocumentImpl.java
74 74

  
75 75
  private Connection conn = null;
76 76
  private String docid = null;
77
  private String updatedVersion=null;
77 78
  private String docname = null;
78 79
  private String doctype = null;
79 80
// DOCTITLE attr cleared from the db
......
175 176
    writeDocumentToDB(action, user, pub, catalogid, serverCode);
176 177
  }
177 178
  
179
  /** 
180
   * Construct a new document instance, writing the contents to the database.
181
   * This method is called from DBSAXHandler because we need to know the
182
   * root element name for documents without a DOCTYPE before creating it.
183
   *
184
   * In this constructor, the docid is without rev. There is a string rev to 
185
   * specify the revision user want to upadate. The revion is only need to be
186
   * greater than current one. It is not need to be sequent number just after
187
   * current one. So it is only used in update action
188
   * @param conn the JDBC Connection to which all information is written
189
   * @param rootnodeid - sequence id of the root node in the document
190
   * @param docname - the name of DTD, i.e. the name immediately following 
191
   *        the DOCTYPE keyword ( should be the root element name ) or
192
   *        the root element name if no DOCTYPE declaration provided
193
   *        (Oracle's and IBM parsers are not aware if it is not the 
194
   *        root element name)
195
   * @param doctype - Public ID of the DTD, i.e. the name immediately 
196
   *                  following the PUBLIC keyword in DOCTYPE declaration or
197
   *                  the docname if no Public ID provided or
198
   *                  null if no DOCTYPE declaration provided
199
   * @param docid the docid to use for the UPDATE, no version number
200
   * @param version, need to be update
201
   * @param action the action to be performed (INSERT OR UPDATE)
202
   * @param user the user that owns the document
203
   * @param pub flag for public "read" access on document
204
   * @param serverCode the serverid from xml_replication on which this document
205
   *        resides.
206
   *
207
   */
208
  public DocumentImpl(Connection conn, long rootNodeId, String docName, 
209
                      String docType, String docId, String newRevision, 
210
                      String action, String user,
211
                      String pub, String catalogId, int serverCode)
212
                      throws SQLException, Exception
213
  {
214
    this.conn = conn;
215
    this.rootnodeid = rootNodeId;
216
    this.docname = docName;
217
    this.doctype = docType;
218
    this.docid = docId;
219
    this.updatedVersion = newRevision;
220
    writeDocumentToDB(action, user, pub, catalogId, serverCode);
221
  }
222
  
178 223
  /**
179 224
   * Register a document that resides on the filesystem with the database.
180 225
   * (ie, just an entry in xml_documents, nothing in xml_nodes).
......
320 365
  public int getRev() {
321 366
    return rev;
322 367
  }
323

  
324
  /**
368
  
369
   /**
325 370
   * Print a string representation of the XML document
326 371
   */
327 372
  public String toString()
......
751 796
  private void writeDocumentToDB(String action, String user, String pub, 
752 797
                                 String catalogid, int serverCode) 
753 798
               throws SQLException, Exception {
754

  
755 799
    String sysdate = dbAdapter.getDateTimeFunction();
756 800

  
757 801
    try {
......
793 837
        DocumentImpl.archiveDocRevision( conn, docid, user );
794 838
        DocumentImpl thisdoc = new DocumentImpl(conn, docid);
795 839
        int thisrev = thisdoc.getRev();
796
        thisrev++;
840
        
841
        //if the updated vesion is not greater than current one,
842
        //throw it into a exception
843
        if (Integer.parseInt(updatedVersion)<=thisrev)
844
        {
845
          throw new Exception("Next revision number couldn't be less"
846
                               +" than or equal "+ thisrev);
847
        }
848
        else
849
        {
850
          //set the user specified revision 
851
          thisrev=Integer.parseInt(updatedVersion);
852
        }
853
        
797 854
        // Delete index for the old version of docid
798 855
        // The new index is inserting on the next calls to DBSAXNode
799 856
        pstmt = conn.prepareStatement(
......
946 1003
    AccessionNumber ac = new AccessionNumber(conn, accnum, action);
947 1004
    String docid = ac.getDocid();
948 1005
    String rev = ac.getRev();
949
    
950 1006
    MetaCatUtil.debugMessage("action: " + action + " servercode: " + 
951 1007
                             serverCode + " override: " + override);
952 1008
                        
......
974 1030
        {
975 1031
          MetacatReplication.replLog("lock granted for " + accnum + " from " +
976 1032
                                      server);
977
          XMLReader parser = initializeParser(conn, action, docid, validate,
978
                                            user, groups, pub, serverCode, dtd);
1033
          XMLReader parser = initializeParser(conn, action, docid, updaterev,
1034
                                  validate, user, groups, pub, serverCode, dtd);
979 1035
          conn.setAutoCommit(false);
980 1036
          parser.parse(new InputSource(xml)); 
981 1037
          conn.commit();
......
1030 1086

  
1031 1087
    try 
1032 1088
    { 
1033
      XMLReader parser = initializeParser(conn, action, docid, validate,
1089
      
1090
      XMLReader parser = initializeParser(conn, action, docid, rev, validate,
1034 1091
                                          user, groups, pub, serverCode, dtd);
1035 1092
      conn.setAutoCommit(false);
1036 1093
      parser.parse(new InputSource(xml));
......
1048 1105
    if(serverCode == 1)
1049 1106
    { //start the thread to replicate this new document out to the other servers
1050 1107
      ForceReplicationHandler frh = new ForceReplicationHandler(accnum, action);
1108
      
1051 1109
    }
1052 1110
      
1053 1111
    return(accnum);
......
1140 1198
   * Set up the parser handlers for writing the document to the database
1141 1199
   */
1142 1200
  private static XMLReader initializeParser(Connection conn, String action,
1143
                                   String docid, boolean validate, 
1201
                               String docid, String rev, boolean validate, 
1144 1202
                                   String user, String[] groups, String pub, 
1145 1203
                                   int serverCode, Reader dtd) 
1146 1204
                           throws Exception 
......
1150 1208
    // Set up the SAX document handlers for parsing
1151 1209
    //
1152 1210
    try {
1153
      ContentHandler chandler = new DBSAXHandler(conn, action, docid,
1211
      //create a DBSAXHandler object which has the revision specification
1212
      ContentHandler chandler = new DBSAXHandler(conn, action, docid, rev,
1154 1213
                                                 user, groups, pub, serverCode);
1155 1214
      EntityResolver eresolver= new DBEntityResolver(conn,
1156 1215
                                                 (DBSAXHandler)chandler, dtd);
......
1190 1249
                                         String user) 
1191 1250
                                         throws SQLException {
1192 1251
    String sysdate = dbAdapter.getDateTimeFunction();
1193
    
1194 1252
    // create a record in xml_revisions table 
1195 1253
    // for that document as selected from xml_documents
1196 1254
    PreparedStatement pstmt = conn.prepareStatement(

Also available in: Unified diff