db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r702235 - in /db/derby/code/branches/10.4/java: engine/org/apache/derby/impl/jdbc/ testing/org/apache/derby/impl/jdbc/
Date Mon, 06 Oct 2008 19:26:21 GMT
Author: kmarsden
Date: Mon Oct  6 12:26:21 2008
New Revision: 702235

URL: http://svn.apache.org/viewvc?rev=702235&view=rev
Log:
DERBY-3655  errror in nightly regression test: LobStreamsTest:encryptedjunit.framework.AssertionFailedError
removing temporary lob file.


Modified:
    db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java
    db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java
    db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
    db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java
    db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/TemporaryClob.java
    db/derby/code/branches/10.4/java/testing/org/apache/derby/impl/jdbc/BiggerTemporaryClobTest.java
    db/derby/code/branches/10.4/java/testing/org/apache/derby/impl/jdbc/SmallTemporaryClobTest.java

Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java?rev=702235&r1=702234&r2=702235&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java (original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java Mon
Oct  6 12:26:21 2008
@@ -133,7 +133,7 @@
      EmbedBlob(byte [] blobBytes,EmbedConnection con) throws SQLException {
         super(con);
          try {
-             control = new LOBStreamControl (con.getDBName(), blobBytes);
+             control = new LOBStreamControl (con, blobBytes);
              materialized = true;
              streamPositionOffset = Integer.MIN_VALUE;
              //add entry in connection so it can be cleared 
@@ -173,7 +173,7 @@
                 SanityManager.ASSERT(dvdBytes != null,"blob has a null value underneath");
             try {
                 control = new LOBStreamControl (
-                            getEmbedConnection().getDBName(), dvdBytes);
+                            getEmbedConnection(), dvdBytes);
             } catch (IOException e) {
                 throw StandardException.newException (
                                         SQLState.SET_STREAM_FAILURE, e);
@@ -842,7 +842,7 @@
                 len = (int) control.write (bytes, offset, len, pos - 1);
             }
             else {
-                control = new LOBStreamControl (getEmbedConnection().getDBName());
+                control = new LOBStreamControl (getEmbedConnection());
                 control.copyData (myStream, length());
                 len = (int) control.write(bytes, offset, len, pos - 1);
                 myStream.close();
@@ -884,7 +884,7 @@
                 }
                 else {
                     control = new LOBStreamControl (
-                                            getEmbedConnection().getDBName());
+                                            getEmbedConnection());
                     control.copyData (myStream, pos - 1);
                     myStream.close ();
                     streamLength = -1;
@@ -922,7 +922,7 @@
                     control.truncate (len);
                 }
                 else {
-                    control = new LOBStreamControl (getEmbedConnection().getDBName());
+                    control = new LOBStreamControl (getEmbedConnection());
                     control.copyData (myStream, len);
                     myStream.close();
                     streamLength = -1;

Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java?rev=702235&r1=702234&r2=702235&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java (original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedClob.java Mon
Oct  6 12:26:21 2008
@@ -90,7 +90,7 @@
      */
     EmbedClob(EmbedConnection con) throws SQLException {
         super(con);
-        this.clob = new TemporaryClob (con.getDBName(), this);
+        this.clob = new TemporaryClob (this);
         con.addLOBReference (this);
     }
 
@@ -119,8 +119,8 @@
         // See if a String or a stream will be the source of the Clob.
         if (storeStream == null) {
             try {
-                clob = new TemporaryClob(con.getDBName(),
-                        dvd.getString(), this);
+                clob = new TemporaryClob(dvd.getString(),
+                        this);
             }
             catch (SQLException sqle) {
                 throw StandardException.newException (sqle.getSQLState(), sqle);

Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java?rev=702235&r1=702234&r2=702235&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
(original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
Mon Oct  6 12:26:21 2008
@@ -65,11 +65,13 @@
 import java.sql.SQLWarning;
 import java.sql.Statement;
 
+import java.util.HashSet;
 import java.util.Map;
 import java.util.WeakHashMap;
 import java.util.HashMap;
 import java.util.Properties;
 import java.util.Iterator;
+import java.io.IOException;
 
 import org.apache.derby.iapi.jdbc.EngineLOB;
 import org.apache.derby.impl.jdbc.authentication.NoneAuthenticationServiceImpl;
@@ -140,6 +142,14 @@
      */
     private WeakHashMap lobReferences = null;
 
+    // Set to keep track of the open LOBFiles, so they can be closed at the end of 
+    // the transaction. This would normally happen as lobReferences are freed as they
+    // get garbage collected after being removed from the WeakHashMap, but it is 
+    // possible that finalization will not have occurred before the user tries to 
+    // remove the database (DERBY-3655).  Therefore we keep this set so that we can
+    // explicitly close the files.
+    private HashSet lobFiles;
+    
 	//////////////////////////////////////////////////////////
 	// STATE (copied to new nested connections, but nesting
 	// specific)
@@ -2921,6 +2931,22 @@
         if (rootConnection.lobHashMap != null) {
             rootConnection.lobHashMap.clear ();
         }
+		
+		synchronized (this) {   
+			if (lobFiles != null) {       
+				Iterator it = lobFiles.iterator();
+				while (it.hasNext()) {
+					try {
+						((LOBFile) it.next()).close();
+					} catch (IOException ioe) {
+						throw Util.javaException(ioe);
+					}
+					finally {
+						lobFiles.clear();
+					}
+				}
+			}
+		}
 	}
 
 	/**
@@ -2989,4 +3015,30 @@
     public String getCurrentSchemaName() {
         return getLanguageConnection().getCurrentSchemaName();
     }
+    
+    
+	/**
+	 * Add a temporary lob file to the lobFiles set.
+	 * This will get closed at transaction end or removed as the lob is freed.
+	 * @param lobFile  LOBFile to add
+	 */
+	void addLobFile(LOBFile lobFile) {
+		synchronized (this) {
+			if (lobFiles == null)
+				lobFiles = new HashSet();
+			lobFiles.add(lobFile);
+		}
+	}
+    
+	/**
+	 * Remove LOBFile from the lobFiles set. This will occur when the lob 
+	 * is freed or at transaction end if the lobFile was removed from the 
+	 * WeakHashMap but not finalized.
+	 * @param lobFile  LOBFile to remove.
+	 */
+	void removeLobFile(LOBFile lobFile) {
+		synchronized (this) {
+			lobFiles.remove(lobFile);
+		}
+	}
 }

Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java?rev=702235&r1=702234&r2=702235&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java
(original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java
Mon Oct  6 12:26:21 2008
@@ -59,16 +59,16 @@
     private byte [] dataBytes = new byte [0];
     private boolean isBytes = true;
     private final int bufferSize;
-    private String dbName;
+    private final EmbedConnection conn;
     private long updateCount;
     private static final int DEFAULT_MAX_BUF_SIZE = 4096;
 
     /**
      * Creates an empty LOBStreamControl.
-     * @param dbName database name
+     * @param conn Connection for this lob
      */
-    LOBStreamControl (String dbName) {
-        this.dbName = dbName;
+    LOBStreamControl (EmbedConnection conn) {
+        this.conn = conn;
         updateCount = 0;
         //default buffer size
         bufferSize = DEFAULT_MAX_BUF_SIZE;
@@ -76,12 +76,12 @@
 
     /**
      * Creates a LOBStreamControl and initializes with a bytes array.
-     * @param dbName database name
+     * @param conn Connection for this lob
      * @param data initial value
      */
-    LOBStreamControl (String dbName, byte [] data)
+    LOBStreamControl (EmbedConnection conn, byte [] data)
             throws IOException, StandardException {
-        this.dbName = dbName;
+        this.conn = conn;
         updateCount = 0;
         bufferSize = Math.max (DEFAULT_MAX_BUF_SIZE, data.length);
         write (data, 0, data.length, 0);
@@ -93,7 +93,7 @@
             AccessController.doPrivileged (new PrivilegedExceptionAction() {
                 public Object run() throws IOException, StandardException {
                     Object monitor = Monitor.findService(
-                            Property.DATABASE_MODULE, dbName);
+                            Property.DATABASE_MODULE, conn.getDBName());
                     DataFactory df =  (DataFactory) Monitor.findServiceModule(
                             monitor, DataFactory.MODULE);
                     //create a temporary file
@@ -104,6 +104,7 @@
                     }
                     else
                         tmpFile = new LOBFile (lobFile);
+                    conn.addLobFile(tmpFile);
                     return null;
                 }
             });
@@ -348,6 +349,7 @@
                 read(dataBytes, 0, dataBytes.length, 0);
                 isBytes = true;
                 tmpFile.close();
+                conn.removeLobFile(tmpFile);
                 tmpFile = null;
             } else {
                 tmpFile.setLength(size);
@@ -407,6 +409,7 @@
         if (tmpFile != null) {
             tmpFile.close();
             deleteFile(lobFile);
+            conn.removeLobFile(tmpFile);
             tmpFile = null;
         }
     }
@@ -479,6 +482,7 @@
                 }while (true);
             }            
             oldFile.close();
+            conn.removeLobFile(oldFile);
             deleteFile(oldStoreFile);
         }
         updateCount++;

Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/TemporaryClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/TemporaryClob.java?rev=702235&r1=702234&r2=702235&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/TemporaryClob.java
(original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/TemporaryClob.java
Mon Oct  6 12:26:21 2008
@@ -73,7 +73,7 @@
                                          ConnectionChild conChild,
                                          InternalClob clob)
             throws IOException, SQLException {
-        TemporaryClob newClob = new TemporaryClob(dbName, conChild);
+        TemporaryClob newClob = new TemporaryClob(conChild);
         newClob.copyClobContent(clob);
         return newClob;
     }
@@ -94,7 +94,7 @@
                                          InternalClob clob,
                                          long length)
             throws IOException, SQLException {
-        TemporaryClob newClob = new TemporaryClob(dbName, conChild);
+        TemporaryClob newClob = new TemporaryClob(conChild);
         newClob.copyClobContent(clob, length);
         return newClob;
     }
@@ -102,18 +102,17 @@
     /**
      * Constructs a <code>TemporaryClob</code> object used to perform
      * operations on a CLOB value.
-     * 
-     * @param dbName name of the database the CLOB value belongs to
      * @param conChild connection object used to obtain synchronization object
+     * 
      * @throws NullPointerException if <code>conChild</code> is
      *      <code>null</code>
      */
-    TemporaryClob (String dbName, ConnectionChild conChild) {
+    TemporaryClob (ConnectionChild conChild) {
         if (conChild == null) {
             throw new NullPointerException("conChild cannot be <null>");
         }
         this.conChild = conChild;
-        this.bytes = new LOBStreamControl(dbName);
+        this.bytes = new LOBStreamControl(conChild.getEmbedConnection());
     }
 
     /**
@@ -148,18 +147,16 @@
     /**
      * Constructs a <code>TemporaryClob</code> object and
      * initializes with a initial String.
-     * 
-     * @param dbName name of the database the CLOB value belongs to
      * @param data initial value in String
      * @param conChild connection object used to obtain synchronization object
      */
-    TemporaryClob (String dbName, String data, ConnectionChild conChild)
+    TemporaryClob (String data, ConnectionChild conChild)
                           throws IOException, SQLException, StandardException {
         if (conChild == null) {
             throw new NullPointerException("conChild cannot be <null>");
         }
         this.conChild = conChild;
-        bytes = new LOBStreamControl(dbName, getByteFromString (data));
+        bytes = new LOBStreamControl(conChild.getEmbedConnection(), getByteFromString (data));
     }
     /**
      * Finds the corresponding byte position for the given UTF-8 character

Modified: db/derby/code/branches/10.4/java/testing/org/apache/derby/impl/jdbc/BiggerTemporaryClobTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derby/impl/jdbc/BiggerTemporaryClobTest.java?rev=702235&r1=702234&r2=702235&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/testing/org/apache/derby/impl/jdbc/BiggerTemporaryClobTest.java
(original)
+++ db/derby/code/branches/10.4/java/testing/org/apache/derby/impl/jdbc/BiggerTemporaryClobTest.java
Mon Oct  6 12:26:21 2008
@@ -53,7 +53,7 @@
         super.bytesPerChar = BYTES_PER_CHAR;
         EmbedStatement embStmt = (EmbedStatement)createStatement();
         EmbedConnection embCon =(EmbedConnection)getConnection();
-        iClob = new TemporaryClob(embCon.getDBName(), embStmt);
+        iClob = new TemporaryClob(embStmt);
         transferData(
             new LoopingAlphabetReader(CLOBLENGTH, CharAlphabet.cjkSubset()),
             iClob.getWriter(1L),

Modified: db/derby/code/branches/10.4/java/testing/org/apache/derby/impl/jdbc/SmallTemporaryClobTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derby/impl/jdbc/SmallTemporaryClobTest.java?rev=702235&r1=702234&r2=702235&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/testing/org/apache/derby/impl/jdbc/SmallTemporaryClobTest.java
(original)
+++ db/derby/code/branches/10.4/java/testing/org/apache/derby/impl/jdbc/SmallTemporaryClobTest.java
Mon Oct  6 12:26:21 2008
@@ -55,7 +55,7 @@
         super.bytesPerChar = BYTES_PER_CHAR;
         EmbedStatement embStmt = (EmbedStatement)createStatement();
         EmbedConnection embCon =(EmbedConnection)getConnection();
-        iClob = new TemporaryClob(embCon.getDBName(), embStmt);
+        iClob = new TemporaryClob(embStmt);
         transferData(
             new LoopingAlphabetReader(CLOBLENGTH, CharAlphabet.tamil()),
             iClob.getWriter(1L),



Mime
View raw message