[rules-users] Retract in a function

Ronald R. DiFrango ron.difrango at gmail.com
Wed Oct 3 11:22:47 EDT 2007


Michael,

In my case, I am modifying the object, so I thought a modifyRetract was the
better option.

As for the differences, I will defer to the Drools team.  Please note that
CC'ed the group again as you did not on my response.

Ron

On 10/3/07, Anstis, Michael (M.) <manstis1 at ford.com> wrote:
>
>  Thanks for posting the solution!
>
> Does it work with just "retract" rather than "modifyRetract"?
>
> Could the Drools' team remind me (the group) of the difference between the
> two?
>
>  ------------------------------
> *From:* Ronald R. DiFrango [mailto:ron.difrango at gmail.com]
> *Sent:* 03 October 2007 14:57
> *To:* Anstis, Michael (M.)
> *Cc:* Rules Users List
> *Subject:* Re: [rules-users] Retract in a function
>
> I got it, the following works:
>
> function void openRTVLines(WorkingMemory workingMemory, QueryResults
> results, String status)
> {
>     System.out.println( "We have " + results.size() + " Open RTV Lines" );
>
>     for ( Iterator it = results.iterator(); it.hasNext(); ) {
>         QueryResult result = ( QueryResult ) it.next();
>         DetailLine line = ( DetailLine ) result.get( "line" );
>         line.setStatus (status);
>
>         // Now retract those objects from Working Memory
>         FactHandle handle = workingMemory.getFactHandle(line);
>         System.out.println("handle : " + handle);
>         workingMemory.modifyRetract(handle);
>     }
> }
>
> On 10/3/07, Ronald R. DiFrango <ron.difrango at gmail.com > wrote:
> >
> > I have now tried the following and it did not seem to have the intended
> > result of removing the detail line from working memory:
> >
> > function void openRTVLines(WorkingMemory workingMemory, QueryResults
> > results, String status)
> > {
> >     System.out.println( "We have " + results.size() + " Open RTV Lines"
> > );
> >     for ( Iterator it = results.iterator(); it.hasNext(); ) {
> >         QueryResult result = ( QueryResult ) it.next ();
> >         DetailLine line = ( DetailLine ) result.get( "line" );
> >         line.setStatus(status);
> >
> >         // Now retract those objects from Working Memory
> >         FactHandle[] handles = result.getFactHandles();
> >         System.out.println("handles.length : " + handles.length);
> >         for(int i = 0; i < handles.length; i++)
> >         {
> >             System.out.println("Retracting : ");
> >             workingMemory.retract(handles[i]);
> >         }
> >     }
> > }
> >
> > Any other thoughts out there?
> >
> > On 10/3/07, Ronald R. DiFrango < ron.difrango at gmail.com> wrote:
> > >
> > > Michael,
> > >
> > > Those detail lines are in working memory for sure.  In fact the query
> > > it self only works on working memory objects.
> > >
> > > As far as I know you can not place the results of a queryResult in the
> > > LHS.
> > >
> > > Ron
> > >
> > > On 10/3/07, Anstis, Michael (M.) < manstis1 at ford.com> wrote:
> > > >
> > > >  Can you not get a reference to a DetailLine in the LHS?
> > > >
> > > > If you have not inserted DetailLine objects into working memory how
> > > > can you expect to retract them?
> > > >
> > > > If you have inserted DetailLine's into working memory what does
> > > > query "Open RTV Lines" return, can it be joined into the LHS? (or split into
> > > > two rules)?
> > > >
> > > >  ------------------------------
> > > > *From:* rules-users-bounces at lists.jboss.org [mailto:
> > > > rules-users-bounces at lists.jboss.org] *On Behalf Of *Ronald R.
> > > > DiFrango
> > > > *Sent:* 03 October 2007 14:01
> > > > *To:* Rules Users List
> > > > *Subject:* [rules-users] Retract in a function
> > > >
> > > >  All,
> > > >
> > > > I have the following function that I call from all of my rules.
> > > > When I execute this function, I need to retract that object from working
> > > > memory.  The problem is that when I insert the comment line below I get a
> > > > compiler error saying that I can only issue a retract on fact handles.
> > > >
> > > > Here is an example of my rule plus the function:
> > > >
> > > > rule "QTY Percentage tolerance - Approval"
> > > >     salience -25
> > > >     no-loop  true
> > > >     when
> > > >         rtvHeader : RtvHeader( totalAmount : totalAmount, status not
> > > > in ( StatusConstants.MATCHED, StatusConstants.APPROVAL) )
> > > >         repaymentCode : RepaymentCode( code == "QTY", matchApprv ==
> > > > "Y", tolDollar ==0, tolPercent != 0, tolPercent : tolPercent )
> > > >         qtyOutput : QTYOutput( sumRTVQty : sumRTVQty , sumCmAndRnr :
> > > > sumCmAndRnr )
> > > >         eval( qtyPercentage(qtyOutput, totalAmount, tolPercent) )
> > > >     then
> > > >         System.out.println("QTY Percentage tolerance - No
> > > > Approval");
> > > >         rtvHeader.setStatus(StatusConstants.APPROVAL );
> > > >         openRTVLines(drools.getWorkingMemory(),
> > > > drools.getWorkingMemory().getQueryResults( "Open RTV Lines" ),
> > > > StatusConstants.MATCHED_WITHIN_TOLERANCE);
> > > > end
> > > >
> > > > function void openRTVLines(WorkingMemory workingMemory, QueryResults
> > > > results, String status)
> > > > {
> > > >     System.out.println( "We have " + results.size() + " Open RTV
> > > > Lines" );
> > > >     for ( Iterator it = results.iterator(); it.hasNext(); ) {
> > > >         QueryResult result = ( QueryResult ) it.next ();
> > > >         DetailLine line = ( DetailLine ) result.get( "line" );
> > > >         line.setStatus(status);
> > > >
> > > >         // I need to add this in
> > > >         // workingMemory.retract(line);
> > > >     }
> > > > }
> > > >
> > > > Thanks in advance,
> > > >
> > > > Ron
> > > >
> > > >
> > > >
> > >
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20071003/86aeecb5/attachment.html 


More information about the rules-users mailing list