From cb10e71ad0a00f46c66565031560f5155a97099f Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Tue, 19 Feb 2013 16:16:17 -0500 Subject: [PATCH] IDEMPIERE-568 Review proper closing of JDBC statements and resultsets --- .../src/org/compiere/model/MOrder.java | 60 +++++++++++-------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MOrder.java b/org.adempiere.base/src/org/compiere/model/MOrder.java index 0a59f8c9af..47a19533a2 100644 --- a/org.adempiere.base/src/org/compiere/model/MOrder.java +++ b/org.adempiere.base/src/org/compiere/model/MOrder.java @@ -2698,15 +2698,22 @@ public class MOrder extends X_C_Order implements DocAction List result = new Vector(); Properties ctx = Env.getCtx(); MOrderLine line; - PreparedStatement ps = conn.prepareStatement(OrderLinesToAllocate); - ps.setInt(1, productId); - ResultSet rs = ps.executeQuery(); - while(rs.next()) { - line = new MOrderLine(ctx, rs, trxName); - result.add(line); + PreparedStatement ps = null; + ResultSet rs = null; + try { + ps = conn.prepareStatement(OrderLinesToAllocate); + ps.setInt(1, productId); + rs = ps.executeQuery(); + while(rs.next()) { + line = new MOrderLine(ctx, rs, trxName); + result.add(line); + } + } catch (SQLException e) { + throw e; + } finally { + DB.close(rs, ps); + rs = null; ps = null; } - rs.close(); - ps.close(); return(result); } @@ -2735,23 +2742,28 @@ public class MOrder extends X_C_Order implements DocAction "(QtyOrdered-QtyDelivered)>0 AND (QtyOrdered-QtyDelivered)>C_OrderLine.QtyAllocated)" + "group by M_Product_ID " + "order by M_Product_ID"; - - PreparedStatement ps = conn.prepareStatement(query1); - ps.setInt(1, WarehouseID); - ps.setInt(2, WarehouseID); - ResultSet rs = ps.executeQuery(); - - while(rs.next()) { - si = new StockInfo(); - si.productId = rs.getInt(1); - si.qtyOnHand = rs.getBigDecimal(2); - si.qtyReserved = rs.getBigDecimal(3); - si.qtyAvailable = si.qtyOnHand.subtract(si.qtyReserved); - si.qtyAllocated = rs.getBigDecimal(4); - result.add(si); + PreparedStatement ps = null; + ResultSet rs = null; + try { + ps = conn.prepareStatement(query1); + ps.setInt(1, WarehouseID); + ps.setInt(2, WarehouseID); + rs = ps.executeQuery(); + while(rs.next()) { + si = new StockInfo(); + si.productId = rs.getInt(1); + si.qtyOnHand = rs.getBigDecimal(2); + si.qtyReserved = rs.getBigDecimal(3); + si.qtyAvailable = si.qtyOnHand.subtract(si.qtyReserved); + si.qtyAllocated = rs.getBigDecimal(4); + result.add(si); + } + } catch (SQLException e) { + throw e; + } finally { + DB.close(rs, ps); + rs = null; ps = null; } - rs.close(); - ps.close(); return(result); }