[rules-users] How to empty the Working memory

Spade87 johan.spade at gmail.com
Mon Mar 12 09:22:21 EDT 2012


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.



More information about the rules-users mailing list