<?xml version="1.0" encoding="UTF-8"?>
<!-- Spring configuration for JPA/database/Transactions -->
<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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:p="http://www.springframework.org/schema/p"
	xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       				    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
       				    http://www.springframework.org/schema/aop 	  http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
       				    http://www.springframework.org/schema/tx 	  http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

    <context:annotation-config />

    <context:component-scan base-package="com.agilex.healthcare.schedulingmanager" />

    <tx:annotation-driven transaction-manager="transactionManager" />

    <bean id="jndiDataSource" lazy-init="true" class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiName">
			<value>${vardb_jndiname}</value>
		</property>
	</bean>

	<bean id="entityManagerFactory"
		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
		lazy-init="true" p:dataSource-ref="jndiDataSource"
		p:jpaVendorAdapter-ref="hibernateJpaVendorAdapter"
		p:jpaDialect-ref="jpaDialect" p:persistenceUnitName="smhadbPU" >
		<!--depends-on="liquibase">-->
		<property name="packagesToScan" value="com.agilex.healthcare.schedulingmanager.datalayer" />
	</bean>

    <bean id="nonJndiDataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${hadb_driver}" />
        <property name="url" value="${hadb_url}" />
        <property name="username" value="${hadb_user}" />
        <property name="password" value="${hadb_password}" />
    </bean>

    <!--<bean id="authJndiDataSource" lazy-init="true" class="org.springframework.jndi.JndiObjectFactoryBean">-->
        <!--<property name="jndiName">-->
            <!--<value>${authdb_jndiname}</value>-->
        <!--</property>-->
    <!--</bean>-->

    <!--<bean id="authTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"-->
          <!--p:entityManagerFactory-ref="entityManagerFactory" p:dataSource-ref="authJndiDataSource"-->
          <!--p:jpaDialect-ref="jpaDialect" />-->

    <!--<bean id="authEntityManagerFactory"-->
          <!--class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"-->
          <!--lazy-init="true" p:dataSource-ref="authJndiDataSource"-->
          <!--p:jpaVendorAdapter-ref="hibernateJpaVendorAdapter"-->
          <!--p:persistenceUnitName="authdbPU" p:jpaDialect-ref="jpaDialect">-->
    <!--</bean>-->

	<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase">
		<property name="dataSource" ref="${dataSource.ref}" />
		<property name="changeLog" value="classpath:/META-INF/liquibase/db.changelog-master.xml" />
		<!--<property name="contexts" value="test" />-->
	</bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
          p:entityManagerFactory-ref="entityManagerFactory" p:dataSource-ref="${dataSource.ref}"
          p:jpaDialect-ref="jpaDialect" />

    <bean id="hibernateJpaVendorAdapter"
          class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
          p:databasePlatform="${hadb_dialect}" p:generateDdl="false"
          p:showSql="true" />

    <bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />

</beans>
