Re: User Defined Types in Java

From: Thomas Hallgren <thomas(at)tada(dot)se>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: User Defined Types in Java
Date: 2006-02-09 15:41:35
Message-ID: 43EB62AF.5030206@tada.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:
> Thomas Hallgren <thomas(at)tada(dot)se> writes:
>
>> Tom Lane wrote:
>>
>>> In particular, it seems unsafe to use a Java class as a PG UDT,
>>> because the method pointers wouldn't remain the same across
>>> backend runs.
>>>
>>>
>> I'm not sure I understand what you mean.
>>
>
> Doesn't a Java object contain a method-table pointer that is used at
> runtime to dispatch method calls on the object? If the object is dumped
> bitwise into a PG table, and then reloaded into another backend session
> (which maybe has loaded Java at different addresses), that pointer will
> be invalid.
>
Ah, now I understand. I'm not planning on using the binary image of the
Java object as such. There's no API that would allow me to do that (JNI
uses handles, not pointers).

Java has a number of standards for how objects can be
serialized/deserialized in a safe, JVM independent way. If the class of
the object is known at all times (as it will be for all UDT's), I can
use a DataInputStream/DataOutputStream pair to read/write data. It's
very similar to how the complex example type uses pg_sendxxx and
pg_getmsgxxx functions. The Java implementation of that example will
also use 16 bytes for storage.

More complex types can use the standard Java serialization mechanism. It
will waste some more space (must be declared variable in length) but it
maintains data integrity over time through serialVersionUUID's (a 64 bit
number generated based on the constitution of the class).

JDBC defines a standard that involves usage of three different
interfaces, SQLData, SQLInput, and SQLOutput. I plan to support that also.

Kind Regards,
Thomas Hallgren

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Mark Woodward 2006-02-09 15:53:33 Re: PostgreSQL 8.0.6 crash
Previous Message Tom Lane 2006-02-09 15:36:15 Re: PostgreSQL 8.0.6 crash