BF [ 1874419 ] JDBC Statement not close in a finally block
This commit is contained in:
parent
8f04152e25
commit
1bd2033620
|
@ -15,14 +15,12 @@
|
|||
*****************************************************************************/
|
||||
package org.eevolution.model;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.compiere.model.MOrgInfo;
|
||||
import org.compiere.model.MResource;
|
||||
import org.compiere.util.CCache;
|
||||
import org.compiere.model.Query;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
|
||||
|
@ -34,19 +32,7 @@ import org.compiere.util.DB;
|
|||
*/
|
||||
public class MPPProductPlanning extends X_PP_Product_Planning
|
||||
{
|
||||
/**
|
||||
* Get from Cache
|
||||
* @param ctx context
|
||||
* @param M_Product_Costing_ID id
|
||||
* @return
|
||||
*/
|
||||
|
||||
|
||||
/** Cache */
|
||||
private static CCache s_cache = new CCache ("M_Product_Costing", 20);
|
||||
|
||||
/** Log */
|
||||
|
||||
private static CLogger log = CLogger.getCLogger(MPPProductPlanning.class);
|
||||
|
||||
|
||||
|
@ -112,51 +98,27 @@ public class MPPProductPlanning extends X_PP_Product_Planning
|
|||
*/
|
||||
public static MPPProductPlanning get(Properties ctx,int ad_client_id, int ad_org_id , int m_warehouse_id, int s_resource_id, int m_product_id, String trxname)
|
||||
{
|
||||
|
||||
log.info("AD_Client_ID=" + ad_client_id + " AD_Org_ID=" + ad_org_id + " M_Product_ID=" + m_product_id + " M_Warehouse_ID=" + m_warehouse_id + " S_Resource_ID=" + s_resource_id );
|
||||
String sql_warehouse = "pp.M_Warehouse_ID = ? ";
|
||||
if(m_warehouse_id == 0)
|
||||
sql_warehouse += "OR pp.M_Warehouse_ID IS NULL ";
|
||||
|
||||
|
||||
String sql = "SELECT * FROM PP_Product_Planning pp WHERE pp.AD_Client_ID = ? AND pp.AD_Org_ID = ? AND pp.M_Product_ID = ? AND "+sql_warehouse+" AND pp.S_Resource_ID = ? ";
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql, trxname);
|
||||
pstmt.setInt(1, ad_client_id);
|
||||
pstmt.setInt(2, ad_org_id);
|
||||
pstmt.setInt(3, m_product_id);
|
||||
pstmt.setInt(4, m_warehouse_id);
|
||||
pstmt.setInt(5, s_resource_id);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
return new MPPProductPlanning(ctx, rs, trxname);
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
String sql_warehouse = COLUMNNAME_M_Warehouse_ID+"=?";
|
||||
if(m_warehouse_id == 0) {
|
||||
sql_warehouse += " OR "+COLUMNNAME_M_Warehouse_ID+" IS NULL";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE,"getProductPlanning", e);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
return null;
|
||||
|
||||
String whereClause =
|
||||
" AD_Client_ID=? AND AD_Org_ID=?"
|
||||
+" AND "+COLUMNNAME_M_Product_ID+"=?"
|
||||
+" AND ("+sql_warehouse+")"
|
||||
+" AND "+COLUMNNAME_S_Resource_ID+"=?";
|
||||
|
||||
return new Query(ctx, MPPProductPlanning.Table_Name, whereClause, trxname)
|
||||
.setParameters(new Object[]{ad_client_id, ad_org_id, m_product_id, m_warehouse_id, s_resource_id})
|
||||
.first();
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* find data planning, try find the specific planning data if do not found then try find data planning general
|
||||
* Find data planning, try find the specific planning data
|
||||
* if do not found then try find data planning general
|
||||
* @param ctx Context
|
||||
* @param AD_Org_ID Organization ID
|
||||
* @param M_Warehouse_ID Resource ID
|
||||
|
@ -164,8 +126,8 @@ public class MPPProductPlanning extends X_PP_Product_Planning
|
|||
* @param M_Product_ID Product ID
|
||||
* @param trxName Transaction Name
|
||||
* @return MPPProductPlanning Planning Data
|
||||
*/
|
||||
public static MPPProductPlanning getFisrt(Properties ctx ,int AD_Client_ID, int AD_Org_ID ,int M_Warehouse_ID, int S_Resource_ID, int M_Product_ID, String trxName)
|
||||
*
|
||||
public static MPPProductPlanning getFirst(Properties ctx ,int AD_Client_ID, int AD_Org_ID ,int M_Warehouse_ID, int S_Resource_ID, int M_Product_ID, String trxName)
|
||||
{
|
||||
MPPProductPlanning pp = null;
|
||||
PreparedStatement pstmt = null;
|
||||
|
@ -235,6 +197,7 @@ public class MPPProductPlanning extends X_PP_Product_Planning
|
|||
}
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
|
||||
/**************************************************************************
|
||||
* find planning data demand & supply to this warehouse
|
||||
|
@ -246,37 +209,10 @@ public class MPPProductPlanning extends X_PP_Product_Planning
|
|||
*/
|
||||
public static MPPProductPlanning getDemandSupplyResource(Properties ctx , int AD_Org_ID , int M_Product_ID, String trxName )
|
||||
{
|
||||
String sql = "SELECT * FROM PP_Product_Planning pp WHERE pp.AD_Org_ID = ? AND pp.M_Product_ID = ?";
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql,trxName);
|
||||
pstmt.setInt(1, AD_Org_ID);
|
||||
pstmt.setInt(2, M_Product_ID);
|
||||
//pstmt.setInt(4, S_Resource_ID);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
return new MPPProductPlanning(ctx, rs,trxName);
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE,"getProductPlanning", e);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
return null;
|
||||
String whereClause = "AD_Org_ID = ? AND "+COLUMNNAME_M_Product_ID+"=?";
|
||||
return new Query(ctx, MPPProductPlanning.Table_Name, whereClause, trxName)
|
||||
.setParameters(new Object[]{AD_Org_ID, M_Product_ID})
|
||||
.first();
|
||||
}
|
||||
} // Product Data Planning
|
||||
|
||||
|
|
Loading…
Reference in New Issue