The usual approach is to add all KPs in a single add call:
val session = createSessionUsingNoPackages
val kbuilder1 = KnowledgeBuilderFactory.newKnowledgeBuilder
kbuilder1.add("rule1.drl", ResourceType.DRL)
val kbuilder2 = KnowledgeBuilderFactory.newKnowledgeBuilder
kbuilder2.add("rule2.drl", ResourceType.DRL)
session addGlobal ("foo", foo)
session addGlobal ("Gar", gar)
session.knowledgeBase addKnowledgePackages (kbuilder2.getKnowledgePackages)
Perhaps this avoids the problem?
-W
On Wed, Dec 2, 2009 at 7:24 PM, Barry Kaplan <groups1(a)memelet.com> wrote:
I'm at my wits end. I have two simple rules in two separate packages, they
are of the form:
rule1:
import somepackage.*
global somepackage.Foo foo
...
then
foo.doSomething(...)
end
rule2:
import otherpackage.*
global otherpackage.Gar gar
...
then
gar.doSomething(...)
end
When mvel is resolving foo for rule1 it does so via
org.mvel2.compiler.CompiledExpression#getValue:line-104
When resolving gar for rule2 it does so via
org.mvel2.compiler.CompiledExpression#getValue:line-107
The difference is that for rule1 the variable 'importInjectionRequired' is
true, which results in 'foo' being resolved, but for rule2 this variable is
false which results in 'gar' not being resolved.
I suspecting that its important that the packages and the global instances
are added dynamically *after* the session is created (in scala'ish dialect):
val session = createSessionUsingNoPackages
val kbuilder1 = KnowledgeBuilderFactory.newKnowledgeBuilder
kbuilder1.add("rule1.drl", ResourceType.DRL)
session.knowledgeBase addKnowledgePackages (kbuilder1.getKnowledgePackages)
session addGlobal ("foo", foo)
val kbuilder2 = KnowledgeBuilderFactory.newKnowledgeBuilder
kbuilder2.add("rule2.drl", ResourceType.DRL)
session.knowledgeBase addKnowledgePackages (kbuilder2.getKnowledgePackages)
session addGlobal ("Gar", gar)
If just one or the other packages are added the session, then either
variable is resolved. But if both are added the session the 'gar' is not
resolved. It does not matter what order they added to the session. I can
also try to access 'gar' in rule1 and it also will not be resolved.
I guess I really don't expect any help on this, but I will boil it down to a
simple test and submit it to jira
-barry
--
View this message in context:
http://n3.nabble.com/MVEL-wows-what-does-importInjectionRequired-mean-tp6...
Sent from the Drools - User mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users