summaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/org/postgresql/largeobject/LargeObject.java
diff options
context:
space:
mode:
authorPeter Mount <peter@retep.org.uk>2001-02-14 17:45:17 +0000
committerPeter Mount <peter@retep.org.uk>2001-02-14 17:45:17 +0000
commitbb7b71826d7a32752ace2f4574752a401fb7fa0f (patch)
treee273ace65b4d32e51e57d481c1be5099d7f3d4df /src/interfaces/jdbc/org/postgresql/largeobject/LargeObject.java
parentc1abe85529da1cd995896fb88492d353eafbfc8d (diff)
downloadpostgresql-bb7b71826d7a32752ace2f4574752a401fb7fa0f.tar.gz
Web Feb 14 17:29:00 GMT 2001 peter@retep.org.uk
- Fixed bug in LargeObject & BlobOutputStream where the stream's output was not flushed when either the stream or the blob were closed. - Fixed PreparedStatement.setBinaryStream() where it ignored the length
Diffstat (limited to 'src/interfaces/jdbc/org/postgresql/largeobject/LargeObject.java')
-rw-r--r--src/interfaces/jdbc/org/postgresql/largeobject/LargeObject.java30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/largeobject/LargeObject.java b/src/interfaces/jdbc/org/postgresql/largeobject/LargeObject.java
index c73301d131..20afda5782 100644
--- a/src/interfaces/jdbc/org/postgresql/largeobject/LargeObject.java
+++ b/src/interfaces/jdbc/org/postgresql/largeobject/LargeObject.java
@@ -62,6 +62,10 @@ public class LargeObject
private int oid; // OID of this object
private int fd; // the descriptor of the open large object
+ private BlobOutputStream os; // The current output stream
+
+ private boolean closed=false; // true when we are closed
+
/**
* This opens a large object.
*
@@ -100,9 +104,25 @@ public class LargeObject
*/
public void close() throws SQLException
{
- FastpathArg args[] = new FastpathArg[1];
- args[0] = new FastpathArg(fd);
- fp.fastpath("lo_close",false,args); // true here as we dont care!!
+ if(!closed) {
+ // flush any open output streams
+ if(os!=null) {
+ try {
+ // we can't call os.close() otherwise we go into an infinite loop!
+ os.flush();
+ } catch(IOException ioe) {
+ throw new SQLException(ioe.getMessage());
+ } finally {
+ os=null;
+ }
+ }
+
+ // finally close
+ FastpathArg args[] = new FastpathArg[1];
+ args[0] = new FastpathArg(fd);
+ fp.fastpath("lo_close",false,args); // true here as we dont care!!
+ closed=true;
+ }
}
/**
@@ -279,7 +299,9 @@ public class LargeObject
*/
public OutputStream getOutputStream() throws SQLException
{
- return new BlobOutputStream(this);
+ if(os==null)
+ os = new BlobOutputStream(this);
+ return os;
}
}