Package org.hibernate.proxy

Examples of org.hibernate.proxy.LazyInitializer


    EventSource source = event.getSession();
    final Object object = event.getObject();
    final PersistenceContext persistenceContext = source.getPersistenceContext();

    if ( object instanceof HibernateProxy ) {
      LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
      Serializable id = li.getIdentifier();
      EntityPersister persister = source.getFactory().getEntityPersister( li.getEntityName() );
      if ( id == null ) {
        throw new IllegalArgumentException("null identifier");
      }

      EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
      persistenceContext.removeProxy( key );

      if ( !li.isUninitialized() ) {
        final Object entity = persistenceContext.removeEntity( key );
        if ( entity != null ) {
          EntityEntry e = event.getSession().getPersistenceContext().removeEntry( entity );
          doEvict( entity, key, e.getPersister(), event.getSession() );
        }
      }
      li.setSession( null );
    }
    else {
      EntityEntry e = persistenceContext.removeEntry( object );
      if ( e != null ) {
        EntityKey key = new EntityKey( e.getId(), e.getPersister(), source.getEntityMode()  );
View Full Code Here


  }

  public void clear() {
    Iterator itr = proxiesByKey.values().iterator();
    while ( itr.hasNext() ) {
      final LazyInitializer li = ( ( HibernateProxy ) itr.next() ).getHibernateLazyInitializer();
      li.setSession( null );
    }
    Map.Entry[] collectionEntryArray = IdentityMap.concurrentEntries( collectionEntries );
    for ( int i = 0; i < collectionEntryArray.length; i++ ) {
      ( ( PersistentCollection ) collectionEntryArray[i].getKey() ).unsetSession( getSession() );
    }
View Full Code Here

      value = ( (ElementWrapper) value ).getElement();
    }
   
    if ( !Hibernate.isInitialized(value) ) {
      HibernateProxy proxy = (HibernateProxy) value;
      LazyInitializer li = proxy.getHibernateLazyInitializer();
      reassociateProxy(li, proxy);
      return true;
    }
    else {
      return false;
View Full Code Here

    }
   
    if ( value instanceof HibernateProxy ) {
      if ( log.isDebugEnabled() ) log.debug("setting proxy identifier: " + id);
      HibernateProxy proxy = (HibernateProxy) value;
      LazyInitializer li = proxy.getHibernateLazyInitializer();
      li.setIdentifier(id);
      reassociateProxy(li, proxy);
    }
  }
View Full Code Here

      maybeProxy = ( (ElementWrapper) maybeProxy ).getElement();
    }
   
    if ( maybeProxy instanceof HibernateProxy ) {
      HibernateProxy proxy = (HibernateProxy) maybeProxy;
      LazyInitializer li = proxy.getHibernateLazyInitializer();
      if ( li.isUninitialized() ) {
        throw new PersistentObjectException(
            "object was an uninitialized proxy for " +
            li.getEntityName()
        );
      }
      return li.getImplementation(); //unwrap the object
    }
    else {
      return maybeProxy;
    }
  }
View Full Code Here

      maybeProxy = ( (ElementWrapper) maybeProxy ).getElement();
    }
   
    if ( maybeProxy instanceof HibernateProxy ) {
      HibernateProxy proxy = (HibernateProxy) maybeProxy;
      LazyInitializer li = proxy.getHibernateLazyInitializer();
      reassociateProxy(li, proxy);
      return li.getImplementation(); //initialize + unwrap the object
    }
    else {
      return maybeProxy;
    }
  }
View Full Code Here

     
    }
    else {
     
      if ( object != null ) {
        LazyInitializer li = ( (HibernateProxy) proxy ).getHibernateLazyInitializer();
        li.setImplementation(object);
      }
     
      return proxy;
     
    }
View Full Code Here

      final EntityKey keyToLoad,
      final LoadEventListener.LoadType options,
      final PersistenceContext persistenceContext,
      final Object proxy) {
    log.trace("entity proxy found in session cache");
    LazyInitializer li = ( (HibernateProxy) proxy ).getHibernateLazyInitializer();
    if ( li.isUnwrap() ) {
      return li.getImplementation();
    }
    Object impl = null;
    if ( !options.isAllowProxyCreation() ) {
      impl = load( event, persister, keyToLoad, options );
      if ( impl == null ) {
View Full Code Here

  // not for internal use:
  public Serializable getIdentifier(Object object) throws HibernateException {
    errorIfClosed();
    checkTransactionSynchStatus();
    if ( object instanceof HibernateProxy ) {
      LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
      if ( li.getSession() != this ) {
        throw new TransientObjectException( "The proxy was not associated with this session" );
      }
      return li.getIdentifier();
    }
    else {
      EntityEntry entry = persistenceContext.getEntry(object);
      if ( entry == null ) {
        throw new TransientObjectException( "The instance was not associated with this session" );
View Full Code Here

    checkTransactionSynchStatus();
    if ( object instanceof HibernateProxy ) {
      //do not use proxiesByKey, since not all
      //proxies that point to this session's
      //instances are in that collection!
      LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
      if ( li.isUninitialized() ) {
        //if it is an uninitialized proxy, pointing
        //with this session, then when it is accessed,
        //the underlying instance will be "contained"
        return li.getSession()==this;
      }
      else {
        //if it is initialized, see if the underlying
        //instance is contained, since we need to
        //account for the fact that it might have been
        //evicted
        object = li.getImplementation();
      }
    }
    // A session is considered to contain an entity only if the entity has
    // an entry in the session's persistence context and the entry reports
    // that the entity has not been removed
View Full Code Here

TOP

Related Classes of org.hibernate.proxy.LazyInitializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.