Frage

I am using an autowired StatefulKnowledgeSession in a service class.

@Service("vbOrderService")
public class 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();
    }
}

Is it possible to remove the inserted object from session in fireRules() called from getOrderStep3() and reuse the same StatefulKnowledgeSession for further requests.If possible how can it be achieved

War es hilfreich?

Lösung

I often do this to ensure performance on a session where it would take time to re-insert large numbers of 'static data' facts.

// 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);

You may wish to fire all rules again after the retract to bring the session back to its previous state.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top