Class TriggerManager


  • final class TriggerManager
    extends java.lang.Object
    An object that manages high level trigger events within a Database context. This manager is designed to manage the map between session and triggers being listened for. It is the responsibility of the language parsing layer to notify this manager of trigger events.

    NOTE: It is intended that this object manages events from the highest layer, so it is possible that trigger events may not get to be notified if queries are not evaluated properly.

    NOTE: This object serves a different purpose than DataTableListener. DataTableListener is guarenteed to pick up all low level access to the tables. This object is only intended as a helper for implementing a trigger event dispatcher by a higher level package (eg. com.mckoi.database.sql)

    CONCURRENCY: This class is thread safe. It may safely be accessed by multiple threads. Any events that are fired are put on the DatabaseDispatcher thread.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  TriggerManager.TriggerAction
      Encapsulates the information of a trigger listener for a specific event for a user.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private HashMapList listener_map
      Maps from the user session (User) to the list of TriggerAction objects for this user.
      private TransactionSystem system
      The parent TransactionSystem object.
      private HashMapList table_map
      Maps from the trigger source string to the list of TriggerAction objects that are listening for events from this source.
    • Field Detail

      • listener_map

        private HashMapList listener_map
        Maps from the user session (User) to the list of TriggerAction objects for this user.
      • table_map

        private HashMapList table_map
        Maps from the trigger source string to the list of TriggerAction objects that are listening for events from this source.
    • Method Detail

      • flushTriggerEvents

        void flushTriggerEvents​(java.util.ArrayList event_list)
        Flushes the list of TriggerEvent objects and dispatches them to the users that are listening. This is called after the given connection has successfully committed and closed.
      • addTriggerListener

        void addTriggerListener​(DatabaseConnection database,
                                java.lang.String trigger_name,
                                int event_id,
                                java.lang.String trigger_source,
                                TriggerListener listener)
        Adds a listener for an event with the given 'id' for this user session.

        For example,
        addTriggerListener(user, "my_trigger", TriggerEvent.UPDATE, "Part", my_listener);

        This listener is notified of all update events on the 'Part' table.

      • removeTriggerListener

        void removeTriggerListener​(DatabaseConnection database,
                                   java.lang.String trigger_name)
        Removes a trigger for the given user session.
      • clearAllDatabaseConnectionTriggers

        void clearAllDatabaseConnectionTriggers​(DatabaseConnection database)
        Clears all the user triggers that have been defined.
      • fireTrigger

        private void fireTrigger​(TriggerEvent evt)
        Notifies all the listeners on a trigger_source (ie. a table) that a specific type of event has happened, as denoted by the type.
        Parameters:
        trigger_source - the source of the trigger.
        trigger_type - either INSERT, DELETE or UPDATE
        fire_count - the number of times the trigger was fired for this event.