<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sembrando Realidades &#187; Flow</title>
	<atom:link href="http://blog.bauna.com.ar/index.php/category/tecno/java/drools/flow/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bauna.com.ar</link>
	<description>Un viaje a inciertos destinos</description>
	<lastBuildDate>Fri, 28 May 2010 18:30:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Drools Flow configuration using Spring</title>
		<link>http://blog.bauna.com.ar/index.php/2010/05/drools-flow-configuration-using-spring/</link>
		<comments>http://blog.bauna.com.ar/index.php/2010/05/drools-flow-configuration-using-spring/#comments</comments>
		<pubDate>Fri, 28 May 2010 15:46:34 +0000</pubDate>
		<dc:creator>bauna</dc:creator>
				<category><![CDATA[Drools]]></category>
		<category><![CDATA[Flow]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[PlugTree]]></category>
		<category><![CDATA[software libre]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[PlugTree Drools Flow]]></category>

		<guid isPermaLink="false">http://blog.bauna.com.ar/?p=116</guid>
		<description><![CDATA[There are a lot of Drools Flow users that ask us about how to use Drools Flow persistence without JTA transactions, so in order to give those users a proper answer we developed a solution based on the Spring integration. We added support to configure a JpaSessionServiceFactory to the Drools’ configuration namespace. Let’s see how [...]]]></description>
			<content:encoded><![CDATA[<p>There are a lot of Drools Flow users that ask us about how to use Drools Flow persistence without JTA transactions, so in order to give those users a proper answer we developed a solution based on the <a title="Drools Spring Integration" href="http://blog.athico.com/2009/12/drools-spring-improvements.html" target="_blank">Spring integration</a>. We added support to configure a JpaSessionServiceFactory to the Drools’ configuration namespace. Let’s see how to use it on a real example (you can donwload it from:<a title="Drools Flow Spring Example" href="http://www.plugtree.com/downloads/DroolsFlowSpring.tgz"> http://www.plugtree.com/downloads/DroolsFlowSpring.tgz</a>).<br />
Firstly, you need to configure EntityManageFactory and SpringTransactionManager as follows:</p>
<pre class="brush: xml; ">

&lt;bean id=&quot;myEmf&quot; class=&quot;org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean&quot;&gt;
&lt;property name=&quot;dataSource&quot; ref=&quot;ds&quot; /&gt;
&lt;property name=&quot;persistenceUnitName&quot; value=&quot;org.drools.persistence.jpa.local&quot; /&gt;
&lt;/bean&gt;

&lt;bean id=&quot;txManager&quot; class=&quot;org.springframework.orm.jpa.JpaTransactionManager&quot;&gt;
&lt;property name=&quot;entityManagerFactory&quot; ref=&quot;myEmf&quot; /&gt;
&lt;/bean&gt;
</pre>
<p>I’m not showing the datasource configuration because it heavily depends on your deployment but you can grab it from the example <img src='http://blog.bauna.com.ar/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p>Secondly, you have to define a kbase that then would be used by the JpaSessionService:</p>
<pre class="brush: xml; ">

&lt;drools:kbase id=&quot;kbase1&quot;&gt;
&lt;drools:resource type=&quot;DRF&quot; source=&quot;classpath:VariablePersistenceStrategyProcess.rf&quot; /&gt;
&lt;/drools:kbase&gt;
</pre>
<p>And finally, you need to define the JpaSessionService:</p>
<pre class="brush: xml; ">

&lt;drools:jpaSessionServiceFactory id=&quot;jpaSingleSessionCommandService&quot; kbase=&quot;kbase1&quot;
entityManagerFactory=&quot;myEmf&quot; transactionManager=&quot;txManager&quot;&gt;
&lt;drools:variablePersisters&gt;
&lt;drools:persister forClass=&quot;javax.persistence.Entity&quot; implementation=&quot;org.drools.persistence.processinstance.persisters.JPAVariablePersister&quot;/&gt;
&lt;drools:persister forClass=&quot;java.lang.String&quot; implementation=&quot;org.plugtree.labs.variablepersistence.StringVariablePersister&quot;/&gt;
&lt;drools:persister forClass=&quot;java.io.Serializable&quot; implementation=&quot;org.drools.persistence.processinstance.persisters.SerializableVariablePersister&quot;/&gt;
&lt;/drools:variablePersisters&gt;
&lt;/drools:jpaSessionServiceFactory&gt;
</pre>
<p>Bear in mind if that you don&#8217;t need to define customs variable persisters the configuration it&#8217;s only one line!.</p>
<p>Then you can inject it to your own beans or create a Spring Context manually, as shown in the this snippet:</p>
<pre class="brush: java; ">

ctx = new ClassPathXmlApplicationContext(&quot;beans.xml&quot;);
JPASingleSessionCommandService jpaService = (JPASingleSessionCommandService) ctx
.getBean(&quot;jpaSingleSessionCommandService&quot;);
SingleSessionCommandService service = jpaService.newStatefulKnowledgeSession();
int sessionId = service.getSessionId();
....
//do something
service.dispose();

Then in a future time retrieve the session:
SingleSessionCommandService service = jpaService.loadStatefulKnowledgeSession(sessionId);
//do something
....
service.dispose();
</pre>
<p>Warning note: when you use the flow persistence with JTA, it automatically reloads the state out the session after a rollback. We couldn&#8217;t do that behavior here since simple database connections doesn&#8217;t provide a listener mechanism as JTA transactions does.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bauna.com.ar/index.php/2010/05/drools-flow-configuration-using-spring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

