Lists: | pljava-dev |
---|
From: | rakesh at rakeshv(dot)org (Rakesh Vidyadharan) |
---|---|
To: | |
Subject: | [Pljava-dev] Passing custom java object to PL/Java |
Date: | 2005-10-17 17:38:57 |
Message-ID: | 1B4E0340-B59B-4152-B6AF-3862B5EF1845@rakeshv.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pljava-dev |
Is it possible to pass custom Java objects to PL/Java (the reverse of
passing from PL/Java to client programs? The error I get seems to
indicate that the custom data type I defined in the deployment
descriptor is not recognised when I do the setType on PGobject.
I tried to do so as shown in the following files:
http://www.rakeshv.org/tmp/test.java - wrapper program that does the
JDBC invocation from client code.
http://www.rakeshv.org/tmp/RecurrenceTest.java - The PL/Java utility
class
http://www.rakeshv.org/tmp/Recurrence.java - The custom data that is
passed from client to server.
http://www.rakeshv.org/tmp/DeploymentDescriptor.ddr - The deployment
descriptor
The following is the stack trace from the program:
org.postgresql.util.PSQLException: Unknown type testType.
at org.postgresql.jdbc2.AbstractJdbc2Statement.setPGobject
(AbstractJdbc2Statement.java:1480)
at org.postgresql.jdbc2.AbstractJdbc2Statement.setObject
(AbstractJdbc2Statement.java:1616)
at org.postgresql.jdbc3.AbstractJdbc3Statement.setObject
(AbstractJdbc3Statement.java:1436)
at org.postgresql.jdbc2.AbstractJdbc2Statement.setObject
(AbstractJdbc2Statement.java:1627)
at test.main(test.java:26)
Rakesh
From: | thomas(dot)hallgren at home(dot)se (Thomas Hallgren) |
---|---|
To: | |
Subject: | [Pljava-dev] Passing custom java object to PL/Java |
Date: | 2005-10-17 18:58:53 |
Message-ID: | 4353F46D.2050603@home.se |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pljava-dev |
rakesh at rakeshv.org wrote:
> Is it possible to pass custom Java objects to PL/Java (the reverse of
> passing from PL/Java to client programs? The error I get seems to
> indicate that the custom data type I defined in the deployment
> descriptor is not recognised when I do the setType on PGobject.
I doubt that the error you get is related to PL/Java. The stack trace
indicates a problem with setObject in the client, not the server. But
even if you do get around sending a UDT to PL/Java, it will not be
accepted at present. The PL/Java type-system needs some more work.
Regards,
Thomas Hallgren
>
> I tried to do so as shown in the following files:
>
> http://www.rakeshv.org/tmp/test.java - wrapper program that does the
> JDBC invocation from client code.
>
> http://www.rakeshv.org/tmp/RecurrenceTest.java - The PL/Java utility
> class
>
> http://www.rakeshv.org/tmp/Recurrence.java - The custom data that is
> passed from client to server.
>
> http://www.rakeshv.org/tmp/DeploymentDescriptor.ddr - The deployment
> descriptor
>
> The following is the stack trace from the program:
>
> org.postgresql.util.PSQLException: Unknown type testType.
> at
> org.postgresql.jdbc2.AbstractJdbc2Statement.setPGobject(AbstractJdbc2Statement.java:1480)
>
> at
> org.postgresql.jdbc2.AbstractJdbc2Statement.setObject(AbstractJdbc2Statement.java:1616)
>
> at
> org.postgresql.jdbc3.AbstractJdbc3Statement.setObject(AbstractJdbc3Statement.java:1436)
>
> at
> org.postgresql.jdbc2.AbstractJdbc2Statement.setObject(AbstractJdbc2Statement.java:1627)
>
> at test.main(test.java:26)
>
> Rakesh
> _______________________________________________
> Pljava-dev mailing list
> Pljava-dev at gborg.postgresql.org
> http://gborg.postgresql.org/mailman/listinfo/pljava-dev
From: | pmichalek at click(dot)cz ( Petr Michálek ) |
---|---|
To: | |
Subject: | [Pljava-dev] Passing custom java object to PL/Java |
Date: | 2005-10-17 21:45:05 |
Message-ID: | 43541B61.8040400@click.cz |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pljava-dev |
Hi!
I don't know, if I'm right, but try to serialize object Recurrence like
this:
CLIENT SIDE:
============
class Recurrence implements Serializable //...should be enough
{
...
}
Recurrence rec = ....;
ByteArrayOutputStream baos = new ...;
ObjectOutputStream oos = new ObjectOutputStream( baos );
oos.writeObject( rec );
oos.close();
byte[] value = baos.toByteArray();
statement.setBinaryStream( i++, new
ByteArrayInputStream(value),value.length); // Try use type BLOB!
// I don't know if this is most effective methond, how to pass BLOB
argument to JDBC statement...
SERVER SIDE:
============
....
Recurrence rec = (Recurrence)new ObjectInputStream( byteArrayInputStream
).readObject();
Try it and tell us if such method works!
If it throws SerializebleException, try to pass simpler argument like
string and so on.
Regards
Petr Michalek
Rakesh Vidyadharan wrote:
> Is it possible to pass custom Java objects to PL/Java (the reverse of
> passing from PL/Java to client programs? The error I get seems to
> indicate that the custom data type I defined in the deployment
> descriptor is not recognised when I do the setType on PGobject.
>
> I tried to do so as shown in the following files:
>
> http://www.rakeshv.org/tmp/test.java - wrapper program that does the
> JDBC invocation from client code.
>
> http://www.rakeshv.org/tmp/RecurrenceTest.java - The PL/Java utility class
>
> http://www.rakeshv.org/tmp/Recurrence.java - The custom data that is
> passed from client to server.
>
> http://www.rakeshv.org/tmp/DeploymentDescriptor.ddr - The deployment
> descriptor
>
> The following is the stack trace from the program:
>
> org.postgresql.util.PSQLException: Unknown type testType.
> at org.postgresql.jdbc2.AbstractJdbc2Statement.setPGobject
> (AbstractJdbc2Statement.java:1480)
> at org.postgresql.jdbc2.AbstractJdbc2Statement.setObject
> (AbstractJdbc2Statement.java:1616)
> at org.postgresql.jdbc3.AbstractJdbc3Statement.setObject
> (AbstractJdbc3Statement.java:1436)
> at org.postgresql.jdbc2.AbstractJdbc2Statement.setObject
> (AbstractJdbc2Statement.java:1627)
> at test.main(test.java:26)
>
> Rakesh
> _______________________________________________
> Pljava-dev mailing list
> Pljava-dev at gborg.postgresql.org
> http://gborg.postgresql.org/mailman/listinfo/pljava-dev
>
>
>
From: | rakesh at rakeshv(dot)org (Rakesh Vidyadharan) |
---|---|
To: | |
Subject: | [Pljava-dev] Passing custom java object to PL/Java |
Date: | 2005-10-18 03:05:30 |
Message-ID: | 127953D5-2CBD-4DFE-85CB-DEF2B131900B@rakeshv.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pljava-dev |
On 17 Oct 2005, at 16:45, Petr Mich?lek wrote:
> Hi!
>
> I don't know, if I'm right, but try to serialize object Recurrence
> like this:
>
> CLIENT SIDE:
> ============
> class Recurrence implements Serializable //...should be enough
> {
> ...
> }
>
> Recurrence rec = ....;
> ByteArrayOutputStream baos = new ...;
> ObjectOutputStream oos = new ObjectOutputStream( baos );
> oos.writeObject( rec );
> oos.close();
>
> byte[] value = baos.toByteArray();
> statement.setBinaryStream( i++, new ByteArrayInputStream
> (value),value.length); // Try use type BLOB!
> // I don't know if this is most effective methond, how to pass BLOB
> argument to JDBC statement...
>
>
> SERVER SIDE:
> ============
> ....
> Recurrence rec = (Recurrence)new ObjectInputStream
> ( byteArrayInputStream ).readObject();
>
>
> Try it and tell us if such method works!
>
> If it throws SerializebleException, try to pass simpler argument
> like string and so on.
>
> Regards
> Petr Michalek
Thanks Petr for your suggestion. It turned out to be unnecessary. I
was indeed thinking of trying raw serialization or using something
like XStream to convert the object into an XML representation and
parsing it back on the server (less efficient but easier to debug).
It turns out that the first problem with my test program was that I
was specifying the type as "testType" and not "testtype", to which
Postgres converted the name in the typname column of
pg_catalog.pg_type. Once I fixed that issue, I was able to send the
object through to the server. The server "nicely" returned an error
message saying it could not find the appropriate method:
java.sql.SQLException: ERROR: Unable to find static method
RecurrenceTest.test with signature (Ljava/sql/ResultSet;)I
That was all the information I needed :-)
I just updated my static method to take as parameter a ResultSet, and
then just walked the ResultSet to get the values I had set. Ability
to use ResultSetMetaData would have been nice, but since I know the
structure of the data I am passing I can easily work without it.
I have updated the source files at the URL's I posted initially with
the working code in case anyone is interested. I only wish it had
been this easy to process the result of a setof returned by a PL/Java
function, instead of having to parse the delimited fields out of a
PGObject.getValue() string.
Thanks Thomas and Petr once again for your responses.
Rakesh