Skip to content

Commit

Permalink
More offset and trace changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeber-ibm committed Sep 12, 2002
1 parent 01813f9 commit 1a360f6
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 83 deletions.
20 changes: 11 additions & 9 deletions src/com/ibm/as400/access/AS400JDBCBlob.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public byte[] getBytes (long start, int length)
--start; // @B1A
long end = start + length - 1;
if ((start < 0) || (length < 0) || (end >= length_) || (start >= length_)) // @B2C
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID);
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID);

// Copy the bytes.
byte[] result = new byte[length];
Expand Down Expand Up @@ -186,7 +186,7 @@ public long position (byte[] pattern, long start)
// Validate the parameters.
--start; // @B1A
if ((start < 0) || (start >= length_) || (pattern == null))
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID);
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID);

return byteSearch (data_.getRawBytes (), data_.getOffset (), pattern, (int) start);
}
Expand Down Expand Up @@ -214,7 +214,7 @@ public long position (Blob pattern, long start)
// Validate the parameters.
--start; // @B1A
if ((start < 0) || (start >= length_) || (pattern == null))
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID);
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID);

return byteSearch (data_.getRawBytes (), data_.getOffset (),
pattern.getBytes (0, (int) pattern.length ()),
Expand All @@ -240,7 +240,7 @@ public OutputStream setBinaryStream(long positionToStartWriting)
throws SQLException
{
if ((positionToStartWriting <= 0) || (positionToStartWriting > length_))
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID);
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID);

return new AS400JDBCLobOutputStream (this, positionToStartWriting);
}
Expand All @@ -267,14 +267,14 @@ public int setBytes (long positionToStartWriting, byte[] bytesToWrite)
// Validate parameters.
if ((positionToStartWriting > length_) || (positionToStartWriting <= 0) ||
(bytesToWrite == null) || (bytesToWrite.length < 0))
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID);
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID);

positionToStartWriting--;

length_ = (int)positionToStartWriting + bytesToWrite.length; //@G5D + 1; Do not add one to this length.

if ((positionToStartWriting >= length_))
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID);
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID);

byte[] data = new byte[length_];
System.arraycopy (data_.getRawBytes(), data_.getOffset(), data, 0, (int)positionToStartWriting);
Expand Down Expand Up @@ -311,8 +311,10 @@ public int setBytes (long positionToStartWriting, byte[] bytesToWrite, int offse
{
// Validate parameters
if ((lengthOfWrite < 0) || (offset < 0) || (bytesToWrite == null) || //@H2C
(bytesToWrite.length < 0))
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID);
(bytesToWrite.length < 0)
|| (positionToStartWriting <= 0) || //@H3A Added cases
(positionToStartWriting > length_) || (offset + lengthOfWrite > bytesToWrite.length)) //@H3A Added cases
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID);

//@H2D offset--;
byte[] newData = new byte[lengthOfWrite];
Expand All @@ -338,7 +340,7 @@ public void truncate(long lengthOfBLOB)
throws SQLException
{
if ((lengthOfBLOB < 0) || (lengthOfBLOB > length_))
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID);
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID);

byte[] newData = new byte[(int)lengthOfBLOB];
System.arraycopy(data_.getRawBytes(), data_.getOffset(), newData, 0, (int)lengthOfBLOB);
Expand Down
94 changes: 46 additions & 48 deletions src/com/ibm/as400/access/AS400JDBCBlobLocator.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class AS400JDBCBlobLocator


// Private data.
private JDLobLocator locator_;
private JDLobLocator locator_;
private Vector bytesToUpdate_; //@G5A
private Vector positionsToStartUpdates_; //@G5A
private Object internalLock_; //@G5A
Expand Down Expand Up @@ -64,7 +64,7 @@ public class AS400JDBCBlobLocator
@exception SQLException If an error occurs.
**/
public InputStream getBinaryStream ()
throws SQLException
throws SQLException
{
return new AS400JDBCInputStream (locator_);
}
Expand All @@ -84,17 +84,14 @@ public InputStream getBinaryStream ()
or an error occurs.
**/
public byte[] getBytes (long start, int length)
throws SQLException
throws SQLException
{
--start; // @B3A
//@H1 This is an unnecessary flow to the server. The server will report an error
//@H1 if our start or length numbers are invalid.
//@H1D long end = start + length - 1; // @G7A
//@H1D long currentLengthOfLocator = locator_.getLength(); // @G7A
//@H1D if (end >= currentLengthOfLocator) // @G7A
//@H1D|| (start >= currentLengthOfLocator) ||
if ((start < 0) || (length < 0)) //@G7A
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID); // @G7A
long end = start + length - 1; // @G7A
long currentLengthOfLocator = locator_.getLength(); // @G7A
if ((start < 0) || (length < 0) || end >= currentLengthOfLocator // @G7A
|| (start >= currentLengthOfLocator) ) //@G7A
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID); // @G7A
DBLobData data = locator_.retrieveData ((int) start, length); // @B1C
int actualLength = data.getLength ();
byte[] bytes = new byte[actualLength];
Expand Down Expand Up @@ -171,7 +168,7 @@ Vector getPositionsToStartUpdates()
@exception SQLException If an error occurs.
**/
public long length ()
throws SQLException
throws SQLException
{
// @C1D // There is no way currently to efficiently compute the @A1A
// @C1D // actual length of the BLOB. We have 2 choices: @A1A
Expand Down Expand Up @@ -205,12 +202,12 @@ public long length ()
or an error occurs.
**/
public long position (byte[] pattern, long start)
throws SQLException
throws SQLException
{
// Validate the parameters. // @B2A
--start; // @B3A
if ((start < 0) || (start >= length()) || (pattern == null)) // @B2A
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID); // @B2A
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID); // @B2A

return -1; // @A1C return locator_.position ("?", pattern, start);
}
Expand All @@ -232,12 +229,12 @@ public long position (byte[] pattern, long start)
or an error occurs.
**/
public long position (Blob pattern, long start)
throws SQLException
throws SQLException
{
// Validate the parameters. // @B2A
--start; // @B3A
if ((start < 0) || (start >= length()) || (pattern == null)) // @B2A
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID); // @B2A
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID); // @B2A

return -1; // @A1A
// @A1D if (pattern instanceof AS400JDBCBlobLocator)
Expand All @@ -264,7 +261,7 @@ public OutputStream setBinaryStream(long positionToStartWriting)
throws SQLException
{
if ((positionToStartWriting <= 0) || (positionToStartWriting > locator_.getLength()))
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID);
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID);

return new AS400JDBCLobOutputStream (this, positionToStartWriting);
}
Expand All @@ -273,24 +270,24 @@ public OutputStream setBinaryStream(long positionToStartWriting)

//@G4A JDBC 3.0
/**
Writes an array of bytes to this BLOB, starting at position <i>positionToStartWriting</i>
in the BLOB. The BLOB will be truncated after the last byte written.
@param positionToStartWriting The position (1-based) in the BLOB where writes should start.
@param bytesToWrite The array of bytes to be written to this BLOB.
@return The number of bytes written to the BLOB.
@exception SQLException If there is an error accessing the BLOB or if the position
specified is greater than the length of the BLOB.
@since Modification 5
**/
Writes an array of bytes to this BLOB, starting at position <i>positionToStartWriting</i>
in the BLOB. The BLOB will be truncated after the last byte written.
@param positionToStartWriting The position (1-based) in the BLOB where writes should start.
@param bytesToWrite The array of bytes to be written to this BLOB.
@return The number of bytes written to the BLOB.
@exception SQLException If there is an error accessing the BLOB or if the position
specified is greater than the length of the BLOB.
@since Modification 5
**/
public int setBytes (long positionToStartWriting, byte[] bytesToWrite)
throws SQLException
{
if ((positionToStartWriting < 1) || (bytesToWrite == null) || (bytesToWrite.length < 0) ||
positionToStartWriting > locator_.getLength())
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID);
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID);

positionToStartWriting--;

Expand All @@ -303,30 +300,31 @@ public int setBytes (long positionToStartWriting, byte[] bytesToWrite)

//@G4A JDBC 3.0
/**
Writes all or part of the byte array the application passes in to this BLOB,
starting at position <i>positionToStartWriting</i> in the BLOB.
The BLOB will be truncated after the last byte written. The <i>lengthOfWrite</i>
bytes written will start from <i>offset</i> in the bytes that were provided by the
application.
@param positionToStartWriting The position (1-based) in the BLOB where writes should start.
@param bytesToWrite The array of bytes to be written to this BLOB.
Writes all or part of the byte array the application passes in to this BLOB,
starting at position <i>positionToStartWriting</i> in the BLOB.
The BLOB will be truncated after the last byte written. The <i>lengthOfWrite</i>
bytes written will start from <i>offset</i> in the bytes that were provided by the
application.
@param positionToStartWriting The position (1-based) in the BLOB where writes should start.
@param bytesToWrite The array of bytes to be written to this BLOB.
@param offset The offset into the array at which to start reading bytes (0-based).
@param length The number of bytes to be written to the BLOB from the array of bytes.
@return The number of bytes written.
@exception SQLException If there is an error accessing the BLOB or if the position
specified is greater than the length of the BLOB.
@since Modification 5
**/
@param length The number of bytes to be written to the BLOB from the array of bytes.
@return The number of bytes written.
@exception SQLException If there is an error accessing the BLOB or if the position
specified is greater than the length of the BLOB.
@since Modification 5
**/
public int setBytes (long positionToStartWriting, byte[] bytesToWrite, int offset, int length)
throws SQLException
{
// Validate parameters
if ((length < 0) || (offset < 0) || (bytesToWrite == null) || (bytesToWrite.length < 0) //@H3C
|| positionToStartWriting > locator_.getLength())
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID);
|| (positionToStartWriting <= 0) || positionToStartWriting > locator_.getLength() ||
(offset + length > bytesToWrite.length)) //@H4A Added cases
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID);

//@H3D offset--;

Expand Down
18 changes: 9 additions & 9 deletions src/com/ibm/as400/access/AS400JDBCClob.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public InputStream getAsciiStream ()
return new ByteArrayInputStream (data_.getBytes ("ISO8859_1"));
}
catch (UnsupportedEncodingException e) {
JDError.throwSQLException (JDError.EXC_INTERNAL, e); // @C2C
JDError.throwSQLException (this, JDError.EXC_INTERNAL, e); // @C2C
return null;
}
}
Expand Down Expand Up @@ -114,7 +114,7 @@ public String getSubString (long start, int length)
--start; // @B1A
long end = start + length - 1;
if ((start < 0) || (length < 0) || (end >= length_) || (start >= length_)) // @B2C
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID);
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID);

// Generate the substring.
return data_.substring ((int) start, (int) start + length);
Expand Down Expand Up @@ -158,7 +158,7 @@ public long position (String pattern, long start)
// Validate the parameters.
--start; // @B1A
if ((start < 0) || (start >= length_) || (pattern == null))
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID);
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID);

return data_.indexOf (pattern, (int) start);
}
Expand Down Expand Up @@ -186,7 +186,7 @@ public long position (Clob pattern, long start)
// Validate the parameters.
--start; // @B1A
if ((start < 0) || (start >= length_) || (pattern == null))
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID);
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID);

return data_.indexOf (pattern.getSubString (1, (int) pattern.length ()), (int) start); // @C1C
}
Expand All @@ -209,7 +209,7 @@ public OutputStream setAsciiStream(long positionToStartWriting)
throws SQLException
{
if (positionToStartWriting <= 0 || positionToStartWriting > length_)
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID);
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID);

//Didn't decrement the position here even though clobs are 1-based and output streams
//are 0-based because output stream uses this number for what position to call
Expand All @@ -236,7 +236,7 @@ public Writer setCharacterStream (long positionToStartWriting)
throws SQLException
{
if (positionToStartWriting <= 0 || positionToStartWriting > length_)
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID);
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID);

//Didn't decrement the position here even though clobs are 1-based and writers
//are 0-based because writer uses this number for what position to call
Expand Down Expand Up @@ -265,7 +265,7 @@ public int setString (long positionToStartWriting, String stringToWrite)
{
// Validate the parameters.
if ((positionToStartWriting > length_) || (positionToStartWriting <= 0) || (stringToWrite == null))
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID);
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID);

positionToStartWriting--;

Expand Down Expand Up @@ -299,8 +299,8 @@ public int setString (long positionToStartWriting, String stringToWrite)
public int setString (long positionToStartWriting, String string, int offset, int lengthOfWrite)
throws SQLException
{
if ((lengthOfWrite < 0) || (offset < 0) || (string == null)) //@H2C
JDError.throwSQLException (JDError.EXC_ATTRIBUTE_VALUE_INVALID);
if ((lengthOfWrite < 0) || (offset < 0) || (string == null) || ((offset + lengthOfWrite) > string.length())) //@H2C @H3A Added case
JDError.throwSQLException (this, JDError.EXC_ATTRIBUTE_VALUE_INVALID);

//@H2D offset--;

Expand Down
Loading

0 comments on commit 1a360f6

Please sign in to comment.