@@ -258,36 +258,25 @@ public List<VMTemplateHostVO> listByTemplateHostStatus(long templateId, long hos
258258 @ Override
259259 public List <VMTemplateHostVO > listByTemplateStatus (long templateId , long datacenterId , long podId , VMTemplateHostVO .Status downloadState ) {
260260 TransactionLegacy txn = TransactionLegacy .currentTxn ();
261- PreparedStatement pstmt = null ;
262261 List <VMTemplateHostVO > result = new ArrayList <VMTemplateHostVO >();
263- ResultSet rs = null ;
264- try {
265- String sql = DOWNLOADS_STATE_DC_POD ;
266- pstmt = txn .prepareStatement (sql );
267-
262+ String sql = DOWNLOADS_STATE_DC_POD ;
263+ try (PreparedStatement pstmt = txn .prepareStatement (sql );) {
268264 pstmt .setLong (1 , datacenterId );
269265 pstmt .setLong (2 , podId );
270266 pstmt .setLong (3 , templateId );
271267 pstmt .setString (4 , downloadState .toString ());
272- rs = pstmt .executeQuery ();
273- while (rs .next ()) {
274- // result.add(toEntityBean(rs, false)); TODO: this is buggy in
275- // GenericDaoBase for hand constructed queries
276- long id = rs .getLong (1 ); // ID column
277- result .add (findById (id ));
278- }
279- } catch (Exception e ) {
280- s_logger .warn ("Exception: " , e );
281- } finally {
282- try {
283- if (rs != null ) {
284- rs .close ();
268+ try (ResultSet rs = pstmt .executeQuery ();) {
269+ while (rs .next ()) {
270+ // result.add(toEntityBean(rs, false)); TODO: this is buggy in
271+ // GenericDaoBase for hand constructed queries
272+ long id = rs .getLong (1 ); // ID column
273+ result .add (findById (id ));
285274 }
286- if (pstmt != null ) {
287- pstmt .close ();
288- }
289- } catch (SQLException e ) {
275+ }catch (SQLException e ) {
276+ s_logger .warn ("listByTemplateStatus:Exception: " +e .getMessage (), e );
290277 }
278+ } catch (Exception e ) {
279+ s_logger .warn ("listByTemplateStatus:Exception: " +e .getMessage (), e );
291280 }
292281 return result ;
293282
0 commit comments