[rules-users] Dynamic Fact(field) Generation in Declarative Model
srinivasasanda
srinivasasanda at gmail.com
Tue Nov 29 08:00:30 EST 2011
Hi All,
Please help on this issue
I created a declarative model Person in personDetails package in Drools
Gunvor with 2 fields(age,amount).Now,I need to insert one field with name
gender and datatype String into that declarative model through POJO
class..Here is my code
RuleAgent agent = RuleAgent.newRuleAgent("/Guvnor.properties");
RuleBase rb = agent.getRuleBase();
WorkingMemory workingMemory = rb.newStatefulSession();
PackageBuilder pkgBuilder=new PackageBuilder(rb);
FactType personType = rb.getFactType( "persondetails.Person" );
ClassDefinition cDefinition=(ClassDefinition)
rb.getFactType("persondetails.Person");
FieldDefinition gen = new FieldDefinition( "gender",
"java.lang.String" );
product.setKey(true);
cDefinition.addField(product);
workingMemory.insert(cDefinition);
FactHandle fc=workingMemory.getFactHandle(cDefinition);
workingMemory.update(fc, cDefinition);
rb.newStatelessSession().execute(new Object[] {cDefinition});
}
String s1=cDefinition.getField(0).getTypeName();
String name1=cDefinition.getField(0).getName();
System.out.println(s1);
System.out.println(name1);
String s2=cDefinition.getField(1).getTypeName();
String name2=cDefinition.getField(1).getName();
System.out.println(s2);
System.out.println(name2);
String s3=cDefinition.getField(2).getTypeName();
String name3=cDefinition.getField(2).getName();
System.out.println(s3);
System.out.println(name3);
Output as Age---Java.lang.Integer
Amount-java.lang.Integer
Gender--Java.lang.String..
And when i am printing
It is executing successfuly first time without errors.but i could not find
gender in declarative model.It is failed to inserting.Can anyone help me in
this..plZzzzzz...I was struggling with this....
When Iam executing second time it is displaying as Exception:couldnot find
gender in declarative model..It means iam unable to commit Data into
Server..(Drools guvnor Model)
Please help on this....
--
View this message in context: http://drools.46999.n3.nabble.com/Dynamic-Fact-field-Generation-in-Declarative-Model-tp3545088p3545088.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
More information about the rules-users
mailing list