Hi,

So this is what I do now right after repopulating the jndi information:

        DataSourceFactory f = new JNDIDataSourceFactory();
        
f.initializeWithParentConfiguration(Configuration.getSharedConfiguration());

        DataSource ds = f.getDataSource("jdbc/DB_DB1");

        
Configuration.getSharedConfiguration().getDomain("Domain1").getNode("Node1").setDataSource(ds);

This overrides the data source but it is done hardcoded.
Is there an easy way to recreate a datasource based on the existing 
configuration?
Are there convenience methods/classes I can reuse to load this information?

I want to prevent manual ds reset/creation code in all my unit tests.

tx

Hans


On 3/21/11 2:00 PM, Hans Pikkemaat wrote:
Sounds good, is there a way to programmatically set my own DataSourceFactory 
before initializing cayenne?
Or is the only way to set it during a reset process.

HPI

On 3/21/11 1:31 PM, Andrus Adamchik wrote:
Yeah, Cayenne DataNode obtains DataSource once and stores it for future use. 
Not sure if a better long-term strategy would be to do JNDI lookups every time 
? (maybe not), but for now you may either (1) write your own factory that 
creates a simple DataSource wrapper that grabs a fresh DS via JNDI every time a 
connection is requested, or (2) call DataNode.setDataSource(..) during your 
environment reset process.

Andrus


On Mar 21, 2011, at 2:12 PM, Hans Pikkemaat wrote:
Hi,

I have a unit test where I use jndi to determine my connection parameters.

When I run one unit test which uses a specific jndi setup and it calls cayenne 
then
all works fine (i use org.apache.cayenne.conf.JNDIDataSourceFactory)

I then clear my jndi container and repopulate it with different connection 
details
(different database).

Running cayenne again still uses the earlier connection. Recreating a data 
context
doesn't seem to help. I also tried 
Configuration.getSharedConfiguration().shutdown()
but this also doesn't help.

Maybe the connections are re-used? If so, is there a way to clear those?

In general, is there a way to reset cayenne in such a way that my above unit 
testing will work?

tx

Hans



Reply via email to