db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r522789 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/jdbc/ engine/org/apache/derby/loc/ shared/org/apache/derby/shared/common/reference/
Date Tue, 27 Mar 2007 06:56:04 GMT
Author: kahatlen
Date: Mon Mar 26 23:56:03 2007
New Revision: 522789

URL: http://svn.apache.org/viewvc?view=rev&rev=522789
Log:
DERBY-2247: Provide set methods for blob in embedded driver

Fixed some review comments. Patch contributed by Anurag Shekhar.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBInputStream.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBOutputStream.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStreamControl.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java?view=diff&rev=522789&r1=522788&r2=522789
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java Mon Mar 26 23:56:03
2007
@@ -113,7 +113,7 @@
         super(con);
          try {
              control = new LOBStreamControl (con.getDBName());
-             control.write (blobBytes, 0);
+             control.write (blobBytes, 0, blobBytes.length, 0);
              materialized = true;
          }
          catch (IOException e) {
@@ -145,13 +145,14 @@
                 SanityManager.ASSERT(dvdBytes != null,"blob has a null value underneath");
             control = new LOBStreamControl (getEmbedConnection().getDBName());
             try {
-                control.write (dvdBytes, pos);
+                control.write (dvdBytes, 0, dvdBytes.length, pos);
             }
             catch (SQLException e) {
                 throw StandardException.newException (e.getSQLState());
             }
             catch (IOException e) {
-                throw StandardException.newException (null, e);
+                throw StandardException.newException (
+                                        SQLState.SET_STREAM_FAILURE, e);
             }
         }
         else
@@ -350,7 +351,7 @@
             // if the blob is materialized
             if (materialized) {
                  result = new byte [length];
-                 int sz = control.read (result, startPos - 1);
+                 int sz = control.read (result, 0, result.length, startPos - 1);
                  if (sz < length) {
                      byte [] tmparray = new byte [sz];
                      System.arraycopy (result, 0, tmparray, 0, sz);
@@ -809,9 +810,6 @@
                     return control.getOutputStream (pos - 1);
                 }
                 else {
-                    if (pos > length())
-                        throw Util.generateCsSQLException (
-                                                SQLState.BLOB_POSITION_TOO_LARGE);
                     control = new LOBStreamControl (
                                             getEmbedConnection().getDBName());
                     control.copyData (myStream, pos - 1);
@@ -841,7 +839,7 @@
 	{
             if (len > length())
                 throw Util.generateCsSQLException(
-                    SQLState.BLOB_NONPOSITIVE_LENGTH, new Long(pos));
+                    SQLState.BLOB_LENGTH_TOO_LONG, new Long(pos));
             try {
                 if (materialized) {
                     control.truncate (len);

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBInputStream.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBInputStream.java?view=diff&rev=522789&r1=522788&r2=522789
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBInputStream.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBInputStream.java Mon Mar
26 23:56:03 2007
@@ -123,59 +123,6 @@
     }
 
     /**
-     * Reads some number of bytes from the input stream and stores them into
-     * the buffer array <code>b</code>. The number of bytes actually read is
-     * returned as an integer.  This method blocks until input data is
-     * available, end of file is detected, or an exception is thrown.
-     *
-     * <p> If <code>b</code> is <code>null</code>, a
-     * <code>NullPointerException</code> is thrown.  If the length of
-     * <code>b</code> is zero, then no bytes are read and <code>0</code>
is
-     * returned; otherwise, there is an attempt to read at least one byte. If
-     * no byte is available because the stream is at end of file, the value
-     * <code>-1</code> is returned; otherwise, at least one byte is read and
-     * stored into <code>b</code>.
-     *
-     * <p> The first byte read is stored into element <code>b[0]</code>,
the
-     * next one into <code>b[1]</code>, and so on. The number of bytes read is,
-     * at most, equal to the length of <code>b</code>. Let <i>k</i>
be the
-     * number of bytes actually read; these bytes will be stored in elements
-     * <code>b[0]</code> through <code>b[</code><i>k</i><code>-1]</code>,
-     * leaving elements <code>b[</code><i>k</i><code>]</code>
through
-     * <code>b[b.length-1]</code> unaffected.
-     *
-     * <p> If the first byte cannot be read for any reason other than end of
-     * file, then an <code>IOException</code> is thrown. In particular, an
-     * <code>IOException</code> is thrown if the input stream has been closed.
-     *
-     * <p> The <code>read(b)</code> method for class <code>InputStream</code>
-     * has the same effect as: <pre><code> read(b, 0, b.length) </code></pre>
-     *
-     * @param b   the buffer into which the data is read.
-     * @return the total number of bytes read into the buffer, or
-     *             <code>-1</code> is there is no more data because the end of
-     *             the stream has been reached.
-     * @exception IOException  if an I/O error occurs.
-     * @exception NullPointerException  if <code>b</code> is <code>null</code>.
-     * @see java.io.InputStream#read(byte[], int, int)
-     */
-    public int read(byte[] b) throws IOException {
-        if (closed)
-            throw new IOException (
-                   MessageService.getTextMessage(SQLState.LANG_STREAM_CLOSED));
-        try {
-            int ret = control.read(b, pos);
-            if (ret > 0) {
-                pos += ret;
-                return ret;
-            }
-            return -1;
-        } catch (SQLException e) {
-            return handleSQLException (e);
-        }
-    }
-
-    /**
      * Closes this input stream and releases any system resources associated
      * with the stream.
      *

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBOutputStream.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBOutputStream.java?view=diff&rev=522789&r1=522788&r2=522789
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBOutputStream.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBOutputStream.java Mon Mar
26 23:56:03 2007
@@ -115,28 +115,6 @@
     }
 
     /**
-     * Writes <code>b.length</code> bytes from the specified byte array
-     * to this output stream. The general contract for <code>write(b)</code>
-     * is that it should have exactly the same effect as the call
-     * <code>write(b, 0, b.length)</code>.
-     *
-     * @param b   the data.
-     * @exception IOException  if an I/O error occurs.
-     * @see java.io.OutputStream#write(byte[], int, int)
-     */
-    public void write(byte[] b) throws IOException {
-        if (closed)
-            throw new IOException (
-                    MessageService.getTextMessage(
-                        SQLState.LANG_STREAM_CLOSED));
-        try {
-            pos = control.write(b, pos);
-        } catch (SQLException e) {
-            throw new IOException(e.getMessage());
-        }
-    }
-
-    /**
      * Closes this output stream and releases any system resources
      * associated with this stream. The general contract of <code>close</code>
      * is that it closes the output stream. A closed stream cannot perform

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?view=diff&rev=522789&r1=522788&r2=522789
==============================================================================
--- 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 Mar
26 23:56:03 2007
@@ -53,7 +53,6 @@
  */
 
 class LOBStreamControl {
-    //private RandomAccessFile tmpFile;
     private StorageRandomAccessFile tmpFile;
     private StorageFile lobFile;
     private byte [] dataBytes = new byte [0];
@@ -75,13 +74,13 @@
                             Property.DATABASE_MODULE, dbName);
                     DataFactory df =  (DataFactory) Monitor.findServiceModule(
                             monitor, DataFactory.MODULE);
+                    //create a temporary file
                     lobFile =
                         df.getStorageFactory().createTemporaryFile("lob", null);
                     tmpFile = lobFile.getRandomAccessFile ("rw");
                     return null;
                 }
             });
-            //create a temporary file
         }
         catch (PrivilegedActionException pae) {
             Exception e = pae.getException();
@@ -156,7 +155,7 @@
         }
     }
 
-    private void isValidOffset(int off, int length) throws SQLException, IOException {
+    private void isValidOffset(int off, int length) throws SQLException {
         if (off < 0 || off > length)
             throw Util.generateCsSQLException(
                     SQLState.BLOB_INVALID_OFFSET, new Integer(off));
@@ -180,8 +179,7 @@
                 init(dataBytes, pos);
             }
         }
-        if (tmpFile.getFilePointer() != pos)
-            tmpFile.seek(pos);
+        tmpFile.seek(pos);
         tmpFile.write(b);
         return tmpFile.getFilePointer();
     }
@@ -208,46 +206,18 @@
                     throw new ArrayIndexOutOfBoundsException (e.getMessage());
         }
         if (isBytes) {
-            long finalLen = (dataBytes != null) ? dataBytes.length + b.length
-                    : b.length;
-            if (finalLen < MAX_BUF_SIZE)
+            if (pos + b.length < MAX_BUF_SIZE)
                 return updateData(b, off, len, pos);
             else {
                 init(dataBytes, pos);
             }
         }
-        if (tmpFile.getFilePointer() != pos)
-            tmpFile.seek(pos);
+        tmpFile.seek(pos);
         tmpFile.write(b, off, len);
         return tmpFile.getFilePointer();
     }
 
     /**
-     * Writes byte array starting from pos.
-     * @param b bytes array
-     * @param pos starting postion
-     * @return new position
-     * @throws IOException, SQLException
-     */
-    synchronized long write(byte[] b, long pos)
-    throws IOException, SQLException {
-        isValidPostion(pos);
-        if (isBytes) {
-            long len = (dataBytes != null) ? dataBytes.length + b.length
-                    : b.length;
-            if (len < MAX_BUF_SIZE)
-                return updateData(b, 0, b.length, pos);
-            else {
-                init(dataBytes, pos);
-            }
-        }
-        if (tmpFile.getFilePointer() != pos)
-            tmpFile.seek(pos);
-        tmpFile.write(b);
-        return tmpFile.getFilePointer();
-    }
-
-    /**
      * Reads one byte.
      * @param pos postion from where to read
      * @return byte
@@ -279,18 +249,6 @@
     }
 
     /**
-     * Copies bytes into byte array starting from pos.
-     * @param b bytes array to copy data
-     * @param pos starting postion
-     * @return new postion
-     * @throws IOException, SQLException
-     */
-    synchronized int read(byte[] b, long pos)
-    throws IOException, SQLException {
-        return read (b, 0, b.length, pos);
-    }
-
-    /**
      * Reads bytes starting from 'position' into bytes array.
      * starting from 'offset'
      * @param buff array into the bytes will be copied
@@ -307,8 +265,7 @@
         if (isBytes) {
             return readBytes(buff, off, len, pos);
         }
-        if (tmpFile.getFilePointer() != pos)
-            tmpFile.seek(pos);
+        tmpFile.seek(pos);
         return tmpFile.read (buff, off, len);
     }
 
@@ -355,7 +312,7 @@
         } else {
             if (size < Integer.MAX_VALUE && size < MAX_BUF_SIZE) {
                 dataBytes = new byte [(int) size];
-                read(dataBytes, 0);
+                read(dataBytes, 0, dataBytes.length, 0);
                 isBytes = true;
                 tmpFile.close();
                 tmpFile = null;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?view=diff&rev=522789&r1=522788&r2=522789
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Mon Mar 26 23:56:03
2007
@@ -3654,6 +3654,11 @@
                 <text>The statement has been cancelled or timed out.</text>
             </msg>
 
+            <msg>
+                <name>XCL53</name>
+                <text>Stream is closed</text>
+            </msg>
+
         </family>
 
 

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?view=diff&rev=522789&r1=522788&r2=522789
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
Mon Mar 26 23:56:03 2007
@@ -942,7 +942,6 @@
 	// MORE GENERIC LANGUAGE STUFF
 	String LANG_COLUMN_DEFAULT										   = "42Z09.U";
 	String LANG_STREAM												   = "42Z11.U";
-    String LANG_STREAM_CLOSED                                          = "42Z12";
 
 	// String LANG_UPDATABLE_VTI_BAD_GETMETADATA						   = "42Z14";
 
@@ -1333,6 +1332,9 @@
 	String LANG_CANT_UPGRADE_DATABASE                                 = "XCL50.S";
 
     String LANG_STATEMENT_CANCELLED_OR_TIMED_OUT                       = "XCL52.S";
+
+    //lob stream error
+    String LANG_STREAM_CLOSED                                     = "XCL53";
 
     /*
 	** Language errors that match DB2



Mime
View raw message