<?xml version="1.0" encoding="UTF-8"?>
<blueprint default-activation="eager" xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:kie="http://drools.org/schema/kie-aries-blueprint/1.0.0"
           xsi:schemaLocation="
           http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0
           http://drools.org/schema/kie-aries-blueprint/1.0.0 http://drools.org/schema/kie-aries-blueprint/1.0.0">

  <reference id="entityManagerFactoryRef" interface="javax.persistence.EntityManagerFactory" filter="(osgi.unit.name=process-persistence)"/>
  <reference id="transactionManagerRef" interface="javax.transaction.TransactionManager"/>
  <reference id="userTransactionRef" interface="javax.transaction.UserTransaction" />
  <reference id="transactionSynchronizationRegistryRef" interface="javax.transaction.TransactionSynchronizationRegistry" />

  <kie:environment id="environmentWithPersistence">
      <kie:transaction-manager ref="transactionManagerRef" />
      <kie:transaction-sync-registry ref="transactionSynchronizationRegistryRef" />
      <kie:user-transaction ref="userTransactionRef" />
      <kie:entity-manager-factory ref="entityManagerFactoryRef" />
  </kie:environment>

    <!-- Configuring persistence using kie:environment -->
  <bean id="processBeanWithEnv" class="org.kie.karaf.itest.beans.ProcessWithPersistenceEnvBean"
        init-method="init" destroy-method="destroy">

     <argument index="0" ref="environmentWithPersistence" />
  </bean>

  <!-- Configuring persistence without using kie:environment -->
  <bean id="processBeanWithoutEnv" class="org.kie.karaf.itest.beans.ProcessWithPersistenceDirectBean"
        init-method="init" destroy-method="destroy">

      <argument index="0" ref="entityManagerFactoryRef" />
      <argument index="1" ref="transactionManagerRef" />
      <argument index="2" ref="userTransactionRef" />
      <argument index="3" ref="transactionSynchronizationRegistryRef" />
  </bean>

  <!-- Exporting KIE Sessions as OSGi services for the test (PAx-Exam won't let me export processBeans themselves) -->
  <bean id="kieSessionWithEnvBean" factory-ref="processBeanWithEnv" factory-method="createKieSession" />
  <service id="kieSessionWithEnvService" interface="org.kie.api.runtime.KieSession" ref="kieSessionWithEnvBean" >
    <service-properties>
        <entry key="osgi.jndi.service.name" value="kiesession/sessionWithEnv"/>
    </service-properties>
  </service>

  <bean id="kieSessionWithoutEnvBean" factory-ref="processBeanWithoutEnv" factory-method="createKieSession" />
  <service id="kieSessionWithoutEnvService" interface="org.kie.api.runtime.KieSession" ref="kieSessionWithoutEnvBean" >
    <service-properties>
        <entry key="osgi.jndi.service.name" value="kiesession/sessionWithoutEnv"/>
    </service-properties>
  </service>

</blueprint>
