BF1874419 JDBC Statement not close in a finally block

+ Fix indentation and format
This commit is contained in:
tspc 2008-08-06 00:46:10 +00:00
parent d6dbceefbe
commit 70d98a06ef
1 changed files with 192 additions and 209 deletions

View File

@ -16,264 +16,247 @@
package org.eevolution.process; package org.eevolution.process;
import java.util.Properties; import java.math.BigDecimal;
import java.util.logging.*; import java.sql.PreparedStatement;
import java.math.*; import java.sql.ResultSet;
import java.sql.*; import java.util.logging.Level;
import org.compiere.model.MWarehouse;
import org.compiere.model.*; import org.compiere.process.ProcessInfoParameter;
import org.compiere.util.*; import org.compiere.process.SvrProcess;
import org.compiere.process.*; import org.compiere.util.DB;
import org.compiere.util.Env;
import org.eevolution.model.MPPProductPlanning; import org.eevolution.model.MPPProductPlanning;
/** /**
* CreateProductPlanning * CreateProductPlanning
* *
* @author Victor Perez, e-Evolution, S.C. * @author Victor Perez, e-Evolution, S.C.
* @version $Id: CreateProductPlanning.java,v 1.1 2004/06/22 05:24:03 vpj-cd Exp $ * @version $Id: CreateProductPlanning.java,v 1.1 2004/06/22 05:24:03 vpj-cd Exp $
*/ */
public class CreateProductPlanning extends SvrProcess public class CreateProductPlanning extends SvrProcess
{ {
/** Process Parameters */; /** Process Parameters */;
private int p_M_Product_Category_ID = 0; private int p_M_Product_Category_ID = 0;
private int p_M_Warehouse_ID = 0; private int p_M_Warehouse_ID = 0;
private int p_S_Resource_ID = 0 ; private int p_S_Resource_ID = 0 ;
private int p_Planner = 0 ; private int p_Planner = 0 ;
private BigDecimal p_DeliveryTime_Promised = Env.ZERO; private BigDecimal p_DeliveryTime_Promised = Env.ZERO;
private int p_DD_NetworkDistribution_ID = 0; private int p_DD_NetworkDistribution_ID = 0;
private int p_AD_Workflow_ID = 0; private int p_AD_Workflow_ID = 0;
private BigDecimal p_TimeFence = Env.ZERO; private BigDecimal p_TimeFence = Env.ZERO;
private boolean p_CreatePlan = false; private boolean p_CreatePlan = false;
private boolean p_MPS = false; private boolean p_MPS = false;
private String p_OrderPolicy = ""; private String p_OrderPolicy = "";
private BigDecimal p_OrderPeriod = Env.ZERO; private BigDecimal p_OrderPeriod = Env.ZERO;
private BigDecimal p_TransferTime = Env.ZERO; private BigDecimal p_TransferTime = Env.ZERO;
private BigDecimal p_SafetyStock = Env.ZERO; private BigDecimal p_SafetyStock = Env.ZERO;
private BigDecimal p_Order_Min = Env.ZERO; private BigDecimal p_Order_Min = Env.ZERO;
private BigDecimal p_Order_Max = Env.ZERO; private BigDecimal p_Order_Max = Env.ZERO;
private BigDecimal p_Order_Pack = Env.ZERO; private BigDecimal p_Order_Pack = Env.ZERO;
private BigDecimal p_Order_Qty = Env.ZERO; private BigDecimal p_Order_Qty = Env.ZERO;
private BigDecimal p_WorkingTime = Env.ZERO; private BigDecimal p_WorkingTime = Env.ZERO;
private int p_Yield = 0; private int p_Yield = 0;
private int m_AD_Org_ID = 0; private int m_AD_Org_ID = 0;
private int m_AD_Client_ID = 0; private int m_AD_Client_ID = 0;
/** /**
* Prepare - e.g., get Parameters. * Prepare - e.g., get Parameters.
*/ */
protected void prepare() protected void prepare()
{ {
m_AD_Client_ID = Env.getAD_Client_ID(getCtx()); m_AD_Client_ID = Env.getAD_Client_ID(getCtx());
ProcessInfoParameter[] para = getParameter(); ProcessInfoParameter[] para = getParameter();
for (int i = 0; i < para.length; i++) for (int i = 0; i < para.length; i++)
{ {
String name = para[i].getParameterName(); String name = para[i].getParameterName();
if (para[i].getParameter() == null)
if (para[i].getParameter() == null) ;
; else if (name.equals("M_Product_Category_ID"))
else if (name.equals("M_Product_Category_ID")) {
{
p_M_Product_Category_ID = ((BigDecimal)para[i].getParameter()).intValue(); 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(); 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(); 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()); p_CreatePlan = "Y".equals((String)para[i].getParameter());
}
} else if (name.equals("IsMPS"))
else if (name.equals("IsMPS")) {
{ p_MPS = "Y".equals((String)para[i].getParameter());
p_MPS = "Y".equals((String)para[i].getParameter()); }
else if (name.equals("DD_NetworkDistribution_ID"))
} {
else if (name.equals("DD_NetworkDistribution_ID")) p_DD_NetworkDistribution_ID = ((BigDecimal)para[i].getParameter()).intValue();
{ }
p_DD_NetworkDistribution_ID = ((BigDecimal)para[i].getParameter()).intValue(); else if (name.equals("AD_Workflow_ID"))
} {
else if (name.equals("AD_Workflow_ID"))
{
p_AD_Workflow_ID = ((BigDecimal)para[i].getParameter()).intValue(); 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()); p_TimeFence = ((BigDecimal)para[i].getParameter());
} }
else if (name.equals("TransfertTime"))
else if (name.equals("TransfertTime")) {
{
p_TransferTime = ((BigDecimal)para[i].getParameter()); p_TransferTime = ((BigDecimal)para[i].getParameter());
} }
else if (name.equals("SafetyStock")) else if (name.equals("SafetyStock"))
{ {
p_SafetyStock = ((BigDecimal)para[i].getParameter()); p_SafetyStock = ((BigDecimal)para[i].getParameter());
} }
else if (name.equals("Order_Min")) else if (name.equals("Order_Min"))
{ {
p_Order_Min = ((BigDecimal)para[i].getParameter()); 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()); 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()); 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()); p_Order_Qty = ((BigDecimal)para[i].getParameter());
} }
else if (name.equals("WorkingTime")) else if (name.equals("WorkingTime"))
{ {
p_WorkingTime = ((BigDecimal)para[i].getParameter()); p_WorkingTime = ((BigDecimal)para[i].getParameter());
} }
else if (name.equals("Yield")) else if (name.equals("Yield"))
{ {
p_Yield = ((BigDecimal)para[i].getParameter()).intValue(); 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()); 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()); p_OrderPeriod = ((BigDecimal)para[i].getParameter());
} }
else if (name.equals("Order_Policy")) else if (name.equals("Order_Policy"))
{ {
p_OrderPolicy = ((String)para[i].getParameter()); p_OrderPolicy = ((String)para[i].getParameter());
System.out.println("MPS " +p_OrderPolicy); System.out.println("MPS " +p_OrderPolicy);
} }
else if (name.equals("Planner_ID")) else if (name.equals("Planner_ID"))
{ {
p_Planner = ((BigDecimal)para[i].getParameter()).intValue(); p_Planner = ((BigDecimal)para[i].getParameter()).intValue();
} }
else else
log.log(Level.SEVERE,"prepare - Unknown Parameter: " + name); log.log(Level.SEVERE,"prepare - Unknown Parameter: " + name);
} }
if(p_M_Warehouse_ID > 0 ) if(p_M_Warehouse_ID > 0 )
{ {
MWarehouse w = MWarehouse.get(getCtx(), p_M_Warehouse_ID); MWarehouse w = MWarehouse.get(getCtx(), p_M_Warehouse_ID);
m_AD_Org_ID = w.getAD_Org_ID(); m_AD_Org_ID = w.getAD_Org_ID();
} }
} // prepare
} // prepare
/********************** /***************************************************************************
* Create Data Planning record * Create Data Planning record
*/ */
protected String doIt() throws Exception protected String doIt() throws Exception
{ {
String sql = null; String sql = null;
PreparedStatement pstmt = 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 = ? "; if (p_M_Product_Category_ID > 0 )
else sql = "SELECT p.M_Product_ID FROM M_Product p WHERE p.AD_Client_ID= ? AND p.M_Product_Category_ID = ? ";
sql = "SELECT p.M_Product_ID FROM M_Product p WHERE p.AD_Client_ID= ? "; else
sql = "SELECT p.M_Product_ID FROM M_Product p WHERE p.AD_Client_ID= ? ";
try try
{ {
pstmt = DB.prepareStatement (sql,get_TrxName()); pstmt = DB.prepareStatement (sql,get_TrxName());
if (p_M_Product_Category_ID > 0 ) if (p_M_Product_Category_ID > 0 )
{ {
pstmt.setInt(1, m_AD_Client_ID); pstmt.setInt(1, m_AD_Client_ID);
pstmt.setInt(2, p_M_Product_Category_ID); pstmt.setInt(2, p_M_Product_Category_ID);
} }
else else pstmt.setInt(1, m_AD_Client_ID);
pstmt.setInt(1, m_AD_Client_ID); rs = pstmt.executeQuery ();
while (rs.next())
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
int M_Product_ID = rs.getInt(1); if (pp==null)
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 pp = new MPPProductPlanning(getCtx(),0,get_TrxName());
if (pp==null) pp.setAD_Org_ID(m_AD_Org_ID);
{ pp.setM_Product_ID(rs.getInt(1));
pp = new MPPProductPlanning(getCtx(),0,get_TrxName()); pp.setDD_NetworkDistribution_ID (p_DD_NetworkDistribution_ID);
pp.setAD_Org_ID(m_AD_Org_ID); pp.setAD_Workflow_ID(p_AD_Workflow_ID);
pp.setM_Product_ID(rs.getInt(1)); pp.setIsActive(true);
pp.setDD_NetworkDistribution_ID (p_DD_NetworkDistribution_ID); pp.setIsCreatePlan(p_CreatePlan);
pp.setAD_Workflow_ID(p_AD_Workflow_ID); pp.setIsMPS(p_MPS);
pp.setIsActive(true); pp.setIsPhantom(false);
pp.setIsCreatePlan(p_CreatePlan); pp.setIsRequiredMRP(true);
pp.setIsMPS(p_MPS); pp.setIsRequiredDRP(true);
pp.setIsPhantom(false); pp.setM_Warehouse_ID(p_M_Warehouse_ID);
pp.setIsRequiredMRP(true); pp.setS_Resource_ID(p_S_Resource_ID);
pp.setIsRequiredDRP(true); pp.setDeliveryTime_Promised(p_DeliveryTime_Promised);
pp.setM_Warehouse_ID(p_M_Warehouse_ID); pp.setOrder_Period(p_OrderPeriod);
pp.setS_Resource_ID(p_S_Resource_ID); pp.setPlanner_ID(p_Planner);
pp.setDeliveryTime_Promised(p_DeliveryTime_Promised); pp.setOrder_Policy(p_OrderPolicy);
pp.setOrder_Period(p_OrderPeriod); pp.setSafetyStock(p_SafetyStock);
pp.setPlanner_ID(p_Planner); pp.setOrder_Qty(p_Order_Qty);
pp.setOrder_Policy(p_OrderPolicy); pp.setOrder_Min(p_Order_Min);
pp.setSafetyStock(p_SafetyStock); pp.setOrder_Max(p_Order_Max);
pp.setOrder_Qty(p_Order_Qty); pp.setOrder_Pack(p_Order_Pack);
pp.setOrder_Min(p_Order_Min); pp.setTimeFence(p_TimeFence);
pp.setOrder_Max(p_Order_Max); pp.setWorkingTime(p_WorkingTime);
pp.setOrder_Pack(p_Order_Pack); pp.setYield(p_Yield);
pp.setTimeFence(p_TimeFence); pp.save();
pp.setWorkingTime(p_WorkingTime); }
pp.setYield(p_Yield); else
pp.save(); {
} pp.setDD_NetworkDistribution_ID (p_DD_NetworkDistribution_ID);
else pp.setAD_Workflow_ID(p_AD_Workflow_ID);
{ pp.setIsCreatePlan(p_CreatePlan);
pp.setDD_NetworkDistribution_ID (p_DD_NetworkDistribution_ID); pp.setIsMPS(p_MPS);
pp.setAD_Workflow_ID(p_AD_Workflow_ID); pp.setIsRequiredMRP(true);
pp.setIsCreatePlan(p_CreatePlan); pp.setIsRequiredDRP(true);
pp.setIsMPS(p_MPS); pp.setDeliveryTime_Promised(p_DeliveryTime_Promised);
pp.setIsRequiredMRP(true); pp.setOrder_Period(p_OrderPeriod);
pp.setIsRequiredDRP(true); pp.setPlanner_ID(p_Planner);
pp.setDeliveryTime_Promised(p_DeliveryTime_Promised); pp.setOrder_Policy(p_OrderPolicy);
pp.setOrder_Period(p_OrderPeriod); pp.setSafetyStock(p_SafetyStock);
pp.setPlanner_ID(p_Planner); pp.setOrder_Qty(p_Order_Qty);
pp.setOrder_Policy(p_OrderPolicy); pp.setOrder_Min(p_Order_Min);
pp.setSafetyStock(p_SafetyStock); pp.setOrder_Max(p_Order_Max);
pp.setOrder_Qty(p_Order_Qty); pp.setOrder_Pack(p_Order_Pack);
pp.setOrder_Min(p_Order_Min); pp.setTimeFence(p_TimeFence);
pp.setOrder_Max(p_Order_Max); pp.setTransfertTime(p_TransferTime);
pp.setOrder_Pack(p_Order_Pack); pp.setWorkingTime(p_WorkingTime);
pp.setTimeFence(p_TimeFence); pp.setYield(p_Yield);
pp.setTransfertTime(p_TransferTime); pp.save();
pp.setWorkingTime(p_WorkingTime); }
pp.setYield(p_Yield); }
pp.save();
}
}
DB.close(rs);
DB.close(pstmt);
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE,"doIt - " + sql, e); log.log(Level.SEVERE,"doIt - " + sql, e);
} }
finally
return "ok"; {
} DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
return "ok";
}
} }