<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
    <title></title>
  </head>
  <body bgcolor="#ffffff" text="#000000">
    On 12/08/2010 02:37, Alex Besogonov wrote:
    <blockquote
      cite="mid:AANLkTinPVY1gTMpuLq_dFLsE76Yo3PUX5fX1xL6m-q5Y@mail.gmail.com"
      type="cite">
      <pre wrap="">Good $time_of_day!

I'm a Drools newbie trying to use it in production. So I want to share
some of my frustration and some of my solutions to this frustration :)

First, let's start with insertLogical - it's useless. It can easily
mislead user into thinking that changed objects are retracted. Of
course, other users bumped into it before me:
<a class="moz-txt-link-freetext" href="http://drools-java-rules-engine.46999.n3.nabble.com/insertLogical-and-modifyRetract-td57727.html">http://drools-java-rules-engine.46999.n3.nabble.com/insertLogical-and-modifyRetract-td57727.html</a>
, but the proposed resolution is ugly. 
</pre>
    </blockquote>
    If you are using Drools 5.0 or 5.1 you no longer need modifyRetract
    and modifyInsert, they were hacks due to the use of shadow facts in
    Drools 4.0, which no longer exist.<br>
    <br>
    Also please stick to interfaces and methods provided in drools-api.<br>
    <br>
    Likewise the other issue from that posting is fixed and no longer an
    issue if you use 5.1. <a class="moz-txt-link-freetext" href="https://jira.jboss.org/browse/JBRULES-1804">https://jira.jboss.org/browse/JBRULES-1804</a><br>
    <br>
    Don't forget to implement equals and hashcode for logicaly inserted
    facts, as the TMS depends on those to work.<br>
    <blockquote
      cite="mid:AANLkTinPVY1gTMpuLq_dFLsE76Yo3PUX5fX1xL6m-q5Y@mail.gmail.com"
      type="cite">
      <pre wrap="">
So I wrote a wrapper around the 'insertLogical' function which
introduces the notion of 'fact key', so only one fact with the given
key can exist in the working memory at a time. To borrow the example
in the referenced mail thread:
============
rule "fact = 1"
   when
       $f : UserFact(fact1 == 1);
   then
         insertLogical(new CreatedFact($f.getFact2()));
end
============
Becomes:
============
global ConsequenceHelper ch; # Code of the ConsequenceHelper is attached

rule "fact = 1" language "mvel"
   when
       $f : UserFact(fact1 == 1);
   then
         ch.insertGuarded(drools, new CreatedFact($f.getFact2()),
{$f.getFact2()}); # Here {$f.getFact2()} is the CreatedFact's key.
end
============
So if this rule fires again, the stale object will be retracted and
the newly created object will be asserted. It would be nice to see
something like this integrated into the Drools core...

</pre>
    </blockquote>
    As mentioned above, already fixed in 5.1 :)<br>
    <blockquote
      cite="mid:AANLkTinPVY1gTMpuLq_dFLsE76Yo3PUX5fX1xL6m-q5Y@mail.gmail.com"
      type="cite">
      <pre wrap="">
Next, I'd like to say something about Drools LHS language. Well, it's
VERY confusing. I spent two hours debugging internals of MVEL to
understand why this doesn't work:
============
rule "Double Shift OT"
       dialect "mvel" agenda-group "OT Calculation"
when
       $at : AcctTransaction()
       exists(AcctTransaction(this!=$at, acct.plannedEndTimestamp
coincides[2h] $at.plannedStartTimestamp))
then
...
end
============
Turns out, I can't use these nice Drools Fusion predicates to for deep
properties. It would be nice, if it was at least mentioned somewhere
in the documentation. No workaround for this one, I had to write
global helper functions.
</pre>
    </blockquote>
    That should work, have you tried 5.1? If it doesn't please open a
    JIRA and we'll attemt to fix it.<br>
    <br>
    We are currently simplifying our backend for LHS which will remove
    the confusion of whether it's drools or mvel doing the evaluation.
    Which should simplify things.<br>
    <blockquote
      cite="mid:AANLkTinPVY1gTMpuLq_dFLsE76Yo3PUX5fX1xL6m-q5Y@mail.gmail.com"
      type="cite">
      <pre wrap="">

And the final problem (so far). Drools has this nice 'from' feature
which allows to use objects not in the working memory. However, it's
not possible to do this:
============
rule "Blah"
when
   $l : Long() from new Long(42L)
then
...
end
============
I had to write a helper function which just returns its parameter to
work around this one.
</pre>
    </blockquote>
    For now you can do this:<br>
    Long() from return( new Long(42) )<br>
    <br>
    It's a parser limitation, we are trying to improve it.<br>
    <blockquote
      cite="mid:AANLkTinPVY1gTMpuLq_dFLsE76Yo3PUX5fX1xL6m-q5Y@mail.gmail.com"
      type="cite">
      <pre wrap="">

And the final note - DRL is too cut&amp;pasty. There's no _good_ way to
reuse predicates used in the LHS (there's rule inheritance, but it's
not always applicable) and actions in the RHS.
</pre>
    </blockquote>
    Always open to suggestions. Better still, get involved and help us
    improve things :)<br>
    <br>
    Mark<br>
    <blockquote
      cite="mid:AANLkTinPVY1gTMpuLq_dFLsE76Yo3PUX5fX1xL6m-q5Y@mail.gmail.com"
      type="cite">
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
rules-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-dev">https://lists.jboss.org/mailman/listinfo/rules-dev</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>