db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r677628 - in /db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc: EmbedBlob.java LOBInputStream.java LOBOutputStream.java LOBStreamControl.java
Date Thu, 17 Jul 2008 16:07:32 GMT
Author: kristwaa
Date: Thu Jul 17 09:07:31 2008
New Revision: 677628

URL: http://svn.apache.org/viewvc?rev=677628&view=rev
Log:
DERBY-3783: LOBStreamControl shouldn't throw SQLException.
Merged revision 677623 (derby-3783-1a-dont_throw_sqlexception.diff) from trunk.

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/LOBInputStream.java
    db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBOutputStream.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/EmbedBlob.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java?rev=677628&r1=677627&r2=677628&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 Thu
Jul 17 09:07:31 2008
@@ -165,11 +165,7 @@
             try {
                 control = new LOBStreamControl (
                             getEmbedConnection().getDBName(), dvdBytes);
-            }
-            catch (SQLException e) {
-                throw StandardException.newException (e.getSQLState());
-            }
-            catch (IOException e) {
+            } catch (IOException e) {
                 throw StandardException.newException (
                                         SQLState.SET_STREAM_FAILURE, e);
             }

Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBInputStream.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBInputStream.java?rev=677628&r1=677627&r2=677628&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBInputStream.java
(original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBInputStream.java
Thu Jul 17 09:07:31 2008
@@ -24,7 +24,6 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.sql.SQLException;
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.services.i18n.MessageService;
@@ -123,11 +122,17 @@
                 return ret;
             }
             return -1;
-        } catch (SQLException e) {
-            return handleSQLException (e);
-        }
-        catch (StandardException se) {
-            throw new IOException (se.getMessage());
+        } catch (StandardException se) {
+            String state = se.getSQLState();
+            if (state.equals(ExceptionUtil.getSQLStateFromIdentifier(
+                                        SQLState.BLOB_POSITION_TOO_LARGE))) {
+                return -1;
+            } else if (state.equals(ExceptionUtil.getSQLStateFromIdentifier(
+                                            SQLState.BLOB_INVALID_OFFSET))) {
+                throw new ArrayIndexOutOfBoundsException(se.getMessage());
+            } else {
+                throw new IOException(se.getMessage());
+            }
         }
     }
 
@@ -167,25 +172,11 @@
             if (ret != -1)
                 pos += 1;
             return ret;
-        } catch (SQLException e) {
-            throw new IOException(e.getMessage());
         } catch (StandardException se) {
             throw new IOException (se.getMessage());
         }
     }
 
-    private int handleSQLException (SQLException e) throws IOException {
-        if (e.getSQLState().equals(
-                ExceptionUtil.getSQLStateFromIdentifier(
-                              SQLState.BLOB_POSITION_TOO_LARGE)))
-            return -1;
-        if (e.getSQLState().equals(
-                ExceptionUtil.getSQLStateFromIdentifier(
-                              SQLState.BLOB_INVALID_OFFSET)))
-                throw new ArrayIndexOutOfBoundsException (e.getMessage());
-            throw new IOException(e.getMessage());
-    }
-    
     /**
      * Checks if underlying StreamControl has been updated.
      * @return if stream is modified since created

Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBOutputStream.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBOutputStream.java?rev=677628&r1=677627&r2=677628&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBOutputStream.java
(original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBOutputStream.java
Thu Jul 17 09:07:31 2008
@@ -22,10 +22,8 @@
  */
 package org.apache.derby.impl.jdbc;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.sql.SQLException;
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.services.i18n.MessageService;
@@ -69,8 +67,6 @@
                         SQLState.LANG_STREAM_CLOSED));
         try {
             pos = control.write(b, pos);
-        } catch (SQLException e) {
-            throw  new IOException(e.getMessage());
         } catch (StandardException se) {
             throw new IOException (se.getMessage());
         }
@@ -111,13 +107,12 @@
                         SQLState.LANG_STREAM_CLOSED));
         try {
             pos = control.write(b, off, len, pos);
-        } catch (SQLException e) {
-             if (e.getSQLState().equals(
-                    ExceptionUtil.getSQLStateFromIdentifier(
-                                  SQLState.BLOB_INVALID_OFFSET)))
-                    throw new ArrayIndexOutOfBoundsException (e.getMessage());
-            throw new IOException(e.getMessage());
         } catch (StandardException se) {
+            if (se.getSQLState().equals(
+                    ExceptionUtil.getSQLStateFromIdentifier(
+                                            SQLState.BLOB_INVALID_OFFSET))) {
+                throw new ArrayIndexOutOfBoundsException(se.getMessage());
+            }
             throw new IOException (se.getMessage());
         }
     }

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=677628&r1=677627&r2=677628&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
Thu Jul 17 09:07:31 2008
@@ -29,7 +29,6 @@
 import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
-import java.sql.SQLException;
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.reference.Property;
 import org.apache.derby.iapi.reference.SQLState;
@@ -81,7 +80,7 @@
      * @param data initial value
      */
     LOBStreamControl (String dbName, byte [] data)
-                throws IOException, SQLException, StandardException {
+            throws IOException, StandardException {
         this.dbName = dbName;
         updateCount = 0;
         bufferSize = Math.max (DEFAULT_MAX_BUF_SIZE, data.length);
@@ -89,7 +88,7 @@
     }
 
     private void init(byte [] b, long len)
-                    throws IOException, SQLException, StandardException {
+            throws IOException, StandardException {
         try {
             AccessController.doPrivileged (new PrivilegedExceptionAction() {
                 public Object run() throws IOException, StandardException {
@@ -112,11 +111,9 @@
         catch (PrivilegedActionException pae) {
             Exception e = pae.getException();
             if (e instanceof StandardException)
-                throw Util.generateCsSQLException ((StandardException) e);
+                throw (StandardException)e;
             if (e instanceof IOException)
                 throw (IOException) e;
-            if (e instanceof RuntimeException)
-                throw (RuntimeException) e;
             IOException ioe = new IOException (e.getMessage());
             ioe.initCause (e);
             throw ioe;
@@ -129,7 +126,7 @@
     }
 
     private long updateData(byte[] bytes, int offset, int len, long pos)
-    throws SQLException {
+            throws StandardException {
         if (dataBytes == null) {
             if ((int) pos == 0) {
                 dataBytes = new byte [len];
@@ -138,14 +135,14 @@
             }
             else {
                 //invalid postion
-                throw Util.generateCsSQLException(
+                throw StandardException.newException(
                         SQLState.BLOB_POSITION_TOO_LARGE, new Long(pos));
             }
         }
         else {
             if (pos > dataBytes.length) {
                 //invalid postion
-                throw Util.generateCsSQLException(
+                throw StandardException.newException(
                         SQLState.BLOB_POSITION_TOO_LARGE, new Long(pos));
             }
             else {
@@ -164,32 +161,32 @@
     }
 
     private void isValidPostion(long pos)
-                        throws SQLException, IOException {
+            throws IOException, StandardException {
         if (pos < 0)
-            throw Util.generateCsSQLException(
+            throw StandardException.newException(
                     SQLState.BLOB_NONPOSITIVE_LENGTH, new Long(pos + 1));
         if (pos > Integer.MAX_VALUE)
-            throw Util.generateCsSQLException(
+            throw StandardException.newException(
                     SQLState.BLOB_POSITION_TOO_LARGE, new Long(pos + 1));
 
         if (isBytes) {
             if (dataBytes == null) {
                 if (pos != 0)
-                    throw Util.generateCsSQLException(
+                    throw StandardException.newException(
                             SQLState.BLOB_POSITION_TOO_LARGE, new Long(pos + 1));
             } else if (dataBytes.length < pos)
-                throw Util.generateCsSQLException(
+                throw StandardException.newException(
                         SQLState.BLOB_POSITION_TOO_LARGE, new Long(pos + 1));
         } else {
             if (pos > tmpFile.length())
-                throw Util.generateCsSQLException(
+                throw StandardException.newException(
                         SQLState.BLOB_POSITION_TOO_LARGE, new Long(pos + 1));
         }
     }
 
-    private void isValidOffset(int off, int length) throws SQLException {
+    private void isValidOffset(int off, int length) throws StandardException {
         if (off < 0 || off > length)
-            throw Util.generateCsSQLException(
+            throw StandardException.newException(
                     SQLState.BLOB_INVALID_OFFSET, new Integer(off));
     }
 
@@ -198,10 +195,10 @@
      * @param b byte
      * @param pos
      * @return new postion
-     * @throws IOException, SQLException, StandardException
+     * @throws IOException, StandardException
      */
     synchronized long write(int b, long pos)
-                throws IOException, SQLException, StandardException {
+            throws IOException, StandardException {
         isValidPostion(pos);
         updateCount++;
         if (isBytes) {
@@ -225,15 +222,14 @@
      * @param len number of bytes to be copied
      * @param pos starting postion
      * @return new postion
-     * @throws IOException, SQLException, StandardException
+     * @throws IOException, StandardException
      */
     synchronized long write(byte[] b, int off, int len, long pos)
-                        throws IOException, SQLException, StandardException {
+            throws IOException, StandardException {
+        isValidPostion(pos);
         try {
-            isValidPostion(pos);
             isValidOffset(off, b.length);
-        }
-        catch (SQLException e) {
+        } catch (StandardException e) {
             if (e.getSQLState().equals(
                     ExceptionUtil.getSQLStateFromIdentifier(
                                   SQLState.BLOB_INVALID_OFFSET)))
@@ -257,10 +253,10 @@
      * Reads one byte.
      * @param pos postion from where to read
      * @return byte
-     * @throws IOException, SQLException, StandardException
+     * @throws IOException, StandardException
      */
     synchronized int read(long pos)
-                throws IOException, SQLException, StandardException {
+            throws IOException, StandardException {
         isValidPostion(pos);
         if (isBytes) {
             if (dataBytes.length == pos)
@@ -294,10 +290,10 @@
      * @param len number of bytes to read
      * @param pos initial postion before reading
      * @return number new postion
-     * @throws IOException, SQLException, StandardException
+     * @throws IOException, StandardException
      */
     synchronized int read(byte[] buff, int off, int len, long pos)
-    throws IOException, SQLException, StandardException {
+            throws IOException, StandardException {
         isValidPostion(pos);
         isValidOffset(off, buff.length);
         if (isBytes) {
@@ -339,10 +335,10 @@
     /**
      * Resets the size.
      * @param size new size should be smaller than exisiting size
-     * @throws IOException, SQLException
+     * @throws IOException
      */
     synchronized void truncate(long size)
-                        throws IOException, SQLException, StandardException {
+            throws IOException, StandardException {
         isValidPostion(size);
         if (isBytes) {
             byte [] tmpByte = new byte [(int) size];
@@ -356,12 +352,7 @@
                 tmpFile.close();
                 tmpFile = null;
             } else {
-                try {
-                    tmpFile.setLength(size);
-                }
-                catch (StandardException se) {
-                    Util.generateCsSQLException (se);
-                }
+                tmpFile.setLength(size);
             }
         }
     }
@@ -370,10 +361,10 @@
      * Copies bytes from stream to local storage.
      * @param inStream
      * @param length length to be copied
-     * @throws IOException, SQLException, StandardException
+     * @throws IOException, StandardException
      */
-    synchronized void copyData(InputStream inStream,
-            long length) throws IOException, SQLException, StandardException {
+    synchronized void copyData(InputStream inStream, long length)
+            throws IOException, StandardException {
         byte [] data = new byte [bufferSize];
         long sz = 0;
         while (sz < length) {
@@ -437,10 +428,9 @@
      * @return Current position after write.
      * @throws IOExcepton if writing to temporary file fails
      * @throws StandardException
-     * @throws SQLException
      */
-    synchronized long replaceBytes (byte [] buf, long stPos, long endPos) 
-                         throws IOException, SQLException, StandardException {
+    synchronized long replaceBytes (byte [] buf, long stPos, long endPos)
+            throws IOException, StandardException {
         long length = getLength();
         long finalLength = length - endPos + stPos + buf.length;
         if (isBytes) {



Mime
View raw message