Project

General

Profile

« Previous | Next » 

Revision 5094

SMS-related addition: retrieve docids for a given doctype

View differences:

src/edu/ucsb/nceas/metacat/DBUtil.java
440 440
  }
441 441
  
442 442
  /**
443
   * return all docids with a given doctype
444
   */
445
  public Vector getAllDocidsByType(String doctype, boolean includeRevs) throws SQLException {
446
		Vector<String> resultVector = new Vector<String>();
447
		String accnum = null;
448
		String sep = ".";
449
	    try {
450
	    	PropertyService.getProperty("document.accNumSeparator");
451
	    } catch (PropertyNotFoundException pnfe) {
452
	    	logMetacat.error("could not get property 'accNumSeparator'.  setting to '.': " 
453
	    			+ pnfe.getMessage());  	
454
	    }
455
		PreparedStatement pstmt = null;
456
		DBConnection dbConn = null;
457
		int serialNumber = -1;
458
		try {
459
			dbConn = DBConnectionPool.getDBConnection("DBUtil.getAllDocidsByType");
460
			serialNumber = dbConn.getCheckOutSerialNumber();
461
			StringBuffer sb = new StringBuffer();
462

  
463
			sb.append("SELECT docid, rev FROM " + "( " + "SELECT docid, rev "
464
					+ "FROM xml_documents ");
465
			if (doctype != null) {
466
				sb.append("WHERE doctype LIKE ? ");
467
			}
468
			if (includeRevs) {
469
				sb.append("UNION " + "SELECT docid, rev " + "FROM xml_revisions ");
470
				if (doctype != null) {
471
					sb.append("WHERE doctype LIKE ?");
472
				}
473
			}
474
			sb.append(") subquery GROUP BY docid, rev");
475
			pstmt = dbConn.prepareStatement(sb.toString());
476

  
477
			if (doctype != null) {
478
				pstmt.setString(1, doctype);
479
				if (includeRevs) {
480
					pstmt.setString(2, doctype);
481
				}
482
			}
483
			pstmt.execute();
484
			ResultSet rs = pstmt.getResultSet();
485

  
486
			String id = null;
487
			String rev = null;
488
			while (rs.next()) {
489
				id = rs.getString(1);
490
				rev = rs.getString(2);
491
				if (id != null) {
492
					resultVector.addElement(id + sep + rev);
493
				}
494
			}
495

  
496
			pstmt.close();
497

  
498
		} catch (SQLException e) {
499
			throw new SQLException("DBUtil.getAllDocidsByType(). " + e.getMessage());
500
		} finally {
501
			try {
502
				pstmt.close();
503
			}// try
504
			finally {
505
				DBConnectionPool.returnDBConnection(dbConn, serialNumber);
506
			}// finally
507
		}// finally
508

  
509
		return resultVector;
510
	}
511
  
512
  /**
443 513
   * get the lastest Accession Number from a particular scope
444 514
   */
445 515
  public Vector<String> getAllDocids(String scope)

Also available in: Unified diff