Title: html versie van handtekening
So this is the best I can find right now

        setupNewJNDIInfo();

        for (Object o:Configuration.getSharedConfiguration().getDomains()) {
            DataDomain d=(DataDomain)o;
            for (Object no : d.getDataNodes()) {
                DataNode n = (DataNode) no;
                DataSourceFactory f = (DataSourceFactory) Class.forName(n.getDataSourceFactory()).newInstance();
                DataSource ds = f.getDataSource(n.getDataSourceLocation());
                n.setDataSource(ds);
            }
        }

This will recreate all datasources for all nodes in all domains.

Is there an easier/better way?

HPI

On 3/21/11 3:12 PM, Hans Pikkemaat wrote:
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



    

--
TSi Solutions
Neptunusstraat 25
7521 WC Enschede

Tel. +31 (0)88 - 25 00 000
Fax. +31 (0)88 - 25 00 122
Hans Pikkemaat
Java Developer (Services Team)
E-mail:
  www.tsi-solutions.nl
www.toeristiek.nl
10 jaar TSi Solutions
... marktleider in het automatiseren en outsourcen van werkprocessen in de reisbranche
... toonaangevende partij voor het verzamelen, structureren en beschikbaarstellen van reiscontent
... Reisrevue Innovatieveer 2008 - Veervolle vermelding
... Winnaar Reisrevue Innovatieveer 2009
... Winnaar Reisrevue Innovatieveer 2010
... Top 20 positie in 2008 Deloitte Technology Fast50 Nederland
... Top 10 positie in 2009 Deloitte Technology Fast50 Benelux
... Top 100 positie in 2009 Deloitte Technology Fast500 EMEA
... Top 50 positie in 2010 Deloitte Technology Fast50 Benelux
TSi Solutions is de handelsnaam van Travel Service International b.v.[KvK 06091935]
DISCLAIMER: De informatie opgenomen in dit bericht kan vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde.
Indien u dit bericht onterecht ontvangt, wordt u verzocht de inhoud niet te gebruiken en de afzender direct te informeren door het bericht te retourneren.
The information contained in this message may be confidential and is intended to be exclusively for the addressee.
Should you receive this message unintentionally, please do not use the contents herein and notify the sender immediately by return e-mail.

Reply via email to