I'm about to start implemention streaming of queries to the server in the
pgsql jdbc drivers when PreparedStatement is used with setBinaryStream...
but before I get started, since I've never contributed before, I wanted to
run it by everyone.

I'm planning on making the following changes:

1. In QueryExecutor.sendQuery, if an object in m_binds is a java.io.Reader,
then instead of calling toString and sending that, I'll read and send the
contents in 16K increments.

2. In AbstractJdbc1Statement.setBinaryStream, instead of delegating to
setBytes, I'll call bind directly, but send a custom java.io.Reader subclass
(which adds the quotes and properly escapes the bytes and such) as the
object.

A couple questions:

- There are a few constants that could probably be tuned for performance
(ie, the size of the buffer used for streaming, and a threshold to avoid the
streaming overhead for very short streams).  Is there a fairly standard way
to handle this stuff in the JDBC drivers?  Should it be made configurable to
the user?  Read from a properties file?  Stored in any specific class as a
constant?

- It seems to be quite a pain that org.postgresql.core.Encoding works only
with String, and can't copy into a provided char[] -- this will mean
creating a large number of String objects during the streaming.  I could fix
this easily with java.nio.CharsetEncoder, but it would make the code
dependent on JDK 1.4.  Not desired?

- If there's a general dislike for runtime testing of object classes among
the developer community, then I could, instead of special-casing Reader in
sendQuery, wrap *all* PreparedStatement parameters in an interface that has
a getReader method, and provide a default non-streaming implementation that
uses StringReader.  This is more intrusive, but I'll go whichever way makes
it more likely for the patch to be committed.

- Am I missing anything?  Is this harder than it seems?  Seems like someone
would have done it already...

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



Fri, 24 Jan 2003 09:56:25 -0700
"Chris Smith" <cdsmith@twu.net>
JDBC drivers and streaming content
Chris,

You will have much better luck on jdbc list, and I have forwarded it
there.

There is no problem with making it jdk1.4 only as long as you only
change the code in the jdbc3 packages. The way the build works they will
only be built if the driver is being build by jdk 1.4.

As far as runtime testing for objects goes, I would try to get this
running first by doing that, then by wrapping the statements. Again, if
you are going to make it jdk 1.4 specific, you can only play in the
jdbc3 package

Dave

On Fri, 2003-01-24 at 11:56, Chris Smith wrote:
> I'm about to start implemention streaming of queries to the server in the
> pgsql jdbc drivers when PreparedStatement is used with setBinaryStream...
> but before I get started, since I've never contributed before, I wanted to
> run it by everyone.
> 
> I'm planning on making the following changes:
> 
> 1. In QueryExecutor.sendQuery, if an object in m_binds is a java.io.Reader,
> then instead of calling toString and sending that, I'll read and send the
> contents in 16K increments.
> 
> 2. In AbstractJdbc1Statement.setBinaryStream, instead of delegating to
> setBytes, I'll call bind directly, but send a custom java.io.Reader subclass
> (which adds the quotes and properly escapes the bytes and such) as the
> object.
> 
> A couple questions:
> 
> - There are a few constants that could probably be tuned for performance
> (ie, the size of the buffer used for streaming, and a threshold to avoid the
> streaming overhead for very short streams).  Is there a fairly standard way
> to handle this stuff in the JDBC drivers?  Should it be made configurable to
> the user?  Read from a properties file?  Stored in any specific class as a
> constant?
> 
> - It seems to be quite a pain that org.postgresql.core.Encoding works only
> with String, and can't copy into a provided char[] -- this will mean
> creating a large number of String objects during the streaming.  I could fix
> this easily with java.nio.CharsetEncoder, but it would make the code
> dependent on JDK 1.4.  Not desired?
> 
> - If there's a general dislike for runtime testing of object classes among
> the developer community, then I could, instead of special-casing Reader in
> sendQuery, wrap *all* PreparedStatement parameters in an interface that has
> a getReader method, and provide a default non-streaming implementation that
> uses StringReader.  This is more intrusive, but I'll go whichever way makes
> it more likely for the patch to be committed.
> 
> - Am I missing anything?  Is this harder than it seems?  Seems like someone
> would have done it already...
> 
> --
> www.designacourse.com
> The Easiest Way to Train Anyone... Anywhere.
> 
> Chris Smith - Lead Software Developer/Technical Trainer
> MindIQ Corporation
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
-- 
Dave Cramer <Dave@micro-automation.net>


24 Jan 2003 14:33:42 -0500
Dave Cramer <Dave@micro-automation.net>
Re: [HACKERS] JDBC drivers and streaming content