Re: setBlob loop performance?

From: Barry Lind <barry(at)xythos(dot)com>
To: David Wall <d(dot)wall(at)computer(dot)org>
Cc: pgsql-jdbc <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: setBlob loop performance?
Date: 2002-09-02 03:15:18
Message-ID: 3D72D7C6.2010009@xythos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

This has been applied to current sources.

--Barry

David Wall wrote:

>>Could you resend this in a diff -c format. Since I don't know the exact
>>version you have it is difficult to pick out the changes. A diff would
>>make that much easier.
>>
>>
>
>Sure. I hope this helps... The 'orig' version was the source included in
>the 7.2.2 download.
>
>David
>
>
>
>[postgresql(at)dev1 jdbc2]$ diff -c PreparedStatement.orig
>PreparedStatement.java
>*** PreparedStatement.orig Mon Jan 14 23:37:33 2002
>--- PreparedStatement.java Tue Aug 27 21:14:02 2002
>***************
>*** 879,907 ****
> public void setBlob(int i, Blob x) throws SQLException
> {
> InputStream l_inStream = x.getBinaryStream();
>- int l_length = (int) x.length();
> LargeObjectManager lom = connection.getLargeObjectAPI();
> int oid = lom.create();
> LargeObject lob = lom.open(oid);
> OutputStream los = lob.getOutputStream();
> try
> {
> // could be buffered, but then the OutputStream
>returned by LargeObject
> // is buffered internally anyhow, so there would be
>no performance
> // boost gained, if anything it would be worse!
>! int c = l_inStream.read();
>! int p = 0;
>! while (c > -1 && p < l_length)
> {
>! los.write(c);
>! c = l_inStream.read();
>! p++;
> }
>- los.close();
> }
> catch (IOException se)
> {
> throw new PSQLException("postgresql.unusual", se);
> }
> // lob is closed by the stream so don't call lob.close()
> setInt(i, oid);
>--- 879,915 ----
> public void setBlob(int i, Blob x) throws SQLException
> {
> InputStream l_inStream = x.getBinaryStream();
> LargeObjectManager lom = connection.getLargeObjectAPI();
> int oid = lom.create();
> LargeObject lob = lom.open(oid);
> OutputStream los = lob.getOutputStream();
>+ byte[] buf = new byte[4096];
> try
> {
> // could be buffered, but then the OutputStream
>returned by LargeObject
> // is buffered internally anyhow, so there would be
>no performance
> // boost gained, if anything it would be worse!
>! int bytesRemaining = (int)x.length();
>! int numRead =
>l_inStream.read(buf,0,Math.min(buf.length,bytesRemaining));
>! while (numRead != -1 && bytesRemaining > 0)
> {
>! bytesRemaining -= numRead;
>! los.write(buf,0,numRead);
>! numRead =
>l_inStream.read(buf,0,Math.min(buf.length,bytesRemaining));
> }
> }
> catch (IOException se)
> {
> throw new PSQLException("postgresql.unusual", se);
>+ }
>+ finally
>+ {
>+ try
>+ {
>+ los.close();
>+ l_inStream.close();
>+ }
>+ catch( Exception e ) {}
> }
> // lob is closed by the stream so don't call lob.close()
> setInt(i, oid);
>
>
>
>
>

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Barry Lind 2002-09-02 03:15:50 Re: JDBC patch, so that bigint indexes get used
Previous Message Barry Lind 2002-09-02 03:14:51 Re: [PATCHES] JDBC timestamp does not understand [-]infinity