Class Triggers
java.lang.Object
org.postgresql.pljava.example.annotation.Triggers
@SQLAction(provides="foobar tables",install={"CREATE TABLE javatest.foobar_1 ( username text, stuff text )","CREATE TABLE javatest.foobar_2 ( username text, value numeric )"},remove={"DROP TABLE javatest.foobar_2","DROP TABLE javatest.foobar_1"}) @SQLAction(requires="constraint triggers",install="INSERT INTO javatest.foobar_2(value) VALUES (45)") @SQLAction(requires="foobar triggers",provides="foobar2_42",install="INSERT INTO javatest.foobar_2(value) VALUES (42)") @SQLAction(requires={"transition triggers","foobar2_42"},install="UPDATE javatest.foobar_2 SET value = 43 WHERE value = 42")
public class Triggers
extends Object
Example creating a couple of tables, and a function to be called when
triggered by insertion into either table. In PostgreSQL 10 or later,
also create a function and trigger that uses transition tables.
This example relies on implementor
tags reflecting the PostgreSQL
version, set up in the ConditionalDDR
example. Transition tables
appear in PG 10.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Throw exception if value to be inserted is 44.static void
Examine old and new rows in reponse to a trigger.static void
insert user name in response to a trigger.
-
Constructor Details
-
Triggers
public Triggers()
-
-
Method Details
-
insertUsername
@Function(requires="foobar tables",provides="foobar triggers",schema="javatest",security=INVOKER,triggers={@Trigger(called=BEFORE,table="foobar_1",events=INSERT),@Trigger(called=BEFORE,scope=ROW,table="foobar_2",events=INSERT)}) public static void insertUsername(TriggerData td) throws SQLException insert user name in response to a trigger.- Throws:
SQLException
-
examineRows
@Function(implementor="postgresql_ge_100000", requires="foobar tables", provides="transition triggers", schema="javatest", security=INVOKER, triggers=@Trigger(called=AFTER,table="foobar_2",events=UPDATE,tableOld="oldrows",tableNew="newrows")) public static void examineRows(TriggerData td) throws SQLException Examine old and new rows in reponse to a trigger. Transition tables first became available in PostgreSQL 10.- Throws:
SQLException
-
disallow44
@Function(requires="foobar tables", provides="constraint triggers", schema="javatest", security=INVOKER, triggers=@Trigger(called=AFTER,table="foobar_2",events=INSERT,scope=ROW,constraint=NOT_DEFERRABLE)) public static void disallow44(TriggerData td) throws SQLException Throw exception if value to be inserted is 44.- Throws:
SQLException
-