MPPProductPlanning.find - improved performance

This commit is contained in:
teo_sarca 2008-08-19 07:08:53 +00:00
parent 6af3e09c77
commit 4513b48f50
1 changed files with 10 additions and 69 deletions

View File

@ -15,10 +15,8 @@
*****************************************************************************/
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;
@ -31,6 +29,8 @@ import org.compiere.util.DB;
*
* @author Victor Perez www.e-evolution.com
* @version $Id: MPProductPlannning.java,v 1.4 2004/05/13 06:05:22 vpj-cd Exp $
*
* @author Teo Sarca, www.arhipac.ro
*/
public class MPPProductPlanning extends X_PP_Product_Planning
{
@ -131,73 +131,14 @@ public class MPPProductPlanning extends X_PP_Product_Planning
**/
public static MPPProductPlanning find(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;
try
{
// Find specific data planning
String sql = "SELECT * FROM PP_Product_Planning pp WHERE pp.AD_Client_ID = ? AND pp.AD_Org_ID = ? AND pp.M_Warehouse_ID=? AND pp.S_Resource_ID = ? AND pp.M_Product_ID = ? ";
pstmt = DB.prepareStatement(sql ,trxName);
pstmt.setInt(1, AD_Client_ID);
pstmt.setInt(2, AD_Org_ID);
pstmt.setInt(3, M_Warehouse_ID);
pstmt.setInt(4, S_Resource_ID);
pstmt.setInt(5, M_Product_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
return new MPPProductPlanning(ctx, rs, trxName);
}
rs.close();
pstmt.close();
pstmt = null;
// Find general data planning Org = * , Wharehouse = *
sql = "SELECT * FROM PP_Product_Planning pp WHERE pp.AD_Client_ID = ? AND (pp.AD_Org_ID = 0 OR AD_Org_ID IS NULL) AND (pp.M_Warehouse_ID = 0 OR pp.M_Warehouse_ID IS NULL) AND pp.S_Resource_ID = ? AND pp.M_Product_ID = ? ";
pstmt = DB.prepareStatement(sql ,trxName);
pstmt.setInt(1, AD_Client_ID);
pstmt.setInt(2, S_Resource_ID);
pstmt.setInt(3, M_Product_ID);
rs = pstmt.executeQuery();
while (rs.next())
{
return new MPPProductPlanning(ctx, rs, trxName);
}
rs.close();
pstmt.close();
pstmt = null;
// Find general data planning Org = * , Wharehouse = * , Resource = *
sql = "SELECT * FROM PP_Product_Planning pp WHERE pp.AD_Client_ID = ? AND (pp.AD_Org_ID = 0 OR AD_Org_ID IS NULL) AND (pp.M_Warehouse_ID = 0 OR pp.M_Warehouse_ID IS NULL) AND (pp.S_Resource_ID =0 OR pp.S_Resource_ID IS NULL ) AND pp.M_Product_ID = ? ";
pstmt = DB.prepareStatement(sql ,trxName);
pstmt.setInt(1, AD_Client_ID);
pstmt.setInt(2, M_Product_ID);
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;
final String whereClause = "AD_Client_ID=? AND M_Product_ID=?"
+ " AND (AD_Org_ID IN (0,?) OR AD_Org_ID IS NULL)"
+ " AND (M_Warehouse_ID IN (0,?) OR M_Warehouse_ID IS NULL)"
+ " AND (S_Resource_ID IN (0,?) OR S_Resource_ID IS NULL)";
return new Query(ctx, Table_Name, whereClause, trxName)
.setParameters(new Object[]{AD_Client_ID, M_Product_ID, AD_Org_ID, M_Warehouse_ID, S_Resource_ID})
.setOrderBy("AD_Org_ID DESC NULLS LAST, M_Warehouse_ID DESC NULLS LAST, S_Resource_ID DESC NULLS LAST")
.first();
}