<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:kie="http://drools.org/schema/kie-spring"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                          http://drools.org/schema/kie-spring http://drools.org/schema/kie-spring.xsd">

  <kie:kstore id="kstore1"/>

  <kie:kmodule id="persistence_spring_module">

    <kie:kbase name="kb_persistence" packages="kb_persistence">

      <kie:ksession name="jpaSingleSessionCommandService">

        <kie:configuration>
          <kie:jpa-persistence>
            <kie:transaction-manager ref="txManager"/>
            <kie:entity-manager-factory ref="myEmf"/>
          </kie:jpa-persistence>

        </kie:configuration>

      </kie:ksession>

      <kie:ksession name="jpaSingleSessionCommandServiceWithListeners">
        <kie:processEventListener>
          <bean class="org.drools.core.event.DebugProcessEventListener"/>
        </kie:processEventListener>
        <kie:agendaEventListener>
          <bean class="org.drools.core.event.DebugAgendaEventListener"/>
        </kie:agendaEventListener>
        <kie:ruleRuntimeEventListener>
          <bean class="org.drools.core.event.DebugRuleRuntimeEventListener"/>
        </kie:ruleRuntimeEventListener>
        <kie:configuration>
          <kie:jpa-persistence>
            <kie:transaction-manager ref="txManager"/>
            <kie:entity-manager-factory ref="myEmf"/>
          </kie:jpa-persistence>

        </kie:configuration>

      </kie:ksession>
    </kie:kbase>

    <kie:kbase name="drl_persistence_rb" packages="drl_persistence_rb">
      <kie:ksession name="jpaSingleSessionCommandServiceRollback"/>
    </kie:kbase>

  </kie:kmodule>

  <bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <!-- org.h2.jdbcx.JdbcDataSource -->
    <property name="driverClassName" value="org.h2.Driver"/>
    <!-- jdbc:h2:mem:mydb
    jdbc:h2:tcp://localhost/DroolsFlow-->
    <property name="url" value="jdbc:h2:tcp://localhost/DroolsFlow"/>
    <property name="username" value="sa"/>
    <property name="password" value=""/>
  </bean>

  <bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="ds"/>
    <property name="persistenceUnitName" value="org.drools.persistence.jpa.local"/>
  </bean>

  <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="myEmf"/>
  </bean>

  <kie:environment id="env">
    <kie:entity-manager-factory ref="myEmf"/>
    <kie:transaction-manager ref="txManager"/>
  </kie:environment>

    <bean id="kiePostProcessor" class="org.kie.spring.KModuleBeanFactoryPostProcessor"/>


</beans>
