Torsten,
That was the general idea. So if you have 2 containers, declare it 2
times:
rule "Item handling"
When
$item : Item(uniqueId)
$container1: Container( values contains $item )
$container2: Container( values contains $item )
Then
if(mustBeDeleted($item)) {
retract($item);
$container1.remove( $item );
$container2.remove( $item );
} else {
doSomethingElse();
modify($item);
}
End
You may or may not call modify($containerX) also, depending on your
rules and what you are trying to achieve.
[]s
Edson
Geise, Thorsten (ext) wrote:
This approach works very well for the first container. But, because the
item-fact is retracted from the working memory, the rule will never
fired for the second container.
Torsten.
-----Original Message-----
From: Edson Tirelli [mailto:[EMAIL PROTECTED]
Sent: Dienstag, 14. November 2006 17:01
To: user@drools.codehaus.org
Subject: Re: [drools-user] Access WorkingMemory from within rules or
functions
Torsten,
If the container is asserted in the working memory, just add it to
the rule:
rule "Item handling"
When
$item : Item(uniqueId)
$container: Container( values contains $item ) Then
if(mustBeDeleted($item)) {
retract($item);
$container.remove( $item );
} else {
doSomethingElse();
modify($item);
}
End
Otherwise, you can set the container as a global:
global my.package.Container container;
rule "Item handling"
When
$item : Item(uniqueId)
Then
if(mustBeDeleted($item)) {
retract($item);
container.remove( $item );
} else {
doSomethingElse();
modify($item);
}
End
You can access workingMemory through a special variable named
"drools", but for your case, I think best approach is one of the above.
[]s
Edson
Geise, Thorsten (ext) wrote:
Is it possible to access the working memory from within a rule or
function?
Example: I have two container objects that refer to another object
(item). Both container have this item in a list.
A rules decides to delete the item and therefore retracts it from the
working memory. But I need to delete the item from the two containers
as well. How to do?
rule "Item handling"
When
$item : Item(uniqueId)
Then
if(mustBeDeleted($item)) {
retract($item);
} else {
doSomethingElse();
modify($item);
}
End
Thanks,
Torsten.
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email
--
---
Edson Tirelli
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3124-6000
Mobile: +55 11 9218-4151
JBoss, a division of Red Hat @ www.jboss.com
IT executives: Red Hat still #1 for value
http://www.redhat.com/promo/vendor/
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email
--
---
Edson Tirelli
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3124-6000
Mobile: +55 11 9218-4151
JBoss, a division of Red Hat @ www.jboss.com
IT executives: Red Hat still #1 for value
http://www.redhat.com/promo/vendor/
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email