Re: setBlob loop performance? - Mailing list pgsql-jdbc
From | David Wall |
---|---|
Subject | Re: setBlob loop performance? |
Date | |
Msg-id | 002001c24ea6$55527480$3201a8c0@expertrade.com Whole thread Raw |
In response to | setBlob loop performance? ("David Wall" <dwall@Yozons.com>) |
List | pgsql-jdbc |
> 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@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);
pgsql-jdbc by date: