Class ConnectionTriggerManager


  • public final class ConnectionTriggerManager
    extends java.lang.Object
    A trigger manager on a DatabaseConnection that maintains a list of all triggers set in the database, and the types of triggers they are. This object is closely tied to a DatabaseConnection.

    The trigger manager actually uses a trigger itself to maintain a list of tables that have triggers, and the action to perform on the trigger.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private DatabaseConnection connection
      The DatabaseConnection.
      private boolean list_validated
      If this is false then the list is not validated and must be refreshed when we next access trigger information.
      private boolean trigger_modified
      True if the trigger table was modified during the last transaction.
      private java.util.ArrayList triggers_active
      The list of triggers currently in view.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void buildTriggerList()
      Build the trigger list if it is not validated.
      (package private) static InternalTableInfo createInternalTableInfo​(Transaction transaction)
      Returns an InternalTableInfo object used to model the list of triggers that are accessible within the given Transaction object.
      void createTableTrigger​(java.lang.String schema, java.lang.String name, int type, TableName on_table, java.lang.String procedure_name, TObject[] params)
      Creates a new trigger action on a stored procedure and makes the change to the transaction of this DatabaseConnection.
      void dropTrigger​(java.lang.String schema, java.lang.String name)
      Drops a trigger that has previously been defined.
      private Table findTrigger​(QueryContext context, DataTable table, java.lang.String schema, java.lang.String name)
      Returns a Table object that contains the trigger information with the given name.
      private void invalidateTriggerList()
      Invalidates the trigger list causing the list to rebuild when a potential triggering event next occurs.
      (package private) void performTriggerAction​(TableModificationEvent evt)
      Performs any trigger action for this event.
      boolean triggerExists​(java.lang.String schema, java.lang.String name)
      Returns true if the trigger exists, false otherwise.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • triggers_active

        private java.util.ArrayList triggers_active
        The list of triggers currently in view. (TriggerInfo)
      • list_validated

        private boolean list_validated
        If this is false then the list is not validated and must be refreshed when we next access trigger information.
      • trigger_modified

        private boolean trigger_modified
        True if the trigger table was modified during the last transaction.
    • Constructor Detail

      • ConnectionTriggerManager

        ConnectionTriggerManager​(DatabaseConnection connection)
        Constructs the manager.
    • Method Detail

      • findTrigger

        private Table findTrigger​(QueryContext context,
                                  DataTable table,
                                  java.lang.String schema,
                                  java.lang.String name)
        Returns a Table object that contains the trigger information with the given name. Returns an empty table if no trigger found.
      • createTableTrigger

        public void createTableTrigger​(java.lang.String schema,
                                       java.lang.String name,
                                       int type,
                                       TableName on_table,
                                       java.lang.String procedure_name,
                                       TObject[] params)
                                throws DatabaseException
        Creates a new trigger action on a stored procedure and makes the change to the transaction of this DatabaseConnection. If the connection is committed then the trigger is made a perminant change to the database.
        Parameters:
        schema - the schema name of the trigger.
        name - the name of the trigger.
        type - the type of trigger.
        procedure_name - the name of the procedure to execute.
        params - any constant parameters for the triggering procedure.
        Throws:
        DatabaseException
      • dropTrigger

        public void dropTrigger​(java.lang.String schema,
                                java.lang.String name)
                         throws DatabaseException
        Drops a trigger that has previously been defined.
        Throws:
        DatabaseException
      • triggerExists

        public boolean triggerExists​(java.lang.String schema,
                                     java.lang.String name)
        Returns true if the trigger exists, false otherwise.
      • invalidateTriggerList

        private void invalidateTriggerList()
        Invalidates the trigger list causing the list to rebuild when a potential triggering event next occurs.

        NOTE: must only be called from the thread that owns the DatabaseConnection.

      • buildTriggerList

        private void buildTriggerList()
        Build the trigger list if it is not validated.
      • performTriggerAction

        void performTriggerAction​(TableModificationEvent evt)
        Performs any trigger action for this event. For example, if we have it setup so a trigger fires when there is an INSERT event on table x then we perform the triggering procedure right here.
      • createInternalTableInfo

        static InternalTableInfo createInternalTableInfo​(Transaction transaction)
        Returns an InternalTableInfo object used to model the list of triggers that are accessible within the given Transaction object. This is used to model all triggers that have been defined as tables.