Usage
Introduction
This document describes steps needed for making datasources defined as Spring beans to be working in Avalon components (like SQLTransformer).
Datasource declaration
Consider you have following datasource declaration in cocoon.xconf file:
<datasources> <jdbc logger="core.datasources.personnel" name="personnel"> <pool-controller max="10" min="5"/> <dburl>jdbc:hsqldb:hsql://localhost:3306/cocoondb</dburl> <user>sa</user> <password></password> </jdbc> </datasources>
Then the only thing you have to do is to create file named datasources.xml in META-INF/cocoon/spring folder of one of your blocks with following contents:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean name="org.apache.avalon.excalibur.datasource.DataSourceComponent/personnel" class="org.apache.cocoon.databases.bridge.spring.avalon.SpringToAvalonDataSourceWrapper"> <property name="wrappedBean"> <bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" > <property name="driverClassName" value="org.hsqldb.jdbcDriver"/> <property name="url" value="jdbc:hsqldb:hsql://localhost:3306/cocoondb"/> <property name="username" value="sa"/> <property name="password" value=""/> </bean> </property> </bean> </beans>
When it comes to configuring DataSource it's all you have to do. What's important datasource configured that way will be working just fine with old Avalon components.
Configuration of wrapped bean uses DriverManagerDataSource class
that does not provide any support for connection pooling. You
may want to consider integration of external libraries.
See
javadocs
comments of DriverManagerDataSource class for details.