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

<beans>

    <!-- load hibernate configuration properties -->
    <bean id="hibernateConfigProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <!--  Load in hibernate defaults -->
        <property name="locations">
            <list>
                <value>classpath:alfresco/domain/hibernate-cfg.properties</value>
            </list>
        </property>
        <!-- Allow global properties to override default settings -->
        <property name="properties">
            <ref bean="global-properties"/>
        </property>
        <property name="localOverride">
            <value>true</value>
        </property>
    </bean>

    <!-- load hibernate entity cache strategies -->
    <bean id="cacheStrategiesPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="ignoreUnresolvablePlaceholders">
            <value>true</value>
        </property>
        <property name="locations">
            <list>
                <value>classpath:alfresco/domain/cache-strategies.properties</value>
            </list>
        </property>
    </bean>

    <!-- Hibernate session factory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" parent="sessionFactoryBase">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
    </bean>

    <!-- Hibernate dialect detector -->
    <bean id="dialect" class="org.alfresco.hibernate.DialectFactoryBean">
        <property name="localSessionFactory">
            <ref bean="&amp;sessionFactory"></ref>  <!-- inject the actual factory, not a session -->
        </property>
    </bean>

    <bean id="sessionFactoryBase" abstract="true">
        <property name="schemaUpdate">
           <value>false</value>
        </property>
        <property name="mappingResources">
            <list>
                <!--  -->
                <!-- Alfresco Node Storage -->
                <!--  -->

                <value>org/alfresco/repo/domain/hibernate/Locale.hbm.xml</value>
                <value>org/alfresco/repo/domain/hibernate/Node.hbm.xml</value>
                <value>org/alfresco/repo/domain/hibernate/Transaction.hbm.xml</value>
                <value>org/alfresco/repo/domain/hibernate/Permission.hbm.xml</value>
                <value>org/alfresco/repo/attributes/hibernate/Attributes.hbm.xml</value>
                <value>org/alfresco/repo/domain/hibernate/UsageDelta.hbm.xml</value>
                <value>org/alfresco/repo/activities/hibernate/Activities.hbm.xml</value>

                <!-- Audit config -->
                <!-- TODO: Move into org/alfresco/repo/domain/hibernate/ -->
                <value>org/alfresco/repo/audit/hibernate/Audit.hbm.xml</value>

                <!--  -->
                <!-- JBoss jBPM Workflow Engine -->
                <!--  -->
                <!-- TODO: Determine if it's possible to inject the following mappings -->
                <!--       from elsewhere -->
                <!--  -->
                <value>org/jbpm/graph/action/Script.hbm.xml</value>
                <value>org/jbpm/db/hibernate.queries.hbm.xml</value>
                <value>org/jbpm/graph/def/ProcessDefinition.hbm.xml</value>
                <value>org/jbpm/graph/def/Node.hbm.xml</value>
                <value>org/jbpm/graph/def/Transition.hbm.xml</value>
                <value>org/jbpm/graph/def/Event.hbm.xml</value>
                <value>org/jbpm/graph/def/Action.hbm.xml</value>
                <value>org/jbpm/graph/def/SuperState.hbm.xml</value>
                <value>org/jbpm/graph/def/ExceptionHandler.hbm.xml</value>
                <value>org/jbpm/instantiation/Delegation.hbm.xml</value>
                <value>org/jbpm/graph/node/StartState.hbm.xml</value>
                <value>org/jbpm/graph/node/EndState.hbm.xml</value>
                <value>org/jbpm/graph/node/ProcessState.hbm.xml</value>
                <value>org/jbpm/graph/node/Decision.hbm.xml</value>
                <value>org/jbpm/graph/node/Fork.hbm.xml</value>
                <value>org/alfresco/repo/workflow/jbpm/jbpm.Join.hbm.xml</value>
                <value>org/jbpm/graph/node/State.hbm.xml</value>
                <value>org/jbpm/graph/node/TaskNode.hbm.xml</value>
                <value>org/jbpm/context/def/ContextDefinition.hbm.xml</value>
                <value>org/jbpm/context/def/VariableAccess.hbm.xml</value>
                <value>org/jbpm/taskmgmt/def/TaskMgmtDefinition.hbm.xml</value>
                <value>org/jbpm/taskmgmt/def/Swimlane.hbm.xml</value>
                <value>org/jbpm/taskmgmt/def/Task.hbm.xml</value>
                <value>org/jbpm/taskmgmt/def/TaskController.hbm.xml</value>
                <value>org/jbpm/module/def/ModuleDefinition.hbm.xml</value>
                <value>org/jbpm/bytes/ByteArray.hbm.xml</value>
                <value>org/jbpm/file/def/FileDefinition.hbm.xml</value>
                <value>org/alfresco/repo/workflow/jbpm/jbpm.CreateTimerAction.hbm.xml</value>
                <value>org/jbpm/scheduler/def/CancelTimerAction.hbm.xml</value>
                <value>org/jbpm/graph/exe/Comment.hbm.xml</value>
                <value>org/jbpm/graph/exe/ProcessInstance.hbm.xml</value>
                <value>org/jbpm/graph/exe/Token.hbm.xml</value>
                <value>org/jbpm/graph/exe/RuntimeAction.hbm.xml</value>
                <value>org/jbpm/module/exe/ModuleInstance.hbm.xml</value>
                <value>org/jbpm/context/exe/ContextInstance.hbm.xml</value>
                <value>org/jbpm/context/exe/TokenVariableMap.hbm.xml</value>
                <value>org/jbpm/context/exe/VariableInstance.hbm.xml</value>
                <value>org/jbpm/context/exe/variableinstance/ByteArrayInstance.hbm.xml</value>
                <value>org/jbpm/context/exe/variableinstance/DateInstance.hbm.xml</value>
                <value>org/jbpm/context/exe/variableinstance/DoubleInstance.hbm.xml</value>
                <value>org/jbpm/context/exe/variableinstance/HibernateLongInstance.hbm.xml</value>
                <value>org/jbpm/context/exe/variableinstance/HibernateStringInstance.hbm.xml</value>
                <value>org/jbpm/context/exe/variableinstance/LongInstance.hbm.xml</value>
                <value>org/jbpm/context/exe/variableinstance/NullInstance.hbm.xml</value>
                <value>org/jbpm/context/exe/variableinstance/StringInstance.hbm.xml</value>
                <value>org/jbpm/job/Job.hbm.xml</value>
                <value>org/jbpm/job/Timer.hbm.xml</value>
                <value>org/alfresco/repo/workflow/jbpm/jbpm.Timer.hbm.xml</value>
                <value>org/jbpm/job/ExecuteNodeJob.hbm.xml</value>
                <value>org/jbpm/job/ExecuteActionJob.hbm.xml</value>
                <value>org/jbpm/taskmgmt/exe/TaskMgmtInstance.hbm.xml</value>
                <value>org/jbpm/taskmgmt/exe/TaskInstance.hbm.xml</value>
                <value>org/alfresco/repo/workflow/jbpm/WorkflowTaskInstance.hbm.xml</value>
                <value>org/jbpm/taskmgmt/exe/PooledActor.hbm.xml</value>
                <value>org/jbpm/taskmgmt/exe/SwimlaneInstance.hbm.xml</value>
                <value>org/jbpm/logging/log/ProcessLog.hbm.xml</value>
                <value>org/jbpm/logging/log/MessageLog.hbm.xml</value>
                <value>org/jbpm/logging/log/CompositeLog.hbm.xml</value>
                <value>org/jbpm/graph/log/ActionLog.hbm.xml</value>
                <value>org/jbpm/graph/log/NodeLog.hbm.xml</value>
                <value>org/jbpm/graph/log/ProcessInstanceCreateLog.hbm.xml</value>
                <value>org/jbpm/graph/log/ProcessInstanceEndLog.hbm.xml</value>
                <value>org/jbpm/graph/log/ProcessStateLog.hbm.xml</value>
                <value>org/jbpm/graph/log/SignalLog.hbm.xml</value>
                <value>org/jbpm/graph/log/TokenCreateLog.hbm.xml</value>
                <value>org/jbpm/graph/log/TokenEndLog.hbm.xml</value>
                <value>org/jbpm/graph/log/TransitionLog.hbm.xml</value>
                <value>org/jbpm/context/log/VariableLog.hbm.xml</value>
                <value>org/jbpm/context/log/VariableCreateLog.hbm.xml</value>
                <value>org/jbpm/context/log/VariableDeleteLog.hbm.xml</value>
                <value>org/jbpm/context/log/VariableUpdateLog.hbm.xml</value>
                <value>org/jbpm/context/log/variableinstance/ByteArrayUpdateLog.hbm.xml</value>
                <value>org/jbpm/context/log/variableinstance/DateUpdateLog.hbm.xml</value>
                <value>org/jbpm/context/log/variableinstance/DoubleUpdateLog.hbm.xml</value>
                <value>org/jbpm/context/log/variableinstance/HibernateLongUpdateLog.hbm.xml</value>
                <value>org/jbpm/context/log/variableinstance/HibernateStringUpdateLog.hbm.xml</value>
                <value>org/jbpm/context/log/variableinstance/LongUpdateLog.hbm.xml</value>
                <value>org/jbpm/context/log/variableinstance/StringUpdateLog.hbm.xml</value>
                <value>org/jbpm/taskmgmt/log/TaskLog.hbm.xml</value>
                <value>org/jbpm/taskmgmt/log/TaskCreateLog.hbm.xml</value>
                <value>org/jbpm/taskmgmt/log/TaskAssignLog.hbm.xml</value>
                <value>org/jbpm/taskmgmt/log/TaskEndLog.hbm.xml</value>
                <value>org/jbpm/taskmgmt/log/SwimlaneLog.hbm.xml</value>
                <value>org/jbpm/taskmgmt/log/SwimlaneCreateLog.hbm.xml</value>
                <value>org/jbpm/taskmgmt/log/SwimlaneAssignLog.hbm.xml</value>
                <value>org/jbpm/job/CleanUpProcessJob.hbm.xml</value>
            </list>
        </property>
        <property name="hibernateProperties" ref="hibernateConfigProperties" />
        <property name="entityCacheStrategies" >
            <props>
                <prop key="org.alfresco.repo.domain.hibernate.NodeImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.ChildAssocImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.NodeAssocImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.StoreImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.TransactionImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.ServerImpl">${cache.strategy}</prop>

                <prop key="org.alfresco.repo.domain.hibernate.DbAccessControlEntryContextImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.DbAccessControlEntryImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.DbAccessControlListChangeSetImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.DbAccessControlListImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.DbAccessControlListMemberImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.DbAuthorityAliasImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.DbAuthorityImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.DbPermissionImpl">${cache.strategy}</prop>
                 
                <prop key="org.alfresco.repo.audit.hibernate.AuditConfigImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.audit.hibernate.AuditDateImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.audit.hibernate.AuditSourceImpl">${cache.strategy}</prop>
            </props>
        </property>
        <property name="collectionCacheStrategies" >
            <props>
                <prop key="org.alfresco.repo.domain.hibernate.NodeImpl.properties">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.NodeImpl.aspects">${cache.strategy}</prop>
            </props>
        </property>
    </bean>

    <!-- create a transaction manager -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="transactionSynchronizationName">
            <value>SYNCHRONIZATION_ALWAYS</value>
        </property>
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>

   <bean id="permissionsDaoComponent" class="org.alfresco.repo.service.StoreRedirectorProxyFactory">
      <property name="proxyInterface">
         <value>org.alfresco.repo.security.permissions.impl.PermissionsDaoComponent</value>
      </property>
      <property name="defaultBinding">
         <ref bean="dmPermissionsDaoComponent"></ref>
      </property>
      <property name="redirectedProtocolBindings">
         <map>
            <entry key="workspace"><ref bean="dmPermissionsDaoComponent"></ref></entry>
            <entry key="versionStore"><ref bean="dmPermissionsDaoComponent"></ref></entry>
            <entry key="avm"><ref bean="avmPermissionsDaoComponent"/></entry>
         </map>
      </property>
   </bean>
    
   <bean id="avmPermissionsDaoComponent" class="org.alfresco.repo.domain.hibernate.PermissionsDaoComponentImpl">
      <property name="aclDaoComponent">
         <ref bean="aclDaoComponent" />
      </property>
      <property name="protocolToACLDAO">
         <map>
            <entry key="workspace"><ref bean="nodeACLDAO"></ref></entry>
            <entry key="avm"><ref bean="avmACLDAO"/></entry>
         </map>
      </property>
      <property name="defaultACLDAO">
          <ref bean="nodeACLDAO"/>
       </property>
   </bean>
    
   <bean id="dmPermissionsDaoComponent" class="org.alfresco.repo.domain.hibernate.DMPermissionsDaoComponentImpl">
      <property name="aclDaoComponent">
         <ref bean="aclDaoComponent" />
      </property>
      <property name="protocolToACLDAO">
         <map>
            <entry key="workspace"><ref bean="nodeACLDAO"></ref></entry>
            <entry key="avm"><ref bean="avmACLDAO"/></entry>
         </map>
      </property>
      <property name="defaultACLDAO">
          <ref bean="nodeACLDAO"/>
       </property>
   </bean>
    
   <bean id="aclDaoComponent" class="org.springframework.aop.framework.ProxyFactoryBean">
      <property name="target">
         <ref bean="aclDaoComponentImpl" />
      </property>
      <property name="interceptorNames">
         <list>
            <value>daoServiceDirtySessionInterceptor</value>
         </list>
      </property>
   </bean>
    
   <bean id="aclDaoComponentImpl" class="org.alfresco.repo.domain.hibernate.AclDaoComponentImpl">
      <property name="sessionFactory">
         <ref bean="sessionFactory" />
      </property>
      <property name="qnameDAO">
         <ref bean="qnameDAO" />
      </property>
      <property name="patchDAO">
         <ref bean="patchDAO" />
      </property>
      <property name="avmNodeDAO">
         <ref bean="newAvmNodeDAO" />
      </property>
	  <property name="aclCache">
         <ref bean="aclCache" />
      </property>
   </bean>
   
    <bean id="nodeACLDAO" class="org.alfresco.repo.domain.hibernate.DMAccessControlListDAO">
        <property name="nodeDaoService">
            <ref bean="nodeDaoService" />
        </property>
		<property name="aclDaoComponent">
            <ref bean="aclDaoComponent"/>
        </property>
		<property name="hibernateSessionHelper">
            <ref bean="hibernateSessionHelper"/>
        </property>
		<property name="nodeService">
            <ref bean="dbNodeService"/>
        </property>
    </bean>
    
    <bean id="avmACLDAO" class="org.alfresco.repo.domain.hibernate.AVMAccessControlListDAO">
        <property name="avmRepository">
            <ref bean="avmRepository"/>
        </property>
        <property name="avmService">
            <ref bean="avmService"/>
        </property>
        <property name="aclDaoComponent">
            <ref bean="aclDaoComponent"/>
        </property>
        <property name="avmSnapShotTriggeredIndexingMethodInterceptor">
            <ref bean="avmSnapShotTriggeredIndexingMethodInterceptor"/>
        </property>
        <property name="hibernateSessionHelper">
            <ref bean="hibernateSessionHelper"/>
      </property>
    </bean>

    <bean id="usageDeltaDAO" class="org.alfresco.repo.domain.hibernate.HibernateUsageDeltaDAO">
       <property name="sessionFactory">
           <ref bean="sessionFactory"/>
       </property>
       <property name="nodeDaoService">
           <ref bean="nodeDaoServiceImpl" />
       </property>
   </bean>
    
   <bean id="auditableTransactionHelper" class="org.alfresco.repo.transaction.RetryingTransactionHelper">
      <property name="transactionService">
         <ref bean="transactionService"/>
      </property>
      <property name="maxRetries">
         <value>1</value>
      </property>
      <property name="minRetryWaitMs">
         <value>50</value>
      </property>
      <property name="maxRetryWaitMs">
         <value>100</value>
      </property>
      <property name="retryWaitIncrementMs">
         <value>50</value>
      </property>
   </bean>

   <bean id="nodeDaoServiceImpl" class="org.alfresco.repo.node.db.hibernate.HibernateNodeDaoServiceImpl" >
      <property name="enableTimestampPropagation">
         <value>${system.enableTimestampPropagation}</value>
      </property>
      <property name="qnameDAO">
         <ref bean="qnameDAO" />
      </property>
      <property name="contentDataDAO">
         <ref bean="contentDataDAO" />
      </property>
      <property name="usageDeltaDAO">
          <ref bean="usageDeltaDAO"/>
      </property>
      <property name="aclDaoComponent">
          <ref bean="aclDaoComponent"/>
      </property>
      <property name="localeDAO">
         <ref bean="localeDAO" />
      </property>
      <property name="dictionaryService">
         <ref bean="dictionaryService" />
      </property>
      <property name="transactionService">
         <ref bean="transactionService" />
      </property>
      <property name="auditableTransactionHelper">
         <ref bean="auditableTransactionHelper" />
      </property>
      <property name="behaviourFilter">
         <ref bean="policyBehaviourFilter" />
      </property>
      <property name="sessionFactory">
         <ref bean="sessionFactory" />
      </property>
      <property name="storeAndNodeIdCache">
         <ref bean="storeAndNodeIdCache"/>
      </property>
      <property name="parentAssocsCache">
         <ref bean="parentAssocsCache"/>
      </property>
   </bean>

   <bean id="sessionSizeResourceInterceptor" class="org.alfresco.repo.transaction.SingleEntryTransactionResourceInterceptor" >
      <property name="methodResourceManagers">
         <list>
            <ref bean="sessionSizeResourceManager"></ref>
         </list>
      </property>
      <property name="elapsedTimeBeforeActivationMillis">
         <value>10000</value>
      </property>
      <property name="resourceManagerCallFrequencyMillis">
         <value>5000</value>
      </property>
   </bean>
   <bean id="sessionSizeResourceManager" class="org.alfresco.repo.domain.hibernate.SessionSizeResourceManager">
      <property name="sessionFactory">
         <ref bean="sessionFactory" />
      </property>
      <property name="writeThreshold">
         <value>2000</value>
      </property>
      <property name="readThreshold">
         <value>50000</value>
      </property>
      <property name="retentionFactor">
         <value>3</value>
      </property>
   </bean>

   <bean id="dbNodeDaoServiceTxnRegistration" class="org.alfresco.repo.transaction.TransactionalDaoInterceptor" >
      <property name="daoService">
         <ref bean="nodeDaoServiceImpl" />
      </property>
   </bean>

   <bean id="daoServiceDirtySessionInterceptor" class="org.alfresco.repo.domain.hibernate.DirtySessionMethodInterceptor" />

   <bean id="nodeDaoService" class="org.springframework.aop.framework.ProxyFactoryBean">
      <property name="target">
         <ref bean="nodeDaoServiceImpl" />
      </property>
      <property name="interceptorNames">
         <list>
            <value>sessionSizeResourceInterceptor</value>
            <value>daoServiceDirtySessionInterceptor</value>
            <value>dbNodeDaoServiceTxnRegistration</value>
         </list>
      </property>
   </bean>

   <bean id="localeDAOImpl" class="org.alfresco.repo.domain.hibernate.HibernateLocaleDAOImpl" >
      <property name="sessionFactory">
         <ref bean="sessionFactory" />
      </property>
      <property name="localeIdCache">
         <ref bean="localeIdCache"/>
      </property>
   </bean>

   <bean id="localeDAO" class="org.springframework.aop.framework.ProxyFactoryBean">
      <property name="target">
         <ref bean="localeDAOImpl" />
      </property>
      <property name="interceptorNames">
         <list>
            <value>daoServiceDirtySessionInterceptor</value>
         </list>
      </property>
   </bean>
    
    <bean id="auditDaoHibernate" class="org.alfresco.repo.audit.hibernate.HibernateAuditDAO">
        <property name="sessionFactory">
            <ref bean="sessionFactory"/>
        </property>
        <property name="contentStore">
            <ref bean="auditFileContentStore"/>
        </property>
        <property name="localSessionFactory">
          <ref bean="&amp;sessionFactory"></ref>  <!-- inject the actual factory, not a session -->
        </property>
    </bean>

   <bean id="hibernateSessionHelper" class="org.alfresco.repo.domain.hibernate.HibernateSessionHelper">
       <property name="sessionFactory">
           <ref bean="sessionFactory"/>
       </property>
   </bean> 
   
</beans>