Re: Recovery from Network error

From: Vassilis Raxenidis (raxe..orthnet.gr)
Date: Fri Feb 27 2004 - 03:55:19 EST

  • Next message: Nenko Ivanov: "Re: Using Cayenne and Firebird embeded JDBC driver"

    Hi,

    I'm trying to follow your advices by using the Jakarta commons-dbcp.
    A properly configured connection pool which is created with the dbcp can
    handle
    network connection problems as the stale connections are droped from the
    pool.
    When a connection is requested, the connection factory validates the
    connection before it
    is returned from the pool. So, when a connection is requested from the pool
    (a new connection will be constructed if no idle
    connections reside in the pool or an idle connection will be activated)
    either a valid connection
    will be returned or an error will occure.
    I tried to use cayenne together with a data source created by dbcp and the
    org.apache.commons.dbcp.PoolingDriver so
    that connections will be obtained from the connection pool.
    The problem is that I can't understand how cayenne manages database
    connections.
    Consider a java thread that periodically performs the same query on a
    batabase.
    What I want to do is the following:
    1. Get a connection from the pool.
    2. Perform the query by using this connection
    3. Release the connection
    This algorithm may ensure that the query will be always performed with a
    valid connection.
    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.
    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. If there was a way to
    close the connection after the query execution then
    cayenne would be enforced to request a connection from the pool for each
    query execution. Such a process could
    solve the stale connections problem which may be arised due to network
    interruption.
    Is there any way to close the connection after a query execution?
    What do you think about my reasoning in realtion to this connection recovery
    problem?

    Regards,

    Vassilis Raxenidis

    ----- Original Message -----
    From: "Andrus Adamchik" <andru..bjectstyle.org>
    To: <cayenne-use..bjectstyle.org>
    Sent: Wednesday, February 11, 2004 7:14 PM
    Subject: Re: Recovery from Network error

    > Hi,
    >
    > This is not a problem with the DataContext per se, but rather with the
    > underlying javax.sql.DataSource. If the DataSource knows how to
    > reconnect, DataContext can still be reused. Now, since different JDBC
    > drivers handle dropped connections differently, Cayenne doesn't handle
    > all of them. Oracle is handled pretty well, MySQL has a "reconnect"
    > feature:
    >
    > http://objectstyle.org/cayenne/faq/deploy.html#reconnect
    >
    >
    > Now what are your options with Sybase.. There are other DataSource
    > implementations that have advanced reconnect feature. E.g. Jakarta
    > commons-dbcp - http://jakarta.apache.org/commons/dbcp/ . You can use
    > them with Cayenne.
    >
    > 1. If you are deploying in a web container like Tomcat, you can map a
    > shared DBCP DataSource per Tomcat documentation, and use a
    > JNDIDataSourceFactory configured here:
    > http://objectstyle.org/cayenne/modelerguide/common-tasks/create-data-
    > node.html
    >
    > 2. If you run a standalone application, you can write your own factory
    > class that implements org.objectstyle.cayenne.conf.DataSourceFactory
    > and instantiates DBCP pool. We would gladly accept such factory as a
    > contribution to Cayenne :-).
    >
    > Andrus
    >
    >
    > On Feb 11, 2004, at 9:27 AM, Vassilis Raxenidis wrote:
    > > Hi,
    > >
    > > I use cayenne together with Sybase.
    > > If the network goes down while trying to execute a query (for example
    > > by
    > > calling performIteratedQuery of DataContext)
    > > then the following exception is thrown:
    > > org.objectstyle.cayenne.CayenneException: [v.1.0.2 October 27 2003]
    > > Error
    > > getting ResultIterator: Global Exception:
    > > java.sql.SQLException: Can't obtain connection. Request timed out.
    > > So far so good as the databse server can't be reached due to network
    > > connection problem.
    > > But when the network connection to database server is recovered any
    > > subsequent call of performIteratedQuery method on the same
    > > DataContext instance keeps on throwing the same exception. Is that
    > > logical?
    > > Is there any recovery actions that have to be taken on the DataContext
    > > object after a network connectivity problem is detected?
    > > Thanks in advance.
    > >
    > > Vassilis Raxenidis
    >



    This archive was generated by hypermail 2.0.0 : Fri Feb 27 2004 - 03:55:24 EST