Save This Page
Home » hibernate-entity-src-20081106 » org.hibernate » ejb » event » [javadoc | source]
    1   //$Id: EJB3PersistEventListener.java 11208 2007-02-15 06:07:38Z epbernard $
    2   package org.hibernate.ejb.event;
    3   
    4   import java.io.Serializable;
    5   
    6   import org.hibernate.event.EventSource;
    7   import org.hibernate.event.def.DefaultPersistEventListener;
    8   import org.hibernate.engine.CascadingAction;
    9   import org.hibernate.engine.EJB3CascadingAction;
   10   import org.hibernate.engine.EJB3CascadeStyle;
   11   
   12   /**
   13    * Overrides the LifeCycle OnSave call to call the PrePersist operation
   14    *
   15    * @author Emmanuel Bernard
   16    */
   17   public class EJB3PersistEventListener extends DefaultPersistEventListener implements CallbackHandlerConsumer {
   18   	static {
   19   		EJB3CascadeStyle.PERSIST_EJB3.hasOrphanDelete(); //triggers class loading
   20   	}
   21   
   22   	private EntityCallbackHandler callbackHandler;
   23   
   24   	public void setCallbackHandler(EntityCallbackHandler callbackHandler) {
   25   		this.callbackHandler = callbackHandler;
   26   	}
   27   
   28   	public EJB3PersistEventListener() {
   29   		super();
   30   	}
   31   
   32   	public EJB3PersistEventListener(EntityCallbackHandler callbackHandler) {
   33   		super();
   34   		this.callbackHandler = callbackHandler;
   35   	}
   36   
   37   	@Override
   38   	protected Serializable saveWithRequestedId(Object entity, Serializable requestedId, String entityName,
   39   											   Object anything, EventSource source) {
   40   		callbackHandler.preCreate( entity );
   41   		return super.saveWithRequestedId( entity, requestedId, entityName, anything,
   42   				source );
   43   	}
   44   
   45   	@Override
   46   	protected Serializable saveWithGeneratedId(Object entity, String entityName, Object anything, EventSource source,
   47   											   boolean requiresImmediateIdAccess) {
   48   		callbackHandler.preCreate( entity );
   49   		return super.saveWithGeneratedId( entity, entityName, anything, source,
   50   				requiresImmediateIdAccess );
   51   	}
   52   
   53   	@Override
   54   	protected CascadingAction getCascadeAction() {
   55   		return EJB3CascadingAction.PERSIST_SKIPLAZY;
   56   	}
   57   }

Save This Page
Home » hibernate-entity-src-20081106 » org.hibernate » ejb » event » [javadoc | source]