Hi,
I have encountered an infinite loop in the following example. Where
TestVariable is has three fields, "context", "name", and
"value". Context and
name are Strings. Value is an Object. To work around the infinite loop, I need
to do some ugly type casting.
---------------------------
package testobjects;
public class TestVariable {
private String context;
private String name;
private Object value;
public TestVariable() {
}
public TestVariable(String context, String name, Object value) {
setContext(context);
setName(name);
setValue(value);
}
public String getContext() {
return context;
}
public void setContext(String context) {
this.context = context;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
public String toString() {
StringBuffer sbResult = new StringBuffer(17);
sbResult.append("");
sbResult
.append("context: ").append(getContext()).append(", ")
.append("name: ").append(getName()).append(", ")
.append("value: ").append(getValue());
return sbResult.toString();
}
}
---------------------------
package com.sample
import testobjects.TestVariable
import java.util.List
rule "init"
salience 1000
when
eval(true);
then
insert (new TestVariable("Price Items Rules Context" , "Unit Price",
null));
insert (new TestVariable("Price Items Rules Context", "Pricing
Category",
"INTERNATIONAL"));
end
rule "test 1"
no-loop true
when
$unitPriceVariable : TestVariable(context == "Price Items Rules Context"
&& name
== "Unit Price")
TestVariable(context == "Price Items Rules Context" && name ==
"Pricing
Category" && $pricingCategoryValue : value)
$pricingCategory : String() from $pricingCategoryValue
eval($pricingCategory.equals("INTERNATIONAL"))
then
$unitPriceVariable.setValue("542.00");
update($unitPriceVariable);
end
------------
The problem goes away if I change the "test 1" rule into the following:
rule "test 1"
no-loop true
when
$unitPriceVariable : TestVariable(context == "Price Items Rules Context"
&& name
== "Unit Price")
TestVariable(context == "Price Items Rules Context" && name ==
"Pricing
Category" && $pricingCategoryValue : value)
eval(((String)$pricingCategoryValue).equals("INTERNATIONAL"))
then
// $unitPriceVariable.setValue("542.00");
update($unitPriceVariable);
end
Show replies by date
I tried to implement the equals and hashCode method. However, the same problem
occurred. Is it caused by the generic Object type of the value attribute?
I have a Fact "SampleFact" that has a member called "member", this
member is of Type "MemberBean".
How can I create a Enumeration in the jbrms like:
'SampleFact.member' : ['choice1=MemberBean.instance1',
'choice2=MemberBean.instance2' ]
As far as I understand currently string and numerical types are supported?
Thanks
--zoly