Project

General

Profile

« Previous | Next » 

Revision 9465

Added by Jing Tao over 8 years ago

Close the sql statements on the four methods - getGUID, getHeadPID, systemMetadataSIDExist and systemMetadataPIDExist.

View differences:

IdentifierManager.java
928 928
        
929 929
        DBConnection dbConn = null;
930 930
        int serialNumber = -1;
931
        PreparedStatement stmt = null;
931 932
        try {
932 933
            // Get a database connection from the pool
933 934
            dbConn = DBConnectionPool.getDBConnection("IdentifierManager.getGUID");
934 935
            serialNumber = dbConn.getCheckOutSerialNumber();
935 936
            
936 937
            // Execute the insert statement
937
            PreparedStatement stmt = dbConn.prepareStatement(query);
938
            stmt = dbConn.prepareStatement(query);
938 939
            stmt.setString(1, docid);
939 940
            stmt.setInt(2, rev);
940 941
            ResultSet rs = stmt.executeQuery();
......
946 947
            {
947 948
            	throw new McdbDocNotFoundException("No guid registered for docid " + docid + "." + rev);
948 949
            }
949
            
950
            if(rs != null) {
951
                rs.close();
952
            }
950 953
        } catch (SQLException e) {
951 954
            logMetacat.error("Error while looking up the guid: " 
952 955
                    + e.getMessage());
953 956
        } finally {
954
            // Return database connection to the pool
955
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
957
            try {
958
                if(stmt != null) {
959
                    stmt.close();
960
                }
961
            } catch (Exception e) {
962
                logMetacat.warn("Couldn't close the prepared statement since "+e.getMessage());
963
            } finally {
964
                // Return database connection to the pool
965
                DBConnectionPool.returnDBConnection(dbConn, serialNumber);
966
            }
967
            
956 968
        }
957 969
        
958 970
        return guid;
......
977 989
            String sql = "select guid from systemMetadata where series_id = ? order by date_uploaded DESC";
978 990
            DBConnection dbConn = null;
979 991
            int serialNumber = -1;
992
            PreparedStatement stmt = null;
980 993
            int endsCount = 0;
981 994
            boolean hasError = false;
982 995
            try {
......
984 997
                dbConn = DBConnectionPool.getDBConnection("IdentifierManager.getHeadPID");
985 998
                serialNumber = dbConn.getCheckOutSerialNumber();
986 999
                // Execute the insert statement
987
                PreparedStatement stmt = dbConn.prepareStatement(sql);
1000
                stmt = dbConn.prepareStatement(sql);
988 1001
                stmt.setString(1, sid.getValue());
989 1002
                ResultSet rs = stmt.executeQuery();
990 1003
                boolean hasNext = rs.next();
......
1062 1075
                    //it is not a sid or at least we don't have anything to match it.
1063 1076
                    //do nothing, so null will be returned
1064 1077
                }
1078
                if(rs != null) {
1079
                    rs.close();
1080
                }
1065 1081
                
1066 1082
            } catch (SQLException e) {
1067 1083
                logMetacat.error("Error while get the head pid for the sid "+sid.getValue()+" : " 
1068 1084
                        + e.getMessage());
1069 1085
                throw e;
1070 1086
            } finally {
1071
                // Return database connection to the pool
1072
                DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1087
                try {
1088
                    if(stmt != null) {
1089
                        stmt.close();
1090
                    }
1091
                } catch (Exception e) {
1092
                    logMetacat.warn("Couldn't close the prepared statement since "+e.getMessage());
1093
                } finally {
1094
                    // Return database connection to the pool
1095
                    DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1096
                }
1073 1097
            }
1074 1098
        }
1075 1099
        return pid;
......
1101 1125
            String sql = "select guid from systemMetadata where series_id = ?";
1102 1126
            DBConnection dbConn = null;
1103 1127
            int serialNumber = -1;
1128
            PreparedStatement stmt = null;
1104 1129
            try {
1105 1130
                // Get a database connection from the pool
1106 1131
                dbConn = DBConnectionPool.getDBConnection("IdentifierManager.serialIdExists");
1107 1132
                serialNumber = dbConn.getCheckOutSerialNumber();
1108 1133
                // Execute the insert statement
1109
                PreparedStatement stmt = dbConn.prepareStatement(sql);
1134
                stmt = dbConn.prepareStatement(sql);
1110 1135
                stmt.setString(1, sid);
1111 1136
                ResultSet rs = stmt.executeQuery();
1112 1137
                if (rs.next()) 
1113 1138
                {
1114 1139
                    exists = true;
1115 1140
                } 
1116
                
1141
                if(rs != null) {
1142
                    rs.close();
1143
                }
1117 1144
            } catch (SQLException e) {
1118 1145
                logMetacat.error("Error while checking if the sid "+sid+" exists on the series_id field of the system metadata table: " 
1119 1146
                        + e.getMessage());
1120 1147
                throw e;
1121 1148
            } finally {
1122
                // Return database connection to the pool
1123
                DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1149
                try {
1150
                    if(stmt != null) {
1151
                        stmt.close();
1152
                    }
1153
                } catch (Exception e) {
1154
                    logMetacat.warn("Couldn't close the prepared statement since "+e.getMessage());
1155
                } finally {
1156
                    // Return database connection to the pool
1157
                    DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1158
                }
1124 1159
            }
1125 1160
        }
1126 1161
        return exists;
......
1147 1182
		String query = "select guid from systemmetadata where guid = ?";
1148 1183
		DBConnection dbConn = null;
1149 1184
		int serialNumber = -1;
1185
		PreparedStatement stmt = null;
1150 1186
		if(guid != null && !guid.trim().equals("")) {
1151 1187
		    try {
1152 1188
	            // Get a database connection from the pool
......
1154 1190
	            serialNumber = dbConn.getCheckOutSerialNumber();
1155 1191

  
1156 1192
	            // Execute the insert statement
1157
	            PreparedStatement stmt = dbConn.prepareStatement(query);
1193
	            stmt = dbConn.prepareStatement(query);
1158 1194
	            stmt.setString(1, guid);
1159 1195
	            ResultSet rs = stmt.executeQuery();
1160 1196
	            if (rs.next()) {
1161 1197
	                exists = true;
1162 1198
	            }
1199
	            if(rs != null) {
1200
	                rs.close();
1201
	            }
1163 1202

  
1164 1203
	        } catch (SQLException e) {
1165 1204
	            logMetacat.error("Error while looking up the system metadata: "
1166 1205
	                    + e.getMessage());
1167 1206
	            throw e;
1168 1207
	        } finally {
1169
	            // Return database connection to the pool
1170
	            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1208
	            try {
1209
	                if(stmt != null) {
1210
	                    stmt.close();
1211
	                }
1212
	            } catch (Exception e) {
1213
	                logMetacat.warn("Couldn't close the prepared statement since "+e.getMessage());
1214
	            } finally {
1215
	                // Return database connection to the pool
1216
	                DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1217
	            }
1171 1218
	        }
1172 1219
		}
1173 1220
		return exists;

Also available in: Unified diff