<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p" xmlns:t="http://dnetlib.eu/springbeans/t"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	<bean id="mongodbMDStoreDao" class="eu.dnetlib.data.mdstore.modular.mongodb.MDStoreDaoImpl"
		p:db-ref="mdstoreMongoDB" p:recordParserFactory-ref="recordParserFactory" 
		p:discardRecords="${services.mdstore.discardrecords}"/>


	<bean id="mongoClient" class="com.mongodb.MongoClient">
		<constructor-arg index="0" type="com.mongodb.ServerAddress">
			<bean class="com.mongodb.ServerAddress">
				<constructor-arg index="0" value="${services.mdstore.mongodb.host}"/>
				<constructor-arg index="1" value="${services.mdstore.mongodb.port}"/>
			</bean>
		</constructor-arg>
		<constructor-arg index="1" type="com.mongodb.MongoClientOptions">
			<bean class="eu.dnetlib.mongodb.MongoOptionsFactory"
			      p:connectionsPerHost="${services.mdstore.mongodb.connectionsPerHost}"/>
		</constructor-arg>
	</bean>
	
	<bean id= "mongoMdStoreTransaction" init-method="garbageTransactionsOnStart"
	      class="eu.dnetlib.data.mdstore.modular.mongodb.MDStoreTransactionManagerImpl"
	      p:db-ref="mdstoreMongoDB" p:expiredDays="${services.mdstore.readlock.expire.days}"/>

	<bean id="mdstoreMongoDB" factory-bean="mongoClient"
	      factory-method="getDatabase">
		<constructor-arg type="java.lang.String" value="${services.mdstore.mongodb.db}"/>
	</bean>
	
	<bean t:id="transctionManagerGarabageCollectionJobSchedulerAccessor"
		class="org.springframework.scheduling.quartz.SchedulerAccessorBean"
		p:scheduler-ref="jobScheduler">
		<property name="triggers">
			<list>
				<bean class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
					<property name="jobDetail">
						<bean class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"
							p:targetObject-ref="mongoMdStoreTransaction" p:targetMethod="garbage" />
					</property>
					<property name="cronExpression" value="${services.mdstore.mongodb.garbage.cron}"/>
				</bean>				
			</list>
		</property>
	</bean>


</beans>
