org.objectweb.cjdbc.driver
Class Blob

java.lang.Object
  extended byorg.objectweb.cjdbc.driver.Blob
All Implemented Interfaces:
java.sql.Blob, java.io.Serializable

public class Blob
extends java.lang.Object
implements java.sql.Blob, java.io.Serializable

The representation (mapping) in the Java TM programming language of an SQL BLOB value. By default drivers implement Blob using an SQL locator(BLOB), which means that a Blob object contains a logical pointer to the SQL BLOB data rather than the data itself. But since this is highly database-specific, we are unable to do that and implement Blobs using a simple private byte array copy instead. This may consume a lot of memory but this is both portable across databases and even legal from a JDBC standard point of view as long as our method DatabaseMetaData.locatorsUpdateCopy() returns true.

Since:
JDK 1.2
Author:
Marc Herbert
See Also:
Blob, Serialized Form

Field Summary
(package private)  byte[] internalArray
          The binary data that makes up this BLOB.
 
Constructor Summary
Blob(byte[] src)
          Creates a new Blob object built from a copy of the given byte array.
 
Method Summary
private  void checkInitialized()
           
private static void checkSQLRangeIsSupported(long sqlStart, int len)
          Checks that indexes (sqlStart) and (sqlStart+len) are correct.
 void free()
          This method frees the Blob object and releases the resources that it holds.
 java.io.InputStream getBinaryStream()
           
 byte[] getBytes(long sqlPos, int length)
           
(package private)  byte[] getInternalByteArray()
          BlobOutputStream needs it
 long length()
           
 long position(java.sql.Blob pattern, long sqlStart)
           
 long position(byte[] pattern, long sqlStart)
           
private  byte[] resizedByteArray(byte[] src, int srcStart, int newSize)
          Returns a copy of the byte array argument starting at srcFrom and extended or shortened to newLength. srcFrom index starts from zero (regular style).
 java.io.OutputStream setBinaryStream(long sqlStart)
           
 int setBytes(long sqlStartPos, byte[] srcArray)
           
 int setBytes(long sqlStartPos, byte[] srcArray, int srcArrayOffset, int copiedLength)
           
 void truncate(long newLen)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

internalArray

byte[] internalArray
The binary data that makes up this BLOB.

Constructor Detail

Blob

public Blob(byte[] src)
Creates a new Blob object built from a copy of the given byte array.

Parameters:
src - the array to copy
Method Detail

length

public long length()
            throws java.sql.SQLException
Specified by:
length in interface java.sql.Blob
Throws:
java.sql.SQLException
See Also:
Blob.length()

getBytes

public byte[] getBytes(long sqlPos,
                       int length)
                throws java.sql.SQLException
Specified by:
getBytes in interface java.sql.Blob
Throws:
java.sql.SQLException
See Also:
Blob.getBytes(long, int)

getBinaryStream

public java.io.InputStream getBinaryStream()
                                    throws java.sql.SQLException
Specified by:
getBinaryStream in interface java.sql.Blob
Throws:
java.sql.SQLException
See Also:
Blob.getBinaryStream()

position

public long position(byte[] pattern,
                     long sqlStart)
              throws java.sql.SQLException
Specified by:
position in interface java.sql.Blob
Throws:
java.sql.SQLException
See Also:
Blob.position(byte[], long)

position

public long position(java.sql.Blob pattern,
                     long sqlStart)
              throws java.sql.SQLException
Specified by:
position in interface java.sql.Blob
Throws:
java.sql.SQLException
See Also:
Blob.position(java.sql.Blob, long)

setBytes

public int setBytes(long sqlStartPos,
                    byte[] srcArray)
             throws java.sql.SQLException
Specified by:
setBytes in interface java.sql.Blob
Throws:
java.sql.SQLException
See Also:
Blob.setBytes(long, byte[], int, int)

setBytes

public int setBytes(long sqlStartPos,
                    byte[] srcArray,
                    int srcArrayOffset,
                    int copiedLength)
             throws java.sql.SQLException
Specified by:
setBytes in interface java.sql.Blob
Throws:
java.sql.SQLException
See Also:
Blob.setBytes(long, byte[], int, int)

setBinaryStream

public java.io.OutputStream setBinaryStream(long sqlStart)
                                     throws java.sql.SQLException
Specified by:
setBinaryStream in interface java.sql.Blob
Throws:
java.sql.SQLException
See Also:
Blob.setBinaryStream(long)

truncate

public void truncate(long newLen)
              throws java.sql.SQLException
Specified by:
truncate in interface java.sql.Blob
Throws:
java.sql.SQLException
See Also:
Blob.truncate(long)

free

public void free()
This method frees the Blob object and releases the resources that it holds.


getInternalByteArray

byte[] getInternalByteArray()
BlobOutputStream needs it


checkInitialized

private void checkInitialized()
                       throws DriverSQLException
Throws:
DriverSQLException

checkSQLRangeIsSupported

private static void checkSQLRangeIsSupported(long sqlStart,
                                             int len)
                                      throws java.sql.SQLException
Checks that indexes (sqlStart) and (sqlStart+len) are correct. Valid sqlStart begins at 1 (SQL-style). A reasonable sqlEnd of Blob is no more than Integer.MAX_VALUE+1 because we implement using Java arrays. This method is basically a check to use before casting from long to int.

Parameters:
sqlStart - start index
len - length
Throws:
java.sql.SQLException

resizedByteArray

private byte[] resizedByteArray(byte[] src,
                                int srcStart,
                                int newSize)
Returns a copy of the byte array argument starting at srcFrom and extended or shortened to newLength. srcFrom index starts from zero (regular style).

This roughly double the memory used... *sigh* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4655503 is tagged "fixed" but nothing changed ?!



Copyright © 2002, 2005 - ObjectWeb Consortium - All Rights Reserved.