agora inbox for pljava-dev@postgresql.org  
help / color / mirror / Atom feed
[Pljava-dev] Custom java objects
2+ messages / 0 participants
[nested] [flat]

* [Pljava-dev] Custom java objects
@ 2006-08-08 13:51 
  2006-08-14 22:44 ` [Pljava-dev] Custom java objects 
  0 siblings, 1 reply; 2+ messages in thread

From:  @ 2006-08-08 13:51 UTC (permalink / raw)

Hello,

I try to write aggregate function in Java for PostgeeSQL 8.1.

I just want to know, are there any ways to pass custom java objects
thorough iterations of row handler?

For example, I have functions in PostgreSQL (a is a table):

CREATE FUNCTION handler1(a, a)
returns a
as 'functions.handler1'
immutable language java;

CREATE FUNCTION handler2(a)
returns a
as 'functions.handler2'
immutable language java;

CREATE AGGREGATE aa ( BASETYPE = a, SFUNC = handler1, STYPE = a, FINALFUNC = handler2);


And two functions in Java:

    public static boolean handler1(ResultSet a, ResultSet record, ResultSet result) throws Exception {
        int v = a == null ? Integer.MIN_VALUE : a.getInt(1);
        if (record.getInt(1) > v) {
            result.updateInt(1, record.getInt(1));
            result.updateString(2, record.getString(2));
        } else {
            result.updateInt(1, a.getInt(1));
            result.updateString(2, a.getString(2));
        }
        return true;
    }

    public static boolean handler2(ResultSet a, ResultSet result) throws Exception {
        if (a == null) return false;
        result.updateInt(1, a.getInt(1));
        result.updateString(2, a.getString(2));
        return true;
    }

    
I Just want to use custom java object instead of "ResultSet a".



-- 
Best regards,
 Maxim Karavaev,
 ISP RAS (www.ispras.ru)







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

* [Pljava-dev] Custom java objects
  2006-08-08 13:51 [Pljava-dev] Custom java objects 
@ 2006-08-14 22:44 ` 
  0 siblings, 0 replies; 2+ messages in thread

From:  @ 2006-08-14 22:44 UTC (permalink / raw)

Hi Maxim,
You should be able to do this by just installing a custom type mapping for type 'a'. See: 
http://wiki.tada.se/wiki/display/pljava/Mapping+an+SQL+type+to+a+Java+class

Regards,
Thomas Hallgren

Maxim wrote:
> Hello,
> 
> I try to write aggregate function in Java for PostgeeSQL 8.1.
> 
> I just want to know, are there any ways to pass custom java objects
> thorough iterations of row handler?
> 
> For example, I have functions in PostgreSQL (a is a table):
> 
> CREATE FUNCTION handler1(a, a)
> returns a
> as 'functions.handler1'
> immutable language java;
> 
> CREATE FUNCTION handler2(a)
> returns a
> as 'functions.handler2'
> immutable language java;
> 
> CREATE AGGREGATE aa ( BASETYPE = a, SFUNC = handler1, STYPE = a, FINALFUNC = handler2);
> 
> 
> And two functions in Java:
> 
>     public static boolean handler1(ResultSet a, ResultSet record, ResultSet result) throws Exception {
>         int v = a == null ? Integer.MIN_VALUE : a.getInt(1);
>         if (record.getInt(1) > v) {
>             result.updateInt(1, record.getInt(1));
>             result.updateString(2, record.getString(2));
>         } else {
>             result.updateInt(1, a.getInt(1));
>             result.updateString(2, a.getString(2));
>         }
>         return true;
>     }
> 
>     public static boolean handler2(ResultSet a, ResultSet result) throws Exception {
>         if (a == null) return false;
>         result.updateInt(1, a.getInt(1));
>         result.updateString(2, a.getString(2));
>         return true;
>     }
> 
>     
> I Just want to use custom java object instead of "ResultSet a".
> 
> 
> 





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


end of thread, other threads:[~2006-08-14 22:44 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-08-08 13:51 [Pljava-dev] Custom java objects 
2006-08-14 22:44 ` 

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