Index: java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java =================================================================== --- java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java (revision 615469) +++ java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java (working copy) @@ -70,12 +70,15 @@ */ -final class EmbedBlob extends ConnectionChild implements Blob +final class EmbedBlob extends ConnectionChild implements Blob, EngineBlob { // blob is either materialized or still in stream private boolean materialized; private InputStream myStream; + // locator key for lob. used by Network Server. + private int locator; + /* * Length of the BLOB if known. Set to -1 if * the current length of the BLOB is not known. @@ -116,7 +119,7 @@ materialized = true; //add entry in connection so it can be cleared //when transaction is not valid - con.addLOBMapping (this); + locator = con.addLOBMapping (this); } catch (IOException e) { throw Util.setStreamFailure (e); @@ -192,7 +195,7 @@ pos = 0; //add entry in connection so it can be cleared //when transaction is not valid - con.addLOBMapping (this); + this.locator = con.addLOBMapping (this); } @@ -992,4 +995,13 @@ boolean isMaterialized () { return materialized; } + + /** + * Return loctor for this lob. + * + * @return + */ + public int getLocator() { + return locator; + } } Index: java/engine/org/apache/derby/impl/jdbc/EmbedClob.java =================================================================== --- java/engine/org/apache/derby/impl/jdbc/EmbedClob.java (revision 615469) +++ java/engine/org/apache/derby/impl/jdbc/EmbedClob.java (working copy) @@ -66,7 +66,7 @@ new update methods can safely be added into implementation. */ -final class EmbedClob extends ConnectionChild implements Clob +final class EmbedClob extends ConnectionChild implements Clob, EngineClob { /** @@ -78,6 +78,8 @@ /** Tells whether the Clob has been freed or not. */ private boolean isValid = true; + private int locator; + /** * Creates an empty Clob object. * @@ -88,7 +90,7 @@ EmbedClob(EmbedConnection con) throws SQLException { super(con); this.clob = new TemporaryClob (con.getDBName(), this); - con.addLOBMapping (this); + this.locator = con.addLOBMapping (this); } /** @@ -153,7 +155,7 @@ throw se; } } - con.addLOBMapping (this); + this.locator = con.addLOBMapping (this); } /** @@ -783,4 +785,11 @@ InternalClob getInternalClob() { return this.clob; } + + /** + * @return locator value for this Clob. + */ + public int getLocator() { + return locator; + } } Index: java/engine/org/apache/derby/impl/jdbc/EngineBlob.java =================================================================== --- java/engine/org/apache/derby/impl/jdbc/EngineBlob.java (revision 0) +++ java/engine/org/apache/derby/impl/jdbc/EngineBlob.java (revision 0) @@ -0,0 +1,19 @@ +package org.apache.derby.impl.jdbc; + +/** + * Additional methods the embedded engine exposes on its Blob object + * implementations. An internal api only, mainly for the network + * server. + * + */ + +public interface EngineBlob { + + /** + * Return lob locator key that can be used with + * EmbedConnection.getLobLobMapping(int) to retrieve this Blob. + * + * @return lob locator for this Blob + */ + public int getLocator(); +} Property changes on: java\engine\org\apache\derby\impl\jdbc\EngineBlob.java ___________________________________________________________________ Name: svn:eol-style + native Index: java/engine/org/apache/derby/impl/jdbc/EngineClob.java =================================================================== --- java/engine/org/apache/derby/impl/jdbc/EngineClob.java (revision 0) +++ java/engine/org/apache/derby/impl/jdbc/EngineClob.java (revision 0) @@ -0,0 +1,18 @@ +package org.apache.derby.impl.jdbc; + +/** + * Additional methods the embedded engine exposes on its Blob object + * implementations. An internal api only, mainly for the network + * server. + * + */ + +public interface EngineClob { + /** + * Return lob locator key that can be used with + * EmbedConnection.getLobLobMapping(int) to retrieve this Clob. + * + * @return lob locator for this Clob + */ + public int getLocator(); +} Property changes on: java\engine\org\apache\derby\impl\jdbc\EngineClob.java ___________________________________________________________________ Name: svn:eol-style + native Index: java/drda/org/apache/derby/impl/drda/DRDAConnThread.java =================================================================== --- java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (revision 615469) +++ java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (working copy) @@ -64,6 +64,8 @@ import org.apache.derby.iapi.jdbc.AuthenticationService; import org.apache.derby.iapi.jdbc.EngineResultSet; import org.apache.derby.impl.jdbc.EmbedSQLException; +import org.apache.derby.impl.jdbc.EngineBlob; +import org.apache.derby.impl.jdbc.EngineClob; import org.apache.derby.impl.jdbc.Util; import org.apache.derby.jdbc.InternalDriver; import org.apache.derby.iapi.jdbc.EnginePreparedStatement; @@ -7381,6 +7383,7 @@ * @param stmt Statement being processed * * @exception DRDAProtocolException + * * @exception SQLException * * @see FdocaConstants @@ -7487,12 +7490,12 @@ case DRDAConstants.DRDA_TYPE_NLONGVARBYTE: writer.writeLDBytes((byte[]) val, index); break; - case DRDAConstants.DRDA_TYPE_NLOBLOC: - case DRDAConstants.DRDA_TYPE_NCLOBLOC: - // Get locator for LOB - int locator = database.getConnection().addLOBMapping(val); - writer.writeInt(locator); - break; + case DRDAConstants.DRDA_TYPE_NLOBLOC: + writer.writeInt(((EngineBlob) val).getLocator()); + break; + case DRDAConstants.DRDA_TYPE_NCLOBLOC: + writer.writeInt(((EngineClob) val).getLocator()); + break; default: if (SanityManager.DEBUG) trace("ndrdaType is: "+ndrdaType); Index: java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java =================================================================== --- java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java (revision 615469) +++ java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java (working copy) @@ -1522,6 +1522,32 @@ } /** + * Make sure we get an error attempting to access the + * lob after commit. + */ + public void testClobAfterCommitWithSecondClob() throws SQLException + { + getConnection().setAutoCommit(false); + Statement s1 = createStatement(); + ResultSet rs1 = s1.executeQuery("values cast('first' as clob)"); + rs1.next(); + Clob first = rs1.getClob(1); + rs1.close(); + commit(); + Statement s2 = createStatement(); + ResultSet rs2 = s2.executeQuery("values cast('second' as clob)"); + rs2.next(); + Clob second = rs2.getClob(1); + try { + first.getSubString(1,100); + fail("first.getSubString should have failed because after the commit"); + } catch (SQLException se){ + assertSQLState(INVALID_LOB,se); + } + assertEquals("second",second.getSubString(1, 100)); + rs2.close(); + } + /** * Test fix for derby-1382. * * Test that the getClob() returns the correct value for the clob before and