Drools global variable 2013

View previous topic View next topic Go down

Drools global variable 2013

Post by Admin on Sun Sep 15, 2013 4:04 am

2013 2013 2013 <div dir="ltr" style="text-align: left;" trbidi="on"><b>What is global in DRL file?</b><br><br> global is the keyword used in drools to define a global variable. Global variable is the one which will be visible to all the rules inside a DRL file.<br>Globals must be used very carefully in a DRL file, since the changes in a global variable are not notified to the working memory. For example, you are using a list variable as a global and in any rule you are adding a value in a list and in one particular rule, you are checking if list size() > 0, then in this case rule may not fire. Global variable can be used for any type of object.<br><br> <b>Where to use global variable?</b><br><br>Consider a scenario, where in the rules there is a requirement for database connection object. In this case, the DB Connection object can be inserted as a global variable in the working memory and the connection object will be visible to all the rules in that DRL file.<br><br> <b>GlobalDrl.drl</b><pre style="background-color: #eeeeee;font-size: 9pt;border: 1px solid #cccccc;margin-bottom: 3em;line-height: 15px;"><br /><br />global java.util.List <b>globalList</b>;<br /><br />rule "Global implementation"<br />when<br /> eval( true )<br />then<br /> globalList.add( "Hello World" );<br />end<br /><br /></pre> Java client file <pre style="background-color: #eeeeee;font-size: 9pt;border: 1px solid #cccccc;margin-bottom: 3em;line-height: 15px;"><br /><br />List list = new ArrayList();<br /><br />KnowledgeSession knowledgeSession = knowledgeBase.newStatefulSession();<br /><br />knowledgeSession.setGlobal( "<b>globalList</b>", list );<br /><br /></pre> It is strongly discouraged to set or change a global value from inside your rules. We recommend to you always set the value from your application using the working memory interface.<br></div><br> 2013 2013 2013 <br><div dir="ltr" style="text-align: left;" trbidi="on"><b>What is global in DRL file?</b><br><br> global is the keyword used in drools to define a global variable. Global variable is the one which will be visible to all the rules inside a DRL file.<br>Globals must be used very carefully in a DRL file, since the changes in a global variable are not notified to the working memory. For example, you are using a list variable as a global and in any rule you are adding a value in a list and in one particular rule, you are checking if list size() > 0, then in this case rule may not fire. Global variable can be used for any type of object.<br><br> <b>Where to use global variable?</b><br><br>Consider a scenario, where in the rules there is a requirement for database connection object. In this case, the DB Connection object can be inserted as a global variable in the working memory and the connection object will be visible to all the rules in that DRL file.<br><br> <b>GlobalDrl.drl</b><pre style="background-color: #eeeeee;font-size: 9pt;border: 1px solid #cccccc;margin-bottom: 3em;line-height: 15px;"><br /><br />global java.util.List <b>globalList</b>;<br /><br />rule "Global implementation"<br />when<br /> eval( true )<br />then<br /> globalList.add( "Hello World" );<br />end<br /><br /></pre> Java client file <pre style="background-color: #eeeeee;font-size: 9pt;border: 1px solid #cccccc;margin-bottom: 3em;line-height: 15px;"><br /><br />List list = new ArrayList();<br /><br />KnowledgeSession knowledgeSession = knowledgeBase.newStatefulSession();<br /><br />knowledgeSession.setGlobal( "<b>globalList</b>", list );<br /><br /></pre> It is strongly discouraged to set or change a global value from inside your rules. We recommend to you always set the value from your application using the working memory interface.<br></div><br>2013 2013 2013 <br> <a href="http://www.matrixar.com/" title="Matrix ">المصفوفة : أجمل الخلفيات والصور</a>

Admin
Admin

Posts : 64122
Join date : 2013-02-22

View user profile http://prowebsites1.forumaroc.net

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum