Java 类org.hibernate.event.PostLoadEventListener 实例源码

项目:screensaver    文件:ConfigurableListenerBeansHibernatePersistence.java   
private void configureListeners(Ejb3Configuration cfg)
{
  EventListeners eventListeners = cfg.getEventListeners();

  cfg.setListeners("post-load", concatListeners(PostLoadEventListener.class, _postLoadEventListeners, eventListeners.getPostLoadEventListeners()));
  cfg.setListeners("save-update", concatListeners(SaveOrUpdateEventListener.class, _saveOrUpdateEventListeners, eventListeners.getSaveOrUpdateEventListeners()));
  cfg.setListeners("merge", concatListeners(MergeEventListener.class, _mergeEventListeners, eventListeners.getMergeEventListeners()));
  cfg.setListeners("create", concatListeners(PersistEventListener.class, _persistEventListeners, eventListeners.getPersistEventListeners()));
  // TODO: do we also need create-on-flush event?
}
项目:cacheonix-core    文件:DefaultLoadEventListener.java   
private Object assembleCacheEntry(
        final CacheEntry entry,
        final Serializable id,
        final EntityPersister persister,
        final LoadEvent event) throws HibernateException {

    final Object optionalObject = event.getInstanceToLoad();
    final EventSource session = event.getSession();
    final SessionFactoryImplementor factory = session.getFactory();

    if ( log.isTraceEnabled() ) {
        log.trace(
                "assembling entity from second-level cache: " +
                MessageHelper.infoString( persister, id, factory )
            );
    }

    EntityPersister subclassPersister = factory.getEntityPersister( entry.getSubclass() );
    Object result = optionalObject == null ? 
            session.instantiate( subclassPersister, id ) : optionalObject;

    // make it circular-reference safe
    TwoPhaseLoad.addUninitializedCachedEntity( 
            new EntityKey( id, subclassPersister, session.getEntityMode() ), 
            result, 
            subclassPersister, 
            LockMode.NONE, 
            entry.areLazyPropertiesUnfetched(),
            entry.getVersion(),
            session
        );

    Type[] types = subclassPersister.getPropertyTypes();
    Object[] values = entry.assemble( result, id, subclassPersister, session.getInterceptor(), session ); // intializes result by side-effect
    TypeFactory.deepCopy( 
            values, 
            types, 
            subclassPersister.getPropertyUpdateability(), 
            values, 
            session
        );

    Object version = Versioning.getVersion( values, subclassPersister );
    if ( log.isTraceEnabled() ) log.trace( "Cached Version: " + version );

    final PersistenceContext persistenceContext = session.getPersistenceContext();
    persistenceContext.addEntry( 
            result, 
            Status.MANAGED, 
            values, 
            null, 
            id, 
            version, 
            LockMode.NONE, 
            true, 
            subclassPersister, 
            false, 
            entry.areLazyPropertiesUnfetched() 
        );
    subclassPersister.afterInitialize( result, entry.areLazyPropertiesUnfetched(), session );
    persistenceContext.initializeNonLazyCollections();
    // upgrade the lock if necessary:
    //lock(result, lockMode);

    //PostLoad is needed for EJB3
    //TODO: reuse the PostLoadEvent...
    PostLoadEvent postLoadEvent = new PostLoadEvent(session).setEntity(result)
            .setId(id).setPersister(persister);
    PostLoadEventListener[] listeners = session.getListeners().getPostLoadEventListeners();
    for ( int i = 0; i < listeners.length; i++ ) {
        listeners[i].onPostLoad(postLoadEvent);
    }

    return result;
}
项目:Lucee4    文件:HibernateORMEngine.java   
private static void addEventListeners(PageContext pc, SessionFactoryData data, Key key) throws PageException {
    if(!data.getORMConfiguration().eventHandling()) return;
    String eventHandler = data.getORMConfiguration().eventHandler();
    AllEventListener listener=null;
    if(!Util.isEmpty(eventHandler,true)){
        //try {
            Component c = pc.loadComponent(eventHandler.trim());

            listener = new AllEventListener(c);
            //config.setInterceptor(listener);
        //}catch (PageException e) {e.printStackTrace();}
    }
    Configuration conf = data.getConfiguration(key);
    conf.setInterceptor(new InterceptorImpl(listener));
       EventListeners listeners = conf.getEventListeners();
       Map<String, CFCInfo> cfcs = data.getCFCs(key);
       // post delete
    List<EventListener> 
    list=merge(listener,cfcs,CommonUtil.POST_DELETE);
    listeners.setPostDeleteEventListeners(list.toArray(new PostDeleteEventListener[list.size()]));

       // post insert
    list=merge(listener,cfcs,CommonUtil.POST_INSERT);
    listeners.setPostInsertEventListeners(list.toArray(new PostInsertEventListener[list.size()]));

    // post update
    list=merge(listener,cfcs,CommonUtil.POST_UPDATE);
    listeners.setPostUpdateEventListeners(list.toArray(new PostUpdateEventListener[list.size()]));

    // post load
    list=merge(listener,cfcs,CommonUtil.POST_LOAD);
    listeners.setPostLoadEventListeners(list.toArray(new PostLoadEventListener[list.size()]));

    // pre delete
    list=merge(listener,cfcs,CommonUtil.PRE_DELETE);
    listeners.setPreDeleteEventListeners(list.toArray(new PreDeleteEventListener[list.size()]));

    // pre insert
    //list=merge(listener,cfcs,CommonUtil.PRE_INSERT);
    //listeners.setPreInsertEventListeners(list.toArray(new PreInsertEventListener[list.size()]));

    // pre load
    list=merge(listener,cfcs,CommonUtil.PRE_LOAD);
    listeners.setPreLoadEventListeners(list.toArray(new PreLoadEventListener[list.size()]));

    // pre update
    //list=merge(listener,cfcs,CommonUtil.PRE_UPDATE);
    //listeners.setPreUpdateEventListeners(list.toArray(new PreUpdateEventListener[list.size()]));
}
项目:screensaver    文件:ConfigurableListenerBeansHibernatePersistence.java   
public List<PostLoadEventListener> getPostLoadEventListeners()
{
  return _postLoadEventListeners;
}
项目:screensaver    文件:ConfigurableListenerBeansHibernatePersistence.java   
public void setPostLoadEventListeners(List<PostLoadEventListener> postLoadEventListeners)
{
  _postLoadEventListeners = postLoadEventListeners;
}