db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r704803 - in /db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc: LOBFile.java LOBStreamControl.java
Date Wed, 15 Oct 2008 08:24:17 GMT
Author: kahatlen
Date: Wed Oct 15 01:24:16 2008
New Revision: 704803

URL: http://svn.apache.org/viewvc?rev=704803&view=rev
Log:
DERBY-3889: LOBStreamControl.truncate() doesn't delete temporary files

Merged fix from trunk (revision 704010).

Modified:
    db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBFile.java
    db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java

Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBFile.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBFile.java?rev=704803&r1=704802&r2=704803&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBFile.java (original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBFile.java Wed Oct
15 01:24:16 2008
@@ -32,7 +32,12 @@
  * in encrypted for without having to change code.
  */
 class LOBFile {
+    /** The temporary file where the contents of the LOB should be stored. */
+    private final StorageFile storageFile;
+
+    /** An object giving random access to {@link #storageFile}. */
     private final StorageRandomAccessFile randomAccessFile;
+
     /**
      * Constructs LOBFile.
      *
@@ -41,10 +46,20 @@
      * cannot be opened
      */
     LOBFile(StorageFile lobFile) throws FileNotFoundException {
+        storageFile = lobFile;
         randomAccessFile = lobFile.getRandomAccessFile("rw");
     }
 
     /**
+     * Get the {@code StorageFile} which represents the file where the
+     * contents of the LOB are stored.
+     * @return a {@code StorageFile} instance
+     */
+    StorageFile getStorageFile() {
+        return storageFile;
+    }
+
+    /**
      * Returns length of the file.
      * @return length of the file
      * @throws IOException if an I/O error occurs

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=704803&r1=704802&r2=704803&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
Wed Oct 15 01:24:16 2008
@@ -55,7 +55,6 @@
 
 class LOBStreamControl {
     private LOBFile tmpFile;
-    private StorageFile lobFile;
     private byte [] dataBytes = new byte [0];
     private boolean isBytes = true;
     private final int bufferSize;
@@ -97,7 +96,7 @@
                     DataFactory df =  (DataFactory) Monitor.findServiceModule(
                             monitor, DataFactory.MODULE);
                     //create a temporary file
-                    lobFile =
+                    StorageFile lobFile =
                         df.getStorageFactory().createTemporaryFile("lob", null);
                     if (df.databaseEncrypted()) {
                         tmpFile = new EncryptedLOBFile (lobFile, df);
@@ -348,8 +347,7 @@
                 dataBytes = new byte [(int) size];
                 read(dataBytes, 0, dataBytes.length, 0);
                 isBytes = true;
-                tmpFile.close();
-                conn.removeLobFile(tmpFile);
+                releaseTempFile(tmpFile);
                 tmpFile = null;
             } else {
                 tmpFile.setLength(size);
@@ -407,12 +405,24 @@
     void free() throws IOException {
         dataBytes = null;
         if (tmpFile != null) {
-            tmpFile.close();
-            deleteFile(lobFile);
-            conn.removeLobFile(tmpFile);
+            releaseTempFile(tmpFile);
             tmpFile = null;
         }
     }
+
+    /**
+     * Close and release all resources held by a temporary file. The file will
+     * also be deleted from the file system and removed from the list of
+     * {@code LOBFile}s in {@code EmbedConnection}.
+     *
+     * @param file the temporary file
+     * @throws IOException if the file cannot be closed or deleted
+     */
+    private void releaseTempFile(LOBFile file) throws IOException {
+        file.close();
+        conn.removeLobFile(file);
+        deleteFile(file.getStorageFile());
+    }
     
     /**
      * Replaces a block of bytes in the middle of the LOB with a another block
@@ -457,7 +467,6 @@
             
             byte tmp [] = new byte [0];
             LOBFile oldFile = tmpFile;
-            StorageFile oldStoreFile = lobFile;
             init (tmp, 0);
             byte [] tmpByte = new byte [1024];
             long sz = stPos;
@@ -481,9 +490,7 @@
                     tmpFile.write (tmpByte, 0, rdLen);
                 }while (true);
             }            
-            oldFile.close();
-            conn.removeLobFile(oldFile);
-            deleteFile(oldStoreFile);
+            releaseTempFile(oldFile);
         }
         updateCount++;
         return stPos + buf.length;



Mime
View raw message