<?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:util="http://www.springframework.org/schema/util"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
						http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd 
						http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd 
						http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

	<bean id="filterCachePersistence"
		class="gov.va.med.cds.filter.HibernateOracleFilterCachePersistence">
		<property name="sessionFactory" ref="hdr2SessionFactory"/>
	</bean>

	<bean id="filterMemoryCache" class="gov.va.med.cds.filter.FilterMemoryCache">
		<constructor-arg index="0">
			<bean class="gov.va.med.cds.util.LRUHashMap">
			<!-- LRU cache size -->
			<constructor-arg index="0" value="1" />
		</bean>
		</constructor-arg>
	</bean>

	<bean id="filterFileSystemCacheManager" class="gov.va.med.cds.filter.FilterFileSystemCacheManager">
	  <property name="filterMetadataPath" value="filtercache"/>
	</bean>

	<bean id="filterService" class="gov.va.med.cds.filter.FilterServiceSimulator">
		<!-- If this property is missing, test templates won't be loaded -->
		<property name="testFilters">
			<props>
				<!--
					If this prop is missing, then it will default to the local directory ("./")
					This can be either a path to a single file or a directory containing files
					with the suffix .meta.  Each file contains information about where the
					template jar file is located and metadata about the template as NVP.
				-->
				<prop key="path">filtercache</prop>
				<!-- If not included, the default for this property is "false" -->
				<prop key="loadTestFilters">true</prop>
			</props>
		</property>
	</bean>

	<aop:config>
		<aop:pointcut id="filterTxMethods" expression="execution(* gov.va.med.cds.filter.FilterCachePersistenceInterface.*(..))"/>
		<aop:advisor advice-ref="filterTxAdvice" pointcut-ref="filterTxMethods" order="1"/>
	</aop:config>

	<tx:advice id="filterTxAdvice" transaction-manager="hdr2TransactionManager">
		<tx:attributes>
			<tx:method name="persistFilterSchema" propagation="REQUIRED" isolation="READ_COMMITTED"/>
			<tx:method name="loadAllFilterSchemasIntoMemoryCache" propagation="REQUIRED" isolation="READ_COMMITTED"/>			
			<tx:method name="loadFilterIntoMemoryCache" propagation="REQUIRED" isolation="READ_COMMITTED"/>
			<tx:method name="removeFilterSchema" propagation="REQUIRED" isolation="READ_COMMITTED"/>
			<tx:method name="replaceFilterPersistence" propagation="REQUIRED" isolation="READ_COMMITTED"/>
			<tx:method name="getFilterIdentifiers" propagation="REQUIRED" isolation="READ_COMMITTED"/>
		</tx:attributes>
	</tx:advice>

	<bean id="hdr2TransactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
		<property name="sessionFactory" ref="hdr2SessionFactory"/>
	</bean>
	
	<bean id="hdr2SessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
		<property name="dataSource" ref="hdrDataSource" />
		<property name="mappingResources">
			<list>
				<!-- Major component mapping files -->

				<!-- TFR Mapping Files -->
				<value>gov/va/med/cds/persistence/hibernate/tfs/DomainEntryPoint.hbm.xml</value>
				<value>gov/va/med/cds/persistence/hibernate/tfs/TemplateSchema.hbm.xml</value>
				<value>gov/va/med/cds/persistence/hibernate/tfs/VhimVersion.hbm.xml</value>
				<value>gov/va/med/cds/persistence/hibernate/tfs/FilterSchema.hbm.xml</value>
				<value>gov/va/med/cds/persistence/hibernate/tfs/EntryFilter.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>
	
</beans>