从drools会话中删除对象,并在spring中重用相同的会话

时间:2014-03-06 04:54:16

标签: spring drools

我在服务类中使用自动装配的StatefulKnowledgeSession。

@服务( “vbOrderService”) 公共类VbOrderService {

@Autowired
private VbOrderDao vbOrderDao ;

@Autowired
StatefulKnowledgeSession vbDiscSession;

public CpSellerDetails getStep1Data(Integer grpSellerId,Integer catalogueId) throws DataNotFoundException{
    return vbOrderDao.getStep1Data(grpSellerId,null,catalogueId);
}
/*public CpSellerDetails getStep1Data(Integer cp_id,Integer orderno) throws DataNotFoundException{
    return vbOrderDao.getStep1Data(cp_id,orderno);
}*/
public void getStep2Data(Integer cp_id,VbCpInfoBean info) throws DataNotFoundException{
    vbOrderDao.getStep2Data(cp_id,info);
}
public Integer updateStep2Data(VbCpInfoBean info,Integer cp_id) throws UpdateFailedException{
    return vbOrderDao.updateStep2Data(info,cp_id);
}

public void getOrderStep3(CpSellerDetails sellerDetails) throws DataNotFoundException {
     vbOrderDao.getOrderStep3(sellerDetails);
      fireRules(sellerDetails);
}
public void orderStep4(LoginBean user,CpSellerDetails sellerDetails) throws UpdateFailedException {
     vbOrderDao.orderStep4(user,sellerDetails);
    // fireRules(sellerDetails);
}
public CpSellerDetails getOrderDetailsForPdfGeneration(String orderno,
        int user) throws DataNotFoundException {
    return vbOrderDao.getOrderDetailsForPdfGeneratio(orderno,user);
}
public void addNewAddress(Address address) throws UpdateFailedException {
    vbOrderDao.addNewAddress(address);
}
private void fireRules(CpSellerDetails sellerDetails){
    vbDiscSession.insert(sellerDetails);
    vbDiscSession.fireAllRules();
}

} 是否可以从getOrderStep3()调用的fireRules()中的会话中删除插入的对象,并为进一步的请求重用相同的StatefulKnowledgeSession。如果可能的话,如何实现

1 个答案:

答案 0 :(得分:3)

我经常这样做是为了确保在重新插入大量“静态数据”事实需要时间的会话上的表现。

// Insert a fact and get a handle on to it
FactHandle handle = mySession.insert(myFact);

// Fire rules
mySession.fireAllRules();

// And retract the fact
mySession.retract(handle);

您可能希望在撤消后再次触发所有规则,以使会话恢复到之前的状态。