Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 94E53F409 for ; Wed, 10 Apr 2013 15:00:54 +0000 (UTC) Received: (qmail 43007 invoked by uid 500); 10 Apr 2013 15:00:54 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 42969 invoked by uid 500); 10 Apr 2013 15:00:54 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 42960 invoked by uid 99); 10 Apr 2013 15:00:54 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Apr 2013 15:00:54 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Apr 2013 15:00:50 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 09EDC2388A9B; Wed, 10 Apr 2013 15:00:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1466503 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc: EncryptedLOBFile.java LOBStreamControl.java Date: Wed, 10 Apr 2013 15:00:28 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130410150029.09EDC2388A9B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kahatlen Date: Wed Apr 10 15:00:28 2013 New Revision: 1466503 URL: http://svn.apache.org/r1466503 Log: DERBY-6161: Simplify code that handles LOB files - remove EncryptedLOBFile.close() and let it inherit from super class - move code that doesn't need privileges out of privileged block in LOBStreamControl.init() - remove unnecessary exception handling in privileged block in LOBStreamControl.deleteFile() - fix typos and misformatted @throws clauses in javadoc comments Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EncryptedLOBFile.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/EncryptedLOBFile.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EncryptedLOBFile.java?rev=1466503&r1=1466502&r2=1466503&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EncryptedLOBFile.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EncryptedLOBFile.java Wed Apr 10 15:00:28 2013 @@ -130,7 +130,7 @@ class EncryptedLOBFile extends LOBFile { * Writes one byte into the file. * @param b byte value * @throws IOException if disk operation fails - * @throws StandardException if error occured during encryption/decryption + * @throws StandardException if error occurred during encryption/decryption */ void write (int b) throws IOException, StandardException { long length = super.length(); @@ -174,7 +174,7 @@ class EncryptedLOBFile extends LOBFile { * data should be written to the file * @param len number of bytes to be written * @throws IOException if disk operation fails - * @throws StandardException if error occured during encryption/decryption + * @throws StandardException if error occurred during encryption/decryption */ void write(byte[] b, int off, int len) throws IOException, StandardException { @@ -248,25 +248,17 @@ class EncryptedLOBFile extends LOBFile { * the file if the total length exceeds the file size. * @param b byte array to be written * @throws IOException if disk operation fails - * @throws StandardException if error occured during encryption/decryption + * @throws StandardException if error occurred during encryption/decryption */ void write(byte[] b) throws IOException, StandardException { write (b, 0, b.length); } /** - * closes the file. - * @throws IOException - */ - void close() throws IOException { - super.close(); - } - - /** * Reads one byte from file. * @return byte * @throws IOException if disk operation fails - * @throws StandardException if error occured during encryption/decryption + * @throws StandardException if error occurred during decryption */ int readByte() throws IOException, StandardException { long fileLength = super.length(); @@ -289,7 +281,7 @@ class EncryptedLOBFile extends LOBFile { * @param len number of bytes to be read * @return number of bytes read * @throws IOException if disk operation fails - * @throws StandardException if error occured during encryption/decryption + * @throws StandardException if error occurred during decryption */ int read(byte[] buff, int off, int len) throws IOException, StandardException { @@ -337,7 +329,7 @@ class EncryptedLOBFile extends LOBFile { * * @param size new file size. Must be lower than file length. * @throws IOException if file i/o fails - * @throws StandardException if error occured during encryption/decryption + * @throws StandardException if error occurred during decryption */ void setLength(long size) throws IOException, StandardException { long fileLength = super.length(); 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=1466503&r1=1466502&r2=1466503&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 Wed Apr 10 15:00:28 2013 @@ -28,6 +28,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.UTFDataFormatException; import java.security.AccessController; +import java.security.PrivilegedAction; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import org.apache.derby.iapi.error.StandardException; @@ -55,7 +56,7 @@ import org.apache.derby.shared.common.re * blob data irrespective of if its in memory or in file. */ -class LOBStreamControl { +final class LOBStreamControl { private LOBFile tmpFile; private byte [] dataBytes = new byte [0]; private boolean isBytes = true; @@ -92,34 +93,30 @@ class LOBStreamControl { private void init(byte [] b, long len) throws IOException, StandardException { + Object monitor = Monitor.findService( + Property.DATABASE_MODULE, conn.getDBName()); + final DataFactory df = (DataFactory) Monitor.findServiceModule( + monitor, DataFactory.MODULE); try { AccessController.doPrivileged (new PrivilegedExceptionAction() { - public Object run() throws IOException, StandardException { - Object monitor = Monitor.findService( - Property.DATABASE_MODULE, conn.getDBName()); - DataFactory df = (DataFactory) Monitor.findServiceModule( - monitor, DataFactory.MODULE); + public Object run() throws IOException { //create a temporary file StorageFile lobFile = df.getStorageFactory().createTemporaryFile("lob", null); if (df.databaseEncrypted()) { tmpFile = new EncryptedLOBFile (lobFile, df); - } - else + } else { tmpFile = new LOBFile (lobFile); - conn.addLobFile(tmpFile); + } return null; } }); } catch (PrivilegedActionException pae) { - Exception e = pae.getException(); - if (e instanceof StandardException) - throw (StandardException)e; - if (e instanceof IOException) - throw (IOException) e; - throw Util.newIOException(e); + throw (IOException) pae.getCause(); } + + conn.addLobFile(tmpFile); isBytes = false; //now this call will write into the file if (len != 0) @@ -196,8 +193,9 @@ class LOBStreamControl { * Writes one byte. * @param b byte * @param pos - * @return new postion - * @throws IOException, StandardException + * @return new position + * @throws IOException if writing to the LOB file fails + * @throws StandardException if encrypting/decrypting the LOB file fails */ synchronized long write(int b, long pos) throws IOException, StandardException { @@ -257,9 +255,10 @@ class LOBStreamControl { /** * Reads one byte. - * @param pos postion from where to read + * @param pos position from where to read * @return byte - * @throws IOException, StandardException + * @throws IOException if reading the LOB file fails + * @throws StandardException if decrypting an encrypted LOB file fails */ synchronized int read(long pos) throws IOException, StandardException { @@ -294,9 +293,10 @@ class LOBStreamControl { * @param buff array into the bytes will be copied * @param off offset from where the array has to be populated * @param len number of bytes to read - * @param pos initial postion before reading - * @return number new postion - * @throws IOException, StandardException + * @param pos initial position before reading + * @return number new position + * @throws IOException if reading the LOB file fails + * @throws StandardException if decrypting an encrypted LOB file fails */ synchronized int read(byte[] buff, int off, int len, long pos) throws IOException, StandardException { @@ -340,7 +340,7 @@ class LOBStreamControl { /** * Resets the size. - * @param size new size should be smaller than exisiting size + * @param size new size should be smaller than existing size * @throws IOException */ synchronized void truncate(long size) @@ -373,7 +373,8 @@ class LOBStreamControl { * @param inStream the stream to copy from * @param length number of bytes to be copied, or {@code Long.MAX_VALUE} to * copy everything until EOF is reached - * @throws IOException, StandardException + * @throws IOException if reading or writing a LOB file fails + * @throws StandardException if encrypting or decrypting a LOB file fails */ synchronized void copyData(InputStream inStream, long length) throws IOException, StandardException { @@ -492,27 +493,18 @@ class LOBStreamControl { free(); } - private void deleteFile (StorageFile file) throws IOException { - try { - final StorageFile sf = file; - AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws IOException { - sf.delete(); - return null; - } - }); - } catch (PrivilegedActionException pae) { - Exception e = pae.getException(); - if (e instanceof IOException) - throw (IOException) e; - if (e instanceof RuntimeException) - throw (RuntimeException) e; - throw Util.newIOException(e); - } + private void deleteFile(final StorageFile file) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + file.delete(); + return null; + } + }); } + /** * Invalidates all the variables and closes file handle if open. - * @throws IOexception + * @throws IOException if closing the file fails */ void free() throws IOException { dataBytes = null; @@ -561,7 +553,7 @@ class LOBStreamControl { * @param stPos inclusive starting position of current block * @param endPos exclusive end position of current block * @return Current position after write. - * @throws IOExcepton if writing to temporary file fails + * @throws IOException if writing to the temporary file fails * @throws StandardException */ synchronized long replaceBytes (byte [] buf, long stPos, long endPos) @@ -623,7 +615,7 @@ class LOBStreamControl { } /** - * Returns the running secquence number to check if the lob is updated since + * Returns the running sequence number to check if the lob is updated since * last access. * * @return The current update sequence number.