<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<!--
    Beans common to iBatis infrastructure
-->
<beans>

    <!-- Hierarchical Resource Loader -->
    <bean id="dialectResourceLoader" class="org.alfresco.util.resource.HierarchicalResourceLoader">
        <property name="dialectBaseClass">
            <value>org.hibernate.dialect.Dialect</value>
        </property>
        <!--  Resolve the (perhaps auto detected) dialect class -->
        <property name="dialectClass">
            <bean class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
                <property name="targetBeanName" value="dialect" />
                <property name="propertyPath" value="class.name" />
            </bean>
        </property>
    </bean>

    <bean id="activitiesDataSource" class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="proxyInterfaces">
            <value>javax.sql.DataSource</value>
        </property>
        <property name="target"><ref bean="dataSource"/></property>
        <property name="interceptorNames">
            <list>
                <idref local="activitiesDataSource_autoCommit" />
            </list>
        </property>
    </bean>

    <bean id="activitiesDataSource_autoCommit" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
        <property name="advice">
            <bean class="org.alfresco.util.AutoCommitInterceptor" />
        </property>
        <property name="mappedName">
            <value>getConnection</value>
        </property>
    </bean>

    <!-- iBatis config for Activities domain -->
   	<bean id="activitiesSqlMapClient" class="org.alfresco.ibatis.HierarchicalSqlMapClientFactoryBean">
        <property name="dataSource" ref="activitiesDataSource"/>
        <property name="resourceLoader" ref="dialectResourceLoader" />
        <property name="configLocation">
            <value>classpath:alfresco/ibatis/activities-SqlMapConfig.xml</value>
        </property> 
    </bean> 

    <!-- iBatis config for Alfresco (using common datasource) -->
    <bean id="alfrescoSqlMapClient" class="org.alfresco.ibatis.HierarchicalSqlMapClientFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="resourceLoader" ref="dialectResourceLoader" />
        <property name="configLocation">
            <value>classpath:alfresco/ibatis/alfresco-SqlMapConfig.xml</value>
        </property> 
    </bean>
    <bean id="repoSqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
        <property name="sqlMapClient" ref="alfrescoSqlMapClient"/>
    </bean>
    <bean id="locksSqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
        <property name="sqlMapClient" ref="alfrescoSqlMapClient"/>
    </bean>
    <bean id="contentSqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
        <property name="sqlMapClient" ref="alfrescoSqlMapClient"/>
    </bean>
    <bean id="propertyValueSqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
        <property name="sqlMapClient" ref="alfrescoSqlMapClient"/>
    </bean>
    <bean id="auditSqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
        <property name="sqlMapClient" ref="alfrescoSqlMapClient"/>
    </bean>
    <bean id="avmSqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
        <property name="sqlMapClient" ref="alfrescoSqlMapClient"/>
    </bean>
    
</beans>
