<beans xmlns="http://www.springframework.org/schema/beans"
	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	   xmlns:context="http://www.springframework.org/schema/context"
	   xmlns:tx="http://www.springframework.org/schema/tx"
	   xmlns:aop="http://www.springframework.org/schema/aop"
	   xmlns:task="http://www.springframework.org/schema/task"
	   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.3.xsd"
>

	<!-- 使用外部的配置文件 -->
	<context:property-placeholder  ignore-unresolvable="true"  location="classpath:workflow-conf/properties/dbconfig.properties" />
	<context:component-scan base-package="com.horizon.**.service, com.horizon.**.init">
		<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
	</context:component-scan>
	<bean id="systemConnectionInfo" class="com.horizon.datasource.config.impl.DatabaseConnectionInfoImpl">
		<!-- 工作流引擎数据库基本信息 -->
		<property name="identifier"          value="${horizon.identifier}" />
		<property name="databaseType"        value="${horizon.databaseType}" />
		<property name="isDefault"           value="${horizon.isDefault}" />
		<property name="connectionType"      value="${horizon.connectionType}" />
		<property name="lobProcessorClass"   value="${horizon.lobProcessorClass}" />
		<property name="lobBufferSize"       value="${horizon.lobBufferSize}" />
		<property name="jndiName"            value="${horizon.jndiName}" />

		<!-- 工作流引擎连接池配置信息: 1、第三方集成时为可选项;2、独立运行时为必须配置项 -->
		<property name="driverClass"         value="${horizon.db.driverClass}" />
		<property name="url"                 value="${horizon.db.jdbcUrl}" />
		<property name="userName"            value="${horizon.db.username}" />
		<property name="userPassword"        value="${horizon.db.password}" />
		<property name="maxPoolSize"         value="${horizon.db.maxPoolSize}" />
		<property name="minPoolSize"         value="${horizon.db.minPoolSize}" />
		<property name="initialPoolSize"     value="${horizon.db.initialPoolSize}" />
		<property name="maxIdelTime"         value="${horizon.db.maxIdelTime}" />
		<property name="datasourceType"      value="${horizon.db.datasourceType}" />
		<property name="connectionProperties" value="remarksReporting=true" />
	</bean>
	<!-- 数据源配置信息 -->
	<bean id="defaultDataSource" class="org.apache.tomcat.jdbc.pool.DataSource">
		<property name="url"                 value="${horizon.db.jdbcUrl}" />
		<property name="driverClassName"     value="${horizon.db.driverClass}" />
		<property name="username"            value="${horizon.db.username}" />
		<property name="password"            value="${horizon.db.password}" />
		<!-- 用于验证数据库连接是否可用的SQL语句。MySQL,SQLServer用select 1，Oracle数据库用select 1 from dual。 -->
		<property name="validationQuery" value="${horizon.db.validationQuery}" />
		<!-- 是否测试空闲的数据库连接 -->
		<property name="testWhileIdle" value="true" />
		<!-- 检查连接是否可用的间隔时间。单位毫秒。默认5秒 -->
		<property name="timeBetweenEvictionRunsMillis" value="5000" />
		<property name="maxActive" value="${horizon.db.maxPoolSize}" />
		<property name="initialSize" value="${horizon.db.initialPoolSize}" />
	</bean>
	<bean id="horizonDynamicDatasource" class="com.horizon.datasource.DynamicDataSource">
		<property name="databaseConnectionInfo"     ref="systemConnectionInfo"  />
		<property name="targetDataSources">
			<map key-type="java.lang.String">
				<entry key="${horizon.identifier}"  value-ref="defaultDataSource" />
			</map>
		</property>
		<property name="defaultTargetDataSource"    ref="defaultDataSource" />
	</bean>

	<!-- MyBatis begin -->
	<bean id="horizonSqlSessionFactory" class=" com.horizon.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="horizonDynamicDatasource" />
		<property name="typeAliasesPackage"    value="com.horizon" />
		<property name="typeAliasesSuperType"  value="com.horizon.core.common.entity.Entity" />
		<property name="configLocation"        value="classpath:workflow-conf/workflow-mybatis.xml" />
		<property name="mapperLocations"       value="classpath*:/com/horizon/**/*.xml" />
	</bean>

	<!-- 扫描basePackage下所有以@HRepository注解的接口 -->
	<bean id="horizonMapperScannerConfigurer" class="com.horizon.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="sqlSessionFactoryBeanName" value="horizonSqlSessionFactory" />
		<property name="basePackage"               value="com.horizon.**.repository" />
		<property name="annotationClass"           value="com.horizon.core.common.annotation.HRepository" />
	</bean>
	<!-- 定义事务 -->
	<bean id="horizonTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="horizonDynamicDatasource" />
	</bean>

	<!-- 配置 Annotation 驱动，扫描@Transactional注解的类定义事务 -->
	<tx:annotation-driven transaction-manager="horizonTransactionManager" />

	<!-- AOP配置事物 -->
	<tx:advice id="horizonTransactionAdvice" transaction-manager="horizonTransactionManager">
		<tx:attributes>
			<tx:method name="delete*"  propagation="REQUIRED" rollback-for="Exception" />
			<tx:method name="update*"  propagation="REQUIRED" rollback-for="Exception" />
			<tx:method name="insert*"  propagation="REQUIRED" rollback-for="Exception" />
			<tx:method name="get*"     propagation="REQUIRED" read-only="true" />
			<tx:method name="find*"    propagation="REQUIRED" read-only="true"/>
			<tx:method name="*"        propagation="REQUIRED" />
		</tx:attributes>
	</tx:advice>

	<!-- 配置AOP切面 -->
	<aop:config>
		<aop:pointcut id="horizonTransactionPointcut" expression="execution(* com.horizon.workflow..service.impl..*.*(..))"/>
		<aop:advisor pointcut-ref="horizonTransactionPointcut" advice-ref="horizonTransactionAdvice"/>
	</aop:config>

	<!-- 实例化数据库操作类 -->
	<bean id="operatorProxy" class="com.horizon.db.DBOperatorProxy">
		<property name="targetAccessMap">
			<map key-type="java.lang.String">
				<entry key="query"       value="com.horizon.db.access.def.ExeQuery" />
				<entry key="update"      value="com.horizon.db.access.def.ExeUpdate" />
				<entry key="saveobject"  value="com.horizon.db.access.def.Object2Database" />
			</map>
		</property>
	</bean>

	<!-- 定时任务属性  -->
	<bean id="propertiesInjectBean" class="com.horizon.task.quartz.util.PropertiesInjectBean">
		<property name="properties">
			<props>
				<prop key="com.horizon.quartz.scheduler.instanceName">HorizonTaskScheduler</prop>
				<prop key="com.horizon.quartz.jobStore.dataSource">horizonDataSource</prop>
				<!-- <prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>  -->
				<prop key="com.horizon.quartz.jobStore.class">com.horizon.task.quartz.util.HorizonJobStore</prop>
				<prop key="com.horizon.quartz.jobStore.misfireThreshold">60000</prop>
				<prop key="com.horizon.quartz.jobStore.tablePrefix">TK_QRTZ_</prop>
				<prop key="com.horizon.quartz.dataSource.horizonDataSource.connectionProvider.class">com.horizon.task.quartz.provider.HorizonTaskConnectionProvider</prop>
				<prop key="com.horizon.quartz.threadPool.class">com.horizon.quartz.simpl.SimpleThreadPool</prop>
				<prop key="com.horizon.quartz.threadPool.threadCount">10</prop>
				<prop key="com.horizon.quartz.threadPool.threadPriority">5</prop>
			</props>
		</property>
	</bean>
	<!-- 定时任务接口-->
	<bean id="horizonTask" class="com.horizon.task.api.impl.HorizonTaskImpl"/>

<!--	 组织机构实现-->
	<bean id="workflowAdapterFactory" class="com.horizon.third.init.WorkflowAdapterFactory">
		<property name="organizationBuilder" value="com.horizon.org.OrgBuilderImpl"/>
	</bean>

	<!-- 流程外部表单 -->
	<bean id="horizonForm" class="com.horizon.workflow.form.service.impl.SimpleFormServiceImpl"/>
	<bean id="bizDataOperate" class="com.horizon.workflow.support.data.BusinessDataOperate">
		<property name="simpleForm" ref="horizonForm"/>
	</bean>
	<!-- 开启@AspectJ AOP代理 -->
	<aop:aspectj-autoproxy proxy-target-class="true"/>

	<!-- 任务调度器 -->
	<task:scheduler id="scheduler" pool-size="10"/>

	<!-- 任务执行器 -->
	<task:executor id="executor" pool-size="10"/>

	<!--开启注解调度支持 @Async @Scheduled-->
	<task:annotation-driven executor="executor" scheduler="scheduler" proxy-target-class="true"/>

	<!-- 分布的情况下的事件机制
	<bean id="applicationEventMulticaster" class="com.horizon.cache.api.modules.redis.HorizonApplicationEventMulticaster" />
	 -->
</beans>
