Обсуждение: Appending to a large object

Поиск
Список
Период
Сортировка

Appending to a large object

От
Ole Streicher
Дата:
Hi,

sorry for bothering you again.

I want to append some data to a LargeObject, but I could not find out
how to do that. When I simply do

ResultSet rs = queryStmt.executeQuery();
try {
  if (rs.next()) {
    int oid = rs.getInt(1); // or wherever my Id is
    LargeObject obj = lobj.open(oid);
    System.out.println("SIze is " + obj.size();
    OutputStream os = obj.getOutputStream();
    os.write(...); // here I want to append to the existing stream
    obj.close();
    dbConn.commit();
  }
} catch (SQLException e) {
  dbConn.rollBack();
} finally {
  rs.close();
}

It is not appended to the stream but overwritten from the beginning.
The LargeObject defines some variables SEEK_SET, SEEK_END, SEEK_CUR
that seem to be useful for my purpose; however I could not find the
method to use them.

Can you give me a hint how I can append to an existing LargeObject
(using the OutputStream interface)?

Ciao

Ole

P.S. Is there a Java standard API documentation (javadoc-converted)
of the extensions (es. LargeObject handling) available?

Re: Appending to a large object

От
Barry Lind
Дата:
Ole,

The outputstream interface is for reading only.  If you want to append
you are going to need to use the LargeObject interface.  This is
documented in the PostgreSQL Programmer's Guide.  See the section
titled:  PostgreSQL Extensions to the JDBC API.

thanks,
--Barry

Ole Streicher wrote:
> Hi,
>
> sorry for bothering you again.
>
> I want to append some data to a LargeObject, but I could not find out
> how to do that. When I simply do
>
> ResultSet rs = queryStmt.executeQuery();
> try {
>   if (rs.next()) {
>     int oid = rs.getInt(1); // or wherever my Id is
>     LargeObject obj = lobj.open(oid);
>     System.out.println("SIze is " + obj.size();
>     OutputStream os = obj.getOutputStream();
>     os.write(...); // here I want to append to the existing stream
>     obj.close();
>     dbConn.commit();
>   }
> } catch (SQLException e) {
>   dbConn.rollBack();
> } finally {
>   rs.close();
> }
>
> It is not appended to the stream but overwritten from the beginning.
> The LargeObject defines some variables SEEK_SET, SEEK_END, SEEK_CUR
> that seem to be useful for my purpose; however I could not find the
> method to use them.
>
> Can you give me a hint how I can append to an existing LargeObject
> (using the OutputStream interface)?
>
> Ciao
>
> Ole
>
> P.S. Is there a Java standard API documentation (javadoc-converted)
> of the extensions (es. LargeObject handling) available?
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
>                http://archives.postgresql.org
>



Re: Appending to a large object

От
Ole Streicher
Дата:
Hi Barry,

Am Donnerstag, 7. August 2003 04:55 schrieb Barry Lind:
> The outputstream interface is for reading only.  If you want to append
> you are going to need to use the LargeObject interface.  This is
> documented in the PostgreSQL Programmer's Guide.  See the section
> titled:  PostgreSQL Extensions to the JDBC API.

I did; but I couldn't find what I need:

5.7.3.1 Methods

* public int getOID() - doesn't help

* public void close() - doesn't help

* public byte[] read(int len) / public int read(byte[] buf, int off, int len)
  - doesn't help since I need writing, not reading

* public void write (byte[] buf) - doesn't help since I cannot specify the
  offset

* public void write(byte[] buf, int off, int len) - doesn't help since the
  offset mentioned is within the array, not within the LargeObject.

What I expected was a function like "seek()", but I couldn't find it there.
So, how can I append to an existing stream? Is there a function I have just
overseen? (PostgreSQL 7.3.2 Programmer's Guide)

Regards

Ole

Re: Appending to a large object

От
Paul Thomas
Дата:
On 07/08/2003 09:15 Ole Streicher wrote:
>
> What I expected was a function like "seek()", but I couldn't find it
> there.
> So, how can I append to an existing stream? Is there a function I have
> just
> overseen? (PostgreSQL 7.3.2 Programmer's Guide)

seek(int pos, int ref) is there in the source for LargeObject (7.3.3).

HTH

--
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for the Smaller
Business |
| Computer Consultants         |
http://www.thomas-micro-systems-ltd.co.uk   |
+------------------------------+---------------------------------------------+

Re: Appending to a large object

От
Barry Lind
Дата:
Ole,

If you look at the source you will see that there is a seek method.  I
don't know why it isn't in the docs.

thanks,
--Barry

Ole Streicher wrote:
> Hi Barry,
>
> Am Donnerstag, 7. August 2003 04:55 schrieb Barry Lind:
>
>>The outputstream interface is for reading only.  If you want to append
>>you are going to need to use the LargeObject interface.  This is
>>documented in the PostgreSQL Programmer's Guide.  See the section
>>titled:  PostgreSQL Extensions to the JDBC API.
>
>
> I did; but I couldn't find what I need:
>
> 5.7.3.1 Methods
>
> * public int getOID() - doesn't help
>
> * public void close() - doesn't help
>
> * public byte[] read(int len) / public int read(byte[] buf, int off, int len)
>   - doesn't help since I need writing, not reading
>
> * public void write (byte[] buf) - doesn't help since I cannot specify the
>   offset
>
> * public void write(byte[] buf, int off, int len) - doesn't help since the
>   offset mentioned is within the array, not within the LargeObject.
>
> What I expected was a function like "seek()", but I couldn't find it there.
> So, how can I append to an existing stream? Is there a function I have just
> overseen? (PostgreSQL 7.3.2 Programmer's Guide)
>
> Regards
>
> Ole
>