Re: Recovery from Network error

From: Vassilis Raxenidis (
Date: Mon Mar 01 2004 - 03:57:03 EST

  • Next message: Andrus Adamchik: "Re: Recovery from Network error"

    Hi Andrus,

    I think I found a solution.

    I think that the cayenne connection pool does not work in the way we want.
    I think that the cayenne connection pool does not perform any
    reinitialization when a network error
    occures and the pooled connections reamain invalid in the pool.
    What I have done to solve this problem are the foolowing:
    1. Create a db connection pool by using the Jakarta DBCP.
    2. Configure a cayenne data source to use the DBCP pooling driver.
        the configuration for the driver used by cayenne datasource looks like
        <driver project-version="1.0"
             <url value="jdbc:apache:commons:dbcp:/datasourcename"/>
    3. Modified the cayenne DriverDataSourceFactory
    to return instances of org.objectstyle.cayenne.conn.DriverDataSource based
    on the driver parameters defined above.
    Then the cayenne.xml file looks like that:
    <?xml version="1.0" encoding="utf-8"?>
    <domains project-version="1.0">
    <domain name="Domain1">
     <map name="Map1" location=""/>
     <node name="Node1"
       <map-ref name="Map1"/>

    JakartaDBCPDriverDataSourceFactory is a sub-class of
    org.objectstyle.cayenne.conf.DriverDataSourceFactory and the getDataSource
    method is implemented like this:
    public DataSource getDataSource(String arg0, Level arg1) throws Exception {
        return new DriverDataSource(getDriverInfo().getJdbcDriver(),

    Then cayenne uses the pooled data source defined by the DBCP and every time
    that cayenne needs a connection then it is aqcuired from the DBCP
    Of course the DBCP pool is configured to validate every connection before it
    is returned from the pool. Moreover every idle connection in the pool
    is periodocally validated. Every invalid connection is dropped from pool.
    Then while the network is down the pool does not contain any valid
    connection (every connection has been dropped). So, when a connection
    is requested an exception is thrown. As soon as the network is up the pool
    creates new validated connections which can be returned.

    What do you think about this solution? I'm testing it and it seems to work


    Vassilis Raxenidis

    ----- Original Message -----
    From: "Andrus Adamchik" <>
    To: <>
    Sent: Friday, February 27, 2004 7:29 PM
    Subject: Re: Recovery from Network error

    > On Feb 27, 2004, at 3:55 AM, Vassilis Raxenidis wrote:
    > > 1. Get a connection from the pool.
    > > 2. Perform the query by using this connection
    > > 3. Release the connection
    > That is exactly how Cayenne works.
    > > If the query is to be performed during a network down time then an
    > > exception
    > > may be thrown.
    > > Then query may keep on trying until the network is up again. When the
    > > network is stabilized then a valid
    > > connection will be returned from the pool and the query will be
    > > performed
    > > properly.
    > This should work ok.
    > > It seems that cayenne acquires a connection the first time that the
    > > query
    > > has to be performed and then uses the
    > > same connection in any subsequent query execution.
    > Not true... Aside from possible bugs, Cayenne always closes connection
    > regardless whether an error has occurred or not. If queries are run in
    > a batch (e.g. commit of multiple modified objects), an exception in any
    > of the batch queries would terminate the whole batch and close the
    > connection.
    > There is a related bug report that may be related to your observations:
    > . It has
    > been fixed, but not yet released. A patched version can be downloaded
    > from here:
    > preview2.tar.gz . Let me know if it fixes the problem. If not, could
    > you send a stack trace of exception that happens when attempting to run
    > a query over broken connection.
    > Regards
    > Andrus

    This archive was generated by hypermail 2.0.0 : Mon Mar 01 2004 - 03:57:06 EST