db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From be...@apache.org
Subject svn commit: r544777 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/jdbc/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
Date Wed, 06 Jun 2007 09:13:13 GMT
Author: bernt
Date: Wed Jun  6 02:13:12 2007
New Revision: 544777

URL: http://svn.apache.org/viewvc?view=rev&rev=544777
Log:
DERBY-2729 temporary lob file should be cleaned when the transaction or connection is no longer
valid. Submitted by  Anurag Shekhar

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobStoredProcedureTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java?view=diff&rev=544777&r1=544776&r2=544777
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java Wed Jun  6 02:13:12
2007
@@ -115,6 +115,9 @@
              control = new LOBStreamControl (con.getDBName());
              control.write (blobBytes, 0, blobBytes.length, 0);
              materialized = true;
+             //add entry in connection so it can be cleared 
+             //when transaction is not valid
+             con.addLOBMapping (this);
          }
          catch (IOException e) {
              throw Util.setStreamFailure (e);
@@ -187,6 +190,9 @@
             buf = new byte[BLOB_BUF_SIZE];
         }
         pos = 0;
+        //add entry in connection so it can be cleared 
+        //when transaction is not valid
+        con.addLOBMapping (this);
     }
 
 
@@ -944,6 +950,9 @@
      * throws SQLException if isvalid is not true.
      */
     private void checkValidity() throws SQLException{
+        //check for connection to maintain sqlcode for closed
+        //connection
+        getEmbedConnection().checkIfClosed();
         if(!isValid)
             throw newSQLException(SQLState.LOB_OBJECT_INVALID);
     }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java?view=diff&rev=544777&r1=544776&r2=544777
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java Wed Jun
 6 02:13:12 2007
@@ -21,6 +21,7 @@
 
 package org.apache.derby.impl.jdbc;
 
+import org.apache.derby.iapi.error.ExceptionSeverity;
 import org.apache.derby.jdbc.InternalDriver;
 
 import org.apache.derby.iapi.reference.Attribute;
@@ -1549,6 +1550,18 @@
 	SQLException handleException(Throwable thrownException)
 			throws SQLException
 	{
+		//assume in case of SQLException cleanup is 
+		//done already. This assumption is inline with
+		//TR's assumption. In case no rollback was 
+		//called lob objects will remain valid.
+		if (thrownException instanceof StandardException) {
+			if (((StandardException) thrownException)
+				.getSeverity() 
+				>= ExceptionSeverity.TRANSACTION_SEVERITY) {
+				clearLOBMapping();
+			}
+		}
+
 		/*
 		** By default, rollback the connection on if autocommit
 	 	** is on.
@@ -1585,6 +1598,17 @@
 									   boolean rollbackOnAutoCommit) 
 			throws SQLException 
 	{
+		//assume in case of SQLException cleanup is 
+		//done already. This assumption is inline with
+		//TR's assumption. In case no rollback was 
+		//called lob objects will remain valid.
+		if (thrownException instanceof StandardException) {
+			if (((StandardException) thrownException)
+				.getSeverity() 
+				>= ExceptionSeverity.TRANSACTION_SEVERITY) {
+				clearLOBMapping();
+			}
+		}
 		return getTR().handleException(thrownException, autoCommit,
 								  rollbackOnAutoCommit); 
 
@@ -1667,6 +1691,7 @@
             try
             {
                 getTR().commit();
+                clearLOBMapping();
             } 
             catch (Throwable t)
             {
@@ -1698,6 +1723,7 @@
             try
             {
                 getTR().commit();
+                clearLOBMapping();
             } 
             catch (Throwable t)
             {
@@ -2295,7 +2321,7 @@
 		//initialize the locator value to 0 and
 		//the hash table object to null.
 		if (lobHashMap != null) {
-			for (Iterator e = getlobHMObj().keySet().iterator();
+			for (Iterator e = getlobHMObj().values().iterator();
 				e.hasNext() ;) {
 				Object obj = e.next();
 				if (obj instanceof Clob)  {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java?view=diff&rev=544777&r1=544776&r2=544777
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java
Wed Jun  6 02:13:12 2007
@@ -2322,17 +2322,10 @@
         getConnection().close();
 
         try {
-            long length = shortBlob.length();
-            // no problem accessing this after commit since it is in memory
-            if (usingEmbedded()) {
-                assertEquals("FAIL - wrong blob length", 26, length);
-            } else {
-                fail("FAIL - should get an exception, connection is closed");
-            }
+            long length = shortBlob.length();                        
+            fail("FAIL - should get an exception, connection is closed");
         } catch (SQLException e) {
-            checkException(NO_CURRENT_CONNECTION, e);
-            assertTrue("FAIL - Embedded should not get this exception",
-                    !usingEmbedded());
+            checkException(NO_CURRENT_CONNECTION, e);            
         }
 
         // these should all give blob/clob data unavailable exceptions
@@ -2341,55 +2334,35 @@
             fail("FAIL - should not be able to access large lob " +
                     "after the connection is closed");
         } catch (SQLException e) {
-            if (usingEmbedded()) {
-                checkException(BLOB_ACCESSED_AFTER_COMMIT, e);
-            } else {
-                checkException(NO_CURRENT_CONNECTION, e);
-            }
+            checkException(NO_CURRENT_CONNECTION, e);
         }
         try {
             blob.getBytes(2,3);
             fail("FAIL - should not be able to access large lob " +
                     "after the connection is closed");
         } catch (SQLException e) {
-            if (usingEmbedded()) {
-                checkException(BLOB_ACCESSED_AFTER_COMMIT, e);
-            } else {
-                checkException(NO_CURRENT_CONNECTION, e);
-            }
+            checkException(NO_CURRENT_CONNECTION, e);
         }
         try {
             blob.getBinaryStream();
             fail("FAIL - should not be able to access large lob " +
                     "after the connection is closed");
         } catch (SQLException e) {
-            if (usingEmbedded()) {
-                checkException(BLOB_ACCESSED_AFTER_COMMIT, e);
-            } else {
-                checkException(NO_CURRENT_CONNECTION, e);
-            }
+            checkException(NO_CURRENT_CONNECTION, e);
         }
         try {
             blob.position("foo".getBytes("US-ASCII"),2);
             fail("FAIL - should not be able to access large lob " +
                     "after the connection is closed");
         } catch (SQLException e) {
-            if (usingEmbedded()) {
-                checkException(BLOB_ACCESSED_AFTER_COMMIT, e);
-            } else {
-                checkException(NO_CURRENT_CONNECTION, e);
-            }
+            checkException(NO_CURRENT_CONNECTION, e);
         }
         try {
             blob.position(blob,2);
             fail("FAIL - should not be able to access large lob " +
                     "after the connection is closed");
         } catch (SQLException e) {
-            if (usingEmbedded()) {
-                checkException(BLOB_ACCESSED_AFTER_COMMIT, e);
-            } else {
-                checkException(NO_CURRENT_CONNECTION, e);
-            }
+            checkException(NO_CURRENT_CONNECTION, e);
         }
 
         // restart the connection
@@ -3217,8 +3190,6 @@
     }
 
 
-
-
     private static final String BLOB_BAD_POSITION = "XJ070";
     private static final String BLOB_NONPOSITIVE_LENGTH = "XJ071";
     private static final String BLOB_POSITION_TOO_LARGE = "XJ076";
@@ -3227,5 +3198,6 @@
     private static final String LOCK_TIMEOUT = "40XL1";
     private static final String BLOB_ACCESSED_AFTER_COMMIT = "XJ073";
     private static final String NO_CURRENT_CONNECTION = "08003";
+    private static final String INVALID_BLOB = "XJ215";
 
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobStoredProcedureTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobStoredProcedureTest.java?view=diff&rev=544777&r1=544776&r2=544777
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobStoredProcedureTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobStoredProcedureTest.java
Wed Jun  6 02:13:12 2007
@@ -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", 2, locator);
+            "SYSIBM.BLOBCREATELOCATOR() are incorrect", 4, locator);
         cs.close();
     }
 



Mime
View raw message