Class 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. Constraint triggers appear in PG 9.1, transition tables in PG 10.

    • Constructor Summary

      Constructors 
      Constructor Description
      Triggers()  
    • Method Summary

      Modifier and Type Method Description
      static void disallow44​(org.postgresql.pljava.TriggerData td)
      Throw exception if value to be inserted is 44.
      static void examineRows​(org.postgresql.pljava.TriggerData td)
      Examine old and new rows in reponse to a trigger.
      static void insertUsername​(org.postgresql.pljava.TriggerData td)
      insert user name in response to a trigger.
    • Method Detail

      • 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​(org.postgresql.pljava.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​(org.postgresql.pljava.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(implementor="postgresql_ge_90100",
                  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​(org.postgresql.pljava.TriggerData td)
                               throws SQLException
        Throw exception if value to be inserted is 44. Constraint triggers first became available in PostgreSQL 9.1.
        Throws:
        SQLException