Eclipse RCP+Spring+EMF+Teneo and the data source
One issue when using these technologies together is the configuration of the HbSessionDataStore. Under spring, you can configure the LocalSessionFactoryBean by setting the data source directly. The data source is typically defined in your context XML as well. But there is no data source property setter under HbSessionDataStore. Under standard hibernate you can set configuration parameter hibernate.connection.provider_class to the name of the connection provider class and spring provides a data source called LocalDataSourceConnectionProvider which can be instantiated without parameters to get a data source. The trick of this spring class is that it access a thread local storage (therefore global location for that thread) to retrieve the data source you may have set in the LocalSessionFactoryBean instance under setDataSource(). The LocalSessionFactoryBean sets the thread local storage when you call setDataSource().
So under teneo’s HbSessionDataStore, we can just extend the class to include this type of property setter, create a small connection provider class just like LocalDataSourceConnectionProvider and do what spring does. Then we just need to ensure that our connection provider is used and that the user does not set it twice, once through the setter and through standard hibernate configuration approaches in the properties specification. Note that the teneo page http://www.elver.org/hibernate/hbdatastore.html describes having to set the data store factory in the HbHelper class. However, since we are using spring, you don’t need to do that (the HbHelper class is acting as a service locator) because it is done for you.
Here’s the example data source connection provider:
The new bean to use:
The namespace org.eclipse.mf.teneo.spring.hibernate has been used but you can change this.
Further investigation is needed to see if the standard spring transaction machinery is working as expected. More on this later.
If you need to dynamically set the properties of the data source, i have blogged about ways to dynamically created hierarchical contexts and other tricks, however, you can easily configure the data source by defining a FactoryBeanPostProcessor, obtaining the bean definition, setting the properties based on your “stored” data source configuration then add the post processor programmatically or by defining the post processor bean in your context (in which case it is automatically picked up). Bean definitions are partially instantiated beans that you can alter/override the configuration of properties with. Its very convenient and easier than what I described in previous blogs. In your post processor callback: