Only in postgresql-jdbc-9.3-1101.src: .classpath
Only in postgresql-jdbc-9.3-1101.src: .project
Only in postgresql-jdbc-9.3-1101.src: bin
Only in postgresql-jdbc-9.3-1101.src: build
Only in postgresql-jdbc-9.3-1101.src: jars
Only in postgresql-jdbc-9.3-1101.src/org/postgresql: Driver.java
Only in postgresql-jdbc-9.3-1101.src/org/postgresql/ds: PGConnectionPoolDataSource.java
Only in postgresql-jdbc-9.3-1101.src/org/postgresql/ds: PGPooledConnection.java
Only in postgresql-jdbc-9.3-1101.src/org/postgresql/ds: PGPoolingDataSource.java
Only in postgresql-jdbc-9.3-1101.src/org/postgresql/ds: PGSimpleDataSource.java
diff -ru postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc2/AbstractJdbc2BlobClob.java postgresql-jdbc-9.3-1101.src/org/postgresql/jdbc2/AbstractJdbc2BlobClob.java
--- postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc2/AbstractJdbc2BlobClob.java	2014-02-18 14:46:31.000000000 +0100
+++ postgresql-jdbc-9.3-1101.src/org/postgresql/jdbc2/AbstractJdbc2BlobClob.java	2014-04-18 17:52:42.949759700 +0200
@@ -30,27 +30,37 @@
 public abstract class AbstractJdbc2BlobClob
 {
     protected BaseConnection conn;
-    protected LargeObject lo;
-
+    
+    private LargeObject currentLo;
+    private long loPos;
+    private boolean currentLoIsWriteable;
+    
+    
     /**
      * We create separate LargeObjects for methods that use streams
      * so they won't interfere with each other.
      */
     private ArrayList subLOs;
+    
+    private final long oid;
 
     public AbstractJdbc2BlobClob(BaseConnection conn, long oid) throws SQLException
     {
         this.conn = conn;
-        LargeObjectManager lom = conn.getLargeObjectAPI();
-        this.lo = lom.open(oid);
+        this.oid = oid;
+        this.currentLo = null;
+        this.currentLoIsWriteable = false;
+        
+       
         subLOs = new ArrayList();
     }
 
     public synchronized void free() throws SQLException
     {
-        if (lo != null) {
-            lo.close();
-            lo = null;
+        if (currentLo != null) {
+        	currentLo.close();
+        	currentLo = null;
+        	currentLoIsWriteable = false;
         }
         Iterator i = subLOs.iterator();
         while (i.hasNext()) {
@@ -81,27 +91,27 @@
             throw new PSQLException(GT.tr("PostgreSQL LOBs can only index to: {0}", new Integer(Integer.MAX_VALUE)), PSQLState.INVALID_PARAMETER_VALUE);
         }
 
-        lo.truncate((int)len);
+        getLo(true).truncate((int)len);
     }
 
     public synchronized long length() throws SQLException
     {
         checkFreed();
-        return lo.size();
+        return getLo(false).size();
     }
 
     public synchronized byte[] getBytes(long pos, int length) throws SQLException
     {
         assertPosition(pos);
-        lo.seek((int)(pos-1), LargeObject.SEEK_SET);
-        return lo.read(length);
+        getLo(false).seek((int)(pos-1), LargeObject.SEEK_SET);
+        return getLo(false).read(length);
     }
 
 
     public synchronized InputStream getBinaryStream() throws SQLException
     {
         checkFreed();
-        LargeObject subLO = lo.copy();
+        LargeObject subLO = getLo(false).copy();
         subLOs.add(subLO);
         subLO.seek(0, LargeObject.SEEK_SET);
         return subLO.getInputStream();
@@ -110,7 +120,7 @@
     public synchronized OutputStream setBinaryStream(long pos) throws SQLException
     {
         assertPosition(pos);
-        LargeObject subLO = lo.copy();
+        LargeObject subLO = getLo(true).copy();
         subLOs.add(subLO);
         subLO.seek((int)(pos-1));
         return subLO.getOutputStream();
@@ -171,7 +181,7 @@
 
         public LOIterator(long start) throws SQLException
         {
-            lo.seek((int) start);
+            getLo(false).seek((int) start);
         }
 
         public boolean hasNext() throws SQLException
@@ -183,7 +193,7 @@
             }
             else
             {
-                numBytes = lo.read(buffer, 0, BUFFER_SIZE);
+                numBytes = getLo(false).read(buffer, 0, BUFFER_SIZE);
                 idx = 0;
                 result = (numBytes > 0);
             }
@@ -242,8 +252,33 @@
      */
     protected void checkFreed() throws SQLException
     {
-        if (lo == null)
+        if (subLOs == null)
             throw new PSQLException(GT.tr("free() was called on this LOB previously"), PSQLState.OBJECT_NOT_IN_STATE);
     }
 
+	protected synchronized LargeObject getLo(boolean forWrite) throws SQLException {
+		
+		
+		if (this.currentLo != null) {
+			if (forWrite && ! currentLoIsWriteable) {
+				// Reopen the stream in read-write, at the same pos.
+				int currentPos = this.currentLo.tell();
+				
+				LargeObjectManager lom = conn.getLargeObjectAPI();
+			    LargeObject newLo = lom.open(oid, LargeObjectManager.READWRITE);
+			    this.subLOs.add(this.currentLo);
+			    this.currentLo = newLo;
+			    
+			    if (currentPos != 0) {
+			    	this.currentLo.seek(currentPos);
+			    }
+			}
+			
+			return this.currentLo;
+		}
+		LargeObjectManager lom = conn.getLargeObjectAPI();
+	    currentLo = lom.open(oid, forWrite ? LargeObjectManager.READWRITE : LargeObjectManager.READ);
+	    currentLoIsWriteable = forWrite;
+	    return currentLo;
+	}
 }
diff -ru postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc2/AbstractJdbc2Clob.java postgresql-jdbc-9.3-1101.src/org/postgresql/jdbc2/AbstractJdbc2Clob.java
--- postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc2/AbstractJdbc2Clob.java	2014-02-18 14:46:31.000000000 +0100
+++ postgresql-jdbc-9.3-1101.src/org/postgresql/jdbc2/AbstractJdbc2Clob.java	2014-04-18 17:44:26.921388500 +0200
@@ -36,8 +36,8 @@
     public synchronized String getSubString(long i, int j) throws SQLException
     {
         assertPosition(i, j);
-        lo.seek((int)i - 1);
-        return new String(lo.read(j));
+        getLo(false).seek((int)i - 1);
+        return new String(getLo(false).read(j));
     }
 
     /*
diff -ru postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3/AbstractJdbc3Blob.java postgresql-jdbc-9.3-1101.src/org/postgresql/jdbc3/AbstractJdbc3Blob.java
--- postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3/AbstractJdbc3Blob.java	2014-02-18 14:46:31.000000000 +0100
+++ postgresql-jdbc-9.3-1101.src/org/postgresql/jdbc3/AbstractJdbc3Blob.java	2014-04-18 17:45:04.953563900 +0200
@@ -63,8 +63,8 @@
     public synchronized int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException
     {
         assertPosition(pos);
-        lo.seek((int) (pos-1));
-        lo.write(bytes, offset, len);
+        getLo(true).seek((int) (pos-1));
+        getLo(true).write(bytes, offset, len);
         return len;
     }
 
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3: Jdbc3Array.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3: Jdbc3Blob.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3: Jdbc3CallableStatement.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3: Jdbc3Clob.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3: Jdbc3Connection.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3: Jdbc3DatabaseMetaData.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3: Jdbc3ParameterMetaData.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3: Jdbc3PreparedStatement.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3: Jdbc3ResultSet.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3: Jdbc3ResultSetMetaData.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3: Jdbc3Statement.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3g: Jdbc3gArray.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3g: Jdbc3gBlob.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3g: Jdbc3gCallableStatement.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3g: Jdbc3gClob.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3g: Jdbc3gConnection.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3g: Jdbc3gDatabaseMetaData.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3g: Jdbc3gParameterMetaData.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3g: Jdbc3gPreparedStatement.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3g: Jdbc3gResultSet.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3g: Jdbc3gResultSetMetaData.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql/jdbc3g: Jdbc3gStatement.java
Only in postgresql-jdbc-9.3-1101.src/org/postgresql/ssl: MakeSSL.java
Only in postgresql-jdbc-9.3-1101.src.org/org/postgresql: test
Only in postgresql-jdbc-9.3-1101.src/org/postgresql/xa: PGXADataSource.java
