Package org.h2.schema

Class TriggerObject

All Implemented Interfaces:
HasSQL

public final class TriggerObject extends SchemaObject
A trigger is created using the statement CREATE TRIGGER
  • Field Details

    • DEFAULT_QUEUE_SIZE

      public static final int DEFAULT_QUEUE_SIZE
      The default queue size.
      See Also:
    • insteadOf

      private boolean insteadOf
    • before

      private boolean before
    • typeMask

      private int typeMask
    • rowBased

      private boolean rowBased
    • onRollback

      private boolean onRollback
    • queueSize

      private int queueSize
    • noWait

      private boolean noWait
    • table

      private Table table
    • triggerClassName

      private String triggerClassName
    • triggerSource

      private String triggerSource
    • triggerCallback

      private Trigger triggerCallback
  • Constructor Details

    • TriggerObject

      public TriggerObject(Schema schema, int id, String name, Table table)
  • Method Details

    • setBefore

      public void setBefore(boolean before)
    • isInsteadOf

      public boolean isInsteadOf()
    • setInsteadOf

      public void setInsteadOf(boolean insteadOf)
    • load

      private void load()
    • loadFromSource

      private Trigger loadFromSource()
    • setTriggerClassName

      public void setTriggerClassName(String triggerClassName, boolean force)
      Set the trigger class name and load the class if possible.
      Parameters:
      triggerClassName - the name of the trigger class
      force - whether exceptions (due to missing class or access rights) should be ignored
    • setTriggerSource

      public void setTriggerSource(String source, boolean force)
      Set the trigger source code and compile it if possible.
      Parameters:
      source - the source code of a method returning a Trigger
      force - whether exceptions (due to syntax error) should be ignored
    • setTriggerAction

      private void setTriggerAction(String triggerClassName, String source, boolean force)
    • fire

      public void fire(SessionLocal session, int type, boolean beforeAction)
      Call the trigger class if required. This method does nothing if the trigger is not defined for the given action. This method is called before or after any rows have been processed, once for each statement.
      Parameters:
      session - the session
      type - the trigger type
      beforeAction - if this method is called before applying the changes
    • convertToObjectList

      private static Object[] convertToObjectList(Row row, JdbcConnection conn)
    • fireRow

      public boolean fireRow(SessionLocal session, Table table, Row oldRow, Row newRow, boolean beforeAction, boolean rollback)
      Call the fire method of the user-defined trigger class if required. This method does nothing if the trigger is not defined for the given action. This method is called before or after a row is processed, possibly many times for each statement.
      Parameters:
      session - the session
      table - the table
      oldRow - the old row
      newRow - the new row
      beforeAction - true if this method is called before the operation is applied
      rollback - when the operation occurred within a rollback
      Returns:
      true if no further action is required (for 'instead of' triggers)
    • createResultSet

      private static JdbcResultSet createResultSet(JdbcConnection conn, Table table, Row row, boolean updatable) throws SQLException
      Throws:
      SQLException
    • getErrorExecutingTrigger

      private DbException getErrorExecutingTrigger(Throwable e)
    • getTypeMask

      public int getTypeMask()
      Returns the trigger type.
      Returns:
      the trigger type
    • setTypeMask

      public void setTypeMask(int typeMask)
      Set the trigger type.
      Parameters:
      typeMask - the type
    • setRowBased

      public void setRowBased(boolean rowBased)
    • isRowBased

      public boolean isRowBased()
    • setQueueSize

      public void setQueueSize(int size)
    • getQueueSize

      public int getQueueSize()
    • setNoWait

      public void setNoWait(boolean noWait)
    • isNoWait

      public boolean isNoWait()
    • setOnRollback

      public void setOnRollback(boolean onRollback)
    • isOnRollback

      public boolean isOnRollback()
    • getCreateSQLForCopy

      public String getCreateSQLForCopy(Table targetTable, String quotedName)
      Description copied from class: DbObject
      Build a SQL statement to re-create the object, or to create a copy of the object with a different name or referencing a different table
      Specified by:
      getCreateSQLForCopy in class DbObject
      Parameters:
      targetTable - the new table
      quotedName - the quoted name
      Returns:
      the SQL statement
    • getTypeNameList

      public StringBuilder getTypeNameList(StringBuilder builder)
      Append the trigger types to the given string builder.
      Parameters:
      builder - the builder
      Returns:
      the passed string builder
    • getCreateSQL

      public String getCreateSQL()
      Description copied from class: DbObject
      Construct the CREATE ... SQL statement for this object.
      Specified by:
      getCreateSQL in class DbObject
      Returns:
      the SQL statement
    • getType

      public int getType()
      Description copied from class: DbObject
      Get the object type.
      Specified by:
      getType in class DbObject
      Returns:
      the object type
    • removeChildrenAndResources

      public void removeChildrenAndResources(SessionLocal session)
      Description copied from class: DbObject
      Delete all dependent children objects and resources of this object.
      Specified by:
      removeChildrenAndResources in class DbObject
      Parameters:
      session - the session
    • getTable

      public Table getTable()
      Get the table of this trigger.
      Returns:
      the table
    • isBefore

      public boolean isBefore()
      Check if this is a before trigger.
      Returns:
      true if it is
    • getTriggerClassName

      public String getTriggerClassName()
      Get the trigger class name.
      Returns:
      the class name
    • getTriggerSource

      public String getTriggerSource()
    • close

      public void close() throws SQLException
      Close the trigger.
      Throws:
      SQLException - on failure
    • isSelectTrigger

      public boolean isSelectTrigger()
      Check whether this is a select trigger.
      Returns:
      true if it is