Package org.hibernate.proxy

Examples of org.hibernate.proxy.LazyInitializer


    }
  }

  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


  }

  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

     
      if (object==LazyPropertyInitializer.UNFETCHED_PROPERTY) return false; //this is kinda the best we can do...
     
      if ( object instanceof HibernateProxy ) {
        // if its an uninitialized proxy it can't be transient
        LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
        if ( li.getImplementation(session) == null ) {
          return false;
          // ie. we never have to null out a reference to
          // an uninitialized proxy
        }
        else {
          //unwrap it
          object = li.getImplementation();
        }
      }
 
      // if it was a reference to self, don't need to nullify
      // unless we are using native id generation, in which
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

  }

  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

   */
  public static boolean isPropertyInitialized(Object proxy, String propertyName) {
   
    Object entity;
    if ( proxy instanceof HibernateProxy ) {
      LazyInitializer li = ( ( HibernateProxy ) proxy ).getHibernateLazyInitializer();
      if ( li.isUninitialized() ) {
        return false;
      }
      else {
        entity = li.getImplementation();
      }
    }
    else {
      entity = proxy;
    }
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

    }
  }

  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

    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

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.