Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To compare dates, you can simply use Drools Fusion's temporal operators (after, before, etc.):</p> <pre><code>when MyClass( myDate after $someOtherDate ) then ... </code></pre> <p>However, there is another problem with your approach: you should not reason against a global in a condition. See the Expert manual <a href="http://docs.jboss.org/drools/release/5.4.0.Beta2/drools-expert-docs/html/ch05.html#d0e3313" rel="noreferrer">section</a> on globals.</p> <p>The notion of "now" is a bit problematic in Drools. Actually, maybe "problematic" isn't the right word; let's go with "tricky". How you represent it depends heavily on your use case. I'll try to summarize:</p> <ul> <li>If you are executing within a stateless session, then your approach will work in combination with the Fusion operators. It is still not a recommended practice, however. A better approach is to define a fact, call it <code>Now</code>, which contains a single <code>Date</code> field. Initialize and insert it along with your other facts then reason against it instead of a global.</li> <li>If you have a stateful session, it gets more tricky because real time is passing even while the session is idle, meaning your <code>Now</code> fact is getting more and more out of date. The way we have solved this is via the use of a <code>WorkingMemoryEventListener</code>. We use the <code>objectInserted</code>, <code>objectRetracted</code>, and <code>objectUpdated</code> methods of this listener to keep our <code>Now</code> fact current (we do not care about precision less than one minute so we check whether a minute has passed from the last update to avoid unnecessary overhead). Rules won't evaluate if working memory isn't changing, so using this listener is sufficient to ensure that <code>Now</code> is updated when it needs to be (unless you have queries that depend on the current value of <code>Now</code>, but that's another topic).</li> <li>You could also look into using Drools Fusion in STREAM mode, which has a notion of "now", but also imposes a few other requirements. See the <a href="http://docs.jboss.org/drools/release/5.4.0.Beta2/drools-fusion-docs/html/" rel="noreferrer">Fusion docs</a> for more information.</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload