From 70d98a06efc55ac862dffe491bd47812f693c517 Mon Sep 17 00:00:00 2001 From: tspc Date: Wed, 6 Aug 2008 00:46:10 +0000 Subject: [PATCH] BF1874419 JDBC Statement not close in a finally block + Fix indentation and format --- .../process/CreateProductPlanning.java | 401 +++++++++--------- 1 file changed, 192 insertions(+), 209 deletions(-) diff --git a/base/src/org/eevolution/process/CreateProductPlanning.java b/base/src/org/eevolution/process/CreateProductPlanning.java index 17e53e54f1..28ed5f75b3 100644 --- a/base/src/org/eevolution/process/CreateProductPlanning.java +++ b/base/src/org/eevolution/process/CreateProductPlanning.java @@ -16,264 +16,247 @@ package org.eevolution.process; -import java.util.Properties; -import java.util.logging.*; -import java.math.*; -import java.sql.*; +import java.math.BigDecimal; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.logging.Level; - -import org.compiere.model.*; -import org.compiere.util.*; -import org.compiere.process.*; +import org.compiere.model.MWarehouse; +import org.compiere.process.ProcessInfoParameter; +import org.compiere.process.SvrProcess; +import org.compiere.util.DB; +import org.compiere.util.Env; import org.eevolution.model.MPPProductPlanning; /** - * CreateProductPlanning - * - * @author Victor Perez, e-Evolution, S.C. - * @version $Id: CreateProductPlanning.java,v 1.1 2004/06/22 05:24:03 vpj-cd Exp $ + * CreateProductPlanning + * + * @author Victor Perez, e-Evolution, S.C. + * @version $Id: CreateProductPlanning.java,v 1.1 2004/06/22 05:24:03 vpj-cd Exp $ */ public class CreateProductPlanning extends SvrProcess { - /** Process Parameters */; - private int p_M_Product_Category_ID = 0; - private int p_M_Warehouse_ID = 0; - private int p_S_Resource_ID = 0 ; - private int p_Planner = 0 ; - private BigDecimal p_DeliveryTime_Promised = Env.ZERO; - private int p_DD_NetworkDistribution_ID = 0; - private int p_AD_Workflow_ID = 0; - private BigDecimal p_TimeFence = Env.ZERO; - private boolean p_CreatePlan = false; - private boolean p_MPS = false; - private String p_OrderPolicy = ""; - private BigDecimal p_OrderPeriod = Env.ZERO; - private BigDecimal p_TransferTime = Env.ZERO; - private BigDecimal p_SafetyStock = Env.ZERO; - private BigDecimal p_Order_Min = Env.ZERO; - private BigDecimal p_Order_Max = Env.ZERO; - private BigDecimal p_Order_Pack = Env.ZERO; - private BigDecimal p_Order_Qty = Env.ZERO; - private BigDecimal p_WorkingTime = Env.ZERO; - private int p_Yield = 0; - private int m_AD_Org_ID = 0; - private int m_AD_Client_ID = 0; + /** Process Parameters */; + private int p_M_Product_Category_ID = 0; + private int p_M_Warehouse_ID = 0; + private int p_S_Resource_ID = 0 ; + private int p_Planner = 0 ; + private BigDecimal p_DeliveryTime_Promised = Env.ZERO; + private int p_DD_NetworkDistribution_ID = 0; + private int p_AD_Workflow_ID = 0; + private BigDecimal p_TimeFence = Env.ZERO; + private boolean p_CreatePlan = false; + private boolean p_MPS = false; + private String p_OrderPolicy = ""; + private BigDecimal p_OrderPeriod = Env.ZERO; + private BigDecimal p_TransferTime = Env.ZERO; + private BigDecimal p_SafetyStock = Env.ZERO; + private BigDecimal p_Order_Min = Env.ZERO; + private BigDecimal p_Order_Max = Env.ZERO; + private BigDecimal p_Order_Pack = Env.ZERO; + private BigDecimal p_Order_Qty = Env.ZERO; + private BigDecimal p_WorkingTime = Env.ZERO; + private int p_Yield = 0; + private int m_AD_Org_ID = 0; + private int m_AD_Client_ID = 0; - - - - /** - * Prepare - e.g., get Parameters. + * Prepare - e.g., get Parameters. */ protected void prepare() { m_AD_Client_ID = Env.getAD_Client_ID(getCtx()); - ProcessInfoParameter[] para = getParameter(); - - - + for (int i = 0; i < para.length; i++) { String name = para[i].getParameterName(); - - if (para[i].getParameter() == null) - ; - else if (name.equals("M_Product_Category_ID")) - { + if (para[i].getParameter() == null) + ; + else if (name.equals("M_Product_Category_ID")) + { p_M_Product_Category_ID = ((BigDecimal)para[i].getParameter()).intValue(); - - } - else if (name.equals("M_Warehouse_ID")) - { + } + else if (name.equals("M_Warehouse_ID")) + { p_M_Warehouse_ID = ((BigDecimal)para[i].getParameter()).intValue(); - - } - else if (name.equals("S_Resource_ID")) - { + } + else if (name.equals("S_Resource_ID")) + { p_S_Resource_ID = ((BigDecimal)para[i].getParameter()).intValue(); - - } - else if (name.equals("IsCreatePlan")) - { + } + else if (name.equals("IsCreatePlan")) + { p_CreatePlan = "Y".equals((String)para[i].getParameter()); - - } - else if (name.equals("IsMPS")) - { - p_MPS = "Y".equals((String)para[i].getParameter()); - - } - else if (name.equals("DD_NetworkDistribution_ID")) - { - p_DD_NetworkDistribution_ID = ((BigDecimal)para[i].getParameter()).intValue(); - } - else if (name.equals("AD_Workflow_ID")) - { + } + else if (name.equals("IsMPS")) + { + p_MPS = "Y".equals((String)para[i].getParameter()); + } + else if (name.equals("DD_NetworkDistribution_ID")) + { + p_DD_NetworkDistribution_ID = ((BigDecimal)para[i].getParameter()).intValue(); + } + else if (name.equals("AD_Workflow_ID")) + { p_AD_Workflow_ID = ((BigDecimal)para[i].getParameter()).intValue(); - - } - else if (name.equals("TimeFence")) - { + } + else if (name.equals("TimeFence")) + { p_TimeFence = ((BigDecimal)para[i].getParameter()); - } - - else if (name.equals("TransfertTime")) - { + } + else if (name.equals("TransfertTime")) + { p_TransferTime = ((BigDecimal)para[i].getParameter()); - } - else if (name.equals("SafetyStock")) - { - p_SafetyStock = ((BigDecimal)para[i].getParameter()); - } - else if (name.equals("Order_Min")) - { + } + else if (name.equals("SafetyStock")) + { + p_SafetyStock = ((BigDecimal)para[i].getParameter()); + } + else if (name.equals("Order_Min")) + { p_Order_Min = ((BigDecimal)para[i].getParameter()); - } - else if (name.equals("Order_Max")) - { + } + else if (name.equals("Order_Max")) + { p_Order_Max = ((BigDecimal)para[i].getParameter()); - } - else if (name.equals("Order_Pack")) - { + } + else if (name.equals("Order_Pack")) + { p_Order_Pack = ((BigDecimal)para[i].getParameter()); - } - else if (name.equals("Order_Qty")) - { + } + else if (name.equals("Order_Qty")) + { p_Order_Qty = ((BigDecimal)para[i].getParameter()); - } - else if (name.equals("WorkingTime")) - { + } + else if (name.equals("WorkingTime")) + { p_WorkingTime = ((BigDecimal)para[i].getParameter()); - } - else if (name.equals("Yield")) - { + } + else if (name.equals("Yield")) + { p_Yield = ((BigDecimal)para[i].getParameter()).intValue(); - } - else if (name.equals("DeliveryTime_Promised")) - { + } + else if (name.equals("DeliveryTime_Promised")) + { p_DeliveryTime_Promised = ((BigDecimal)para[i].getParameter()); - } - else if (name.equals("Order_Period")) - { + } + else if (name.equals("Order_Period")) + { p_OrderPeriod = ((BigDecimal)para[i].getParameter()); - } - else if (name.equals("Order_Policy")) - { + } + else if (name.equals("Order_Policy")) + { p_OrderPolicy = ((String)para[i].getParameter()); - System.out.println("MPS " +p_OrderPolicy); - } - else if (name.equals("Planner_ID")) - { + System.out.println("MPS " +p_OrderPolicy); + } + else if (name.equals("Planner_ID")) + { p_Planner = ((BigDecimal)para[i].getParameter()).intValue(); - } - else + } + else log.log(Level.SEVERE,"prepare - Unknown Parameter: " + name); } - if(p_M_Warehouse_ID > 0 ) { MWarehouse w = MWarehouse.get(getCtx(), p_M_Warehouse_ID); m_AD_Org_ID = w.getAD_Org_ID(); } - - } // prepare + } // prepare - /********************** - * Create Data Planning record - */ - protected String doIt() throws Exception + /*************************************************************************** + * Create Data Planning record + */ + protected String doIt() throws Exception { - String sql = null; - PreparedStatement pstmt = null; - - if (p_M_Product_Category_ID > 0 ) - sql = "SELECT p.M_Product_ID FROM M_Product p WHERE p.AD_Client_ID= ? AND p.M_Product_Category_ID = ? "; - else - sql = "SELECT p.M_Product_ID FROM M_Product p WHERE p.AD_Client_ID= ? "; + String sql = null; + PreparedStatement pstmt = null; + ResultSet rs = null; + + if (p_M_Product_Category_ID > 0 ) + sql = "SELECT p.M_Product_ID FROM M_Product p WHERE p.AD_Client_ID= ? AND p.M_Product_Category_ID = ? "; + else + sql = "SELECT p.M_Product_ID FROM M_Product p WHERE p.AD_Client_ID= ? "; try { - pstmt = DB.prepareStatement (sql,get_TrxName()); - if (p_M_Product_Category_ID > 0 ) - { - pstmt.setInt(1, m_AD_Client_ID); - pstmt.setInt(2, p_M_Product_Category_ID); - } - else - pstmt.setInt(1, m_AD_Client_ID); - - ResultSet rs = pstmt.executeQuery (); - while (rs.next()) - { - - int M_Product_ID = rs.getInt(1); - MPPProductPlanning pp = MPPProductPlanning.get(getCtx(),m_AD_Client_ID , m_AD_Org_ID , p_M_Warehouse_ID, p_S_Resource_ID,M_Product_ID, get_TrxName()); - //Create Product Data Planning - if (pp==null) - { - pp = new MPPProductPlanning(getCtx(),0,get_TrxName()); - pp.setAD_Org_ID(m_AD_Org_ID); - pp.setM_Product_ID(rs.getInt(1)); - pp.setDD_NetworkDistribution_ID (p_DD_NetworkDistribution_ID); - pp.setAD_Workflow_ID(p_AD_Workflow_ID); - pp.setIsActive(true); - pp.setIsCreatePlan(p_CreatePlan); - pp.setIsMPS(p_MPS); - pp.setIsPhantom(false); - pp.setIsRequiredMRP(true); - pp.setIsRequiredDRP(true); - pp.setM_Warehouse_ID(p_M_Warehouse_ID); - pp.setS_Resource_ID(p_S_Resource_ID); - pp.setDeliveryTime_Promised(p_DeliveryTime_Promised); - pp.setOrder_Period(p_OrderPeriod); - pp.setPlanner_ID(p_Planner); - pp.setOrder_Policy(p_OrderPolicy); - pp.setSafetyStock(p_SafetyStock); - pp.setOrder_Qty(p_Order_Qty); - pp.setOrder_Min(p_Order_Min); - pp.setOrder_Max(p_Order_Max); - pp.setOrder_Pack(p_Order_Pack); - pp.setTimeFence(p_TimeFence); - pp.setWorkingTime(p_WorkingTime); - pp.setYield(p_Yield); - pp.save(); - } - else - { - pp.setDD_NetworkDistribution_ID (p_DD_NetworkDistribution_ID); - pp.setAD_Workflow_ID(p_AD_Workflow_ID); - pp.setIsCreatePlan(p_CreatePlan); - pp.setIsMPS(p_MPS); - pp.setIsRequiredMRP(true); - pp.setIsRequiredDRP(true); - pp.setDeliveryTime_Promised(p_DeliveryTime_Promised); - pp.setOrder_Period(p_OrderPeriod); - pp.setPlanner_ID(p_Planner); - pp.setOrder_Policy(p_OrderPolicy); - pp.setSafetyStock(p_SafetyStock); - pp.setOrder_Qty(p_Order_Qty); - pp.setOrder_Min(p_Order_Min); - pp.setOrder_Max(p_Order_Max); - pp.setOrder_Pack(p_Order_Pack); - pp.setTimeFence(p_TimeFence); - pp.setTransfertTime(p_TransferTime); - pp.setWorkingTime(p_WorkingTime); - pp.setYield(p_Yield); - pp.save(); - } - } - DB.close(rs); - DB.close(pstmt); - + pstmt = DB.prepareStatement (sql,get_TrxName()); + if (p_M_Product_Category_ID > 0 ) + { + pstmt.setInt(1, m_AD_Client_ID); + pstmt.setInt(2, p_M_Product_Category_ID); + } + else pstmt.setInt(1, m_AD_Client_ID); + rs = pstmt.executeQuery (); + while (rs.next()) + { + int M_Product_ID = rs.getInt(1); + MPPProductPlanning pp = MPPProductPlanning.get(getCtx(),m_AD_Client_ID , m_AD_Org_ID , p_M_Warehouse_ID, p_S_Resource_ID,M_Product_ID, get_TrxName()); + // Create Product Data Planning + if (pp==null) + { + pp = new MPPProductPlanning(getCtx(),0,get_TrxName()); + pp.setAD_Org_ID(m_AD_Org_ID); + pp.setM_Product_ID(rs.getInt(1)); + pp.setDD_NetworkDistribution_ID (p_DD_NetworkDistribution_ID); + pp.setAD_Workflow_ID(p_AD_Workflow_ID); + pp.setIsActive(true); + pp.setIsCreatePlan(p_CreatePlan); + pp.setIsMPS(p_MPS); + pp.setIsPhantom(false); + pp.setIsRequiredMRP(true); + pp.setIsRequiredDRP(true); + pp.setM_Warehouse_ID(p_M_Warehouse_ID); + pp.setS_Resource_ID(p_S_Resource_ID); + pp.setDeliveryTime_Promised(p_DeliveryTime_Promised); + pp.setOrder_Period(p_OrderPeriod); + pp.setPlanner_ID(p_Planner); + pp.setOrder_Policy(p_OrderPolicy); + pp.setSafetyStock(p_SafetyStock); + pp.setOrder_Qty(p_Order_Qty); + pp.setOrder_Min(p_Order_Min); + pp.setOrder_Max(p_Order_Max); + pp.setOrder_Pack(p_Order_Pack); + pp.setTimeFence(p_TimeFence); + pp.setWorkingTime(p_WorkingTime); + pp.setYield(p_Yield); + pp.save(); + } + else + { + pp.setDD_NetworkDistribution_ID (p_DD_NetworkDistribution_ID); + pp.setAD_Workflow_ID(p_AD_Workflow_ID); + pp.setIsCreatePlan(p_CreatePlan); + pp.setIsMPS(p_MPS); + pp.setIsRequiredMRP(true); + pp.setIsRequiredDRP(true); + pp.setDeliveryTime_Promised(p_DeliveryTime_Promised); + pp.setOrder_Period(p_OrderPeriod); + pp.setPlanner_ID(p_Planner); + pp.setOrder_Policy(p_OrderPolicy); + pp.setSafetyStock(p_SafetyStock); + pp.setOrder_Qty(p_Order_Qty); + pp.setOrder_Min(p_Order_Min); + pp.setOrder_Max(p_Order_Max); + pp.setOrder_Pack(p_Order_Pack); + pp.setTimeFence(p_TimeFence); + pp.setTransfertTime(p_TransferTime); + pp.setWorkingTime(p_WorkingTime); + pp.setYield(p_Yield); + pp.save(); + } + } } catch (Exception e) { log.log(Level.SEVERE,"doIt - " + sql, e); } - - return "ok"; - } - + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } + return "ok"; + } } \ No newline at end of file