[Pljava-dev] PLJAVA Trigger Function more arguments

Lists: PostgreSQL : PostgreSQL 메일 링리스트 : 2005-11-02 이후 배트맨 토토Dev 13:50
From: ilazaro at tekniker(dot)es ( Ignacio Lázaro )
To:
Subject: [Pljava-dev] PLJAVA Trigger Function more arguments
Date: 2005-11-02 13:34:02
Message-ID: 5234B8D9C36F9E4D9B1AF01013708B6B0152C01B@txindoki.tekniker.es
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pljava-dev

Hello Thomas

My intention is define a trigger in a table, that execute a java method defined in a java class 'tekniker.udpip.SendUdpMessage.sendudpmessagetr'

The way in which I have defined the trigger is with the TRIGGER tu_elementos_instalacion_monitorizar_tr and the FUNCTION sendudpmessagetr (that is associated to the java class).

I need to pass to the method of the java class 2 additional arguments ( stored in a table of the database ) but I don?t know which is the way to define this in the TRIGGER tu_elementos_instalacion_monitorizar_tr or in the FUNCTION sendudpmessagetr, perhaps there is other way more efficient to do

Probably I can define this

CREATE TRIGGER tu_elementos_instalacion_monitorizar_tr
AFTER UPDATE
ON elementos_instalacion_monitorizar
FOR EACH ROW
EXECUTE PROCEDURE sendudpmessagetr(varchar,varchar);

but how can I define the values for both varchar arguments

Best Regards
Nacho

-----Mensaje original-----
De: Thomas Hallgren [mailto:thomas at tada.se]
Enviado el: mi?rcoles, 02 de noviembre de 2005 14:18
Para: Ignacio L?zaro
CC: pljava-dev at gborg.postgresql.org
Asunto: Re: [Pljava-dev] PLJAVA Trigger Function more arguments

Nacho wrote:
> Hello
>
> I have a question, I have defined a java trigger and I want send from
> PostgreSQL more arguments than the TriggerData object
>
> I have the following code
>
> CREATE TRIGGER tu_elementos_instalacion_monitorizar_tr
> AFTER UPDATE
> ON elementos_instalacion_monitorizar
> FOR EACH ROW
> EXECUTE PROCEDURE sendudpmessagetr('valor');
>
> CREATE OR REPLACE FUNCTION sendudpmessagetr()
> RETURNS "trigger" AS
> 'tekniker.udpip.SendUdpMessage.sendudpmessagetr'
> LANGUAGE 'javau' VOLATILE;
> ALTER FUNCTION sendudpmessagetr() OWNER TO optemi;
>
> public static void sendudpmessagetr(TriggerData td) throws SQLException{...}
>
> My question is that if is it possible define
>
> public static void sendudpmessagetr(TriggerData td, String str1, String str2)
> throws SQLException{...}
>
> Or if it is possible to define inside the TriggerData more arguments because I
> have see in documentation that is avaliable the getArguments() method, but I
> don?t know how define these new arguments in the TRIGGER function
>
I'm not sure I understand the question. The TriggerData.getArguments()
will return an array of strings. There's no limit to the number of
strings. These strings are the arguments that you define in your EXECUTE
PROCEDURE xxx(arg1, arg2, arg3). In your case you can do

String[] args = td.getArguments();
if(td[0].equals("valor")) { ... }

But perhaps you're after something completely different?

Regards,
Thomas Hallgren


From: thomas at tada(dot)se (Thomas Hallgren)
To:
Subject: [Pljava-dev] PLJAVA Trigger Function more arguments
Date: 2005-11-02 13:50:20
Message-ID: 4368C41C.4010408@tada.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: PostgreSQL : PostgreSQL 메일 링리스트 : 2005-11-02 이후 배트맨 토토Dev 13:50

Ignacio L?zaro wrote:
> Hello Thomas
>
> My intention is define a trigger in a table, that execute a java method defined in a java class 'tekniker.udpip.SendUdpMessage.sendudpmessagetr'
>
> The way in which I have defined the trigger is with the TRIGGER tu_elementos_instalacion_monitorizar_tr and the FUNCTION sendudpmessagetr (that is associated to the java class).
>
> I need to pass to the method of the java class 2 additional arguments ( stored in a table of the database ) but I don?t know which is the way to define this in the TRIGGER tu_elementos_instalacion_monitorizar_tr or in the FUNCTION sendudpmessagetr, perhaps there is other way more efficient to do
>
> Probably I can define this
>
> CREATE TRIGGER tu_elementos_instalacion_monitorizar_tr
> AFTER UPDATE
> ON elementos_instalacion_monitorizar
> FOR EACH ROW
> EXECUTE PROCEDURE sendudpmessagetr(varchar,varchar);
>
> but how can I define the values for both varchar arguments
>
I don't understand. Let's say you issue the following statement:

UPDATE elementos_instalacion_monitorizar SET xyz = 'abc' WHERE foo = 'bar';

This will trigger a call to your trigger. How did you plan to select
stuff from 'a table in the database' and pass parameters at that point?
PostgreSQL allows you to set fixed values which makes sense. Different
CREATE TRIGGER can appoint the same PROCEDURE but use different fixed
arguments.

Can you give me an example on how you would like to pass your values?
Just use SQL and forget about PL/Java for a moment.

Regards,
Thomas Hallgren