<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:aop="http://www.springframework.org/schema/aop" xmlns="http://www.springframework.org/schema/beans"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
		
		<!-- 
		FOR USE BY INTEGRATION TEST CLASSES ONLY
		
		All logging to the CDS and Pathways application log happens asynchronously through the 
		Logger Message Driven Bean in the real application. I understand the need 
		to do applicaiton logging in integration tests, but to have his deployed 
		with the cds-core JAR file to the EAR is a little bit dangerous.
		-->

	<bean id="loggerJdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource" ref="hdrDataSource" />
	</bean>

	<bean id="loggerPersistenceManager" class="gov.va.med.cds.log4j.persistence.hibernate.HibernateLoggerPersistenceManager">
		<property name="cdsLoggerHibernateTemplate" ref="cdsLoggerHibernateTemplate" />
		<property name="pathwaysLoggerHibernateTemplate" ref="pathwaysLoggerHibernateTemplate" />
		<property name="pathwaysAppName" ref="pathwaysAppName" />
	</bean>

	<bean id="cdsLoggerHibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate">
		<property name="sessionFactory" ref="cdsLoggerSessionFactory" />
	</bean>

	<bean id="cdsLoggerSessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
		<property name="dataSource" ref="hdrDataSource" />
		<property name="mappingResources">
			<list>
				<value>gov/va/med/cds/log4j/persistence/hibernate/CdsApplicationLogEvent.hbm.xml</value>
			</list>
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
				<prop key="hibernate.show_sql">${hibernate.show.sql}</prop>
			</props>
		</property>
	</bean>
	
	<aop:config>
		<aop:pointcut id="cdsLoggerTxMethods" expression="execution(* gov.va.med.cds.log4j.persistence.LoggerPersistenceManagerInterface.*(..))" />
		<aop:advisor advice-ref="cdsLoggerTxAdvice" pointcut-ref="cdsLoggerTxMethods" order="1" />
	</aop:config>

	<tx:advice id="cdsLoggerTxAdvice" transaction-manager="cdsLoggerTransactionManager">
		<tx:attributes>
			<tx:method name="persistApplicationLogEvent" propagation="REQUIRES_NEW" isolation="READ_COMMITTED" />
		</tx:attributes>
	</tx:advice>

	<bean id="cdsLoggerTransactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
		<property name="sessionFactory" ref="cdsLoggerSessionFactory" />
	</bean>

	<bean id="pathwaysLoggerHibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate">
		<property name="sessionFactory" ref="pathwaysLoggerSessionFactory" />
	</bean>

	<bean id="pathwaysLoggerSessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
		<property name="dataSource" ref="hdrDataSource" />
		<property name="mappingResources">
			<list>
				<value>gov/va/med/cds/log4j/persistence/hibernate/PathwaysApplicationLogEvent.hbm.xml</value>
			</list>
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
				<prop key="hibernate.show_sql">${hibernate.show.sql}</prop>
			</props>
		</property>
	</bean>

	<aop:config>
		<aop:pointcut id="pathwaysLoggerTxMethods" expression="execution(* gov.va.med.cds.log4j.persistence.LoggerPersistenceManagerInterface.*(..))" />
		<aop:advisor advice-ref="pathwaysLoggerTxAdvice" pointcut-ref="pathwaysLoggerTxMethods" order="1" />
	</aop:config>

	<tx:advice id="pathwaysLoggerTxAdvice" transaction-manager="pathwaysLoggerTransactionManager">
		<tx:attributes>
			<tx:method name="persistApplicationLogEvent" propagation="REQUIRES_NEW" isolation="READ_COMMITTED" />
		</tx:attributes>
	</tx:advice>

	<bean id="pathwaysLoggerTransactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
		<property name="sessionFactory" ref="pathwaysLoggerSessionFactory" />
	</bean>

</beans>
