<?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">


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

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

	<bean id="loggerPersistenceManager2" 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>

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

	<bean id="pathwasyLoggerSessionFactory" 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>
	
	<!-- adding transaction pointcut/advice for read audits -->
	<aop:config>
		<aop:pointcut id="readAuditTxMethods" expression="execution(* gov.va.med.cds.audit.persistence.AuditLogPersistenceManagerInterface.*(..))" />
		<aop:advisor advice-ref="readAuditTxAdvice" pointcut-ref="readAuditTxMethods" order="1" />
	</aop:config>

	<tx:advice id="readAuditTxAdvice" transaction-manager="loggerTransactionManager">
		<tx:attributes>
			<tx:method name="storeAuditLog" propagation="REQUIRES_NEW" isolation="READ_COMMITTED" />
		</tx:attributes>
	</tx:advice>

	<bean id="auditLogSessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
		<property name="dataSource" ref="hdrDataSource" />
		<property name="mappingResources">
			<list>
				<value>gov/va/med/cds/audit/persistence/hibernate/LegacyReadAuditLog.hbm.xml</value>
				<value>gov/va/med/cds/audit/persistence/hibernate/VhimReadAuditLog.hbm.xml</value>
				<value>gov/va/med/cds/audit/persistence/hibernate/TemplateId.hbm.xml</value>
				<value>gov/va/med/cds/audit/persistence/hibernate/FilterId.hbm.xml</value>
				<value>gov/va/med/cds/audit/persistence/hibernate/ClientMapping.hbm.xml</value>
				
				<!-- Pathways mapping -->
				<value>gov/va/med/cds/audit/persistence/hibernate/VhimReadPathwaysAuditLog.hbm.xml</value>
				<value>gov/va/med/cds/audit/persistence/hibernate/ClientMappingPathways.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>
	
    <bean id="auditLogSessionFactoryHa" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="hdrDataSource" />
        <property name="mappingResources">
            <list>
                <value>gov/va/med/cds/audit/persistence/hibernate/VhimReadAuditLogHa.hbm.xml</value>
                <value>gov/va/med/cds/audit/persistence/hibernate/TemplateId.hbm.xml</value>
                <value>gov/va/med/cds/audit/persistence/hibernate/FilterId.hbm.xml</value>
                <value>gov/va/med/cds/audit/persistence/hibernate/ClientMapping.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>
	
	<bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate">
		<property name="sessionFactory" ref="auditLogSessionFactory" />
	</bean>
	
    <bean id="hibernateTemplateHa" class="org.springframework.orm.hibernate4.HibernateTemplate">
        <property name="sessionFactory" ref="auditLogSessionFactoryHa" />
    </bean>
	
	<bean id="cdsHibernateAuditLogPersistenceManager" class="gov.va.med.cds.audit.persistence.hibernate.HibernateAuditLogPersistenceManager">
		<property name="hibernateTemplate" ref="hibernateTemplate" />
		<property name="hibernateTemplateHa" ref="hibernateTemplateHa" />
		<property name="appName" ref="cdsAppName" />
		<property name="haTemplateIdList" ref="haTemplateIdList"/>
		<property name="requestIdClientNameMap" ref="cdsRequestIdClientNameMap"/>		
	</bean>
	
	<bean id="rpcHibernateAuditLogPersistenceManager" class="gov.va.med.cds.audit.persistence.hibernate.HibernatePathwaysAuditLogPersistenceManager">
		<property name="hibernateTemplate" ref="hibernateTemplate" />
		<property name="appName" ref="pathwaysAppName" />
	</bean>

	<util:map id="cdsRequestIdClientNameMap">
		<entry key="RDI" value="Remote Data Interoperability" />
		<entry key="MHV" value="My Healthy Vet" />
		<entry key="vistaweb" value="VistA Web" />
	</util:map>
    	
	<util:list id="haTemplateIdList">
       <value>HealthAdapterRead1</value>
       <value>HealthAdapterCreate1</value>
       <value>HealthAdapterUpdate1</value>
       <value>HealthAdapterDelete1</value>
       <value>HealthAdapterAssessmentDocumentDetailRead1</value>
       <value>HealthAdapterJournalDetailRead1</value>
    </util:list>
	
</beans>