Revision 9629
Added by Jing Tao over 8 years ago
src/edu/ucsb/nceas/metacat/IdentifierManager.java | ||
---|---|---|
31 | 31 |
import java.sql.Timestamp; |
32 | 32 |
import java.util.ArrayList; |
33 | 33 |
import java.util.Date; |
34 |
import java.util.HashMap; |
|
34 | 35 |
import java.util.Hashtable; |
35 | 36 |
import java.util.List; |
36 | 37 |
import java.util.Vector; |
... | ... | |
992 | 993 |
PreparedStatement stmt = null; |
993 | 994 |
int endsCount = 0; |
994 | 995 |
boolean hasError = false; |
996 |
HashMap<String, String> obsoletesIdGuidMap = new HashMap<String, String>();//the key is an obsoletes id, the value is an guid |
|
995 | 997 |
try { |
996 | 998 |
// Get a database connection from the pool |
997 | 999 |
dbConn = DBConnectionPool.getDBConnection("IdentifierManager.getHeadPID"); |
... | ... | |
1008 | 1010 |
while(hasNext) { |
1009 | 1011 |
String guidStr = rs.getString(1); |
1010 | 1012 |
String obsoletedByStr = rs.getString(2); |
1011 |
String obsoetesStr = rs.getString(3); |
|
1013 |
String obsoletesStr = rs.getString(3);
|
|
1012 | 1014 |
Identifier guid = new Identifier(); |
1013 | 1015 |
guid.setValue(guidStr); |
1016 |
if(obsoletesStr != null && !obsoletesStr.trim().equals("")) { |
|
1017 |
if(obsoletesIdGuidMap.containsKey(obsoletesStr) && !guidStr.equals(obsoletesIdGuidMap.get(obsoletesStr))) { |
|
1018 |
logMetacat.error("Both id "+guidStr+" and id "+obsoletesIdGuidMap.get(obsoletesStr)+" obsoletes the id"+obsoletesStr+ |
|
1019 |
". It is illegal. So the head pid maybe is wrong."); |
|
1020 |
hasError = true; |
|
1021 |
} |
|
1022 |
obsoletesIdGuidMap.put(obsoletesStr, guidStr); |
|
1023 |
} |
|
1014 | 1024 |
if(first) { |
1015 | 1025 |
firstOne = guid; |
1016 | 1026 |
first =false; |
... | ... | |
1036 | 1046 |
endsCount++; |
1037 | 1047 |
} |
1038 | 1048 |
} else { |
1049 |
logMetacat.debug("The object "+obsoletedBy+" which obsoletes "+guidStr+" is missing."); |
|
1039 | 1050 |
//obsoletedBySysmeta doesn't exist; it means the object is missing |
1040 | 1051 |
//generally, we consider it we generally consider it a type 2 end except: |
1041 | 1052 |
//there is another object in the chain (has the same series id) that obsoletes the missing object. |
1042 |
String sql2 = "select guid from systemMetadata where obsoletes = ? and series_id = ?"; |
|
1053 |
/*String sql2 = "select guid from systemMetadata where obsoletes = ? and series_id = ?";
|
|
1043 | 1054 |
PreparedStatement stmt2 = dbConn.prepareStatement(sql2); |
1044 | 1055 |
stmt2.setString(1, obsoletedBy.getValue()); |
1045 | 1056 |
stmt2.setString(2, sid.getValue()); |
... | ... | |
1062 | 1073 |
// something is wrong - there are more than one objects obsolete the missing object! |
1063 | 1074 |
hasError = true; |
1064 | 1075 |
break; |
1076 |
}*/ |
|
1077 |
if(obsoletesIdGuidMap != null && obsoletesIdGuidMap.containsKey(obsoletedByStr)) { |
|
1078 |
//This is the exception - another object in the chain (has the same series id) that obsoletes the missing object |
|
1079 |
//The obsoletesIdGuidMap maintains the relationship (with the same series id) |
|
1080 |
logMetacat.debug("Though the object "+obsoletedBy+" which obsoletes "+guidStr+" is missing."+ |
|
1081 |
" However, there is another object "+obsoletesIdGuidMap.get(obsoletedByStr)+" in the chain obsoleting it. So it is not an end."); |
|
1082 |
|
|
1083 |
} else { |
|
1084 |
//the exception (another object in the chain (has the same series id) that obsoletes the missing object) doesn't exist |
|
1085 |
// it is a type 2 end |
|
1086 |
logMetacat.debug(""+guidStr+" is a type 2 end for sid "+sid.getValue()); |
|
1087 |
pid = guid; |
|
1088 |
endsCount++; |
|
1065 | 1089 |
} |
1066 | 1090 |
} |
1067 | 1091 |
} |
Also available in: Unified diff
Use a hashmap to replace a sql query to improve performance in the getHeadPID method.