Project

General

Profile

« Previous | Next » 

Revision 9015

Added by Jing Tao about 10 years ago

Add a method to get the pid of the head version of a sid.

View differences:

src/edu/ucsb/nceas/metacat/IdentifierManager.java
920 920
        return guid;
921 921
    }
922 922
    
923
    /**
924
     * Get the pid of the head (current) version of objects match the specified sid.
925
     * DataONE defines the latest version as "current" if the object in question has 
926
     * a matching SID and no value in the "obsoletedBy" field, regardless if it is "archived" or not.
927
     * @param sid specified sid which should match.
928
     * @return the pid of the head version. The null will be returned if there is no pid found.
929
     */
930
    public Identifier getHeadPID(Identifier sid) {
931
        Identifier pid = null;
932
        if(sid != null && sid.getValue() != null && !sid.getValue().trim().equals("")) {
933
            logMetacat.debug("getting pid of the head version for matching the sid: " + sid.getValue());
934
            String sql = "select guid from systemMetadata where obsoleted_by is null and series_id = ?";
935
            DBConnection dbConn = null;
936
            int serialNumber = -1;
937
            try {
938
                // Get a database connection from the pool
939
                dbConn = DBConnectionPool.getDBConnection("IdentifierManager.getHeadPID");
940
                serialNumber = dbConn.getCheckOutSerialNumber();
941
                // Execute the insert statement
942
                PreparedStatement stmt = dbConn.prepareStatement(sql);
943
                stmt.setString(1, sid.getValue());
944
                ResultSet rs = stmt.executeQuery();
945
                if (rs.next()) 
946
                {
947
                    pid = new Identifier();
948
                    pid.setValue(rs.getString(1));
949
                   
950
                } 
951
                
952
            } catch (SQLException e) {
953
                logMetacat.error("Error while get the head pid for the sid "+sid.getValue()+" : " 
954
                        + e.getMessage());
955
            } finally {
956
                // Return database connection to the pool
957
                DBConnectionPool.returnDBConnection(dbConn, serialNumber);
958
            }
959
        }
960
        return pid;
961
    }
962
    
923 963
    public boolean systemMetadataExists(String guid) {
924 964
		logMetacat.debug("looking up system metadata for guid " + guid);
925 965
		boolean exists = false;

Also available in: Unified diff