[libpostgresql-jdbc-java] 36/93: add functions to allow LargeObjectMaager to commit on close from Marc Cousin
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:18:49 UTC 2017
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to annotated tag REL9_3_1102
in repository libpostgresql-jdbc-java.
commit b0eed5b4bcb090cc4d689beb0a494b61fda747e4
Author: Dave Cramer <davecramer at gmail.com>
Date: Tue Oct 15 06:54:23 2013 -0400
add functions to allow LargeObjectMaager to commit on close from Marc Cousin
---
org/postgresql/largeobject/LargeObject.java | 38 +++++++++++-
org/postgresql/largeobject/LargeObjectManager.java | 67 ++++++++++++++++++++--
2 files changed, 100 insertions(+), 5 deletions(-)
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);
}
/**
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git
More information about the pkg-java-commits
mailing list