I have a PostgreSQL server and I need to run some code whenever an update happens on some table. The PostgreSQL triggers (using PL/java) allows me to call a static java method. The method I need to execute does an RPC to an external server with the information about what the update was.
What I couldn't figure out is how I can create a global resource (in this case, the network conection with the external server) which persists across calls.
One way is probably to create a static variables for the global resources. When my trigger method is called the first time, initialize those variables. In subsequent calls just use it. Will this work, and is there any other way?
What I would have loved is a general trigger interface which I could implement for my trigger.
Even if you'd do it - it would be "global" only for given session - not across many sessions.
But - the point is moot, because, as I see it, the approach it wrong.
Instead of adding trigger which connects to external system, I would much rather: