db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Knut Anders Hatlen (JIRA)" <derby-...@db.apache.org>
Subject [jira] Commented: (DERBY-1417) Add new, lengthless overloads to the streaming api
Date Sat, 26 Aug 2006 18:18:26 GMT
    [ http://issues.apache.org/jira/browse/DERBY-1417?page=comments#action_12430769 ] 
Knut Anders Hatlen commented on DERBY-1417:

Hi Kristian,

I am not completely comfortable with the 8a patch. It might be the
case that all callers of SQLBlob.getLength() will work correctly if a
negative value is returned, but I have a feeling that it will work by
accident, not by design, and that it might fail later because of
changes in other parts of the code.

My two main objections are

  1) SQLBlob.getLength() breaks the contract of
     DataValueDescriptor.getLength() and SQLBinary.getLength() as the
     length in bytes is not returned for parameters set with one of
     the length-less streaming methods.

  2) There will be an inconsistency between the return values from
     SQLBlob.getLength() and SQLClob.getLength(). SQLBlob will return
     a negative value when a length-less method has been used, SQLClob
     will materialize the stream and return a non-negative value.

I propose a slightly different approach:

  a) Don't make any changes to getLength().

  b) Add a new method (say getLengthIfAvailable()) to the
     DataValueDescriptor interface, with a javadoc similar to

      * Returns the same value as getLength() if there is a simple and
      * resource-friendly way to find the value. If a call to
      * getLength() would require heavy work (for instance,
      * materializing a stream to get its length), this method is
      * allowed to return a negative value indicating that.

  c) Add a default implementation of the method in DataType. The
     default implementation could just forward calls to the
     getLength() method.

  d) Override the method in SQLBlob (should be equal to the
     getLength() method you added).

  e) Identify all calls to getLength() which would cause a binary
     stream to be materialized, check if they would work correctly
     with a negative value (fix them if they wouldn't), and replace
     the call to getLength() with a call to getLengthIfAvailable().

I believe this approach is safer. The calls to getLengthIfAvailable()
make it explicit in the code that a negative value can be returned and
must be handled. Also, if there is a call to getLength() that has been
overlooked and that won't work with negative values, it will still
work as before, materializing the stream and returning the correct

> Add new, lengthless overloads to the streaming api
> --------------------------------------------------
>                 Key: DERBY-1417
>                 URL: http://issues.apache.org/jira/browse/DERBY-1417
>             Project: Derby
>          Issue Type: New Feature
>          Components: JDBC
>    Affects Versions:
>            Reporter: Rick Hillegas
>         Assigned To: Kristian Waagan
>             Fix For:
>         Attachments: derby-1417-01-castsInTests.diff, derby-1417-1a-notImplemented.diff,
derby-1417-1a-notImplemented.stat, derby-1417-2a-rstest-refactor.diff, derby-1417-3a-embimpl-and-tests.diff,
derby-1417-3a-embimpl-and-tests.stat, derby-1417-3b-embimpl-and-tests.diff, derby-1417-3b-embimpl-and-tests.stat,
derby-1417-4a-disable-psTestsDnc.diff, derby-1417-5a-brokered.diff, derby-1417-5a-brokered.stat,
derby-1417-6a-clientimpl.diff, derby-1417-6a-clientimpl.stat, derby-1417-6b-clientimpl.diff,
derby-1417-6c-clientimpl.diff, derby-1417-6d-clientimpl.diff, derby-1417-7a-clientborderfix.diff,
derby-1417-7a-clientborderfix.stat, derby-1417-8a-enableblobstreaming.diff, derby-1417-8a-enableblobstreaming.stat
> The JDBC4 Expert Group has approved a new set of overloads for the streaming methods.
These overloads do not take a length argument. Here are the new overloads:
> PreparedStatement.setAsciiStream(int parameterIndex, java.io.InputStream x)
> PreparedStatement.setBinaryStream(int parameterIndex, java.io.InputStream x)
> PreparedStatement.setCharacterStream(int parameterIndex, java.io.Reader reader)
> PreparedStatement.setNCharacterStream(int parameterIndex, java.io.Reader reader)
> PreparedStatement.setBlob(int parameterIndex, java.io.InputStream inputStream)
> PreparedStatement.setClob(int parameterIndex, java.io.Reader reader)
> PreparedStatement.setNClob(int parameterIndex, java.io.Reader reader)
> CallableStatement.setAsciiStream(java.lang.String parameterName, java.io.InputStream
> CallableStatement.setBinaryStream(java.lang.String parameterName, java.io.InputStream
> CallableStatement.setCharacterStream(java.lang.String parameterName, java.io.Reader reader)
> CallableStatement.setNCharacterStream(java.lang.String parameterName, java.io.Reader
> CallableStatement.setBlob(java.lang.String parameterName, java.io.InputStream inputStream)
> CallableStatement.setClob(java.lang.String parameterName, java.io.Reader reader)
> CallableStatement.setNClob(java.lang.String parameterName, java.io.Reader reader)
> ResultSet.updateAsciiStream(int columnIndex, java.io.InputStream x)
> ResultSet.updateAsciiStream(java.lang.String columnLabel, java.io.InputStream x)
> ResultSet.updateBinaryStream(int columnIndex, java.io.InputStream x)
> ResultSet.updateBinaryStream(java.lang.String columnLabel, java.io.InputStream x, int
> ResultSet.updateCharacterStream(int columnIndex, java.io.Reader x)
> ResultSet.updateCharacterStream(java.lang.String columnLabel, java.io.Reader x)
> ResultSet.updateNCharacterStream(int columnIndex, java.io.Reader x)
> ResultSet.updateNCharacterStream(java.lang.String columnLabel, java.io.Reader x)  
> ResultSet.updateBlob(int columnIndex, java.io.InputStream inputStream)
> ResultSet.updateBlob(java.lang.String columnLabel, java.io.InputStream inputStream)
> ResultSet.updateClob(int columnIndex, java.io.Reader reader)
> ResultSet.updateClob(java.lang.String columnLabel, java.io.Reader reader)
> ResultSet.updateNClob(int columnIndex, java.io.Reader reader)
> ResultSet.updateNClob(java.lang.String columnLabel, java.io.Reader reader)
> We should add these new overloads soon so that the build will not break when this methods
turn up in a published Mustang build.

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


View raw message