Le 2024-07-10 à 18 h 00, Archie Cobbs a écrit :

So would you accept a solution to this problem in the java.sql package instead? For example by adding two new methods:

java.sql.Blob.asByteBuffer()
java.sql.Clob.asCharBuffer()

Yes, it would work for me if JDBC drivers provide their own implementation. But it would not be exactly equivalent. A Blob.asByteBuffer() method would be efficient when the JDBC driver loads all bytes anyway, but may be expansive if the JDBC driver was really doing streaming. Maybe some JDBC drivers do streaming only when the Blob size is over some threshold (I didn't verified). Since a Blob can be very large, wouldn't it be safer to avoid adding API that performs an unconditional loading of all bytes? Unless the plan was to return an Optional.

By contrast, the ByteArrayInputStream.asByteBuffer() proposal never loads bytes that were not already in memory. Therefore, it can be used in a more opportunistic way ("only if all bytes happen to be in memory anyway, opportunistically use them directly without copy"). Also, it does not require changes in JDBC drivers, and could be used in contexts other than JDBC as well.

    Martin

Reply via email to