<br> It all depends on how many simultaneous instances you have in your working memory. If you have just a few instances, a simple and single rule can handle your case... you don't need to check for nulls, unless you want to explicitly handle them:
<br><br>rule "Overlapping Dates"<br> when<br> $a : Address ( )<br> $b : Address ( this != $a, beginDate > $a.beginDate, beginDate < $a.endDate )<br> then<br> // $a and $b overlap<br>end
<br><br> Now, I had to do the same thing for a system that handled telecom calls and we had hundreds of thousands of call objects at once in the working memory. As you may be aware, rules like the one above have the potential to generate combinatorial explosions. In my case, I created a high performance data structure to index the dates and detect the overlaps and used the rules only to drive the execution (of course, there were hundreds of other rules doing other things too). This way I avoided the combinatorial explosion.
<br><br> Hope it helps.<br><br> Edson<br><br><div><span class="gmail_quote">2007/8/29, Brian Enderle <<a href="mailto:brianke@gmail.com">brianke@gmail.com</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I have a situation where I need to check for overlapping dates in a collection<br>of previous addresses. I am only performing this check after checking that<br>the beginDate and endDate are not null.<br><br>Currently I am using an eval to perform an outside method. Does anyone know
<br>if and how I could perform this same check using Drools.<br><br>Curently my rules look something like this<br><br>gloabl java.lang.Boolean dateErrorExists; // starts off as false<br>global ValidationUtils utils;<br>
<br>rule "beginDate must exist"<br> when<br> Address ( beginDate != null )<br> then<br> dateMissing = true;<br> <display error><br>end<br><br>rule "endDate must exist"<br> when
<br> Address ( endDate != null )<br> then<br> dateMissing = true;<br> <display error><br>end<br><br>rule "Previous Address dates cannot overlap"<br> salience -10<br> when<br> eval (dateMissing)
<br> eval (utils.doAddressDatesOverlap())<br> then<br> <display error><br>end<br><br>Our system simply runs thru the data checking the rules (no facts are changed)<br>so the dateMissing global is reset to false everytime we perform our
<br>validation.<br><br>The downside to this is I am having to re-get the data from the DB within the<br>doAddressDatesOverlap() function. This function orders the Address objects by<br>their startDates and then compares the endDate of one with the startDate of
<br>the next and returns false if they overlap.<br><br>If anyone knows of a cleaner, simpler or better way to perform this check<br>within Drools I would appreciate the input.<br><br>Thanks in advance,<br>Brian Enderle<br>
<br>_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br><a href="https://lists.jboss.org/mailman/listinfo/rules-users">
https://lists.jboss.org/mailman/listinfo/rules-users</a><br></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> Software Engineer - JBoss Rules Core Developer<br> Office: +55 11 3529-6000<br> Mobile: +55 11 9287-5646
<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a>