agora inbox for pljava-dev@postgresql.org  
help / color / mirror / Atom feed
[Pljava-dev] Passing custom java object to PL/Java
4+ messages / 0 participants
[nested] [flat]

* [Pljava-dev] Passing custom java object to PL/Java
@ 2005-10-17 17:38 
  2005-10-17 18:58 ` [Pljava-dev] Passing custom java object to PL/Java 
  2005-10-17 21:45 ` [Pljava-dev] Passing custom java object to PL/Java 
  0 siblings, 2 replies; 4+ messages in thread

From:  @ 2005-10-17 17:38 UTC (permalink / raw)

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




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

* [Pljava-dev] Passing custom java object to PL/Java
  2005-10-17 17:38 [Pljava-dev] Passing custom java object to PL/Java 
@ 2005-10-17 18:58 ` 
  1 sibling, 0 replies; 4+ messages in thread

From:  @ 2005-10-17 18:58 UTC (permalink / raw)

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





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

* [Pljava-dev] Passing custom java object to PL/Java
  2005-10-17 17:38 [Pljava-dev] Passing custom java object to PL/Java 
@ 2005-10-17 21:45 ` 
  2005-10-18 03:05   ` [Pljava-dev] Passing custom java object to PL/Java 
  1 sibling, 1 reply; 4+ messages in thread

From:  @ 2005-10-17 21:45 UTC (permalink / raw)

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
> 
> 
> 





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

* [Pljava-dev] Passing custom java object to PL/Java
  2005-10-17 17:38 [Pljava-dev] Passing custom java object to PL/Java 
  2005-10-17 21:45 ` [Pljava-dev] Passing custom java object to PL/Java 
@ 2005-10-18 03:05   ` 
  0 siblings, 0 replies; 4+ messages in thread

From:  @ 2005-10-18 03:05 UTC (permalink / raw)


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




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


end of thread, other threads:[~2005-10-18 03:05 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-10-17 17:38 [Pljava-dev] Passing custom java object to PL/Java 
2005-10-17 18:58 ` 
2005-10-17 21:45 ` 
2005-10-18 03:05   ` 

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