Hi,
I have an example of two rules we use in our project.
Rule CheckStationNumber checks if the station number field is null in
BillingRecord Object which is
stored as a list in AssertionObject object.
Rule AssignBAC gets a value from a static map(we dont want to do database
calls eachtime.so we store the
required values in a static map) and assigns it to bac field in
BillingRecord based
on certain other field values in Billing Record.
So we have around 10 more rules similiar to this pattern and we run this
rule against against
100,000 billing records and the execution time is very long.
I know that i am not supposed to use eval in rules which slows down the
performance. Can you please
suggest me few other ways how i can accomplish these tasks and improve the
execution time?
thanks
ABRA2
example.drl
import ct.fw.web.rules.*;
import ct.fw.rules.*;
import ct.fw.utils.*;
import ct.fw.rules.*;
import ct.fw.pf.*;
import ct.fw.pf.dbi.DbAccess;
import ct.fw.logging.*;
import ct.fw.ex.*;
import org.apache.commons.lang.*;
import com.aa.gccp.domain.*;
import com.aa.gccp.domain.persistence.dao.*;
import com.aa.gccp.utils.*;
import com.aa.gccp.processor.*;
global ct.fw.logging.SmartLogger log
function BillingRecord getRecord(AssertionObject ao)
{
return (BillingRecord) ao.get(0);
}
function Object getRecordData(AssertionObject ao, String key)
{
return getRecord(ao).get(key);
}
function void error(String msg,SmartLogger log)
{
log.error(BusinessRulesValidator.class, msg);
}
function void info(String msg,SmartLogger log)
{
log.info(BusinessRulesValidator.class, msg);
}
function String getBillActCode(String stationno,String tiktcrncy,String
cardtype)
{
String bac="";
Map<String,String> bacamap = new HashMap<String,String>();
if(stationno!=null && !stationno.equals("") && tiktcrncy!=null
&&
!tiktcrncy.equals("") && cardtype!=null &&
!cardtype.equals(""))
{
if(stationno.length()<7){stationno=stationno.substring(0,3);}
bacamap=FileFormatLoader.BACAMap;
if(bacamap.size()>0)
{
bac=bacamap.get(stationno+tiktcrncy+cardtype);
}
}
return bac;
}
rule CheckStationNumber
salience 100
no-loop true
when
$ao:AssertionObject()
$stno:String() from getRecordData($ao,"stationNo")
eval(($stno.equals("")) || ($stno == null))
then
$ao.addError(BillingRecordHelper.STATION_NO_NULL_ERROR,"CheckStationNumber");
error(BillingRecordHelper.STATION_NO_NULL_ERROR,log);
end
rule AssignBAC
salience 50
no-loop true
when
$ao:AssertionObject()
$stno:String() from getRecordData($ao,"stationNo")
$cardtype:String() from getRecordData($ao,"cardType")
$tktcuralphacd:String() from getRecordData($ao,"tktCurrAlphaCd")
$bac:String() from getBillActCode($stno,$tktcuralphacd,$cardtype)
eval(((((getRecord($ao)).getBillingActionCd())==null) ||
(((getRecord($ao)).getBillingActionCd()).equals(""))) &&
!($bac.equals("")))
then
modify($ao){setBillingRecord("billingActionCd",$bac);}
info(BillingRecordHelper.BAC_ASSIGNED_INFO,log);
end
--
View this message in context:
http://old.nabble.com/Help-me-improve-my-rules-performance.-tp26261345p26...
Sent from the drools - user mailing list archive at
Nabble.com.