<html><head></head><body bgcolor="#FFFFFF"><div>Thanks so much! I'll have a chance to test it tomorrow.&nbsp;</div><div><br></div><div>Hank<br><br>Sent from my iPhone</div><div><br>On Jul 31, 2011, at 12:48 PM, "Mark Proctor" &lt;<a href="mailto:mproctor@codehaus.org">mproctor@codehaus.org</a>&gt; wrote:<br><br></div><div></div><blockquote type="cite"><div>
  
    <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
  
  
    On 31/07/2011 17:45, Mark Proctor wrote:
    <blockquote cite="mid:4E3586C7.4000209@codehaus.org" type="cite">
      <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
      On 31/07/2011 17:25, Heijink, Hank wrote:
      <blockquote cite="mid:67E60ADC-6E96-44DA-BA40-C7710F633EE5@audible.com" type="cite">
        <div>Aha! I missed the line about the dispose. That makes a lot
          of sense. What I don't understand is why the example 3.37 in
          the docs would work. If I understand what you're saying, it
          shouldn't. <br>
        </div>
      </blockquote>
      It should work, as long as the query is executed as part of the
      same execute batch. We have unit tests f or that too somewhere.<br>
    </blockquote>
    ok I see the problem. Your rules will not fire until the all the
    command shave been executed. i.e. the implicit fireAllRules() is
    once all commands have been executed. Which means the query will be
    invoked before your rule fires to insert the object.<br>
    <br>
    Instead you need to add the FireAllRules command before executing
    the query.<br>
    <br>
    Mark<br>
    <blockquote cite="mid:4E3586C7.4000209@codehaus.org" type="cite"> <br>
      mark<br>
      <blockquote cite="mid:67E60ADC-6E96-44DA-BA40-C7710F633EE5@audible.com" type="cite">
        <div><br>
        </div>
        <div>Thanks!</div>
        <div>Hank<br>
          <br>
          Sent from my iPhone</div>
        <div><br>
          On Jul 30, 2011, at 8:27 AM, "Wolfgang Laun" &lt;<a moz-do-not-send="true" href="mailto:wolfgang.laun@gmail.com"><a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a></a>&gt;

          wrote:<br>
          <br>
        </div>
        <blockquote type="cite">
          <div>StatelessKnowledgeSession.execute(...) executes the
            command(s) and <i>finally calls dispose()</i> on the
            session. Use a stateful session or a global (filled with a
            low-salience rule) or&nbsp; -&nbsp; simply use the getObjects command.<br>
            -W<br>
            <br>
            <div class="gmail_quote">On 29 July 2011 22:47, Heijink,
              Hank <span dir="ltr">&lt;<a moz-do-not-send="true" href="mailto:heijink@audible.com"><a href="mailto:heijink@audible.com">heijink@audible.com</a></a>&gt;</span>
              wrote:<br>
              <blockquote class="gmail_quote" style="border-left: 1px
                solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex;
                padding-left: 1ex;"> Hi all,<br>
                <br>
                I'm new to Drools, so please excuse me if I'm asking
                about the obvious--it's certainly not obvious to me. The
                problem is this: I use a stateless knowledge session
                where a list of facts is inserted. The rules that fire
                create new facts, and after all the rules have fired,
                I'd like to obtain a list of all the facts (the old and
                the new). The best way seemed to use a query. I'm using
                Drools 5.1 on Linux.<br>
                This is part of my .drl file (without the imports):<br>
                <br>
                rule "create badge"<br>
                when<br>
                &nbsp; &nbsp; &nbsp; &nbsp;Event ( eventType == EventType.SOME_EVENT_TYPE )<br>
                &nbsp; &nbsp; &nbsp; &nbsp;not BadgeState ( identifier == "badge" )<br>
                then<br>
                &nbsp; &nbsp; &nbsp; &nbsp;insert( new BadgeState("badge") );<br>
                end<br>
                <br>
                query "all badges"<br>
                &nbsp; &nbsp; &nbsp; &nbsp;aBadge : BadgeState()<br>
                end<br>
                <br>
                This is the Java code:<br>
                <br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StatelessKnowledgeSession ksession =
                StatsKnowledgeBase.getKnowledgeBase().newStatelessKnowledgeSession();<br>
                <br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Create a list of share events<br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ArrayList&lt;Event&gt; events = new
                ArrayList&lt;Event&gt;();<br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Date now = new Date();<br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MobileDevice aDevice = new
                MobileDevice("uniqueId", "deviceType");<br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i &lt; 5; i++) {<br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Event anEvent = new
                Event.Builder(now, aDevice, "aCustomer",
                EventType.SOME_EVENT_TYPE).build();<br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;events.add(anEvent);<br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
                <br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Create the query for the badges<br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;List&lt;Command&gt; commands = new
                ArrayList&lt;Command&gt;();<br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                &nbsp;commands.add(CommandFactory.newInsertElements(events));<br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;commands.add(CommandFactory.newQuery("all
                badges", "all badges"));<br>
                <br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Feed the events into Drools<br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;KnowledgeRuntimeLogger logger =
                KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);<br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ExecutionResults results =
                ksession.execute(
                CommandFactory.newBatchExecution(commands) );<br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NativeQueryResults queryResults =
                (NativeQueryResults)results.getValue("all badges");<br>
                <br>
                // At this point, queryResults is empty.<br>
                <br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;logger.close();<br>
                <br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Get a list of badges<br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;List&lt;BadgeState&gt; badges = new
                ArrayList&lt;BadgeState&gt;();<br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (Iterator&lt;QueryResultsRow&gt; i =
                queryResults.iterator(); i.hasNext(); ) {<br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;QueryResultsRow result =
                i.next();<br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BadgeState obj =
                (BadgeState)result.get("aBadge");<br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;badges.add(obj);<br>
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
                <br>
                The logger shows me that the BadgeState object is
                created, but the query returns an empty list. I've
                searched the documentation, which suggests that I'm
                doing it right (<a moz-do-not-send="true" href="http://drools.herod.net/drools-expert/html/ch03.html#d0e1956"><a href="http://drools.herod.net/drools-expert/html/ch03.html#d0e1956">http://drools.herod.net/drools-expert/html/ch03.html#d0e1956</a></a>,
                example 3.37), the archives of this mailinglist, and the
                web, so far without success.<br>
                <br>
                Clearly, I'm missing something, and I have the nagging
                feeling that it's something simple...<br>
                <br>
                Any help is much appreciated!<br>
                <br>
                Best,<br>
                Hank<br>
                <br>
                <br>
                _______________________________________________<br>
                rules-users mailing list<br>
                <a moz-do-not-send="true" href="mailto:rules-users@lists.jboss.org"><a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a></a><br>
                <a moz-do-not-send="true" href="https://lists.jboss.org/mailman/listinfo/rules-users"><a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a></a><br>
              </blockquote>
            </div>
            <br>
          </div>
        </blockquote>
        <blockquote type="cite">
          <div><span>_______________________________________________</span><br>
            <span>rules-users mailing list</span><br>
            <span><a moz-do-not-send="true" href="mailto:rules-users@lists.jboss.org"><a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a></a></span><br>
            <span><a moz-do-not-send="true" href="https://lists.jboss.org/mailman/listinfo/rules-users"><a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a></a></span><br>
          </div>
        </blockquote>
        <br>
        <fieldset class="mimeAttachmentHeader"></fieldset>
        <br>
        <pre wrap="">_______________________________________________
rules-users mailing list
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org"><a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a></a>
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users"><a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a></a>
</pre>
      </blockquote>
      <br>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org"><a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a></a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users"><a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a></a>
</pre>
    </blockquote>
    <br>
  

</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>rules-users mailing list</span><br><span><a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a></span><br><span><a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a></span><br></div></blockquote></body></html>