[rules-users] How to empty the Working memory

Johan Spaedtke johan.spade at gmail.com
Mon Mar 12 10:18:22 EDT 2012


Thank you that worked out nicely =)

//Johan

2012/3/12 Wolfgang Laun <wolfgang.laun at gmail.com>

> You can save the FactHandle returned from the insert() and retract that.
>
> Or you can retrieve the FactHandle via the WorkingMemorEntryPoint
> method getFactHandle( Object obj ).
>
> -W
>
>
>
> On 12/03/2012, Spade87 <johan.spade at gmail.com> wrote:
> > Using that rule worked, sort of... It correctly removes all of the
> objects
> > in
> > the working memory. The problem is that it clears everything... If you
> use
> > mule together with drools the drools module will send back whatever you
> sen
> > to it to mule when there are no more rules fireing. If I delete
> everything
> > as a last step then I wont get my modified data back. Right now i have
> one
> > method that takes a WorkingMemory and a collection and inserts everything
> > from the collection in the working memory.
> >
> > *Rule*
> > rule 'addAllFromCollection'
> > when
> >       c : MyCollection ( newCollection == true )
> > then
> >       DroolsUtil.insertCollection(drools.workingMemory, c )
> > end
> >
> > *JavaCode*
> > public static void insertCollection(WorkingMemory workingMemory,
> Collection
> > collection) {
> >       Iterator iterator = collection.iterator();
> >       while (iterator.hasNext()) {
> >               workingMemory.insert(iterator.next());
> >       }
> > }
> >
> > Basically what i want to do is write a corresponding function to retract
> > everything that is old
> >
> > *Rule*
> > rule 'retractAllFromCollection'
> > when
> >       c : MyCollection ( newCollection == false )
> > then
> >       DroolsUtil.retractCollection(drools.workingMemory, c )
> > end
> >
> > *JavaCode*
> > public static void retractCollection(WorkingMemory workingMemory,
> Collection
> > collection) {
> >       Iterator iterator = collection.iterator();
> >       while (iterator.hasNext()) {
> >               workingMemory.retract(iterator.next());
> >       }
> > }
> >
> > The problem is that the method workingMemory.retract() doesn't take a
> > argument but a FactHandle as an argument but if i try something like
> >
> > *JavaCode*
> > public static void retractCollection(WorkingMemory workingMemory) {
> >       Collection collection = workingMemory.getFactHandles();
> >       Iterator iterator = collection.iterator();
> >       while (iterator.hasNext()) {
> >               workingMemory.retract(iterator.next());
> >       }
> > }
> >
> > I get a rather strange exception
> > java.lang.UnsupportedOperationException: this is implementedby
> > StatefulKnowledgeImpl
> >       at
> >
> org.drools.reteoo.ReteooWorkingMemory.getFactHandles(ReteooWorkingMemory.java:363)
> >       at
> >
> se.sunstone.ebs.mama.oneqc.drools.DroolsUtil.insertCollection(DroolsUtil.java:21)
> >       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >
> > Any thoughts?
> >
> > --
> > View this message in context:
> >
> http://drools.46999.n3.nabble.com/How-to-empty-the-Working-memory-tp3818693p3819245.html
> > Sent from the Drools: User forum mailing list archive at Nabble.com.
> > _______________________________________________
> > rules-users mailing list
> > rules-users at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
RF kap. 2 §6 Varje medborgare är gentemot det allmänna skyddad mot
påtvingat kroppsligt ingrepp även i annat fall än som avses i 4 och 5 §§.
Han är därjämte skyddad mot kroppsvisitation, husrannsakan och liknande
intrång samt mot undersökning av brev eller annan förtrolig försändelse och
mot hemlig avlyssning eller upptagning av telefonsamtal eller annat
förtroligt meddelande. Lag (1976:871).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20120312/8a6c470f/attachment.html 


More information about the rules-users mailing list