<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    
    <!-- Transaction management for XA transactions involving multiple JDBC and/or JMS -->
    <bean id="jotmFactory" class="org.mule.module.jotm.JotmTransactionManagerFactory"/>
    <bean id="jotm" factory-bean="jotmFactory" factory-method="create"/>
 
     <!-- This def is used for Spring/Hibernate usage from within Components.
     Both Mule and Spring use a JOTM singleton if one is already built, so whoever builds
     this first, the other one uses it. -->
     <bean id="springJotmFactory" class="org.springframework.transaction.jta.JotmFactoryBean"/>
    <bean id="springJotm" class="org.springframework.transaction.jta.JtaTransactionManager">
        <property name="userTransaction" ref="springJotmFactory"/>
    </bean>
    
    <bean id="myManager" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
        <property name="transactionManager">
            <ref local="springJotm"/>
        </property>
        <property name="target">
            <ref local="libraryDao"/>
        </property>
        <property name="transactionAttributes">
            <props>
                <prop key="insertBook">
                    PROPAGATION_MANDATORY
                </prop>
            </props>
        </property>
    </bean>
  
    <bean id="libraryDao" class="org.mule.test.integration.transaction.extras.JdbcLibraryDao" singleton="false">
        <property name="jdbcTemplate">
            <ref bean="jdbcTemplate" />
        </property>
    </bean>

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <constructor-arg>
            <ref bean="jdbcDataSourceXa" />
        </constructor-arg>
    </bean>

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
	    <property name="location">
            <value>classpath:derby.properties</value>
        </property>
    </bean>
        <!-- Data Source -->
    <bean id="innerDataSource"
        class="org.enhydra.jdbc.standard.StandardXADataSource"
        destroy-method="shutdown">
        <property name="transactionManager">
            <ref local="jotm"/>
        </property>
        <property name="driverName">
            <value>org.apache.derby.jdbc.EmbeddedDriver</value>
        </property>
        <property name="url">
            <value>${database.connection}</value>
        </property>
    </bean>
    
    <bean id="jdbcDataSourceXa"
        class="org.enhydra.jdbc.pool.StandardXAPoolDataSource"
        destroy-method="shutdown">
        <property name="dataSource">
            <ref local="innerDataSource"/>
        </property>
        <property name="maxSize">
            <value>10</value>
        </property>
    </bean>

    <!-- ActiveMQ -->       
    <bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL"><value>vm://localhost?broker.persistent=false&amp;broker.useJmx=false</value></property>
    </bean>

    <!-- My Component -->
    <bean id="MyComponent" class="org.mule.test.integration.transaction.extras.MyComponent"/>
    
</beans>