db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Knut Anders Hatlen <Knut.Hat...@Sun.COM>
Subject Re: Should I be able to select the same Blob column twice?
Date Thu, 24 Apr 2008 19:42:45 GMT
Kathey Marsden <kmarsdenderby@sbcglobal.net> writes:

> I was looking at DERBY-2349, and am looking at the simpler case of
> just selecting the BLOB column twice and performing getBinaryStream()
> on both columns.  The program below does just that and prints the
> first 10 bytes of the stream.
> With embedded the output is:
> 4 5 6 7 8 9 10 11 12 13
> 14 15 16 17 18 19 20 21 22 23
> I am done
> Two things seem to be happening with embedded.
> 1) Both getBinaryStream() calls are returning the same stream.
> 2) The second getBinaryStream() call throws away 4 bytes.

I also think the deadlock reported in DERBY-3604 is a related
problem. Taken from memory, the test that fails does something like


Both Blob objects refer to the same underlying stream, and in some cases
the first Blob object is garbage collected and closes the stream at the
same time as the second Blob object tries to retrieve the
stream. Sometimes it leads to a deadlock, sometimes it causes and
exception saying that the Blob is no longer accessible, and sometimes
(most times?) no failure occurs since the first Blob isn't garbage
collected until the second Blob has finished using the stream.

> So my question is, is this a legal case to select the Blob column
> twice? 

It's legal, but not guaranteed to work. This is what ResultSet's class
javadoc says:

    For maximum portability, result set columns within each row should
    be read in left-to-right order, and each column should be read only

> Should the embedded driver behave similar to the client and
> close and reopen the stream on the second getBinaryStream()?

It sounds reasonable to harmonize the two drivers. We could also
disallow the second call to getBinaryStream() (or getBlob()) on both
drivers, but that would possibly cause more compatibility problems than
just closing and reopening the stream.

Knut Anders

View raw message