Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VQyMB-0001bR-ER for pgsql-jdbc@arkaria.postgresql.org; Tue, 01 Oct 2013 11:43:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VQyMA-0006a2-Sm for pgsql-jdbc@arkaria.postgresql.org; Tue, 01 Oct 2013 11:43:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VQyMA-0006Zw-90 for pgsql-jdbc@postgresql.org; Tue, 01 Oct 2013 11:43:10 +0000 Received: from mail-we0-x22d.google.com ([2a00:1450:400c:c03::22d]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VQyM6-0002uP-K3 for pgsql-jdbc@postgresql.org; Tue, 01 Oct 2013 11:43:09 +0000 Received: by mail-we0-f173.google.com with SMTP id w62so7002325wes.18 for ; Tue, 01 Oct 2013 04:43:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:user-agent:in-reply-to :references:mime-version:content-transfer-encoding:content-type; bh=lHkj+kRUrFQSVYOPBsNjwPr9V0f8yRU1Ed+LXjsFtGE=; b=N24BYOo9p24MGb4VzPGfklE93YvyMV0nlRFas7d+Ut0iEDWKT78puEOs6Sb9ad7hMw wlrLc0pX7d1a5tr9AJM93EChZgYT4EuQVkmAUp6HmxSThHwjKDDxWKXSCHAa0hlDByLA qQ9SNHc91phVx7nQh3ZSpffqJW+WEgz0Dqkt6G/Vhx6/hOYkb+ZXF/0wd5qNbe4Xcciz ydCuX6C8lgKcUm/X3wNo4IRPcDnXMrXODPgrGaABevbfsl9E8QcL8lhsA3T7Yj25xtdW L2Ou5h8cVkDYYIoljc0Yc2yNsVJUya2R7JCOeLCS/4OCKMS5MV++09+yY7LDMEqvAgCt C/wQ== X-Received: by 10.180.36.80 with SMTP id o16mr18270469wij.1.1380627786193; Tue, 01 Oct 2013 04:43:06 -0700 (PDT) Received: from marco-dalibo.localnet ([82.66.247.92]) by mx.google.com with ESMTPSA id jf2sm5283628wic.2.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Oct 2013 04:43:05 -0700 (PDT) From: Marc Cousin To: Dave Cramer Cc: List Subject: Re: problem with LargeObject and commit Date: Tue, 01 Oct 2013 09:52:05 +0200 Message-ID: <2155001.o66iMCTO3Y@marco-dalibo> User-Agent: KMail/4.11.1 (Linux/3.11.1-2-ARCH; KDE/4.11.1; x86_64; ; ) In-Reply-To: References: <4745149.zA9zVFDa06@marco> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Pg-Spam-Score: -0.4 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org Sorry, I don't think I get it, so please correct me below if I didn't. I currently use getInputStream() on my large object. How could I provide a connection to the extended InputStream ? I am calling a LargeObject method. Or maybe extend LargeObject to have a new getInputStream method with a connection provided, and then provide this connection to the extended InputStream ? My initial idea was to not have to provide the connection as a parameter, so I wanted to use the Lob Manager. Anyway, shouldn't streaming a large object in this special case be easier to do ? The original code (from SQL Server) didn't have to do all these workarounds, and I'll get this objection from people that will have to use this code :) Just having conn as protected instead of private in the LargeObjectManager would have made it possible to me to do it simply: I could have provided the connection to my extended LargeObject, and from there end the transaction on close(). Regards. On Monday 30 September 2013 17:08:18 Dave Cramer wrote: > Marc, > > You required the connection to create the LargeObjectManager, so why not > just extend the InputStream and add the connection to that object. > When you close the input stream, close the connection ???? > > Dave Cramer > > dave.cramer(at)credativ(dot)ca > http://www.credativ.ca > > On Mon, Sep 30, 2013 at 11:18 AM, Marc Cousin wrote: > > Hi, > > > > I'm having the following problem: I need to stream a LOB to a web client, > > without consuming > > a lot of memory. So I am returning getInputStream() to the caller. > > > > This works perfectly, except that I have to keep a transaction open to > > return the large object > > stream, and I have (or found) no way of closing the transaction when the > > filestream is closed. > > > > So of course, if I did that, I would get a lot of IDLE in transaction > > sessions... > > > > So the logical way seemed to me to extend LargeObjectManager and > > LargeObject to have a > > close method on my LargeObject that closes the transaction, meaning that > > my LargeObject > > should have a connection attribute. So I wanted to do something like this > > (not working, > > it's just for the sake of explanation): > > > > > > public class StreamLargeObjectManager extends LargeObjectManager{ > > > > public StreamLargeObject openStreamLargeObject(long oid, int > > > > mode) > > > > throws SQLException > > > > { > > > > LargeObject lo = super.open(oid, mode); > > StreamLargeObject so = new StreamLargeObject(lo, > > > > super.getConn()); //cannot be done because no access to connection > > > > return so; > > > > } > > > > } > > > > > > and > > > > public class StreamLargeObject extends > > org.postgresql.largeobject.LargeObject{ > > > > Connection conn; > > > > LargeObject lobj; > > > > > > public StreamLargeObject(LargeObject lg, BaseConnection conn) > > > > throws SQLException { > > > > this.lobj = lg; > > this.conn = conn; > > > > } > > > > > > @Override > > public void close() throws SQLException { > > > > lobj.close(); > > this.conn.commit(); > > > > } > > > > public getInputStream() throws SQLException > > > > { > > > > return lobj.getInputStream(); > > > > } > > > > } > > > > > > As the comment says it all, I cannot do this: conn is private in > > LargeObjectManager. For now, the problem has been > > worked around by duplicating all the LargeObjectManager code, but this is > > obviously ugly and not > > maintainable. So my question is: have I missed some obvious solution ? > > Could a getter be added to > > the LargeObjectManager's connection ? > > > > Regards, > > > > Marc > > > > > > -- > > Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) > > To make changes to your subscription: > > http://www.postgresql.org/mailpref/pgsql-jdbc -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc