<?xml version="1.0" encoding="UTF-8"?>
<!--

    Licensed to Jasig under one or more contributor license
    agreements. See the NOTICE file distributed with this work
    for additional information regarding copyright ownership.
    Jasig licenses this file to you under the Apache License,
    Version 2.0 (the "License"); you may not use this file
    except in compliance with the License.  You may obtain a
    copy of the License at the following location:

      http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.

-->
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:p="http://www.springframework.org/schema/p"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">


  <!-- 
  NOTE:
  This bean supports testing JPA components on multiple platforms.
  In order to test a particular database platform, do the following:
   1. Place a database.properties at the root of the cas-server-core module directory
   2. Copy the database driver jar to cas-server-core/target/test-lib/jdbc-driver.jar
   3. OPTIONAL: Set cas.jpa.concurrent system property to invoke concurrent tests
   4. Execute test goal as usual
   -->  
  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
    p:location="file:database.properties"
    p:ignoreResourceNotFound="true"
    p:ignoreUnresolvablePlaceholders="true">
    <property name="properties">
      <props>
        <prop key="database.driverClass">org.hsqldb.jdbcDriver</prop>
        <prop key="database.user">sa</prop>
        <prop key="database.password"></prop>
        <prop key="database.url">jdbc:hsqldb:mem:cas-ticket-registry</prop>
        <prop key="database.dialect">org.hibernate.dialect.HSQLDialect</prop>
        <prop key="database.batchSize">1</prop>
      </props>
    </property>
  </bean>

  <bean class="org.springframework.jdbc.datasource.SimpleDriverDataSource"
    id="dataSource"
    p:driverClass="${database.driverClass}"
    p:username="${database.user}"
    p:password="${database.password}"
    p:url="${database.url}" />

  <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    id="factoryBean"
    p:dataSource-ref="dataSource"
    p:jpaVendorAdapter-ref="jpaVendorAdapter">
    <property name="jpaProperties">
      <props>
        <prop key="hibernate.dialect">${database.dialect}</prop>
        <prop key="hibernate.hbm2ddl.auto">update</prop>
        <prop key="hibernate.jdbc.batch_size">${database.batchSize}</prop>
      </props>
    </property>
  </bean>

  <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
    id="jpaVendorAdapter"
    p:generateDdl="true"
    p:showSql="true" />

  <bean class="org.jasig.cas.services.JpaServiceRegistryDaoImpl" id="dao"
    p:entityManagerFactory-ref="factoryBean" />

  <bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager"
    p:entityManagerFactory-ref="factoryBean" />
    
  <bean id="ticketRegistry" class="org.jasig.cas.ticket.registry.JpaTicketRegistry" />

  <!--
    Injects EntityManager/Factory instances into beans with
    @PersistenceUnit and @PersistenceContext
  -->
  <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
    
</beans>


