[Pljava-dev] PLJAVA Trigger Function more arguments

Lists: PostgreSQL : PostgreSQL 메일 링리스트 : 2005-11-02 이후 스포츠 토토 결과Dev 14:03
From: ilazaro at tekniker(dot)es ( Ignacio Lázaro )
To:
Subject: [Pljava-dev] PLJAVA Trigger Function more arguments
Date: 2005-11-02 14:03:43
Message-ID: 5234B8D9C36F9E4D9B1AF01013708B6B0152C03A@txindoki.tekniker.es
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: PostgreSQL : PostgreSQL 메일 링리스트 : 2005-11-02 이후 스포츠 토토 결과Dev 14:03

Hello

I have the table 'elementos_intalacion_monitorizar' with the fields 'value' and 'code'
After one UPDATE of this table I want send a UDP message to a port of a IP with the code and value modified (only if the value has changed)

I have a java class to send a UDP message and the required parameters are IP, port and code&value. IP and port are defined in a table named configuration

So what I need, is to define a trigger that
1- check if the value of the code has really changed
2- get the ip and port from configuration table
3- execute the java class that send the UDP message with the required values

What I have done
1- I have installed in postgreSQL the java class
2- I have defined the TRIGGER and FUNCTION explained before, but as I can understand with your last message and for my tests is that it is not possible get dinamically from a table the ip and port values inside the definition of the trigger

My question at this stage : is there another way of executing a java class from PostgreSQL trigger or function?

Many thanks for your comments
Nacho

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

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


From: thomas at tada(dot)se (Thomas Hallgren)
To:
Subject: [Pljava-dev] PLJAVA Trigger Function more arguments
Date: 2005-11-02 14:15:03
Message-ID: 4368C9E7.60202@tada.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pljava-dev

Ignacio L?zaro wrote:
> Hello
>
> I have the table 'elementos_intalacion_monitorizar' with the fields 'value' and 'code'
> After one UPDATE of this table I want send a UDP message to a port of a IP with the code and value modified (only if the value has changed)
>
> I have a java class to send a UDP message and the required parameters are IP, port and code&value. IP and port are defined in a table named configuration
>
> So what I need, is to define a trigger that
> 1- check if the value of the code has really changed
> 2- get the ip and port from configuration table
> 3- execute the java class that send the UDP message with the required values
>
> What I have done
> 1- I have installed in postgreSQL the java class
> 2- I have defined the TRIGGER and FUNCTION explained before, but as I can understand with your last message and for my tests is that it is not possible get dinamically from a table the ip and port values inside the definition of the trigger
>
> My question at this stage : is there another way of executing a java class from PostgreSQL trigger or function?
>
>
A trigger has a concept of an 'old' and a 'new' row. What you're after
is the 'new' row, i.e.

ResultSet newRow = td.getNew();
String value = newRow.getString("value");
String code = newRow.getString("code");

Regards,
Thomas Hallgren