<?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:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="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/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
	
	<!--  This bean sets up property replacement so that variables can be externalized to system properties -->
	<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
	</bean>

	<bean id="hdrDataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
		<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
		<property name="url" value="${cds.jdbc.url}" />
		<property name="username" value="${cds.jdbc.username}" />
		<property name="password" value="${cds.jdbc.password}" />
		<property name="defaultAutoCommit" value="true"/>
	</bean>
	
	
	<bean id="cdsAuditClobStore" class="gov.va.med.cds.audit.persistence.hibernate.PersistAuditStore">
		<property name="hibernateTemplate" ref="auditLogHibernateTemplate" />
	</bean>
	
	
	<bean id="auditLogHibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate">
		<property name="sessionFactory" ref="auditLogSessionFactory" />
	</bean>

	<!-- <tx:annotation-driven transaction-manager="transactionManager"/> -->
	<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
		<property name="sessionFactory" ref="auditLogSessionFactory"/>
	</bean>
	
	<aop:config>
		<aop:pointcut id="clobStoreTxMethods" expression="execution(* gov.va.med.cds.audit.persistence.CdsAuditClobStoreInterface.*(..))" />
		<aop:advisor advice-ref="clobStoreTxAdvice" pointcut-ref="clobStoreTxMethods" order="1" />
	</aop:config>

	<tx:advice id="clobStoreTxAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="persistCdsAuditClob" 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/CdsAuditClobStore.hbm.xml</value>
                <value>gov/va/med/cds/audit/persistence/hibernate/TemplateId.hbm.xml</value>
				<!-- <value>gov/va/med/cds/audit/persistence/hibernate/HaAuditClobStore.hbm.xml</value> -->
			</list>
		</property>
		<property name="hibernateProperties">
			<props>
			    <prop key="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory</prop>
				<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
				<prop key="hibernate.show_sql">${hibernate.show.sql}</prop>
				<!-- <prop key="hibernate.transaction.flush_before_completion">true</prop>
				<prop key="hibernate.current_session_context_class">thread</prop> -->
			</props>
		</property>
	</bean>
	
</beans>