<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:tahoma,new york,times,serif;font-size:10pt"><div>Ken,<br><br>Neither solution makes any assumption about data storage. Hibernate entities could be used or simple POJOs, matters not. As to your Example, I have used something similar to the following:<br><br>public class Entity {<br><br> private String firstName;<br> <br> public String getFirstName() { return firstName; }<br> public void setFirstname(String firstName) { this.firstName = firstName; }<br>}<br><br>public class FactEntity {<br> private Entity entity;<br> private String additionalAttribute;<br><br> public FactEntity(Entity entity) { this.entity = entity; }<br> public Entity getEntity() { return entity; }<br> public void
setEntity(Entity entity) { this.entity = entity; }<br> public String getAdditionalAttribute() { return additionalAttribute; }<br> public void setAdditionalAttribute(String additionalAttribute) { this.additionalAttribute = additionalAttribute; }<br>}<br><br>In your class that inserts the Entity facts into working memory, you just;<br><br> FactEntity fe = new FactEntity(originalEntity);<br> workingMemory.insert(fe);<br><br>In your rule, you can then do something like;<br><br>rule<br> when<br> $fe : FactEntity(additionalAttribute == "Supervisor")<br> then<br> System.out.println($fe.entity.firstName);<br>end<br></div><div style="font-family: tahoma,new york,times,serif; font-size: 10pt;"><br>Earnie!<br><div style="font-family: times new roman,new york,times,serif; font-size:
12pt;"><font size="2" face="Tahoma"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> Ken Archer <archerovi@hotmail.com><br><b><span style="font-weight: bold;">To:</span></b> rules-users@lists.jboss.org<br><b><span style="font-weight: bold;">Sent:</span></b> Thursday, July 30, 2009 9:13:35 AM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [rules-users] How to Enrich Facts with Data from a Database<br></font><br>
<style>
.hmmessage P
{
margin:0px;padding:0px;}
body.hmmessage
{
font-size:10pt;font-family:Verdana;}
</style>
Earnie,<br><br>Thanks for this. Do your two solutions to fact enrichment presume use of the Hibernate framework to interact with a database in the rules? Would an example of your first solution be the following?<br><br>when<br> $w : WMFact($key : id)<br> $d : DatabaseFact(parentKey == $key)<br>then<br> $w.Field1=$d.Field1 AND $w.Field2=$d.Field2 AND $w.Field3=$d.Field3<br><br>Ken <br><br><hr id="stopSpelling">Date: Tue, 28 Jul 2009 09:35:47 -0700<br>From: earniedyke@yahoo.com<br>To: rules-users@lists.jboss.org<br>Subject: Re: [rules-users] How to Enrich Facts with Data from a Database<br><br>
<style>
.ExternalClass DIV
{}
</style><div style="font-family: tahoma,new york,times,serif; font-size: 10pt;"><div style="font-family: tahoma,new york,times,serif; font-size: 10pt;">One way is to extend the original classes and add the desired attributes, then insert the extended class into WorkingMemory. You could then use RHS to modify matched facts. Another way is to inject "related" facts. So your LHS matches a fact and you insert a new "related" fact in the RHS. Rules that must evaluate data from both facts can the do something like this:<br><br>when<br> $b : BaseFact($key : id)<br> $r : RelatedFact(parentKey == $key)<br>then<br> ...<br><br>I have used both albeit on small sets of facts and both worked fine.<br><br>Earnie!<br><br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><font size="2" face="Tahoma"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> Ken Archer
<archerovi@hotmail.com><br><b><span style="font-weight: bold;">To:</span></b> rules-users@lists.jboss.org<br><b><span style="font-weight: bold;">Sent:</span></b> Tuesday, July 28, 2009 12:22:37 PM<br><b><span style="font-weight: bold;">Subject:</span></b> [rules-users] How to Enrich Facts with Data from a Database<br></font><br>
<style>
.ExternalClass .EC_hmmessage P
{padding:0px;}
.ExternalClass body.EC_hmmessage
{font-size:10pt;font-family:Verdana;}
</style>
<p class="EC_EC_MsoNormal">I would like to append values to facts in working memory with
values from a database before rules processing. The Fusion documentation
says, “one of the most common use cases for rules is event data enrichment”,
but no documentation seems to explain how this is done whether we’re talking
about events or just plain old facts. And the RHS syntax seems to be
limited to working with data already in working memory. How can I enrich
facts with data from another system? Thanks in advance.</p>
<p class="EC_EC_MsoNormal"> </p>
<p class="EC_EC_MsoNormal">Ken Archer</p>
<p class="EC_EC_MsoNormal">Telogical Systems</p>
<br><br></div></div></div></div></div></div></body></html>