<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>Hmm … so the use of batch execution instead of InsertObjectCommand improved things. However I have noticed that although rules are activating as expected, and facts are being inserted, my queries don’t seem to get any results. For instance with the following code:</div><div><br></div><div>Based on a stateless session:</div><div><br></div><div><pre style="font-family: Consolas, 'Liberation Mono', Courier, monospace; margin-top: 0px; margin-bottom: 0px; color: rgb(51, 51, 51); line-height: 18px;"><div class="line" id="LC95" style="padding-left: 10px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">List</span><span class="o" style="font-weight: bold;">&lt;</span><span class="n">Command</span><span class="o" style="font-weight: bold;">&gt;</span> <span class="n">cmds</span> <span class="o" style="font-weight: bold;">=</span> <span class="k" style="font-weight: bold;">new</span> <span class="n">ArrayList</span><span class="o" style="font-weight: bold;">&lt;</span><span class="n">Command</span><span class="o" style="font-weight: bold;">&gt;();</span></div><div class="line" id="LC96" style="padding-left: 10px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">cmds</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: teal;">add</span><span class="o" style="font-weight: bold;">(</span><span class="n">CommandFactory</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: teal;">newInsert</span><span class="o" style="font-weight: bold;">(</span><span class="k" style="font-weight: bold;">new</span> <span class="n">IbanValidationRequest</span><span class="o" style="font-weight: bold;">(</span><span class="n">iban</span><span class="o" style="font-weight: bold;">),</span> <span class="s" style="color: rgb(221, 17, 68);">"request"</span><span class="o" style="font-weight: bold;">));</span></div><div class="line" id="LC97" style="padding-left: 10px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">cmds</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: teal;">add</span><span class="o" style="font-weight: bold;">(</span><span class="n">CommandFactory</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: teal;">newQuery</span><span class="o" style="font-weight: bold;">(</span><span class="s" style="color: rgb(221, 17, 68);">"annotations"</span><span class="o" style="font-weight: bold;">,</span> <span class="s" style="color: rgb(221, 17, 68);">"annotations"</span><span class="o" style="font-weight: bold;">));</span></div><div class="line" id="LC98" style="padding-left: 10px;"><br></div><div class="line" id="LC99" style="padding-left: 10px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">ExecutionResults</span> <span class="n">results</span> <span class="o" style="font-weight: bold;">=</span> <span class="n">ksession</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: teal;">execute</span><span class="o" style="font-weight: bold;">(</span><span class="n">CommandFactory</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: teal;">newBatchExecution</span><span class="o" style="font-weight: bold;">(</span><span class="n">cmds</span><span class="o" style="font-weight: bold;">));</span></div><div class="line" id="LC100" style="padding-left: 10px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class="line" id="LC101" style="padding-left: 10px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">QueryResults</span> <span class="n">queryResults</span> <span class="o" style="font-weight: bold;">=</span> <span class="o" style="font-weight: bold;">(</span> <span class="n">QueryResults</span> <span class="o" style="font-weight: bold;">)</span> <span class="n">results</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: teal;">getValue</span><span class="o" style="font-weight: bold;">(</span> <span class="s" style="color: rgb(221, 17, 68);">"annotations"</span> <span class="o" style="font-weight: bold;">);</span></div><div class="line" id="LC102" style="padding-left: 10px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">System</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: teal;">out</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: teal;">println</span><span class="o" style="font-weight: bold;">(</span><span class="s" style="color: rgb(221, 17, 68);">"Found ["</span> <span class="o" style="font-weight: bold;">+</span> <span class="n">queryResults</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: teal;">size</span><span class="o" style="font-weight: bold;">()</span> <span class="o" style="font-weight: bold;">+</span> <span class="s" style="color: rgb(221, 17, 68);">"]"</span><span class="o" style="font-weight: bold;">);</span></div></pre><div><br></div></div><div>Based on a stateful session:</div><div><br></div><div><pre style="font-family: Consolas, 'Liberation Mono', Courier, monospace; margin-top: 0px; margin-bottom: 0px; color: rgb(51, 51, 51); line-height: 18px;"><div class="line" id="LC133" style="padding-left: 10px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">statefulSession</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: teal;">insert</span><span class="o" style="font-weight: bold;">(</span><span class="k" style="font-weight: bold;">new</span> <span class="n">IbanValidationRequest</span><span class="o" style="font-weight: bold;">(</span><span class="n">iban</span><span class="o" style="font-weight: bold;">));</span></div><div class="line" id="LC134" style="padding-left: 10px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">statefulSession</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: teal;">fireAllRules</span><span class="o" style="font-weight: bold;">();</span></div><div class="line" id="LC136" style="padding-left: 10px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">QueryResults</span> <span class="n">queryResults</span> <span class="o" style="font-weight: bold;">=</span> <span class="n">statefulSession</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: teal;">getQueryResults</span><span class="o" style="font-weight: bold;">(</span><span class="s" style="color: rgb(221, 17, 68);">"annotations"</span><span class="o" style="font-weight: bold;">);</span></div><div class="line" id="LC138" style="padding-left: 10px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">System</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: teal;">out</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: teal;">println</span><span class="o" style="font-weight: bold;">(</span><span class="s" style="color: rgb(221, 17, 68);">"Found ["</span> <span class="o" style="font-weight: bold;">+</span> <span class="n">queryResults</span><span class="o" style="font-weight: bold;">.</span><span class="na" style="color: teal;">size</span><span class="o" style="font-weight: bold;">()</span> <span class="o" style="font-weight: bold;">+</span> <span class="s" style="color: rgb(221, 17, 68);">"]"</span><span class="o" style="font-weight: bold;">);</span></div></pre><div><br></div></div><div>What I’m finding is that if I invoke a query against a stateful session, I get a result. However, with stateless sessions, I am examining the ExecutionResults, and finding that they do contain a reference to an “annotations” QueryResults. However that collection of query results is empty.</div><div><br></div><div>btw - I’m also noticing that the code example in the user guide for batch executions with queries doesn’t use the current syntax for adding a query command. I’m guessing this syntax changed without an associated update to the user guide.</div><div><br></div><div>Steve</div><div><br></div><div><br></div><div><br></div><br><div><div>On 11 Dec 2013, at 11:49, Wolfgang Laun &lt;<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">The mean thing is that the code<br> &nbsp;&nbsp;org.drools.command.CommandFactory<br>uses the generic interface<br> &nbsp;&nbsp;org.drools.command.Command&lt;T&gt;<br>for all commands without specifying the generic parameter with the many<br>newXyz methods. If it were written well, it would tell you what to<br>expect from the command execution, since interface<br> &nbsp;&nbsp;org.drools.runtime.CommandExecutor<br>has the generic<br> &nbsp;&nbsp;&lt;T&gt; T execute(Command&lt;T&gt; command)<br><br>So you dig around in the code and may detect that ksession.execute(<br>cmd ) with cmd being made by newInsertElements(...) returns a<br>Collection&lt;FactHandle&gt;. Mighty helpful.<br><br>Fixing the Experts would help a little, avoiding utter stupefaction.<br><br>Cheers<br>-W<br><br><br><br>On 11/12/2013, Stephen Masters &lt;<a href="mailto:stephen.masters@me.com">stephen.masters@me.com</a>&gt; wrote:<br><blockquote type="cite">Thanks for that, Wolfgang. I have been working on something else for a few<br>days, but just switched over to batch execution, and that is giving me some<br>appropriate results (my tests are passing).<br><br>Which leads me to the question ...<br><br>Given that Example 3.4.1 in the Drools 5.5.0.Final user guide does not<br>compile, is that because there is a bug in the implementation of command<br>execution? Or is it a bug in the example. i.e.<br>The results should just not be assigned to anything?<br>The results (an ArrayList containing the facts which were just inserted)<br>should be assigned to a List of Object?<br>The example should just be removed from the user guide, as it is no longer a<br>valid/recommended approach?<br><br>Anybody with thoughts on that? Assuming that the answer is a documentation<br>fix, I’ll be happy to correct it appropriately and submit a pull request.<br><br>Cheers,<br><br>Steve<br><br><br><br><br>On 4 Dec 2013, at 12:24, Wolfgang Laun &lt;<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt; wrote:<br><br><blockquote type="cite">I think you have to put your insert command into a list<br> List&lt;Command&lt;?&gt;&gt; cmds = new ArrayList();<br>and pass this via batch execution<br> CommandFactory.newBatchExecution( cmds )<br><br>-W<br><br>On 04/12/2013, Stephen Masters &lt;<a href="mailto:stephen.masters@me.com">stephen.masters@me.com</a>&gt; wrote:<br><blockquote type="cite">Hi folks,<br><br>Can anyone explain how stateless session execution results should work?<br>Working through the docs and tracing the code, it’s getting a bit<br>confusing.<br><br>Firstly, according to the user manual, one should be able to insert a<br>list<br>of facts as a Command, and get an instance of ExecutionResults back,<br>which<br>can then be queried. Here’s the example code:<br>StatelessKnowledgeSession ksession =<br>kbase.newStatelessKnowledgeSession();<br><br>Command cmd = CommandFactory.newInsertElements( Arrays.asList( Object[]<br>{<br><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Cheese( "stilton" ),<br><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Cheese( "brie" ),<br><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Cheese( "cheddar" ),<br><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<br><br>ExecutionResults bresults = ksession.execute( cmd );<br><br>That doesn’t compile, so I fixed it as follows:<br><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Command cmd = CommandFactory.newInsertElements( Arrays.asList(<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Cheese( "stilton" ),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Cheese( "brie" ),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Cheese( "cheddar" )<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;));<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExecutionResults bresults = ksession.execute( cmd );<br><br>This does now compile, but running it throws a ClassCastException:<br><span class="Apple-tab-span" style="white-space:pre">        </span>java.lang.ClassCastException: java.util.ArrayList cannot be cast to<br>org.drools.runtime.ExecutionResults<br><br>Taking a look through the Drools code, it would appear that Command has<br>a<br>generic type, which in the case of an InsertElementsCommand is:<br>GenericCommand&lt;Collection&lt;FactHandle&gt;&gt;<br><br>In turn, the execute command in StatelessKnowledgeSessionImpl casts its<br>result to that generic type:<br><span class="Apple-tab-span" style="white-space:pre">        </span>public &lt;T&gt; T execute(Command&lt;T&gt; command) {<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>Object o = ((GenericCommand) command).execute( context );<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>...<br><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>return (T) o;<br><br>So the ClassCastException is because the execute method returns an<br>ArrayList<br>of FactHandle instead of an ExecutionResults.<br><br>I’m assuming that I must have got the wrong end of the stick somewhere,<br>so<br>what should I be doing to get an ExecutionResults from a stateless<br>session,<br>which I can then query?<br><br>Cheers,<br><br>Steve<br></blockquote><br>_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/rules-users<br></blockquote><br><br></blockquote><br>_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/rules-users<br></blockquote></div><br></body></html>