pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Roy Smith <roy.smith@primetext.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: "create type" custom types not supported by JDBC
Date: Sun, 02 Dec 2007 09:24:44 +0000
Message-ID: <475279DC.8050109@primetext.com> (raw)
In-Reply-To: <13658722.71591196500766061.JavaMail.root@fh1>
References: <475112C4.9060403@primetext.com>
	<Pine.BSO.4.64.0712010330160.12362@leary.csoft.net>
	<13658722.71591196500766061.JavaMail.root@fh1>

Thanks for the pointer Kris.
It's now working.

For the sake of anybody trying the same, here's what I did ...

In the database:-
create type couk_cleverthinking_gwappo_db_Money as (local_value 
numeric(11,2),mnemonic char(3), exchange_rate numeric(9,5),base_value 
numeric(11,2));
CREATE TABLE prices (price couk_cleverthinking_gwappo_db_Money);
insert into prices values(ROW(100,'PHP',.943,0.94));
select * from prices;
        price        
----------------------
 (100.00,PHP,0.943,0.94)


My Custom class is:-
public class Money extends PGobject implements SQLData, Serializable{
    public Money() {
        setType("couk_cleverthinking_gwappo_db_money");
    }
    public Money(String _value) {
        setType("couk_cleverthinking_gwappo_db_money");
    ... stuff ...
    }
... stuff ...
}

To use it I do :-
            Connection conn = DriverManager.getConnection(url, userName, 
password);
            ((PGConnection) 
conn).addDataType("couk_cleverthinking_gwappo_db_money",Class.forName("couk.cleverthinking.gwappo.db.Money"));
            Money m2 = new Money("(100,USD,0.534,0.53)");
            PreparedStatement pst;
            pst = conn.prepareStatement("insert into prices values(?)");
            pst.setObject(1,m2);


I do have a follow up question about how this might all work in a JPA 
layer (Oracle Toplink). That's another post :-)

Many thanks




Kris Jurka wrote:
> On Sat, 1 Dec 2007, Kris Jurka wrote:
>>> Poking around the source code of AbstractJdbc2Connection it looks 
>>> like this functionality isn't support. Perhaps an "Unsupported 
>>> feature" error would be more helpful than a ClassCastException.
> I've put a fix for this into CVS.




view thread (4+ messages)

Message-ID: <475279DC.8050109@primetext.com>
Permalink:  ../475279DC.8050109@primetext.com/
Also on:    postgresql.org/message-id/475279DC.8050109@primetext.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: roy.smith@primetext.com
  Subject: Re: "create type" custom types not supported by JDBC
  In-Reply-To: <475279DC.8050109@primetext.com>
  References: <475112C4.9060403@primetext.com> <Pine.BSO.4.64.0712010330160.12362@leary.csoft.net> <13658722.71591196500766061.JavaMail.root@fh1> <475279DC.8050109@primetext.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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