Package org.hibernate.proxy

Examples of org.hibernate.proxy.LazyInitializer


  // 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

    }
  }

  public String bestGuessEntityName(Object object) {
    if (object instanceof HibernateProxy) {
      LazyInitializer initializer = ( ( HibernateProxy ) object ).getHibernateLazyInitializer();
      // it is possible for this method to be called during flush processing,
      // so make certain that we do not accidently initialize an uninitialized proxy
      if ( initializer.isUninitialized() ) {
        return initializer.getEntityName();
      }
      object = initializer.getImplementation();
    }
    EntityEntry entry = persistenceContext.getEntry(object);
    if (entry==null) {
      return guessEntityName(object);
    }
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

    Iterator elems = getElementsIterator( collection, session );
    while ( elems.hasNext() ) {
      Object element = elems.next();
      // worrying about proxies is perhaps a little bit of overkill here...
      if ( element instanceof HibernateProxy ) {
        LazyInitializer li = ( (HibernateProxy) element ).getHibernateLazyInitializer();
        if ( !li.isUninitialized() ) element = li.getImplementation();
      }
      if ( element == childObject ) return true;
    }
    return false;
  }
View Full Code Here

    final SessionImplementor source = event.getSession();
    final Object object = event.getObject();
   
    final Object entity;
    if (object instanceof HibernateProxy) {
      LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
      if ( li.isUninitialized() ) {
        if ( li.getSession()==source ) {
          return; //NOTE EARLY EXIT!
        }
        else {
          throw new PersistentObjectException("uninitialized proxy passed to persist()");
        }
      }
      entity = li.getImplementation();
    }
    else {
      entity = object;
    }
   
View Full Code Here

    if ( original != null ) {

      final Object entity;
      if ( original instanceof HibernateProxy ) {
        LazyInitializer li = ( (HibernateProxy) original ).getHibernateLazyInitializer();
        if ( li.isUninitialized() ) {
          log.trace("ignoring uninitialized proxy");
          event.setResult( source.load( li.getEntityName(), li.getIdentifier() ) );
          return; //EARLY EXIT!
        }
        else {
          entity = li.getImplementation();
        }
      }
      else {
        entity = original;
      }
View Full Code Here

  }

  public Object readObject(Object target, String name, Object oldValue) {
    Object value = intercept( target, name, oldValue );
    if (value instanceof HibernateProxy) {
      LazyInitializer li = ( (HibernateProxy) value ).getHibernateLazyInitializer();
      if ( li.isUnwrap() ) {
        value = li.getImplementation();
      }
    }
    return value;
  }
View Full Code Here

    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.unsetSession();
    }
    else {
      EntityEntry e = persistenceContext.removeEntry( object );
      if ( e != null ) {
        persistenceContext.removeEntity( e.getEntityKey() );
View Full Code Here

  }

  public void clear() {
    Iterator itr = proxiesByKey.values().iterator();
    while ( itr.hasNext() ) {
      final LazyInitializer li = ( ( HibernateProxy ) itr.next() ).getHibernateLazyInitializer();
      li.unsetSession();
    }
    Map.Entry[] collectionEntryArray = IdentityMap.concurrentEntries( collectionEntries );
    for ( int i = 0; i < collectionEntryArray.length; i++ ) {
      ( ( PersistentCollection ) collectionEntryArray[i].getKey() ).unsetSession( getSession() );
    }
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.