I just had a chance to spend some time looking at Cayenne/Spring
integration. I haven't looked deeply into transactions, wrapping
exceptions, etc yet, but I figured out the basic stuff and wanted to
share it, as there seems to be real interest.
http://objectstyle.org/downloads/cayenne/demos/cayenne-spring-
preview.tar.gz
This is the link to two classes that provide a factory for Cayenne
configuration and a web app interceptor to bind DataContext to a
request thread (in a non-web environment some other kind of interceptor
is needed). Factory currently supports loading cayenne.xml from
CLASSPATH (it should be easy to add any other options - different file
locations, file name other than cayenne.xml, etc.), and it also
supports DataSource provided by Spring (it will override whatever is
configured in CayenneModeler). Example configuration:
1. From app context XML file:
<!-- configure interceptor singleton that may be referenced from one or
more servlet configs -->
<bean id="cayenneWebInterceptor"
class="org.springframework.orm.cayenne.WebInterceptor">
<!-- configuring to use default domain from configuration -->
<constructor-arg><ref local="cayenneConfig"/></constructor-arg>
</bean>
<!-- Load Cayenne with default location of cayenne.xml and
Cayenne-configured DataSource
To use Spring provided DataSource, add "dataSource" property to this
bean.
-->
<bean id="cayenneConfig"
class="org.springframework.orm.cayenne.ConfigurationFactory"/>
2. From Petclinic servlet XML file:
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<!-- This interceptor will bind Cayenne session DataContext to the
request thread.
Interceptor is defined in the application context and can be
shared by multiple servlets.
-->
<property name="interceptors">
<list>
<ref bean="cayenneWebInterceptor"/>
</list>
</property>
<property name="mappings">
<props>
<prop key="/welcome.htm">clinicController</prop>
....
</props>
</property>
</bean>
This is still very raw and is posted here as guidance for your own
Spring configuration. Hopefully this will help a few people to get
started. Comments are welcome.
Andrus
This archive was generated by hypermail 2.0.0 : Mon Dec 20 2004 - 20:56:13 EST