Blob and unknown length

Поиск
Список
Период
Сортировка
От Oscar Picasso
Тема Blob and unknown length
Дата
Msg-id 431485F5.1010407@videotron.ca
обсуждение исходный текст
Список pgsql-jdbc
Hi,

I have the following requirement for blobs:
- use of standard JDBC API (not the LargeObject API);
- blobs can be potentially huge in size;
- the blob length is not known ahead of time;

I have tried many things and decided to use oid instead of bytea (I got
many OutOfMemoryExceptions with bytea).

To push the data into the db it seems to just work fine with the JDBC API.

But to pull the data from the db, I need to provide a custom Blob
implementation. At least that what I have understood.

To test the solution I have done the following custom Blob implementation.

...
public class BlobImpl implements Blob {
    private final int limit = 10; // Change this value for testing
    private int cur = 0;

    public long length() throws SQLException {
        return Integer.MAX_VALUE;
    }

    public InputStream getBinaryStream() throws SQLException {
        return new InputStream() {

            @Override
            public int read() throws IOException {
                return cur++ < limit ? 'a' : -1;
            }};
    }

    // All other methods throw an Exception
    ...
}

And the code that uses the Blob implementation (no postgresql specific
code).
...
insertStmt.setBlob(1, new BlobImpl());
insertStmt.executeUpdate();
conn.commit();
...
It seems to works fine.

If I retrieve the inserted Blob from the database it's length is the
value of the limit field not the length() value.

So it seems I can use this kind of workaround to insert unknown length
data in the db. The driver seems to ignore the length() value when
inserting the data with the getBinaryStream().

Am I correct? If so it would be great. I will only use the custom Blob
implement for insertions and updates.

But are they some potential problem if I use this kind of implementation
the way I describe it?

Thanks

Oscar



В списке pgsql-jdbc по дате отправления:

Предыдущее
От: "Hina Chauhan"
Дата:
Сообщение: max connection
Следующее
От: Mark Lewis
Дата:
Сообщение: Re: max connection