X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 55861329C89 for ; Mon, 11 Oct 2004 22:30:45 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 74547-09 for ; Mon, 11 Oct 2004 21:30:34 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id 2A1C032A1A4 for ; Mon, 11 Oct 2004 22:30:35 +0100 (BST) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=opencloud.com) by yass.opencloud.co.nz with asmtp (Exim 3.35 #1 (Debian)) id 1CH7kO-0000c7-00; Tue, 12 Oct 2004 10:30:24 +1300 Message-ID: <416AFB6F.5060600@opencloud.com> Date: Tue, 12 Oct 2004 10:30:23 +1300 From: Oliver Jowett User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Kris Jurka Cc: pgsql-jdbc@postgresql.org Subject: Re: datatype conversion thoughts References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/92 X-Sequence-Number: 11197 Kris Jurka wrote: > I've been looking at a number of driver todo items that are all centered > around converting between datatypes. Specifically adding COPY support, > array handling, composite types (SQLInput/Ouptut), and binary data > transfer. All of these center around converting pg datatypes to Java > types and back. > There are some isses about when and how this conversion happens regarding > excessive object creation or protecting a fixed set of these objects from > multithreaded access, but I just wanted to throw this basic concept out > there for any feedback. The basic concept is good. I was going in roughly the same direction with ParameterList and friends. To avoid threading/object creation issues you might want to look at a strategy/flyweight implementation where the per-type codec objects are stateless and are passed all the context they need, i.e: interface ParameterCodec { String getTextFormat(Object parameter); byte[] getBinaryFormat(Object parameter); void streamAsBinary(Object parameter, PGstream toStream); // etc. } This would also mean you can construct (for example) codec instances for Array types fairly painlessly; you have one instance per element type, configured to delegate to the element's codec for converting the elements. Also, separating the codec from storing the actual parameter data seems like a win when you need to handle Array/COPY/SQLOutput etc, since they all have different requirements. For the ResultSet side and binary data, I was looking at reading the entire DataRow message into a single array and passing array offsets to the codecs. That should help reduce the amount of garbage generation: we'd have one bytearray per row, not one per row per column. For results where we do not yet have a binary-format parser, I realized we can convert them to text on demand fairly easily: issue a "SELECT ?" passing the uninterpretable binary data as the parameter value (with correct type OID), and ask for results in text format. This should hopefully mean we can do binary format results by default without having to do an extra roundtrip to Describe the statement before every execution (to work out which result columns to make binary); you only pay the roundtrip cost when the user asks for a non-binary value, which should hopefully be rare (e.g. external PGobject implementations that haven't been updated for the changes). I've done some more detailed design, mostly in my head at the moment; if you want I can send you more details. -O