Re: problem with LargeObject and commit

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: Marc Cousin <cousinmarc(at)gmail(dot)com>
Cc: List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: problem with LargeObject and commit
Date: 2013-09-30 21:08:18
Message-ID: CADK3HH+5=SXA-afEpuy2PzcSx-7QsUEkEXkQ5ZnJ7GbHSbkUtg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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 <cousinmarc(at)gmail(dot)com> 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(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2013-10-01 04:37:33 Re: JDBC executeBatch() hangs without error
Previous Message Marc Cousin 2013-09-30 15:18:13 problem with LargeObject and commit