You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by km...@apache.org on 2008/02/01 18:23:33 UTC
svn commit: r617566 - in /db/derby/code/branches/10.3/java:
drda/org/apache/derby/impl/drda/ engine/org/apache/derby/iapi/jdbc/
engine/org/apache/derby/impl/jdbc/
testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
Author: kmarsden
Date: Fri Feb 1 09:23:20 2008
New Revision: 617566
URL: http://svn.apache.org/viewvc?rev=617566&view=rev
Log:
[C:/svn/10.3] cat svn-commit.9.tmp
DERBY-3365 Network Server stores a duplicate entry in the lob hash map for every lob
port revision 617186 from trunk and fix EmbedBlob replacement
Added:
db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineBlob.java (with props)
db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineClob.java (with props)
Modified:
db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java
db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java
db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java
db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java
db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java
db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java
db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobStoredProcedureTest.java
db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobStoredProcedureTest.java
Modified: db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java?rev=617566&r1=617565&r2=617566&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (original)
+++ db/derby/code/branches/10.3/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Fri Feb 1 09:23:20 2008
@@ -61,6 +61,9 @@
import org.apache.derby.iapi.services.stream.HeaderPrintWriter;
import org.apache.derby.iapi.tools.i18n.LocalizedResource;
import org.apache.derby.iapi.jdbc.AuthenticationService;
+import org.apache.derby.iapi.jdbc.EngineBlob;
+import org.apache.derby.iapi.jdbc.EngineClob;
+import org.apache.derby.iapi.jdbc.EngineResultSet;
import org.apache.derby.impl.jdbc.EmbedSQLException;
import org.apache.derby.impl.jdbc.Util;
import org.apache.derby.jdbc.InternalDriver;
@@ -7276,6 +7279,7 @@
* @param stmt Statement being processed
*
* @exception DRDAProtocolException
+ *
* @exception SQLException
*
* @see FdocaConstants
@@ -7382,12 +7386,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);
Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java?rev=617566&r1=617565&r2=617566&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java Fri Feb 1 09:23:20 2008
@@ -615,21 +615,7 @@
return holdability;
}
- /**
- * Add the locator and the corresponding LOB object into the
- * HashMap
- *
- * @param LOBReference The object which contains the LOB object that
- * that is added to the HashMap.
- * @return an integer that represents the locator that has been
- * allocated to this LOB.
- */
- public int addLOBMapping(Object LOBReference) throws SQLException {
- //Forward the methods implementation to the implementation in the
- //underlying EmbedConnection object.
- return getRealConnection().addLOBMapping(LOBReference);
- }
-
+
/**
* Clear the HashMap of all entries.
* Called when a commit or rollback of the transaction
Added: db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineBlob.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineBlob.java?rev=617566&view=auto
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineBlob.java (added)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineBlob.java Fri Feb 1 09:23:20 2008
@@ -0,0 +1,19 @@
+package org.apache.derby.iapi.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.getLobMapping(int) to retrieve this Blob.
+ *
+ * @return lob locator for this Blob
+ */
+ public int getLocator();
+}
Propchange: db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineBlob.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineClob.java?rev=617566&view=auto
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineClob.java (added)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineClob.java Fri Feb 1 09:23:20 2008
@@ -0,0 +1,18 @@
+package org.apache.derby.iapi.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.getLobMapping(int) to retrieve this Clob.
+ *
+ * @return lob locator for this Clob
+ */
+ public int getLocator();
+}
Propchange: db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineClob.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java?rev=617566&r1=617565&r2=617566&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java Fri Feb 1 09:23:20 2008
@@ -91,16 +91,6 @@
throws SQLException;
/**
- * Add the locator and the corresponding LOB object into the
- * HashMap
- * @param LOBReference The object which contains the LOB object that
- * that is added to the HashMap.
- * @return an integer that represents the locator that has been
- * allocated to this LOB.
- */
- public int addLOBMapping(Object LOBReference) throws SQLException;
-
- /**
* Clear the HashTable of all entries.
* Called when a commit or rollback of the transaction
* happens.
Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java?rev=617566&r1=617565&r2=617566&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java Fri Feb 1 09:23:20 2008
@@ -24,13 +24,11 @@
import org.apache.derby.iapi.reference.SQLState;
import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.jdbc.EngineBlob;
import org.apache.derby.iapi.services.monitor.Monitor;
import org.apache.derby.iapi.services.sanity.SanityManager;
import org.apache.derby.iapi.types.DataValueDescriptor;
import org.apache.derby.iapi.types.Resetable;
-import org.apache.derby.impl.jdbc.ConnectionChild;
-import org.apache.derby.impl.jdbc.EmbedConnection;
-import org.apache.derby.impl.jdbc.Util;
import org.apache.derby.iapi.services.io.NewByteArrayInputStream;
import org.apache.derby.iapi.services.io.InputStreamUtil;
import org.apache.derby.iapi.services.io.ArrayInputStream;
@@ -70,12 +68,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 final int locator;
+
/*
* Length of the BLOB if known. Set to -1 if
* the current length of the BLOB is not known.
@@ -116,7 +117,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 +193,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);
}
@@ -991,5 +992,14 @@
*/
boolean isMaterialized () {
return materialized;
+ }
+
+ /**
+ * Return locator for this lob.
+ *
+ * @return
+ */
+ public int getLocator() {
+ return locator;
}
}
Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java?rev=617566&r1=617565&r2=617566&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java Fri Feb 1 09:23:20 2008
@@ -24,6 +24,7 @@
import org.apache.derby.iapi.reference.SQLState;
import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.jdbc.EngineClob;
import org.apache.derby.iapi.services.sanity.SanityManager;
import org.apache.derby.iapi.types.DataValueDescriptor;
import org.apache.derby.iapi.types.Resetable;
@@ -66,7 +67,7 @@
new update methods can safely be added into implementation.
</UL>
*/
-final class EmbedClob extends ConnectionChild implements Clob
+final class EmbedClob extends ConnectionChild implements Clob, EngineClob
{
/**
@@ -78,6 +79,8 @@
/** Tells whether the Clob has been freed or not. */
private boolean isValid = true;
+ private final int locator;
+
/**
* Creates an empty Clob object.
*
@@ -88,7 +91,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 +156,7 @@
throw se;
}
}
- con.addLOBMapping (this);
+ this.locator = con.addLOBMapping (this);
}
/**
@@ -782,5 +785,12 @@
*/
InternalClob getInternalClob() {
return this.clob;
+ }
+
+ /**
+ * @return locator value for this Clob.
+ */
+ public int getLocator() {
+ return locator;
}
}
Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java?rev=617566&r1=617565&r2=617566&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java Fri Feb 1 09:23:20 2008
@@ -27,6 +27,8 @@
import java.sql.DriverManager;
import java.sql.SQLException;
+import org.apache.derby.iapi.jdbc.EngineBlob;
+import org.apache.derby.iapi.jdbc.EngineClob;
import org.apache.derby.iapi.reference.SQLState;
/**
@@ -42,8 +44,8 @@
* @throws a SQLException.
*/
public static int CLOBCREATELOCATOR() throws SQLException {
- Clob clob = getEmbedConnection().createClob();
- return getEmbedConnection().addLOBMapping(clob);
+ EngineClob clob = (EngineClob) getEmbedConnection().createClob();
+ return clob.getLocator();
}
/**
@@ -201,8 +203,8 @@
* @throws a SQLException.
*/
public static int BLOBCREATELOCATOR() throws SQLException {
- Blob blob = getEmbedConnection().createBlob();
- return getEmbedConnection().addLOBMapping(blob);
+ EngineBlob blob = (EngineBlob) getEmbedConnection().createBlob();
+ return blob.getLocator();
}
/**
Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java?rev=617566&r1=617565&r2=617566&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java (original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java Fri Feb 1 09:23:20 2008
@@ -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
Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobStoredProcedureTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobStoredProcedureTest.java?rev=617566&r1=617565&r2=617566&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobStoredProcedureTest.java (original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobStoredProcedureTest.java Fri Feb 1 09:23:20 2008
@@ -164,7 +164,7 @@
//remember in setup a locator is already created
//hence expected value is 2
assertEquals("The locator values returned by " +
- "SYSIBM.BLOBCREATELOCATOR() are incorrect", 4, locator);
+ "SYSIBM.BLOBCREATELOCATOR() are incorrect", 2, locator);
cs.close();
}
Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobStoredProcedureTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobStoredProcedureTest.java?rev=617566&r1=617565&r2=617566&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobStoredProcedureTest.java (original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobStoredProcedureTest.java Fri Feb 1 09:23:20 2008
@@ -76,7 +76,6 @@
cs.registerOutParameter(1, java.sql.Types.INTEGER);
cs.executeUpdate();
locator = cs.getInt(1);
-
cs.close();
cs = prepareCall("CALL SYSIBM.CLOBSETSTRING(?,?,?,?)");
cs.setInt(1, locator);
@@ -139,7 +138,7 @@
//remember in setup a locator is already created
//hence expected value is 2
assertEquals("The locator values returned by " +
- "SYSIBM.CLOBCREATELOCATOR() are incorrect", 4, locator);
+ "SYSIBM.CLOBCREATELOCATOR() are incorrect", 2, locator);
cs.close();
}