The Artima Developer Community
Sponsored Link

Java Buzz Forum
Configuring Kodo inside Spring

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Marc Logemann

Posts: 594
Nickname: loge
Registered: Sep, 2002

Marc Logemann is founder of www.logentis.de a Java consultancy
Configuring Kodo inside Spring Posted: Mar 11, 2005 3:48 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Marc Logemann.
Original Post: Configuring Kodo inside Spring
Feed Title: Marc's Java Blog
Feed URL: http://www.logemann.org/day/index_java.xml
Feed Description: Java related topics for all major areas. So you will see J2ME, J2SE and J2EE issues here.
Latest Java Buzz Posts
Latest Java Buzz Posts by Marc Logemann
Latest Posts From Marc's Java Blog

Advertisement

Inspired from this great documentation on how to define a Kodo PersistenceManagerFactory inside Spring with using DataSources, i want to add the missing piece in there.

First a short explanation why doing all these things when something like this works too:

<bean id="pmf2" class="org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean">
        <property name="jdoProperties">
            <props>
                <prop key="javax.jdo.PersistenceManagerFactoryClass">kodo.jdbc.runtime.JDBCPersistenceManagerFactory</prop>
                <prop key="javax.jdo.option.ConnectionDriverName">com.mysql.jdbc.Driver</prop>
                <prop key="javax.jdo.option.ConnectionUserName">root</prop>
                <prop key="javax.jdo.option.ConnectionPassword">urkunde</prop>
                <prop key="javax.jdo.option.ConnectionURL">jdbc:mysql://localhost/versysng?useUnicode=true</prop>
[..]
</bean>

The reason why this configuration is not the best one is that you dont have a seperate DataSource definition inside Spring, thus preventing you from doing persistence things without Kodo. Right now we would have to define a real Datasource and use this with Quartz for example (when you want to persist Job definitions). But then you have some double definition when it comes to data access, because you also have your connection definition inside the LocalPersistenceManagerFactoryBean as you can see easily. Changing the database would need changing configuration in two places then.

By using the approach mentioned in the really nice documentation by Colin Sampaleanu, you can define a dataSource and link it to the KodoPersistenceManagerFactoryBean. As you can see, its not the default LocalPersistenceManagerFactoryBean but a subclass of it, because there is no standard in JDO in ascociating a datasource with a PMF.

The missing piece is the DataSource implementation. While most folks would use Apache DBCP for this, i want to stay within the Kodo world and just use this one:

    <bean id="dataSource" class="com.solarmetric.jdbc.PoolingDataSource">
        <property name="connectionURL">
            <value>jdbc:mysql://localhost/somedb?useUnicode=true</value>
        </property>
        <property name="connectionDriverName">
            <value>com.mysql.jdbc.Driver</value>
        </property>
        <property name="connectionPassword">
            <value>root</value>
        </property>
        <property name="connectionUserName">
            <value>root</value>
        </property>
    </bean>

This DataSource is also capable of pooling and uses some default pooling behavior. If you need fine grained control on how pooling is done, you can supply a ConnectionPoolImpl to the PoolingDataSource. You have to use constructor injection though, because the DataSource doesnt support defining the pool via setters.

Read: Configuring Kodo inside Spring

Topic: Abstraction on your "Code View" Previous Topic   Next Topic Topic: Why the Patent System Inhibits Innovation Today

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use