db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r704010 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc: LOBFile.java LOBStreamControl.java
Date Mon, 13 Oct 2008 11:04:04 GMT
Author: kahatlen
Date: Mon Oct 13 04:04:03 2008
New Revision: 704010

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

Created helper method for closing and deleting temporary files to make
it less likely that some of the required operations are
forgotten. Also moved the lobFile field into the LOBFile class to
reduce the risk of getting inconsistencies between the fields tmpFile
and lobFile.

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

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBFile.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBFile.java?rev=704010&r1=704009&r2=704010&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBFile.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBFile.java Mon Oct 13 04:04:03
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/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java?rev=704010&r1=704009&r2=704010&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java Mon Oct
13 04:04:03 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);
@@ -352,8 +351,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);
@@ -436,12 +434,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
@@ -486,7 +496,6 @@
             
             byte tmp [] = new byte [0];
             LOBFile oldFile = tmpFile;
-            StorageFile oldStoreFile = lobFile;
             init (tmp, 0);
             byte [] tmpByte = new byte [1024];
             long sz = stPos;
@@ -510,9 +519,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