FAQ
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

Search Discussions

  • Andrus Adamchik at Mar 21, 2011 at 12:31 pm
    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
  • Michael Gentry at Mar 21, 2011 at 12:55 pm
    For some reason I thought Cayenne made a JNDI request whenever it
    needed a connection? Typically the JNDI data source (such as in
    Tomcat/JBoss/etc) is managing the connection pool, so this seems to me
    the logical thing.

    For Cayenne-managed pools, I know it caches the connection
    information. I was thinking of changing that behavior a while back
    because if you store your DB password outside the model it won't
    re-read the password when attempting to reconnect.

    mrg

    On Mon, Mar 21, 2011 at 8:31 AM, 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
  • Andrus Adamchik at Mar 21, 2011 at 12:59 pm

    On Mar 21, 2011, at 2:55 PM, Michael Gentry wrote:

    For some reason I thought Cayenne made a JNDI request whenever it
    needed a connection? Typically the JNDI data source (such as in
    Tomcat/JBoss/etc) is managing the connection pool, so this seems to me
    the logical thing.
    I think so too... So it is a question of JNDI call overhead on very query. Anyone has any data on that?

    Andrus
  • Michael Gentry at Mar 21, 2011 at 1:32 pm
    I don't have any data on the JNDI call overhead, but it seems like it
    would be worth trying out.

    mrg
    On Mon, Mar 21, 2011 at 8:59 AM, Andrus Adamchik wrote:
    On Mar 21, 2011, at 2:55 PM, Michael Gentry wrote:

    For some reason I thought Cayenne made a JNDI request whenever it
    needed a connection?  Typically the JNDI data source (such as in
    Tomcat/JBoss/etc) is managing the connection pool, so this seems to me
    the logical thing.
    I think so too... So it is a question of JNDI call overhead on very query. Anyone has any data on that?

    Andrus
  • Hans Pikkemaat at Mar 21, 2011 at 1:00 pm
    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
  • Hans Pikkemaat at Mar 21, 2011 at 2:12 pm
    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
  • Hans Pikkemaat at Mar 21, 2011 at 2:30 pm
    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: h.pikkemaat@tsi-solutions.nl
    www.tsi-solutions.nl <http://www.tsi-solutions.nl/>
    www.toeristiek.nl <http://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.
  • Andrus Adamchik at Mar 21, 2011 at 2:32 pm
    With this approach this is as best as you can get. Alternatively see option (1) in my original message. It should work for both test and production use.

    Andrus

    On Mar 21, 2011, at 4:29 PM, Hans Pikkemaat wrote:

    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_logo.png> 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: h.pikkemaat@tsi-solutions.nl
    www.tsi-solutions.nl
    www.toeristiek.nl
    <tsi_sunset.png> <tsi_pictos.png>
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedMar 21, '11 at 12:12p
activeMar 21, '11 at 2:32p
posts9
users3
websitecayenne.apache.org

People

Translate

site design / logo © 2022 Grokbase