Package org.hibernate.engine

Examples of org.hibernate.engine.EntityEntry


    for ( int i = 0; i < size; i++ ) {

      // Update the status of the object and if necessary, schedule an update

      Map.Entry me = list[i];
      EntityEntry entry = (EntityEntry) me.getValue();
      Status status = entry.getStatus();

      if ( status != Status.LOADING && status != Status.GONE ) {
        FlushEntityEvent entityEvent = new FlushEntityEvent( source, me.getKey(), entry );
        FlushEntityEventListener[] listeners = source.getListeners().getFlushEntityEventListeners();
        for ( int j = 0; j < listeners.length; j++ ) {
View Full Code Here


      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()  );
        persistenceContext.removeEntity( key );
        doEvict( object, key, e.getPersister(), source );
      }
    }
  }
View Full Code Here

  }

  protected Serializable entityIsPersistent(SaveOrUpdateEvent event) throws HibernateException {
    log.trace( "ignoring persistent instance" );

    EntityEntry entityEntry = event.getEntry();
    if ( entityEntry == null ) {
      throw new AssertionFailure( "entity was transient or detached" );
    }
    else {

      if ( entityEntry.getStatus() == Status.DELETED ) {
        throw new AssertionFailure( "entity was deleted" );
      }

      final SessionFactoryImplementor factory = event.getSession().getFactory();

      Serializable requestedId = event.getRequestedId();

      Serializable savedId;
      if ( requestedId == null ) {
        savedId = entityEntry.getId();
      }
      else {

        final boolean isEqual = !entityEntry.getPersister().getIdentifierType()
            .isEqual( requestedId, entityEntry.getId(), event.getSession().getEntityMode(), factory );

        if ( isEqual ) {
          throw new PersistentObjectException(
              "object passed to save() was already persistent: " +
                  MessageHelper.infoString( entityEntry.getPersister(), requestedId, factory )
          );
        }

        savedId = requestedId;

      }

      if ( log.isTraceEnabled() ) {
        log.trace(
            "object already associated with session: " +
                MessageHelper.infoString( entityEntry.getPersister(), savedId, factory )
        );
      }

      return savedId;
View Full Code Here

   * @param session The session from which the request is originating.
   * @return The collection owner's key
   */
  public Serializable getKeyOfOwner(Object owner, SessionImplementor session) {
   
    EntityEntry entityEntry = session.getPersistenceContext().getEntry( owner );
    if ( entityEntry == null ) return null; // This just handles a particular case of component
                    // projection, perhaps get rid of it and throw an exception
   
    if ( foreignKeyPropertyName == null ) {
      return entityEntry.getId();
    }
    else {
      // TODO: at the point where we are resolving collection references, we don't
      // know if the uk value has been resolved (depends if it was earlier or
      // later in the mapping document) - now, we could try and use e.getStatus()
      // to decide to semiResolve(), trouble is that initializeEntity() reuses
      // the same array for resolved and hydrated values
      Object id;
      if ( entityEntry.getLoadedState() != null ) {
        id = entityEntry.getLoadedValue( foreignKeyPropertyName );
      }
      else {
        id = entityEntry.getPersister().getPropertyValue( owner, foreignKeyPropertyName, session.getEntityMode() );
      }

      // NOTE VERY HACKISH WORKAROUND!!
      // TODO: Fix this so it will work for non-POJO entity mode
      Type keyType = getPersister( session ).getKeyType();
      if ( !keyType.getReturnedClass().isInstance( id ) ) {
        id = (Serializable) keyType.semiResolve(
            entityEntry.getLoadedValue( foreignKeyPropertyName ),
            session,
            owner
          );
      }

View Full Code Here

  public Object initializeLazyProperty(String fieldName, Object entity, SessionImplementor session)
      throws HibernateException {

    final Serializable id = session.getContextEntityIdentifier( entity );

    final EntityEntry entry = session.getPersistenceContext().getEntry( entity );
    if ( entry == null ) {
      throw new HibernateException( "entity is not associated with the session: " + id );
    }

    if ( log.isTraceEnabled() ) {
View Full Code Here

      //
      // Note, it potentially could be a proxy, so perform the location the safe way...
      EntityKey key = new EntityKey( id, this, session.getEntityMode() );
      Object entity = session.getPersistenceContext().getEntity( key );
      if ( entity != null ) {
        EntityEntry entry = session.getPersistenceContext().getEntry( entity );
        loadedState = entry.getLoadedState();
      }
    }

    final String[] deleteStrings;
    if ( isImpliedOptimisticLocking && loadedState != null ) {
View Full Code Here

   * Flushes a single entity's state to the database, by scheduling
   * an update action, if necessary
   */
  public void onFlushEntity(FlushEntityEvent event) throws HibernateException {
    final Object entity = event.getEntity();
    final EntityEntry entry = event.getEntityEntry();
    final EventSource session = event.getSession();
    final EntityPersister persister = entry.getPersister();
    final Status status = entry.getStatus();
    final EntityMode entityMode = session.getEntityMode();
    final Type[] types = persister.getPropertyTypes();

    final boolean mightBeDirty = entry.requiresDirtyCheck(entity);

    final Object[] values = getValues( entity, entry, entityMode, mightBeDirty, session );

    event.setPropertyValues(values);

View Full Code Here

    }
  }

  private boolean scheduleUpdate(final FlushEntityEvent event) {
   
    final EntityEntry entry = event.getEntityEntry();
    final EventSource session = event.getSession();
    final Object entity = event.getEntity();
    final Status status = entry.getStatus();
    final EntityMode entityMode = session.getEntityMode();
    final EntityPersister persister = entry.getPersister();
    final Object[] values = event.getPropertyValues();
   
    if ( log.isTraceEnabled() ) {
      if ( status == Status.DELETED ) {
        log.trace(
            "Updating deleted entity: " +
            MessageHelper.infoString( persister, entry.getId(), session.getFactory() )
          );
      }
      else {
        log.trace(
            "Updating entity: " +
            MessageHelper.infoString( persister, entry.getId(), session.getFactory()  )
          );
      }
    }

    final boolean intercepted;
    if ( !entry.isBeingReplicated() ) {
      // give the Interceptor a chance to process property values, if the properties
      // were modified by the Interceptor, we need to set them back to the object
      intercepted = handleInterception( event );
    }
    else {
      intercepted = false;
    }

    validate( entity, persister, status, entityMode );

    // increment the version number (if necessary)
    final Object nextVersion = getNextVersion(event);

    // if it was dirtied by a collection only
    int[] dirtyProperties = event.getDirtyProperties();
    if ( event.isDirtyCheckPossible() && dirtyProperties == null ) {
      if ( ! intercepted && !event.hasDirtyCollection() ) {
        throw new AssertionFailure( "dirty, but no dirty properties" );
      }
      dirtyProperties = ArrayHelper.EMPTY_INT_ARRAY;
    }

    // check nullability but do not perform command execute
    // we'll use scheduled updates for that.
    new Nullability(session).checkNullability( values, persister, true );

    // schedule the update
    // note that we intentionally do _not_ pass in currentPersistentState!
    session.getActionQueue().addAction(
        new EntityUpdateAction(
            entry.getId(),
            values,
            dirtyProperties,
            event.hasDirtyCollection(),
            entry.getLoadedState(),
            entry.getVersion(),
            nextVersion,
            entity,
            entry.getRowId(),
            persister,
            session
          )
      );
   
View Full Code Here

    }
  }
 
  protected boolean handleInterception(FlushEntityEvent event) {
    SessionImplementor session = event.getSession();
    EntityEntry entry = event.getEntityEntry();
    EntityPersister persister = entry.getPersister();
    Object entity = event.getEntity();
   
    //give the Interceptor a chance to modify property values
    final Object[] values = event.getPropertyValues();
    final boolean intercepted = invokeInterceptor( session, entity, entry, values, persister );

    //now we might need to recalculate the dirtyProperties array
    if ( intercepted && event.isDirtyCheckPossible() && !event.isDirtyCheckHandledByInterceptor() ) {
      int[] dirtyProperties;
      if ( event.hasDatabaseSnapshot() ) {
        dirtyProperties = persister.findModified( event.getDatabaseSnapshot(), values, entity, session );
      }
      else {
        dirtyProperties = persister.findDirty( values, entry.getLoadedState(), entity, session );
      }
      event.setDirtyProperties(dirtyProperties);
    }
   
    return intercepted;
View Full Code Here

  /**
   * Convience method to retreive an entities next version value
   */
  private Object getNextVersion(FlushEntityEvent event) throws HibernateException {
   
    EntityEntry entry = event.getEntityEntry();
    EntityPersister persister = entry.getPersister();
    if ( persister.isVersioned() ) {

      Object[] values = event.getPropertyValues();
       
      if ( entry.isBeingReplicated() ) {
        return Versioning.getVersion(values, persister);
      }
      else {
        int[] dirtyProperties = event.getDirtyProperties();
       
        final boolean isVersionIncrementRequired = isVersionIncrementRequired(
            event,
            entry,
            persister,
            dirtyProperties
          );
       
        final Object nextVersion = isVersionIncrementRequired ?
            Versioning.increment( entry.getVersion(), persister.getVersionType(), event.getSession() ) :
            entry.getVersion(); //use the current version
           
        Versioning.setVersion(values, nextVersion, persister);
       
        return nextVersion;
      }
View Full Code Here

TOP

Related Classes of org.hibernate.engine.EntityEntry

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.