Fixed Coverity Issues Reported

This commit is contained in:
Santhosh Edukulla 2014-07-25 16:39:16 +05:30
parent 3bb344281a
commit 2018d7d977
1 changed files with 8 additions and 20 deletions

View File

@ -115,33 +115,21 @@ public class DefaultEndPointSelector implements EndPointSelector {
// TODO: order by rand() is slow if there are lot of hosts
sbuilder.append(" ORDER by rand() limit 1");
String sql = sbuilder.toString();
PreparedStatement pstmt = null;
ResultSet rs = null;
HostVO host = null;
TransactionLegacy txn = TransactionLegacy.currentTxn();
try {
pstmt = txn.prepareStatement(sql);
try(PreparedStatement pstmt = txn.prepareStatement(sql);) {
pstmt.setLong(1, poolId);
rs = pstmt.executeQuery();
while (rs.next()) {
long id = rs.getLong(1);
host = hostDao.findById(id);
try(ResultSet rs = pstmt.executeQuery();) {
while (rs.next()) {
long id = rs.getLong(1);
host = hostDao.findById(id);
}
}catch (SQLException e) {
s_logger.warn("can't find endpoint", e);
}
} catch (SQLException e) {
s_logger.warn("can't find endpoint", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
}
if (host == null) {
return null;
}