Re: setBlob loop performance?

Поиск
Список
Период
Сортировка
От Barry Lind
Тема Re: setBlob loop performance?
Дата
Msg-id 3D72D7C6.2010009@xythos.com
обсуждение исходный текст
Ответ на setBlob loop performance?  ("David Wall" <dwall@Yozons.com>)
Список 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@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 по дате отправления:

Предыдущее
От: Barry Lind
Дата:
Сообщение: Re: [PATCHES] JDBC timestamp does not understand [-]infinity
Следующее
От: Barry Lind
Дата:
Сообщение: Re: JDBC patch, so that bigint indexes get used