Project

General

Profile

« Previous | Next » 

Revision 1841

Added by Jing Tao over 20 years ago

Add a checking for xml_nodes insert finished, then start build index table.

View differences:

src/edu/ucsb/nceas/metacat/DBSAXHandler.java
400 400
    int step = 0;
401 401
    int counter = 0;
402 402

  
403
    try {
404

  
403
    try 
404
    {
405
      // stop 5 second
406
      Thread.sleep(5000);
405 407
      // Opening separate db connection for writing XML Index
406 408
      dbConn=DBConnectionPool.getDBConnection("DBSAXHandler.run");
407 409
      serialNumber=dbConn.getCheckOutSerialNumber();
408 410
      dbConn.setAutoCommit(false);
411
      //make sure record is done
412
      checkDocumentTable();   
413
      // Going through the elements of the document and writing its Index
414
      Enumeration nodes = nodeIndex.elements();
415
      while ( nodes.hasMoreElements() ) {
416
        currNode = (DBSAXNode)nodes.nextElement();
417
        currNode.updateNodeIndex(dbConn, docid, doctype);
418
      }
419
      dbConn.commit();
409 420

  
421
    } catch (Exception e) {
422
      try {
423
        dbConn.rollback();
424
        //dbconn.close();
425
      } catch (SQLException sqle) {}
426
      MetaCatUtil.debugMessage("Error in DBSAXHandler.run " + 
427
                                e.getMessage(), 30);
428
      
429
    }
430
    finally
431
    {
432
      DBConnectionPool.returnDBConnection(dbConn, serialNumber);
433
    }//finally
434
  }
435

  
436
  /* method to make sure insert is finished before create index table
437
   * If new version of record is in xml_documents every thing will be fine
438
   */
439
  private void checkDocumentTable() throws Exception
440
  {
441
    
442
    DBConnection dbConn = null;
443
    int serialNumber = -1;
444
   
445
    try 
446
    {
447
       // Opening separate db connection for writing XML Index
448
      dbConn=DBConnectionPool.getDBConnection("DBSAXHandler.checkDocumentTable");
449
      serialNumber=dbConn.getCheckOutSerialNumber();
450
     
410 451
      //the following while loop construct checks to make sure that the docid
411 452
      //of the document that we are trying to index is already
412 453
      //in the xml_documents table.  if this is not the case, the foreign
......
416 457
      long startTime = System.currentTimeMillis();
417 458
      while(!inxmldoc)
418 459
      {
419
        String xmlDocumentsCheck = "select distinct docid from xml_documents";
460
        String xmlDocumentsCheck = "select distinct docid from xml_documents" +
461
                                   " where docid ='" + docid + "' and " +
462
                                   " rev ='" + revision + "'";
463
       
420 464
        PreparedStatement xmlDocCheck =
421 465
                                 dbConn.prepareStatement(xmlDocumentsCheck);
422 466
        // Increase usage count
......
424 468
        xmlDocCheck.execute();
425 469
        ResultSet doccheckRS = xmlDocCheck.getResultSet();
426 470
        boolean tableHasRows = doccheckRS.next();
427
        Vector docids = new Vector();
428
        while(tableHasRows)
471
        if (tableHasRows)
429 472
        {
430
          docids.add(doccheckRS.getString(1).trim());
431
          tableHasRows = doccheckRS.next();
473
           MetaCatUtil.debugMessage("=========== find the correct document", 35);
474
           inxmldoc = true;
432 475
        }
433

  
434
        for(int i=0; i<docids.size(); i++)
435
        {
436
          String d = ((String)docids.elementAt(i)).trim();
437
          if(docid.trim().equals(d))
438
          {
439
            inxmldoc = true;
440
          }
441
        }
442
        doccheckRS.close();
443
        xmlDocCheck.close();
444
        // make sure the while loop will be ended in reseaonable time
445
        long stopTime = System.currentTimeMillis();
446
        if ((stopTime - startTime) > INDEXDELAY)
447
        {
448
          throw new Exception("Couldn't find the docid for index build in" +
476
         doccheckRS.close();
477
         xmlDocCheck.close();
478
         // make sure the while loop will be ended in reseaonable time
479
         long stopTime = System.currentTimeMillis();
480
         if ((stopTime - startTime) > INDEXDELAY)
481
         {
482
           throw new Exception("Couldn't find the docid for index build in" +
449 483
                              "reseaonable time!");
450
        }
451
      }
452

  
453
      // Going through the elements of the document and writing its Index
454
      Enumeration nodes = nodeIndex.elements();
455
      while ( nodes.hasMoreElements() ) {
456
        currNode = (DBSAXNode)nodes.nextElement();
457
        currNode.updateNodeIndex(dbConn, docid, doctype);
458
      }
459

  
460

  
461
      dbConn.commit();
462

  
463
      //if this is a package file
464
    
465
   
466

  
467
    } catch (Exception e) {
468
      try {
484
         }
485
       }//while
486
    } 
487
    catch (Exception e) 
488
    {
489
      try 
490
      {
469 491
        dbConn.rollback();
470 492
        //dbconn.close();
471
      } catch (SQLException sqle) {}
493
      } 
494
      catch (SQLException sqle) 
495
      {}
472 496
      MetaCatUtil.debugMessage("Error in DBSAXHandler.run " + 
473 497
                                e.getMessage(), 30);
474 498
      
......
477 501
    {
478 502
      DBConnectionPool.returnDBConnection(dbConn, serialNumber);
479 503
    }//finally
504
  
480 505
  }
481

  
506
  
482 507
  /** SAX Handler that is called for each XML text node */
483 508
  public void characters(char[] cbuf, int start, int len) throws SAXException 
484 509
  {

Also available in: Unified diff