An application-wide event handler CFC can be defined to handle callback when any entity is inserted, updated, deleted, or retrieved. This CFC must be configured at the application level as an ORM setting:

ormsettings.evenHandler="X.Y.EventHandler"

The event handler CFC needs to implement the CFIDE.ORM.IEventHandler interface. This CFC gets the callbacks from all persistence-related events and handles them accordingly. In this case, a single CFC handles the events for all the CFCs.
This interface contains the following methods for the event handler CFC:
For application-wide event handler CFC, you need to specify the component name also along with other arguments. 
The methods for application-wide event handler are:

  • preFlush(entity): This method is called before the flush operation is complete. This function can be overridden only in a global event handler for an application. CFCs for individual entities will not get this event call.

  • postFlush(entity): This method is called after the flush operation is complete. This function can be overridden only in a global event handler for an application. CFCs for individual entities will not get this event call.
  • preLoad(entity): This method is called before the load operation or before the data is loaded from the database.
  • postLoad(entity): This method is called after the load operation is complete.
  • preInsert(entity): This method is called just before the object is inserted.
  • postInsert(entity): This method is called after the insert operation is complete.
  • preUpdate(entity, Struct oldData): This method is called just before the object is updated. A struct of old data is passed to this method to know the original state of the entity being updated.

    Note: When you call the EntitySave() method on an object that is not loaded using EntityLoad(), it gets updated but the intercepter call fails. This happens because an empty map is created for the object and there is no previous data associated with it.

     

  • postUpdate(entity): This method is called after the update operation is complete.
  • preDelete(entity): This method is called before the object is deleted.
  • postDelete(entity): This method is called after the delete operation is complete.

    Note: If event handlers are defined in both persistent CFC and event handler CFC, the persistent CFC is given the callback before calling the application wide event handler.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy