|
18 | 18 |
|
19 | 19 | import java.sql.PreparedStatement; |
20 | 20 | import java.sql.ResultSet; |
21 | | -import java.sql.SQLException; |
22 | 21 | import java.util.ArrayList; |
23 | 22 | import java.util.Date; |
24 | 23 | import java.util.List; |
@@ -170,71 +169,49 @@ public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId, long |
170 | 169 | @Override |
171 | 170 | public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId, long datacenterId, long podId, VMTemplateStoragePoolVO.Status downloadState) { |
172 | 171 | TransactionLegacy txn = TransactionLegacy.currentTxn(); |
173 | | - PreparedStatement pstmt = null; |
174 | 172 | 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);) { |
180 | 175 | pstmt.setLong(1, datacenterId); |
181 | 176 | pstmt.setLong(2, podId); |
182 | 177 | pstmt.setLong(3, templateId); |
183 | 178 | 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); |
190 | 188 | } |
191 | 189 | } catch (Exception e) { |
192 | 190 | 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 | | - } |
203 | 191 | } |
204 | 192 | return result; |
205 | 193 |
|
206 | 194 | } |
207 | 195 |
|
208 | 196 | public List<VMTemplateStoragePoolVO> listByHostTemplate(long hostId, long templateId) { |
209 | 197 | TransactionLegacy txn = TransactionLegacy.currentTxn(); |
210 | | - PreparedStatement pstmt = null; |
211 | 198 | 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);) { |
217 | 201 | pstmt.setLong(1, hostId); |
218 | 202 | 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); |
225 | 212 | } |
226 | 213 | } catch (Exception e) { |
227 | 214 | 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 | | - } |
238 | 215 | } |
239 | 216 | return result; |
240 | 217 |
|
|
0 commit comments