Project

General

Profile

« Previous | Next » 

Revision 10185

Added by Jing Tao over 7 years ago

Add a new method to determine if a docid and rev is in the xml_revision table.

View differences:

src/edu/ucsb/nceas/metacat/IdentifierManager.java
2439 2439
        logMetacat.debug("IdentifierManager.getObjectFilePath - the file path for the object with localId "+localId+" which is scienceMetacat "+isScienceMetadata+", is "+documentPath+". If the value is null, this means we can't find it.");
2440 2440
        return documentPath;   
2441 2441
    }
2442
    
2443
    /**
2444
     * IF the given localId exists on the xml_revisions table
2445
     * @param localId
2446
     * @return
2447
     * @throws SQLException
2448
     */
2449
    public boolean existsInXmlLRevisionTable(String docid, int rev) throws SQLException{
2450
        boolean exist =false;
2451
        DBConnection conn = null;
2452
        int serialNumber = -1;
2453
        PreparedStatement pstmt = null;
2454
        ResultSet rs = null;
2455
        logMetacat.info("IdentifierManager.existsInXmlLRevisionTable - the docid is "+docid +" and rev is "+rev);
2456
        try {
2457
            //check out DBConnection
2458
            conn = DBConnectionPool.getDBConnection("IdentifierManager.existsInXmlLRevisionTable");
2459
            serialNumber = conn.getCheckOutSerialNumber();
2460
            // Check if the document exists in xml_revisions table.
2461
            //this only archives a document from xml_documents to xml_revisions (also archive the xml_nodes table as well)
2462
            logMetacat.debug("IdentifierManager.existsInXmlLRevisionTable - check if the document "+docid+"."+rev+ " exists in the xml_revision table");
2463
            pstmt = conn.prepareStatement("SELECT rev, docid FROM xml_revisions WHERE docid = ? AND rev = ?");
2464
            pstmt.setString(1, docid);
2465
            pstmt.setInt(2, rev);
2466
            logMetacat.debug("IdentifierManager.existsInXmlLRevisionTable - executing SQL: " + pstmt.toString());
2467
            pstmt.execute();
2468
            rs = pstmt.getResultSet();
2469
            if(rs.next()){
2470
                exist = true;
2471
            }
2472
            conn.increaseUsageCount(1);
2473
        } catch (Exception e) {
2474
            throw new SQLException(e.getMessage());
2475
        } finally {
2476
            // Return database connection to the pool
2477
            DBConnectionPool.returnDBConnection(conn, serialNumber);
2478
            if(rs != null) {
2479
                rs.close();
2480
            }
2481
            if(pstmt != null) {
2482
                pstmt.close();
2483
            }
2484
        }
2485
        logMetacat.info("IdentifierManager.existsInXmlLRevisionTable - Does the docid "+docid+"."+rev+ " exist in the xml_revision table? - "+exist);
2486
        return exist;
2487
    }
2442 2488
}
2443 2489

  

Also available in: Unified diff