public void executeEntityListeners ( CallbackType callbackType , Object entity ) { // We may get null entities here. For example loading a nonexistent ID // or IDs. if ( entity == null ) { return ; } EntityListenersMetadata entityListenersMetadata = EntityIntrospector . getEntityListenersMetadata ( entity ) ; List < CallbackMetadata > callbacks = entityListenersMetadata . getCallbacks ( callbackType ) ; if ( ! entityListenersMetadata . isExcludeDefaultListeners ( ) ) { executeGlobalListeners ( callbackType , entity ) ; } if ( callbacks == null ) { return ; } for ( CallbackMetadata callback : callbacks ) { switch ( callback . getListenerType ( ) ) { case EXTERNAL : Object listener = ListenerFactory . getInstance ( ) . getListener ( callback . getListenerClass ( ) ) ; invokeCallbackMethod ( callback . getCallbackMethod ( ) , listener , entity ) ; break ; case INTERNAL : invokeCallbackMethod ( callback . getCallbackMethod ( ) , entity ) ; break ; default : String message = String . format ( "Unknown or unimplemented callback listener type: %s" , callback . getListenerType ( ) ) ; throw new EntityManagerException ( message ) ; } } }
Executes the entity listeners associated with the given entity .