pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
PGobject overhaul (was Re: tightening up on use of oid 0)
5+ messages / 3 participants
[nested] [flat]

* PGobject overhaul (was Re: tightening up on use of oid 0)
@ 2004-10-28 02:18  Oliver Jowett <oliver@opencloud.com>
  0 siblings, 3 replies; 5+ messages in thread

From: Oliver Jowett @ 2004-10-28 02:18 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc

Kris Jurka wrote:
> 
> On Thu, 14 Oct 2004, Oliver Jowett wrote:
>   [... PGobject and NULL ...]
>>It's hardly ideal but it kept the changes to a minimum. If you don't 
>>mind a more invasive set of changes, I can probably come up with 
>>something better.
> 
> Yes, let's think about this a little more.  I unfortunately don't have any 
> brilliant ideas, perhaps just adding a boolean everywhere is simplest.

I've applied the non-PGobject bits of this patch.

For PGobject it turned into a bit of a general overhaul. Currently I have:

PGobject layer:

- PGobject becomes an interface
- Implementations of PGobject should provide a ctor taking a single 
String; this is called by the driver to construct non-null objects.
- PGobject.setType() and PGobject.setValue() go away entirely
- A new helper class, PGunknown, provides an immutable type+value 
implementation of PGobject (i.e. 'new PGunknown("mytype","myvalue")'). 
This gives the functionality currently available via PGobject.setType() 
/ setValue, and is used by the driver when it receives an unhandled type 
in a resultset.

PGobject subclasses:

Mutability:
- Generally, classes become immutable where it's easy to do (PGmoney, 
PGinterval, PGpoint, PGline, PGlseg, PGcircle, PGbox)
- PGpoint.translate() returns a new PGpoint rather than modifying the 
existing point (I'm not sure why this method even exists really..)
- Constant-sized PGpoint[] arrays in PGline, PGlseg, PGbox become 
separate fields; this makes immutability much easier.
- PGpolygon and PGpath remain mutable as it's hard to make them 
immutable without incurring lots of array copies.

NULL-handling:
- No-arg ctors construct NULL objects.
- PGmoney and PGpoint get boolean isNull fields, the other types reuse 
an existing reference field.
- equals(), hashCode(), getValue() take account of NULL-ness.
- Add per-class static NULL singleton fields for convenience; for 
mutable types, I'm not sure whether to just omit the singletons 
(slightly less convenient/readable), or to use PGunknown to get an 
immutable NULL (works, but 'instanceof' on NULL becomes misleading).

Much of the mutability changes here are just personal preference, 
they're not necessary to support NULLs but I thought I'd clean things up 
while I was in the area.

When we come to do binary-format types, I'd expect we would have a 
subinterface (PGbinaryobject?) that adds whatever methods are needed for 
binary parameter formatting. Objects that implement PGbinaryobject 
become candidates for binary transfer.

Any thoughts on this general approach?

-O



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: PGobject overhaul (was Re: tightening up on use of oid
@ 2004-10-28 23:33  Oliver Jowett <oliver@opencloud.com>
  parent: Oliver Jowett <oliver@opencloud.com>
  2 siblings, 0 replies; 5+ messages in thread

From: Oliver Jowett @ 2004-10-28 23:33 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc

Oliver Jowett wrote:

> For PGobject it turned into a bit of a general overhaul. Currently I have: [...]

I've put my current changes up at: 
http://visible.randomly.org/pgjdbc/pgjdbc-pgobject-changes.txt

-O



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: PGobject overhaul (was Re: tightening up on use of oid
@ 2004-10-29 16:57  Markus Schaber <schabios@logi-track.com>
  parent: Oliver Jowett <oliver@opencloud.com>
  2 siblings, 0 replies; 5+ messages in thread

From: Markus Schaber @ 2004-10-29 16:57 UTC (permalink / raw)
  To: pgsql-jdbc

Hi, Oliver,

On Thu, 28 Oct 2004 15:18:13 +1300
Oliver Jowett <oliver@opencloud.com> wrote:

> - Implementations of PGobject should provide a ctor taking a single 
> String; this is called by the driver to construct non-null objects.

Is it possible to use a static factory function instead?

This would make it possible to produce different subclasses depending on
the String, which would be useful e. G. for PostGIS, als all the
geometry classes share the same postgres type "geometry".

> When we come to do binary-format types, I'd expect we would have a 
> subinterface (PGbinaryobject?) that adds whatever methods are needed for 
> binary parameter formatting. Objects that implement PGbinaryobject 
> become candidates for binary transfer.

What do you think about the factory / handler object approach that AFAIR
was discussed here some days ago?

So the driver gets registered one PGfactory for every postgres type, and
this factory then has methods to transform objects to text and binary
representation and vice-versa.

This would allow us to read and write instances of third-party defined
classes that don't implement any postgres specific interface.

We still could have a default factory implementation that gets used
whenever any legacy application uses PGObject subclasses.

Markus

-- 
markus schaber | dipl. informatiker
logi-track ag | rennweg 14-16 | ch 8001 zürich
phone +41-43-888 62 52 | fax +41-43-888 62 53
mailto:schabios@logi-track.com | www.logi-track.com



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: PGobject overhaul (was Re: tightening up on use of oid
@ 2004-10-30 15:43  Kris Jurka <books@ejurka.com>
  parent: Oliver Jowett <oliver@opencloud.com>
  2 siblings, 1 reply; 5+ messages in thread

From: Kris Jurka @ 2004-10-30 15:43 UTC (permalink / raw)
  To: Oliver Jowett <oliver@opencloud.com>; +Cc: pgsql-jdbc



On Thu, 28 Oct 2004, Oliver Jowett wrote:

> For PGobject it turned into a bit of a general overhaul. Currently I have:

These changes are way too drastic for something as minor as preventing a 
user from accidentally mutating a NULL PGobject.  These API changes suck 
for both developers and users.  There's no way to make a PGobject 
implementation compile against both 7.4 and 8.0 drivers.  Altering the 
PGline API means user code can't compile against both 7.4 and 8.0 drivers.

If we were providing exciting new features, then maybe, but for now we've
got to find a way to make this work without huge API changes or we should
abandon the whole idea and go back to your original patch.  What
immediately comes to mind is making the PGobject interface an abstract
class with all abstract methods so that a developer can implement a type
that can work with both driver versions.


Kris Jurka



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: PGobject overhaul (was Re: tightening up on use of oid
@ 2004-10-31 02:17  Oliver Jowett <oliver@opencloud.com>
  parent: Kris Jurka <books@ejurka.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Oliver Jowett @ 2004-10-31 02:17 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc

Kris Jurka wrote:
> 
> On Thu, 28 Oct 2004, Oliver Jowett wrote:
> 
> 
>>For PGobject it turned into a bit of a general overhaul. Currently I have:
> 
> 
> These changes are way too drastic for something as minor as preventing a 
> user from accidentally mutating a NULL PGobject.

That wasn't really my motivation. It was a general cleanup of PGobject 
and subclasses. The current implementations leave something to be desired.

> These API changes suck 
> for both developers and users.  There's no way to make a PGobject 
> implementation compile against both 7.4 and 8.0 drivers.  Altering the 
> PGline API means user code can't compile against both 7.4 and 8.0 drivers.

The feedback I got earlier was that changing the PGobject API wasn't a 
big deal and that external users of the API (which seems to boil down to 
PostGIS & co only) would just track the changes. Is this not true?

> If we were providing exciting new features, then maybe, but for now we've
> got to find a way to make this work without huge API changes or we should
> abandon the whole idea and go back to your original patch.  What
> immediately comes to mind is making the PGobject interface an abstract
> class with all abstract methods so that a developer can implement a type
> that can work with both driver versions.

That's possible. I'd almost prefer doing a new interface and having 
PGobject be a completely-abstract implementation of it. Having the 
driver-required bit as an interface makes it much easier to integrate 
into whatever representation of the data is convenient to the application.

This might be moot if we look at a mapping mechanism that is external to 
the data objects themselves, as suggested by Markus.

Either way, I can't really justify spending much more time on this: we 
don't use extension types in our code at all, and there is still an 
(admittedly ugly) way to set NULL values for extension types in the 
existing driver.

-O



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2004-10-31 02:17 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-10-28 02:18 PGobject overhaul (was Re: tightening up on use of oid 0) Oliver Jowett <oliver@opencloud.com>
2004-10-28 23:33 ` Re: PGobject overhaul (was Re: tightening up on use of oid Oliver Jowett <oliver@opencloud.com>
2004-10-29 16:57 ` Re: PGobject overhaul (was Re: tightening up on use of oid Markus Schaber <schabios@logi-track.com>
2004-10-30 15:43 ` Re: PGobject overhaul (was Re: tightening up on use of oid Kris Jurka <books@ejurka.com>
2004-10-31 02:17   ` Re: PGobject overhaul (was Re: tightening up on use of oid Oliver Jowett <oliver@opencloud.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox