Project

General

Profile

« Previous | Next » 

Revision 3140

Added by berkley over 17 years ago

added getalldocids function to get all docids that match a certain scope.

View differences:

DBUtil.java
405 405
  }
406 406
  
407 407
  /**
408
   * get the lastest Accession Number from a particular scope
409
   */
410
  public Vector getAllDocids(String scope)
411
        throws SQLException  {
412
    Vector resultVector = new Vector();
413
    String accnum = null;
414
    String sep = MetaCatUtil.getOption("accNumSeparator");
415
    PreparedStatement pstmt = null;
416
    DBConnection dbConn = null;
417
    int serialNumber = -1;
418
    try 
419
    {
420
      dbConn=DBConnectionPool.
421
                getDBConnection("DBUtil.getAllDocids");
422
      serialNumber=dbConn.getCheckOutSerialNumber();
423
      StringBuffer sb = new StringBuffer();
424
      
425
      sb.append("SELECT docid, rev FROM " +
426
                "( " +
427
                "SELECT docid, rev " + 
428
                "FROM xml_documents ");
429
      if(scope != null)
430
      {
431
        sb.append("WHERE docid LIKE ? ");
432
      }
433
      sb.append("UNION " + 
434
                "SELECT docid, rev " + 
435
                "FROM xml_revisions ");
436
      if(scope != null)
437
      {
438
        sb.append("WHERE docid LIKE ?");
439
      }
440
      sb.append(") subquery GROUP BY docid, rev");
441
      pstmt = dbConn.prepareStatement(sb.toString());
442

  
443
      if(scope != null)
444
      {
445
        pstmt.setString(1,scope + sep + "%");
446
        pstmt.setString(2,scope + sep + "%");
447
      }
448
      pstmt.execute();
449
      ResultSet rs = pstmt.getResultSet();
450
      
451
      long max = 0;
452
      String id = null;
453
      String rev = null;
454
      while(rs.next()){
455
    	  id = rs.getString(1);
456
        rev = rs.getString(2);
457
    	  if(id != null){
458
    		  //temp = temp.substring(id.indexOf(scope) + scope.length() + 1);
459
          resultVector.addElement(id + sep + rev);
460
        }
461
      }
462
      
463
      pstmt.close();
464

  
465
    } catch (SQLException e) {
466
      throw new SQLException("DBUtil.getAllDocids(). " + e.getMessage());
467
    }
468
    finally
469
    {
470
      try
471
      {
472
        pstmt.close();
473
      }//try
474
      finally
475
      {
476
        DBConnectionPool.returnDBConnection(dbConn, serialNumber);
477
      }//finally
478
    }//finally
479

  
480
    return resultVector;
481
  }
482
  
483
  /**
408 484
   * To a given docid, found a dataset docid which conatains the the given doicd
409 485
   * This will be done by searching xml_relation table
410 486
   * If couldn't find, null will be return

Also available in: Unified diff