Return-Path: X-Original-To: apmail-cayenne-user-archive@www.apache.org Delivered-To: apmail-cayenne-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 74A0B17F48 for ; Wed, 15 Oct 2014 00:38:44 +0000 (UTC) Received: (qmail 10963 invoked by uid 500); 15 Oct 2014 00:38:44 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 10936 invoked by uid 500); 15 Oct 2014 00:38:44 -0000 Mailing-List: contact user-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cayenne.apache.org Delivered-To: mailing list user@cayenne.apache.org Received: (qmail 10924 invoked by uid 99); 15 Oct 2014 00:38:43 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Oct 2014 00:38:43 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of lon.varscsak@gmail.com designates 209.85.216.47 as permitted sender) Received: from [209.85.216.47] (HELO mail-qa0-f47.google.com) (209.85.216.47) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Oct 2014 00:38:18 +0000 Received: by mail-qa0-f47.google.com with SMTP id cm18so143123qab.34 for ; Tue, 14 Oct 2014 17:38:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ulnG5+yHvW7LKk1jhMdK2rJDZ6ukTeF/v2JoOMcM7kY=; b=hF/NAj52+ONof4z3nbkYFsdMRuPYYap/thTw/wNMhyRU/K2UHe6TCcYYE5KKPg24KD 9HRBZ+va0eXOEhQ1HWFIn3fZ58xrrhz9vzq6g/dU23b9ooQK8xGFGDo3U7LPZ8Pccyxi 09MNBl51IMCTQdDkIjlGIJZgzVLqSi9wl8yJYf008KgNJSW6D3zjWzZpyJ6BbjSqE+li JbSZbrTLEzgqTJ0v5eTy6IidNszy5wohwPExHH2MXgEK1PtsTQudb3AogK30zCt4H2w7 J2iF2jM29lon/73OvUlHaFdVgNAIt3KOh/64/UL4dcHqerGob1aMqb3bQHaIU95d2Sxp DZUQ== MIME-Version: 1.0 X-Received: by 10.224.129.66 with SMTP id n2mr15375158qas.32.1413333496889; Tue, 14 Oct 2014 17:38:16 -0700 (PDT) Received: by 10.140.39.102 with HTTP; Tue, 14 Oct 2014 17:38:16 -0700 (PDT) In-Reply-To: References: <12FA7F56-D33D-41AA-BEE8-1A2FE0B971BB@objectstyle.org> Date: Tue, 14 Oct 2014 17:38:16 -0700 Message-ID: Subject: Re: Access to JDBC Connection From: Lon Varscsak To: Apache Cayenne Content-Type: multipart/alternative; boundary=001a11c1db98080af405056b594a X-Virus-Checked: Checked by ClamAV on apache.org --001a11c1db98080af405056b594a Content-Type: text/plain; charset=UTF-8 Okay, that's the issue (not calling close()). I thought what I was getting back was a real JDBC Connection, but it looks like I'm getting back a ConnectionWrapper, which when closed, returns the connection to pool. I can do something conditionally with this. Thanks, Lon On Tue, Oct 14, 2014 at 5:12 PM, Lon Varscsak wrote: > 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 > 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 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 >> >> > --001a11c1db98080af405056b594a--