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 ka...@apache.org on 2008/10/15 10:25:18 UTC
svn commit: r704804 - in
/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc:
LOBFile.java LOBStreamControl.java
Author: kahatlen
Date: Wed Oct 15 01:25:18 2008
New Revision: 704804
URL: http://svn.apache.org/viewvc?rev=704804&view=rev
Log:
DERBY-3889: LOBStreamControl.truncate() doesn't delete temporary files
Merged fix from trunk (revision 704010).
Modified:
db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/LOBFile.java
db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java
Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/LOBFile.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/LOBFile.java?rev=704804&r1=704803&r2=704804&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/LOBFile.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/LOBFile.java Wed Oct 15 01:25:18 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.3/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java?rev=704804&r1=704803&r2=704804&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java Wed Oct 15 01:25:18 2008
@@ -61,7 +61,6 @@
class LOBStreamControl {
private LOBFile tmpFile;
- private StorageFile lobFile;
private byte [] dataBytes = new byte [0];
private boolean isBytes = true;
private final int bufferSize;
@@ -103,7 +102,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);
@@ -360,8 +359,7 @@
dataBytes = new byte [(int) size];
read(dataBytes, 0, dataBytes.length, 0);
isBytes = true;
- tmpFile.close();
- conn.removeLobFile(tmpFile);
+ releaseTempFile(tmpFile);
tmpFile = null;
} else {
try {
@@ -426,12 +424,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
@@ -477,7 +487,6 @@
byte tmp [] = new byte [0];
LOBFile oldFile = tmpFile;
- StorageFile oldStoreFile = lobFile;
init (tmp, 0);
byte [] tmpByte = new byte [1024];
long sz = stPos;
@@ -501,9 +510,7 @@
tmpFile.write (tmpByte, 0, rdLen);
}while (true);
}
- oldFile.close();
- conn.removeLobFile(oldFile);
- deleteFile(oldStoreFile);
+ releaseTempFile(oldFile);
}
updateCount++;
return stPos + buf.length;