Project

General

Profile

« Previous | Next » 

Revision 1292

Added by Jing Tao almost 22 years ago

Merge cvs branch replication to cvs head.

View differences:

DBUtil.java
470 470

  
471 471
    return accnum;
472 472
  }
473

  
473
  
474
  /**
475
   * To a given docid, found a dataset docid which conatains the the given doicd
476
   * This will be done by searching xml_relation table
477
   * If couldn't find, null will be return
478
   * @param givenDocId, the docid which we want to find
479
   */
480
  public static String findDataSetDocIdForGivenDocument(String givenDocId)
481
  {
482
    // Prepared statement for sql
483
    PreparedStatement pStmt = null;
484
    // Result set
485
    ResultSet resultSet = null;
486
    // String to store the data set docid
487
    String dataSetDocId = null;
488
    // DBConnection will be checkout
489
    DBConnection dbConn = null;
490
    int serialNumber = -1;
491
    // String to store the sql command
492
    String sqlCommand = null;
493
    try
494
    {
495
      // Checkout DBConnection from pool
496
      dbConn=DBConnectionPool.
497
                  getDBConnection("DBUtil.findDataSetDocIdForGivenDocument");
498
      serialNumber=dbConn.getCheckOutSerialNumber();
499
      // Sql command to chose a docid from xm_relation table
500
      sqlCommand = "select docid from xml_relation where object like ? or " 
501
                                                    + "subject like ?";
502
      // Prepared statement
503
      pStmt = dbConn.prepareStatement(sqlCommand);
504
      // Bind variable
505
      pStmt.setString(1, givenDocId);
506
      pStmt.setString(2, givenDocId);
507
      // Excute prepared statement
508
      pStmt.execute();
509
      // Get result set
510
      resultSet = pStmt.getResultSet();
511
      
512
      // There has record
513
      if (resultSet.next())
514
      {
515
        // Put the docid into dataSetDocid
516
        dataSetDocId = resultSet.getString(1);
517
        return dataSetDocId;
518
      }//if
519
      else
520
      {
521
        // No record in xml_relation table for given doicd, null returned
522
        return dataSetDocId;
523
      }//else
524
    
525
    }//try
526
    catch ( SQLException e)
527
    {
528
      // Print out excepition
529
      MetaCatUtil.debugMessage("Error in DBUil.findDataSEtDocIdForGivenDocument"
530
                                +e.getMessage(), 30);
531
      // return null
532
      return dataSetDocId;
533
     
534
    }//catch
535
    finally
536
    {
537
      try
538
      {
539
        // Close result set
540
        resultSet.close();
541
        // Close preparedStatement
542
        pStmt.close();
543
      }//try
544
      catch ( SQLException e)
545
      {
546
        // Print out excepition
547
        MetaCatUtil.debugMessage("Error in DBUil.findDataSetDocIdForGivenDoc"
548
                                + e.getMessage(), 30);
549
     
550
      }//catch
551
      finally
552
      {
553
        // Return DBConnection to the pool
554
        DBConnectionPool.returnDBConnection(dbConn, serialNumber);
555
      }//finally
556
    }//finally
557
        
558
  }//findDataSetDocIdForGivenDocument
559
  
560
  /**
561
   * Method to get current revision and doctype for a given docid
562
   * The output will look like "rev;doctype"
563
   * @param givenDocId, the docid which we want 
564
   */
565
  public String getCurrentRevisionAndDocTypeForGivenDocument(String givenDocId)
566
                                                 throws SQLException
567
  {
568
    // DBConection for JDBC
569
    DBConnection dbConn = null;
570
    int serialNumber = -1;
571
    // Prepared Statement
572
    PreparedStatement pstmt = null;
573
    // String to store a docid without rev
574
    String docIdWithoutRevision = null;
575
    // SQL comand
576
    String sqlCommand = null;
577
    // Resulst set
578
    ResultSet rs = null;
579
    // String to store the revision
580
    String revision = null;
581
    // String to store the doctype
582
    String docType = null;
583
    
584
    // Get docid without rev
585
    docIdWithoutRevision = MetaCatUtil.getDocIdFromString(givenDocId);
586
    // SQL comand is:
587
    sqlCommand = "select rev, doctype from xml_documents where docid like ?";
588
    
589
    try
590
    {
591
      // Check out the connection
592
      dbConn=DBConnectionPool.
593
         getDBConnection("DBUtil.getCurrentRevisionAndDocTypeForGivenDocument");
594
      serialNumber=dbConn.getCheckOutSerialNumber();
595
      
596
      // Prepare the sql command
597
      pstmt = dbConn.prepareStatement(sqlCommand);
598
      // Bin vairable
599
      pstmt.setString(1, docIdWithoutRevision);
600
      // Excute the prepared statement
601
      pstmt.execute();
602
      // Get result set
603
      rs = pstmt.getResultSet();
604
      // If there is some record
605
      if (rs.next())
606
      {
607
        revision = rs.getString(1);
608
        docType = rs.getString(2);
609
      }//if
610
      else
611
      {
612
        // No record, throw a exception
613
        throw new 
614
              SQLException("There is not record for given docid:"+givenDocId);
615
      }//else
616
        
617
    }
618
    finally
619
    {
620
      try
621
      {
622
        // Close result set
623
        rs.close();
624
        // Close preparedStatement
625
        pstmt.close();
626
      }//try
627
      catch ( SQLException e)
628
      {
629
        // Print out excepition
630
        MetaCatUtil.debugMessage("Error in DBUil.getCurrentRevisionAndDocType"
631
                                + e.getMessage(), 30);
632
     
633
      }//catch
634
      finally
635
      {
636
        // Return DBConnection to the pool
637
        DBConnectionPool.returnDBConnection(dbConn, serialNumber);
638
      }//finally
639
    }
640
    return revision+";"+docType;
641
  }//getCurrentRevisionAndDocTypeForGivenDocument
642
   
474 643
}

Also available in: Unified diff