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.
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:
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:
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.