cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lon Varscsak <lon.varsc...@gmail.com>
Subject Re: Access to JDBC Connection
Date Wed, 15 Oct 2014 00:12:44 GMT
That's basically what I'm doing...

     DataSource dataSource = serverRuntime().getDataSource(dataNodeName);



    try {

    return dataSource.getConnection();

    } catch (SQLException sqe) {

    throw new RuntimeException(sqe);

    }

No exception is being throw.  My query executes (a simple select) and
returns results.  I then immediately do a "normal" Cayenne fetch, but it
times out with the error I mentioned.  My code doesn't explicitly close the
connection, because historically I wouldn't want to disconnect from the
database.

-Lon

On Tue, Oct 14, 2014 at 4:46 PM, Andrus Adamchik <andrus@objectstyle.org>
wrote:

> Hi Lon,
>
> Some code samples showing how you get and release connection would help to
> understand your problem better. But... You can actually bypass dealing with
> the internals of Cayenne stack and work with DataSource as you would in a
> straight JDBC application:
>
> ServerRuntime r = ...
> DataSource ds = r.getDataSource("mydatanode");
>
> try(Connection c = ds.getConnection()) {
>    // do your thing here.. and the Java will close the connection
>    // on exit from the "try" block
> }
>
>
> Or you can use SQLTemplate for raw SQL and avoid dealing with connections
> all together, which is a preferred way:
>
>
> http://cayenne.apache.org/docs/3.1/cayenne-guide/queries.html#sqltemplate
>
> Andrus
>
>
> On Oct 14, 2014, at 6:54 PM, Lon Varscsak <lon.varscsak@gmail.com> wrote:
>
> > Hey all,
> >
> > I have some code that executes some raw SQL and historically (with EOF) I
> > just get the connection that would normally be used for that editing
> > context.  No problems.  So I'm trying to implement that similarly in
> > Cayenne, and I'm getting the DataNode's DataSource's connection, and it
> > works, but then any subsequent calls (at least within the same request) I
> > get a timeout because it's like the connection is being used (even though
> > I'm done executing my query) and unavailable to the pool (error:  Can't
> > obtain connection. Request timed out. Total used connections: 1)
> >
> > I've been using this code with a JDBC Connection for a very long time,
> and
> > I think I'm releasing the resources I create (the Statement).  What
> could I
> > be missing here?  Is there a better way to "checkout" and then "release"
> > the connection?
> >
> > Thanks,
> >
> > Lon
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message