Skip to content

Commit 3bb3442

Browse files
committed
Fixed Coverity issues Reported
1 parent 0a5940c commit 3bb3442

1 file changed

Lines changed: 22 additions & 45 deletions

File tree

‎engine/schema/src/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java‎

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.sql.PreparedStatement;
2020
import java.sql.ResultSet;
21-
import java.sql.SQLException;
2221
import java.util.ArrayList;
2322
import java.util.Date;
2423
import java.util.List;
@@ -170,71 +169,49 @@ public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId, long
170169
@Override
171170
public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId, long datacenterId, long podId, VMTemplateStoragePoolVO.Status downloadState) {
172171
TransactionLegacy txn = TransactionLegacy.currentTxn();
173-
PreparedStatement pstmt = null;
174172
List<VMTemplateStoragePoolVO> result = new ArrayList<VMTemplateStoragePoolVO>();
175-
ResultSet rs = null;
176-
try {
177-
String sql = DOWNLOADS_STATE_DC_POD;
178-
pstmt = txn.prepareStatement(sql);
179-
173+
String sql = DOWNLOADS_STATE_DC_POD;
174+
try(PreparedStatement pstmt = txn.prepareStatement(sql);) {
180175
pstmt.setLong(1, datacenterId);
181176
pstmt.setLong(2, podId);
182177
pstmt.setLong(3, templateId);
183178
pstmt.setString(4, downloadState.toString());
184-
rs = pstmt.executeQuery();
185-
while (rs.next()) {
186-
// result.add(toEntityBean(rs, false)); TODO: this is buggy in
187-
// GenericDaoBase for hand constructed queries
188-
long id = rs.getLong(1); // ID column
189-
result.add(findById(id));
179+
try(ResultSet rs = pstmt.executeQuery();) {
180+
while (rs.next()) {
181+
// result.add(toEntityBean(rs, false)); TODO: this is buggy in
182+
// GenericDaoBase for hand constructed queries
183+
long id = rs.getLong(1); // ID column
184+
result.add(findById(id));
185+
}
186+
}catch (Exception e) {
187+
s_logger.warn("Exception: ", e);
190188
}
191189
} catch (Exception e) {
192190
s_logger.warn("Exception: ", e);
193-
} finally {
194-
try {
195-
if (rs != null) {
196-
rs.close();
197-
}
198-
if (pstmt != null) {
199-
pstmt.close();
200-
}
201-
} catch (SQLException e) {
202-
}
203191
}
204192
return result;
205193

206194
}
207195

208196
public List<VMTemplateStoragePoolVO> listByHostTemplate(long hostId, long templateId) {
209197
TransactionLegacy txn = TransactionLegacy.currentTxn();
210-
PreparedStatement pstmt = null;
211198
List<VMTemplateStoragePoolVO> result = new ArrayList<VMTemplateStoragePoolVO>();
212-
ResultSet rs = null;
213-
try {
214-
String sql = HOST_TEMPLATE_SEARCH;
215-
pstmt = txn.prepareStatement(sql);
216-
199+
String sql = HOST_TEMPLATE_SEARCH;
200+
try(PreparedStatement pstmt = txn.prepareStatement(sql);) {
217201
pstmt.setLong(1, hostId);
218202
pstmt.setLong(2, templateId);
219-
rs = pstmt.executeQuery();
220-
while (rs.next()) {
221-
// result.add(toEntityBean(rs, false)); TODO: this is buggy in
222-
// GenericDaoBase for hand constructed queries
223-
long id = rs.getLong(1); // ID column
224-
result.add(findById(id));
203+
try(ResultSet rs = pstmt.executeQuery();) {
204+
while (rs.next()) {
205+
// result.add(toEntityBean(rs, false)); TODO: this is buggy in
206+
// GenericDaoBase for hand constructed queries
207+
long id = rs.getLong(1); // ID column
208+
result.add(findById(id));
209+
}
210+
}catch (Exception e) {
211+
s_logger.warn("Exception: ", e);
225212
}
226213
} catch (Exception e) {
227214
s_logger.warn("Exception: ", e);
228-
} finally {
229-
try {
230-
if (rs != null) {
231-
rs.close();
232-
}
233-
if (pstmt != null) {
234-
pstmt.close();
235-
}
236-
} catch (SQLException e) {
237-
}
238215
}
239216
return result;
240217

0 commit comments

Comments
 (0)