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

<beans>

	<bean id="org.sakaiproject.db.api.SqlService"
			class="org.sakaiproject.db.impl.BasicSqlService"
			init-method="init" destroy-method="destroy" singleton="true">

		<lookup-method name="usageSessionService" bean="org.sakaiproject.event.api.UsageSessionService" />
	
		<property name="defaultDataSource">
			<ref bean="javax.sql.DataSource" />
		</property>
		
		<property name="longDataSource">
			<ref bean="javax.sql.LongDataSource" />
		</property>
		
		<property name="autoDdl">
			<value>${auto.ddl}</value>
		</property>

		<property name="commitAfterRead">
			<value>false</value>
		</property>
		
		<!-- HSQLDB configuration -->
		<property name="vendor">
			<value>hsqldb</value>
		</property>

	</bean>

	<!-- Base DataSource for all pooled database connections -->
	<!-- See http://jakarta.apache.org/commons/dbcp/configuration.html -->
	<bean id="javax.sql.BaseDataSource" abstract="true"
			class="org.apache.commons.dbcp.SakaiBasicDataSource"
			destroy-method="close">
	
		<!--  The fully qualified Java class name of the JDBC driver to be used. -->
		<property name="driverClassName">
			<value>org.hsqldb.jdbcDriver</value>
		</property>
		
		<!-- The connection URL to be passed to our JDBC driver to establish a connection. -->
		<property name="url">
			<value>jdbc:hsqldb:mem:sakai</value>
		</property>
		
		<!-- The connection username to be passed to our JDBC driver to establish a connection. -->
		<property name="username">
			<value>sa</value>
		</property>
		
		<!-- The connection password to be passed to our JDBC driver to establish a connection. -->
		<property name="password">
			<value></value>
		</property>
		
		<!--  The initial number of connections that are created when the pool is started. -->
		<property name="initialSize">
			<value>10</value>
		</property>
		
		<!-- The maximum number of active connections that can be allocated from this pool at the same time, or zero for no limit. -->
		<property name="maxActive">
			<value>50</value>
		</property>
		
		<!-- The maximum number of active connections that can remain idle in the pool, without extra ones being released, or zero for no limit. -->
		<property name="maxIdle">
			<value>10</value>
		</property>
		
		<!-- The minimum number of active connections that can remain idle in the pool, without extra ones being created, or 0 to create none. -->
		<property name="minIdle">
			<value>10</value>
		</property>
		
		<!-- The maximum number of milliseconds that the pool will wait (when there 
		  are no available connections) for a connection to be returned before 
		  throwing an exception, or -1 to wait indefinitely. -->
		<property name="maxWait">
			<value>300000</value>
		</property>
		
		<!-- The number of objects to examine during each run of the idle object 
		  evictor thread (if any). -->
		<property name="numTestsPerEvictionRun">
			<value>3</value>
		</property>
		
		<!--  The indication of whether objects will be validated before being 
		  borrowed from the pool. If the object fails to validate, it will be 
		  dropped from the pool, and we will attempt to borrow another.
		  Note: this has been shown to cause performance problems with Oracle (leave it false) -->
		<property name="testOnBorrow">
			<value>true</value>
		</property>
		
		<!-- The indication of whether objects will be validated before being 
		  returned to the pool. -->
		<property name="testOnReturn">
			<value>false</value>
		</property>

		<!-- The indication of whether objects will be validated by the idle object 
		  evictor (if any). If an object fails to validate, it will be dropped from 
		  the pool. -->
		<property name="testWhileIdle">
			<value>false</value>
		</property>

		<!-- The SQL query that will be used to validate connections from this pool 
		  before returning them to the caller. If specified, this query MUST be a 
		  SQL SELECT statement that returns at least one row.
		  Note: This has been shown to cause performance problems under Oracle: leave it unset. -->
		<property name="validationQuery">
			<value>select 1 from INFORMATION_SCHEMA.SYSTEM_USERS</value>
		</property>
		
		<!-- The default auto-commit state of connections created by this pool. -->
		<property name="defaultAutoCommit">
			<value>false</value>
		</property>
		
		<!-- The default read-only state of connections created by this pool. -->
		<property name="defaultReadOnly">
			<value>false</value>
		</property>
		
		<!-- Use TRANSACTION_READ_COMMITTED for MySQL -->
		<!-- DO NOT SET for Oracle (the default TRANSACTION_READ_COMMITTED is fine, and setting it causes performance problems) -->
		<!-- Up to and including 1.7.1, HSQLDB supports only Connection.TRANSACTION_READ_UNCOMMITTED. -->
		<property name="defaultTransactionIsolationString">
			<value>TRANSACTION_READ_UNCOMMITTED</value>
		</property>
		
		<!-- Prepared statement pooling for this pool. -->
		<property name="poolPreparedStatements">
			<value>false</value>
		</property>
		
		<!-- The maximum number of open statements that can be allocated from the 
		  statement pool at the same time, or zero for no limit. Since a connection 
		  usually only uses one or two statements at a time, this is mostly used to 
		  help detect resource leaks. -->
		<property name="maxOpenPreparedStatements">
			<value>0</value>
		</property>
		
		<!-- The minimum amount of time an object may sit idle in the pool before it 
		  is eligable for eviction by the idle object evictor (if any). -->
		<property name="minEvictableIdleTimeMillis">
			<value>1800000</value>
		</property>
		
		<!-- The number of milliseconds to sleep between runs of the idle object 
		  evictor thread. When non-positive, no idle object evictor thread will be 
		  run. -->
		<property name="timeBetweenEvictionRunsMillis">
			<value>900000</value>
		</property>
	
	</bean>

	<!-- Shared DataSource for all pooled database connections -->
	<bean id="javax.sql.DataSource" parent="javax.sql.BaseDataSource">
	</bean>

	<!-- The "slow" connection pool for streaming downloads from db -->
	<bean id="javax.sql.LongDataSource"
			parent="javax.sql.BaseDataSource">
	</bean>

	<!-- Base Hibernate SessionFactory -->
	<bean
			id="org.sakaiproject.springframework.orm.hibernate.SessionFactoryBase"
			abstract="true"
			class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
	
		<property name="dataSource">
			<ref local="javax.sql.DataSource" />
		</property>
		
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">${hibernate.dialect}</prop>
				<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>
				<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
				<prop key="hibernate.query.substitutions">
					true 1, false 0, yes 'Y', no 'N'
				</prop>
				<prop key="hibernate.jdbc.use_streams_for_binary">true</prop>
				<prop key="hibernate.cache.use_query_cache">true</prop>
				<prop key="hibernate.cache.provider_class">
					org.hibernate.cache.EhCacheProvider
				</prop>
			</props>
		</property>
		
		<!--  update the database schema when starting -->
		<property name="schemaUpdate">
			<value>${auto.ddl}</value>
		</property>
	
	</bean>

	<!--  The "Global" Hibernate Session Factory -->
	<bean
			id="org.sakaiproject.springframework.orm.hibernate.GlobalSessionFactory"
			parent="org.sakaiproject.springframework.orm.hibernate.SessionFactoryBase"
			class="org.sakaiproject.springframework.orm.hibernate.AddableSessionFactoryBean">
	</bean>

	<!--  The "Global" Transaction Manager -->
	<bean
			id="org.sakaiproject.springframework.orm.hibernate.GlobalTransactionManager"
			class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory">
			<ref bean="org.sakaiproject.springframework.orm.hibernate.GlobalSessionFactory" />
		</property>
	</bean>

</beans>
