pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedproblem with LargeObject and commit
9+ messages / 2 participants
[nested] [flat]
* problem with LargeObject and commit
@ 2013-09-30 15:18 Marc Cousin <cousinmarc@gmail.com>
0 siblings, 1 reply; 9+ messages in thread
From: Marc Cousin @ 2013-09-30 15:18 UTC (permalink / raw)
To: pgsql-jdbc
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
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: problem with LargeObject and commit
@ 2013-09-30 21:08 Dave Cramer <pg@fastcrypt.com>
parent: Marc Cousin <cousinmarc@gmail.com>
0 siblings, 1 reply; 9+ messages in thread
From: Dave Cramer @ 2013-09-30 21:08 UTC (permalink / raw)
To: Marc Cousin <cousinmarc@gmail.com>; +Cc: 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@gmail.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@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: problem with LargeObject and commit
@ 2013-10-01 07:52 Marc Cousin <cousinmarc@gmail.com>
parent: Dave Cramer <pg@fastcrypt.com>
0 siblings, 1 reply; 9+ messages in thread
From: Marc Cousin @ 2013-10-01 07:52 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc
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 <cousinmarc@gmail.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@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
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: problem with LargeObject and commit
@ 2013-10-01 12:11 Dave Cramer <pg@fastcrypt.com>
parent: Marc Cousin <cousinmarc@gmail.com>
0 siblings, 1 reply; 9+ messages in thread
From: Dave Cramer @ 2013-10-01 12:11 UTC (permalink / raw)
To: Marc Cousin <cousinmarc@gmail.com>; +Cc: pgsql-jdbc
Well I don't see any reason not to open up the LOM class to allow you to
extend it.
Can you send a git pull?
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
On Tue, Oct 1, 2013 at 3:52 AM, Marc Cousin <cousinmarc@gmail.com> wrote:
> 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 <cousinmarc@gmail.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@postgresql.org)
> > > To make changes to your subscription:
> > > http://www.postgresql.org/mailpref/pgsql-jdbc
>
>
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: problem with LargeObject and commit
@ 2013-10-06 17:14 Marc Cousin <cousinmarc@gmail.com>
parent: Dave Cramer <pg@fastcrypt.com>
0 siblings, 1 reply; 9+ messages in thread
From: Marc Cousin @ 2013-10-06 17:14 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc
Hi,
Attached is an attempt to do this (git diff on head).
The code seems to work. It has been tested on the program we are migrating
from SQL Server, we can now stream LOBs directly to web browsers...
Please note that I am not usually a Java developper. I did my best to do this
correctly, and the Java way (as far as I know :) ). If some things are not
done the right way, or there is a smarter solution, tell me, I'll improve
this.
Regards,
Marc
On Tuesday 01 October 2013 08:11:21 Dave Cramer wrote:
> Well I don't see any reason not to open up the LOM class to allow you to
> extend it.
>
> Can you send a git pull?
>
> Dave Cramer
>
> dave.cramer(at)credativ(dot)ca
> http://www.credativ.ca
>
> On Tue, Oct 1, 2013 at 3:52 AM, Marc Cousin <cousinmarc@gmail.com> wrote:
> > 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 <cousinmarc@gmail.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@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
Attachments:
pgjdbc-largeobject-commitonclose.diff (text/x-patch, 6.5K) download
diff --git a/org/postgresql/largeobject/LargeObject.java b/org/postgresql/largeobject/LargeObject.java
index 0c48cd1..c1ac30d 100644
--- a/org/postgresql/largeobject/LargeObject.java
+++ b/org/postgresql/largeobject/LargeObject.java
@@ -11,6 +11,7 @@ import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.SQLException;
+import org.postgresql.core.BaseConnection;
import org.postgresql.util.PSQLException;
import org.postgresql.util.PSQLState;
import org.postgresql.fastpath.Fastpath;
@@ -67,6 +68,9 @@ public class LargeObject
private boolean closed = false; // true when we are closed
+ private BaseConnection conn; // Only initialized when open a LOB with CommitOnClose
+ private boolean commitOnClose; // Only initialized when open a LOB with CommitOnClose
+
/**
* This opens a large object.
*
@@ -75,15 +79,26 @@ public class LargeObject
* @param fp FastPath API for the connection to use
* @param oid of the Large Object to open
* @param mode Mode of opening the large object
+ * @param conn the connection to the database used to access this LOB
+ * @param commitOnClose commit the transaction when this LOB will be closed
* (defined in LargeObjectManager)
* @exception SQLException if a database-access error occurs.
* @see org.postgresql.largeobject.LargeObjectManager
*/
- protected LargeObject(Fastpath fp, long oid, int mode) throws SQLException
+ protected LargeObject(Fastpath fp, long oid, int mode, BaseConnection conn, boolean commitOnClose) throws SQLException
{
this.fp = fp;
this.oid = oid;
this.mode = mode;
+ if (commitOnClose == true)
+ {
+ this.commitOnClose = true;
+ this.conn = conn;
+ }
+ else
+ {
+ this.commitOnClose = false;
+ }
FastpathArg args[] = new FastpathArg[2];
args[0] = Fastpath.createOIDArg(oid);
@@ -91,6 +106,23 @@ public class LargeObject
this.fd = fp.getInteger("lo_open", args);
}
+ /**
+ * This opens a large object.
+ *
+ * <p>If the object does not exist, then an SQLException is thrown.
+ *
+ * @param fp FastPath API for the connection to use
+ * @param oid of the Large Object to open
+ * @param mode Mode of opening the large object
+ * (defined in LargeObjectManager)
+ * @exception SQLException if a database-access error occurs.
+ * @see org.postgresql.largeobject.LargeObjectManager
+ */
+ protected LargeObject(Fastpath fp, long oid, int mode) throws SQLException
+ {
+ this(fp,oid,mode,null,false);
+ }
+
public LargeObject copy() throws SQLException
{
return new LargeObject(fp, oid, mode);
@@ -160,6 +192,10 @@ public class LargeObject
args[0] = new FastpathArg(fd);
fp.fastpath("lo_close", false, args); // true here as we dont care!!
closed = true;
+ if (this.commitOnClose == true)
+ {
+ this.conn.commit();
+ }
}
}
diff --git a/org/postgresql/largeobject/LargeObjectManager.java b/org/postgresql/largeobject/LargeObjectManager.java
index b2c8469..e07cc14 100644
--- a/org/postgresql/largeobject/LargeObjectManager.java
+++ b/org/postgresql/largeobject/LargeObjectManager.java
@@ -154,7 +154,23 @@ public class LargeObjectManager
*/
public LargeObject open(int oid) throws SQLException
{
- return open((long)oid);
+ return open((long)oid,false);
+ }
+
+ /**
+ * This opens an existing large object, same as previous method,
+ * but commits the transaction on close if asked. This is useful when
+ * the LOB is returned to a caller which won't take care of transactions by
+ * itself.
+ * @param oid of large object
+ * @param commitOnClose commit the transaction when this LOB will be closed
+ * @return LargeObject instance providing access to the object
+ * @exception SQLException on error
+ */
+
+ public LargeObject open(int oid, boolean commitOnClose) throws SQLException
+ {
+ return open((long)oid,commitOnClose);
}
/**
@@ -167,7 +183,21 @@ public class LargeObjectManager
*/
public LargeObject open(long oid) throws SQLException
{
- return open(oid, READWRITE);
+ return open(oid, READWRITE, false);
+ }
+
+ /**
+ * This opens an existing large object, same as previous method,
+ * but commits the transaction on close if asked
+ * @param oid of large object
+ * @param commitOnClose commit the transaction when this LOB will be closed
+ * @return LargeObject instance providing access to the object
+ * @exception SQLException on error
+ */
+
+ public LargeObject open(long oid, boolean commitOnClose) throws SQLException
+ {
+ return open((long)oid,READWRITE,commitOnClose);
}
/**
@@ -181,7 +211,22 @@ public class LargeObjectManager
*/
public LargeObject open(int oid, int mode) throws SQLException
{
- return open((long)oid, mode);
+ return open((long)oid,mode,false);
+ }
+
+ /**
+ * This opens an existing large object, same as previous method,
+ * but commits the transaction on close if asked
+ * @param oid of large object
+ * @param mode mode of open
+ * @param commitOnClose commit the transaction when this LOB will be closed
+ * @return LargeObject instance providing access to the object
+ * @exception SQLException on error
+ */
+
+ public LargeObject open(int oid, int mode, boolean commitOnClose) throws SQLException
+ {
+ return open((long)oid,mode,commitOnClose);
}
/**
@@ -194,10 +239,24 @@ public class LargeObjectManager
*/
public LargeObject open(long oid, int mode) throws SQLException
{
+ return open((long)oid,mode,false);
+ }
+
+ /**
+ * This opens an existing large object, based on its OID
+ *
+ * @param oid of large object
+ * @param mode mode of open
+ * @param commitOnClose commit the transaction when this LOB will be closed
+ * @return LargeObject instance providing access to the object
+ * @exception SQLException on error
+ */
+ public LargeObject open(long oid, int mode, boolean commitOnClose) throws SQLException
+ {
if (conn.getAutoCommit())
throw new PSQLException(GT.tr("Large Objects may not be used in auto-commit mode."),
PSQLState.NO_ACTIVE_SQL_TRANSACTION);
- return new LargeObject(fp, oid, mode);
+ return new LargeObject(fp, oid, mode, conn, commitOnClose);
}
/**
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: problem with LargeObject and commit
@ 2013-10-14 14:38 Marc Cousin <cousinmarc@gmail.com>
parent: Marc Cousin <cousinmarc@gmail.com>
0 siblings, 1 reply; 9+ messages in thread
From: Marc Cousin @ 2013-10-14 14:38 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc
Hi,
Did you give it a look ?
Regards
Marc
On Sunday 06 October 2013 19:14:41 Marc Cousin wrote:
> Hi,
>
> Attached is an attempt to do this (git diff on head).
>
> The code seems to work. It has been tested on the program we are migrating
> from SQL Server, we can now stream LOBs directly to web browsers...
>
> Please note that I am not usually a Java developper. I did my best to do
> this correctly, and the Java way (as far as I know :) ). If some things are
> not done the right way, or there is a smarter solution, tell me, I'll
> improve this.
>
> Regards,
>
> Marc
>
> On Tuesday 01 October 2013 08:11:21 Dave Cramer wrote:
> > Well I don't see any reason not to open up the LOM class to allow you to
> > extend it.
> >
> > Can you send a git pull?
> >
> > Dave Cramer
> >
> > dave.cramer(at)credativ(dot)ca
> > http://www.credativ.ca
> >
> > On Tue, Oct 1, 2013 at 3:52 AM, Marc Cousin <cousinmarc@gmail.com> wrote:
> > > 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 <cousinmarc@gmail.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@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
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: problem with LargeObject and commit
@ 2013-10-15 10:48 Dave Cramer <pg@fastcrypt.com>
parent: Marc Cousin <cousinmarc@gmail.com>
0 siblings, 1 reply; 9+ messages in thread
From: Dave Cramer @ 2013-10-15 10:48 UTC (permalink / raw)
To: Marc Cousin <cousinmarc@gmail.com>; +Cc: pgsql-jdbc
Marc,
Sorry I have been travelling. Just looked at it, It's fine albeit more than
just changing the visibility of the function.
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
On Mon, Oct 14, 2013 at 10:38 AM, Marc Cousin <cousinmarc@gmail.com> wrote:
> Hi,
>
> Did you give it a look ?
>
> Regards
>
> Marc
>
> On Sunday 06 October 2013 19:14:41 Marc Cousin wrote:
> > Hi,
> >
> > Attached is an attempt to do this (git diff on head).
> >
> > The code seems to work. It has been tested on the program we are
> migrating
> > from SQL Server, we can now stream LOBs directly to web browsers...
> >
> > Please note that I am not usually a Java developper. I did my best to do
> > this correctly, and the Java way (as far as I know :) ). If some things
> are
> > not done the right way, or there is a smarter solution, tell me, I'll
> > improve this.
> >
> > Regards,
> >
> > Marc
> >
> > On Tuesday 01 October 2013 08:11:21 Dave Cramer wrote:
> > > Well I don't see any reason not to open up the LOM class to allow you
> to
> > > extend it.
> > >
> > > Can you send a git pull?
> > >
> > > Dave Cramer
> > >
> > > dave.cramer(at)credativ(dot)ca
> > > http://www.credativ.ca
> > >
> > > On Tue, Oct 1, 2013 at 3:52 AM, Marc Cousin <cousinmarc@gmail.com>
> wrote:
> > > > 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 <
> cousinmarc@gmail.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@postgresql.org)
> > > > > > To make changes to your subscription:
> > > > > > http://www.postgresql.org/mailpref/pgsql-jdbc
>
>
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: problem with LargeObject and commit
@ 2013-10-15 10:54 Dave Cramer <pg@fastcrypt.com>
parent: Dave Cramer <pg@fastcrypt.com>
0 siblings, 1 reply; 9+ messages in thread
From: Dave Cramer @ 2013-10-15 10:54 UTC (permalink / raw)
To: Marc Cousin <cousinmarc@gmail.com>; +Cc: pgsql-jdbc
Marc,
I just pushed it to github, thanks!
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
On Tue, Oct 15, 2013 at 6:48 AM, Dave Cramer <pg@fastcrypt.com> wrote:
> Marc,
>
> Sorry I have been travelling. Just looked at it, It's fine albeit more
> than just changing the visibility of the function.
>
> Dave Cramer
>
> dave.cramer(at)credativ(dot)ca
> http://www.credativ.ca
>
>
> On Mon, Oct 14, 2013 at 10:38 AM, Marc Cousin <cousinmarc@gmail.com>wrote:
>
>> Hi,
>>
>> Did you give it a look ?
>>
>> Regards
>>
>> Marc
>>
>> On Sunday 06 October 2013 19:14:41 Marc Cousin wrote:
>> > Hi,
>> >
>> > Attached is an attempt to do this (git diff on head).
>> >
>> > The code seems to work. It has been tested on the program we are
>> migrating
>> > from SQL Server, we can now stream LOBs directly to web browsers...
>> >
>> > Please note that I am not usually a Java developper. I did my best to do
>> > this correctly, and the Java way (as far as I know :) ). If some things
>> are
>> > not done the right way, or there is a smarter solution, tell me, I'll
>> > improve this.
>> >
>> > Regards,
>> >
>> > Marc
>> >
>> > On Tuesday 01 October 2013 08:11:21 Dave Cramer wrote:
>> > > Well I don't see any reason not to open up the LOM class to allow you
>> to
>> > > extend it.
>> > >
>> > > Can you send a git pull?
>> > >
>> > > Dave Cramer
>> > >
>> > > dave.cramer(at)credativ(dot)ca
>> > > http://www.credativ.ca
>> > >
>> > > On Tue, Oct 1, 2013 at 3:52 AM, Marc Cousin <cousinmarc@gmail.com>
>> wrote:
>> > > > 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 <
>> cousinmarc@gmail.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@postgresql.org)
>> > > > > > To make changes to your subscription:
>> > > > > > http://www.postgresql.org/mailpref/pgsql-jdbc
>>
>>
>
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: problem with LargeObject and commit
@ 2013-10-16 13:40 Marc Cousin <cousinmarc@gmail.com>
parent: Dave Cramer <pg@fastcrypt.com>
0 siblings, 0 replies; 9+ messages in thread
From: Marc Cousin @ 2013-10-16 13:40 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc
Great, thanks :)
On Tuesday 15 October 2013 06:54:48 Dave Cramer wrote:
> Marc,
>
> I just pushed it to github, thanks!
>
> Dave Cramer
>
> dave.cramer(at)credativ(dot)ca
> http://www.credativ.ca
>
> On Tue, Oct 15, 2013 at 6:48 AM, Dave Cramer <pg@fastcrypt.com> wrote:
> > Marc,
> >
> > Sorry I have been travelling. Just looked at it, It's fine albeit more
> > than just changing the visibility of the function.
> >
> > Dave Cramer
> >
> > dave.cramer(at)credativ(dot)ca
> > http://www.credativ.ca
> >
> > On Mon, Oct 14, 2013 at 10:38 AM, Marc Cousin <cousinmarc@gmail.com>wrote:
> >> Hi,
> >>
> >> Did you give it a look ?
> >>
> >> Regards
> >>
> >> Marc
> >>
> >> On Sunday 06 October 2013 19:14:41 Marc Cousin wrote:
> >> > Hi,
> >> >
> >> > Attached is an attempt to do this (git diff on head).
> >> >
> >> > The code seems to work. It has been tested on the program we are
> >>
> >> migrating
> >>
> >> > from SQL Server, we can now stream LOBs directly to web browsers...
> >> >
> >> > Please note that I am not usually a Java developper. I did my best to
> >> > do
> >> > this correctly, and the Java way (as far as I know :) ). If some things
> >>
> >> are
> >>
> >> > not done the right way, or there is a smarter solution, tell me, I'll
> >> > improve this.
> >> >
> >> > Regards,
> >> >
> >> > Marc
> >> >
> >> > On Tuesday 01 October 2013 08:11:21 Dave Cramer wrote:
> >> > > Well I don't see any reason not to open up the LOM class to allow you
> >>
> >> to
> >>
> >> > > extend it.
> >> > >
> >> > > Can you send a git pull?
> >> > >
> >> > > Dave Cramer
> >> > >
> >> > > dave.cramer(at)credativ(dot)ca
> >> > > http://www.credativ.ca
> >> > >
> >> > > On Tue, Oct 1, 2013 at 3:52 AM, Marc Cousin <cousinmarc@gmail.com>
> >>
> >> wrote:
> >> > > > 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 <
> >>
> >> cousinmarc@gmail.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@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
^ permalink raw reply [nested|flat] 9+ messages in thread
end of thread, other threads:[~2013-10-16 13:40 UTC | newest]
Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-09-30 15:18 problem with LargeObject and commit Marc Cousin <cousinmarc@gmail.com>
2013-09-30 21:08 ` Dave Cramer <pg@fastcrypt.com>
2013-10-01 07:52 ` Marc Cousin <cousinmarc@gmail.com>
2013-10-01 12:11 ` Dave Cramer <pg@fastcrypt.com>
2013-10-06 17:14 ` Marc Cousin <cousinmarc@gmail.com>
2013-10-14 14:38 ` Marc Cousin <cousinmarc@gmail.com>
2013-10-15 10:48 ` Dave Cramer <pg@fastcrypt.com>
2013-10-15 10:54 ` Dave Cramer <pg@fastcrypt.com>
2013-10-16 13:40 ` Marc Cousin <cousinmarc@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox