yes you are right.. did you try removing the insert cmd from the second code snippet?<br>just to have the same scenario?<br>The first code should fail as the second. With the message Unexpected global [test2]<br><br><div class="gmail_quote">
On Tue, Jun 22, 2010 at 8:40 AM, Samuli Saarinen <span dir="ltr"><<a href="mailto:samuli.saarinen@remion.com">samuli.saarinen@remion.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Actually I am trying to set an unexistent variable (test2) in both<br>
snippets. But for some reason only the second one produces the exception.<br>
<br>
Samuli<br>
<div><div></div><div class="h5"><br>
Salaboy wrote:<br>
> Well, in the second code snippet you are trying to set an unexistent<br>
> variable called test2. For setting a global variable you need to<br>
> define it first in the drl file. Greetings!<br>
><br>
> - CTO @ <a href="http://www.plugtree.com" target="_blank">http://www.plugtree.com</a><br>
> - MyJourney @ <a href="http://salaboy.wordpress.com" target="_blank">http://salaboy.wordpress.com</a><br>
> - Co-Founder @ <a href="http://www.jbug.com.ar" target="_blank">http://www.jbug.com.ar</a><br>
> - Mauricio "Salaboy" Salatino -<br>
><br>
> On Jun 22, 2010, at 4:32, Samuli Saarinen <<a href="mailto:samuli.saarinen@remion.com">samuli.saarinen@remion.com</a>><br>
> wrote:<br>
><br>
>> Hello,<br>
>><br>
>> I'm new to drools and have problems with globals or with the different<br>
>> behaviour of drools depending on how the globals are specified.<br>
>><br>
>> I have the following simple rule:<br>
>><br>
>> global String test<br>
>><br>
>> rule "Global"<br>
>> when<br>
>> then<br>
>> System.out.println(test);<br>
>> end<br>
>><br>
>> If i run the rule with:<br>
>><br>
>> KnowledgeBase kb = getKnowledgeBase("global.drl");<br>
>> StatelessKnowledgeSession ses = kb.newStatelessKnowledgeSession();<br>
>> ses.setGlobal("test2", "foo");<br>
>> ses.execute("");<br>
>><br>
>> I get the expected result of null printed<br>
>><br>
>> but if I use commands:<br>
>><br>
>> KnowledgeBase kb = getKnowledgeBase("global.drl");<br>
>> StatelessKnowledgeSession ses = kb.newStatelessKnowledgeSession();<br>
>> List<Command<?>> cmds = new ArrayList<Command<?>>();<br>
>> cmds.add(CommandFactory.newSetGlobal("test2", "bar"));<br>
>> cmds.add(CommandFactory.newInsert(""));<br>
>> ses.execute(CommandFactory.newBatchExecution(cmds));<br>
>><br>
>> I get java.lang.RuntimeException: Unexpected global [test2]<br>
>><br>
>> Why is the behaviour different and which one is correct?<br>
>><br>
>> Regards,<br>
>><br>
>> Samuli<br>
>><br>
>><br>
>> --<br>
>> Remion Oy Etävalvontajärjestelmät liiketoiminnan<br>
>> Samuli Saarinen tehostamiseen<br>
>> gsm +358 (0)50 3560075<br>
>> fax +358 (0)3 2125064 <a href="http://www.remion.com" target="_blank">www.remion.com</a><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" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><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" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
><br>
</div></div>> --<br>
> STOP Virus, STOP SPAM, SAVE Bandwidth!<br>
> <a href="http://www.safentrix.com/adlink?cid=0" target="_blank">http://www.safentrix.com/adlink?cid=0</a><br>
<div><div></div><div class="h5">> -<br>
<br>
<br>
<br>
--<br>
Remion Oy Etävalvontajärjestelmät liiketoiminnan<br>
Samuli Saarinen tehostamiseen<br>
gsm +358 (0)50 3560075<br>
fax +358 (0)3 2125064 <a href="http://www.remion.com" target="_blank">www.remion.com</a><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" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br> - CTO @ <a href="http://www.plugtree.com">http://www.plugtree.com</a> <br> - MyJourney @ <a href="http://salaboy.wordpress.com">http://salaboy.wordpress.com</a><br>
- Co-Founder @ <a href="http://www.jbug.com.ar">http://www.jbug.com.ar</a><br> <br> - Salatino "Salaboy" Mauricio -<br>