Project

General

Profile

« Previous | Next » 

Revision 9016

Added by Jing Tao about 10 years ago

Add a method to check if a serial id exists.

View differences:

src/edu/ucsb/nceas/metacat/IdentifierManager.java
926 926
     * a matching SID and no value in the "obsoletedBy" field, regardless if it is "archived" or not.
927 927
     * @param sid specified sid which should match.
928 928
     * @return the pid of the head version. The null will be returned if there is no pid found.
929
     * @throws SQLException 
929 930
     */
930
    public Identifier getHeadPID(Identifier sid) {
931
    public Identifier getHeadPID(Identifier sid) throws SQLException {
931 932
        Identifier pid = null;
932 933
        if(sid != null && sid.getValue() != null && !sid.getValue().trim().equals("")) {
933 934
            logMetacat.debug("getting pid of the head version for matching the sid: " + sid.getValue());
......
952 953
            } catch (SQLException e) {
953 954
                logMetacat.error("Error while get the head pid for the sid "+sid.getValue()+" : " 
954 955
                        + e.getMessage());
956
                throw e;
955 957
            } finally {
956 958
                // Return database connection to the pool
957 959
                DBConnectionPool.returnDBConnection(dbConn, serialNumber);
......
960 962
        return pid;
961 963
    }
962 964
    
963
    public boolean systemMetadataExists(String guid) {
965
    /**
966
     * Check if the specified sid exists on the serial id field on the system metadata table
967
     * @param id
968
     * @return true if it exists; false otherwise.
969
     */
970
    public boolean serialIdExists(String sid) throws SQLException {
971
        boolean exists = false;
972
        if(sid != null && !sid.trim().equals("")) {
973
            logMetacat.debug("Check if the  sid: " + sid +" exists on the series_id field of the system metadata table.");
974
            String sql = "select guid from systemMetadata where series_id = ?";
975
            DBConnection dbConn = null;
976
            int serialNumber = -1;
977
            try {
978
                // Get a database connection from the pool
979
                dbConn = DBConnectionPool.getDBConnection("IdentifierManager.serialIdExists");
980
                serialNumber = dbConn.getCheckOutSerialNumber();
981
                // Execute the insert statement
982
                PreparedStatement stmt = dbConn.prepareStatement(sql);
983
                stmt.setString(1, sid);
984
                ResultSet rs = stmt.executeQuery();
985
                if (rs.next()) 
986
                {
987
                    exists = true;
988
                } 
989
                
990
            } catch (SQLException e) {
991
                logMetacat.error("Error while checking if the sid "+sid+" exists on the series_id field of the system metadata table: " 
992
                        + e.getMessage());
993
                throw e;
994
            } finally {
995
                // Return database connection to the pool
996
                DBConnectionPool.returnDBConnection(dbConn, serialNumber);
997
            }
998
        }
999
        return exists;
1000
    }
1001
    
1002
    public boolean systemMetadataExists(String guid) throws SQLException {
964 1003
		logMetacat.debug("looking up system metadata for guid " + guid);
965 1004
		boolean exists = false;
966 1005
		String query = "select guid from systemmetadata where guid = ?";
......
983 1022
		} catch (SQLException e) {
984 1023
			logMetacat.error("Error while looking up the system metadata: "
985 1024
					+ e.getMessage());
1025
			throw e;
986 1026
		} finally {
987 1027
			// Return database connection to the pool
988 1028
			DBConnectionPool.returnDBConnection(dbConn, serialNumber);

Also available in: Unified diff