Apache » Cocoon »

  Cocoon Databases Block

Cocoon Databases Block 1.0



This document describes steps needed for making datasources defined as Spring beans to be working in Avalon components (like SQLTransformer).

Note: This guide assumes that you use cocoon-databases-impl artifact with version at least 1.0.0-RC2.

Datasource declaration

Note: Migration of datasources is not mandatory. You can leave Avalon-style declaration of datasources untouched and use such declared database connection in both Avalon and Spring components. Nevertheless, it's highly recommended to migrate to Spring declarations because they will be the only one actively supported in future versions of Cocoon Databases block.

Consider you have following datasource declaration in cocoon.xconf file:

    <jdbc logger="core.datasources.personnel" name="personnel">
      <pool-controller max="10" min="5"/>

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"
       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=""/>



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.

Note: When you don't plan to use your database connection in Avalon-based components you can resign from declaring wrapping bean and only declare wrapped bean on its own.
Errors and Improvements? If you see any errors or potential improvements in this document please help us: View, Edit or comment on the latest development version (registration required).