IDEMPIERE-2649 Not properly closed ResultSet in M_PriceList_Create

This commit is contained in:
tsvikruha 2015-07-01 19:59:37 -05:00
parent 821c8c3f5e
commit 27588c7801
1 changed files with 55 additions and 45 deletions

View File

@ -685,54 +685,64 @@ public class M_PriceList_Create extends SvrProcess {
sqlpc.append(" WHERE s.T_Selection_ID=p.M_Product_ID"); sqlpc.append(" WHERE s.T_Selection_ID=p.M_Product_ID");
sqlpc.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID + ")"); sqlpc.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID + ")");
PreparedStatement ps = DB.prepareStatement(sqlpc.toString(), get_TrxName()); PreparedStatement ps = null;
ResultSet rs = ps.executeQuery(); ResultSet rs = null;
while(rs.next())
{
int M_Product_ID = rs.getInt(MProductPrice.COLUMNNAME_M_Product_ID);
ProductCost m_productCost = new ProductCost (getCtx(), M_Product_ID, 0, get_TrxName());
m_productCost.setQty(BigDecimal.ONE);
BigDecimal costs = m_productCost.getProductCosts(as, rsCurgen.getInt("AD_Org_ID"), null, 0, false);
if (costs == null || costs.signum() == 0) // zero costs OK try{
ps = DB.prepareStatement(sqlpc.toString(), get_TrxName());
rs = ps.executeQuery();
while(rs.next())
{ {
MProduct product = new MProduct(getCtx(), M_Product_ID, get_TrxName()); int M_Product_ID = rs.getInt(MProductPrice.COLUMNNAME_M_Product_ID);
if (product.isStocked()) ProductCost m_productCost = new ProductCost (getCtx(), M_Product_ID, 0, get_TrxName());
log.log(Level.WARNING, "No Costs for " + product.getName()); m_productCost.setQty(BigDecimal.ONE);
} BigDecimal costs = m_productCost.getProductCosts(as, rsCurgen.getInt("AD_Org_ID"), null, 0, false);
else
{ if (costs == null || costs.signum() == 0) // zero costs OK
sqlupd = new StringBuilder("UPDATE M_ProductPrice p "); {
sqlupd.append(" SET PriceList = (DECODE('").append(rsDiscountLine.getString(MDiscountSchemaLine.COLUMNNAME_List_Base)).append("', 'P', ?, PriceList) + ?) * (1 - ?/100), "); MProduct product = new MProduct(getCtx(), M_Product_ID, get_TrxName());
sqlupd.append(" PriceStd = (DECODE('").append(rsDiscountLine.getString(MDiscountSchemaLine.COLUMNNAME_Std_Base)).append("', 'P', ?, PriceStd) + ?) * (1 - ?/100),"); if (product.isStocked())
sqlupd.append(" PriceLimit = (DECODE('").append(rsDiscountLine.getString(MDiscountSchemaLine.COLUMNNAME_Limit_Base)).append("', 'P', ?, PriceLimit) + ?) * (1 - ?/100)"); log.log(Level.WARNING, "No Costs for " + product.getName());
sqlupd.append(" WHERE M_PriceList_Version_ID=").append(p_PriceList_Version_ID); }
sqlupd.append(" AND M_Product_ID = ?"); else
sqlupd.append(" AND EXISTS (SELECT * FROM T_Selection s"); {
sqlupd.append(" WHERE s.T_Selection_ID=p.M_Product_ID"); sqlupd = new StringBuilder("UPDATE M_ProductPrice p ");
sqlupd.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID + ")"); sqlupd.append(" SET PriceList = (DECODE('").append(rsDiscountLine.getString(MDiscountSchemaLine.COLUMNNAME_List_Base)).append("', 'P', ?, PriceList) + ?) * (1 - ?/100), ");
sqlupd.append(" PriceStd = (DECODE('").append(rsDiscountLine.getString(MDiscountSchemaLine.COLUMNNAME_Std_Base)).append("', 'P', ?, PriceStd) + ?) * (1 - ?/100),");
pstmu = DB.prepareStatement(sqlupd.toString(), sqlupd.append(" PriceLimit = (DECODE('").append(rsDiscountLine.getString(MDiscountSchemaLine.COLUMNNAME_Limit_Base)).append("', 'P', ?, PriceLimit) + ?) * (1 - ?/100)");
ResultSet.TYPE_SCROLL_INSENSITIVE, sqlupd.append(" WHERE M_PriceList_Version_ID=").append(p_PriceList_Version_ID);
ResultSet.CONCUR_UPDATABLE, get_TrxName()); sqlupd.append(" AND M_Product_ID = ?");
sqlupd.append(" AND EXISTS (SELECT * FROM T_Selection s");
pstmu.setBigDecimal(1, costs); sqlupd.append(" WHERE s.T_Selection_ID=p.M_Product_ID");
pstmu.setDouble(2, rsDiscountLine.getDouble(MDiscountSchemaLine.COLUMNNAME_List_AddAmt)); sqlupd.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID + ")");
pstmu.setDouble(3, rsDiscountLine.getDouble(MDiscountSchemaLine.COLUMNNAME_List_Discount));
pstmu.setBigDecimal(4, costs); pstmu = DB.prepareStatement(sqlupd.toString(),
pstmu.setDouble(5, rsDiscountLine.getDouble(MDiscountSchemaLine.COLUMNNAME_Std_AddAmt)); ResultSet.TYPE_SCROLL_INSENSITIVE,
pstmu.setDouble(6, rsDiscountLine.getDouble(MDiscountSchemaLine.COLUMNNAME_Std_Discount)); ResultSet.CONCUR_UPDATABLE, get_TrxName());
pstmu.setBigDecimal(7, costs);
pstmu.setDouble(8, rsDiscountLine.getDouble(MDiscountSchemaLine.COLUMNNAME_Limit_AddAmt)); pstmu.setBigDecimal(1, costs);
pstmu.setDouble(9, rsDiscountLine.getDouble(MDiscountSchemaLine.COLUMNNAME_Limit_Discount)); pstmu.setDouble(2, rsDiscountLine.getDouble(MDiscountSchemaLine.COLUMNNAME_List_AddAmt));
pstmu.setInt(10, M_Product_ID); pstmu.setDouble(3, rsDiscountLine.getDouble(MDiscountSchemaLine.COLUMNNAME_List_Discount));
pstmu.setBigDecimal(4, costs);
cntu = pstmu.executeUpdate(); pstmu.setDouble(5, rsDiscountLine.getDouble(MDiscountSchemaLine.COLUMNNAME_Std_AddAmt));
pstmu.setDouble(6, rsDiscountLine.getDouble(MDiscountSchemaLine.COLUMNNAME_Std_Discount));
if (cntu == -1) pstmu.setBigDecimal(7, costs);
raiseError("Update M_ProductPrice ", sqlupd.toString()); pstmu.setDouble(8, rsDiscountLine.getDouble(MDiscountSchemaLine.COLUMNNAME_Limit_AddAmt));
if (log.isLoggable(Level.FINE)) log.fine("Updated " + cntu); pstmu.setDouble(9, rsDiscountLine.getDouble(MDiscountSchemaLine.COLUMNNAME_Limit_Discount));
pstmu.setInt(10, M_Product_ID);
cntu = pstmu.executeUpdate();
if (cntu == -1)
raiseError("Update M_ProductPrice ", sqlupd.toString());
if (log.isLoggable(Level.FINE)) log.fine("Updated " + cntu);
}
} }
} catch (SQLException e) {
throw e;
} finally {
DB.close(rs, ps);
rs = null; ps = null;
} }
} }