Package org.hibernate.engine.spi

Examples of org.hibernate.engine.spi.EntityEntry


    boolean shouldDelayIdentityInserts = !inTxn && !requiresImmediateIdAccess;

    // Put a placeholder in entries, so we don't recurse back and try to save() the
    // same object again. QUESTION: should this be done before onSave() is called?
    // likewise, should it be done before onUpdate()?
    EntityEntry original = source.getPersistenceContext().addEntry(
        entity,
        Status.SAVING,
        null,
        null,
        id,
        null,
        LockMode.WRITE,
        useIdentityColumn,
        persister,
        false,
        false
    );

    cascadeBeforeSave( source, persister, entity, anything );

    Object[] values = persister.getPropertyValuesToInsert( entity, getMergeMap( anything ), source );
    Type[] types = persister.getPropertyTypes();

    boolean substitute = substituteValuesIfNecessary( entity, id, values, persister, source );

    if ( persister.hasCollections() ) {
      substitute = substitute || visitCollectionsBeforeSave( entity, id, values, types, source );
    }

    if ( substitute ) {
      persister.setPropertyValues( entity, values );
    }

    TypeHelper.deepCopy(
        values,
        types,
        persister.getPropertyUpdateability(),
        values,
        source
    );

    AbstractEntityInsertAction insert = addInsertAction(
        values, id, entity, persister, useIdentityColumn, source, shouldDelayIdentityInserts
    );

    // postpone initializing id in case the insert has non-nullable transient dependencies
    // that are not resolved until cascadeAfterSave() is executed
    cascadeAfterSave( source, persister, entity, anything );
    if ( useIdentityColumn && insert.isEarlyInsert() ) {
      if ( !EntityIdentityInsertAction.class.isInstance( insert ) ) {
        throw new IllegalStateException(
            "Insert should be using an identity column, but action is of unexpected type: " +
                insert.getClass().getName()
        );
      }
      id = ((EntityIdentityInsertAction) insert).getGeneratedId();

      insert.handleNaturalIdPostSaveNotifications( id );
    }

    markInterceptorDirty( entity, persister, source );

    EntityEntry newEntry = source.getPersistenceContext().getEntry( entity );

    if ( newEntry != original ) {
      OgmEntityEntryState ogmEntityState = newEntry.getExtraState( OgmEntityEntryState.class );
      if ( ogmEntityState == null ) {
        newEntry.addExtraState( original.getExtraState( OgmEntityEntryState.class ) );
      }
    }

    return id;
  }
View Full Code Here


    boolean shouldDelayIdentityInserts = !inTxn && !requiresImmediateIdAccess;

    // Put a placeholder in entries, so we don't recurse back and try to save() the
    // same object again. QUESTION: should this be done before onSave() is called?
    // likewise, should it be done before onUpdate()?
    EntityEntry original = source.getPersistenceContext().addEntry(
        entity,
        Status.SAVING,
        null,
        null,
        id,
        null,
        LockMode.WRITE,
        useIdentityColumn,
        persister,
        false,
        false
    );

    cascadeBeforeSave( source, persister, entity, anything );

    Object[] values = persister.getPropertyValuesToInsert( entity, getMergeMap( anything ), source );
    Type[] types = persister.getPropertyTypes();

    boolean substitute = substituteValuesIfNecessary( entity, id, values, persister, source );

    if ( persister.hasCollections() ) {
      substitute = substitute || visitCollectionsBeforeSave( entity, id, values, types, source );
    }

    if ( substitute ) {
      persister.setPropertyValues( entity, values );
    }

    TypeHelper.deepCopy(
        values,
        types,
        persister.getPropertyUpdateability(),
        values,
        source
    );

    AbstractEntityInsertAction insert = addInsertAction(
        values, id, entity, persister, useIdentityColumn, source, shouldDelayIdentityInserts
    );

    // postpone initializing id in case the insert has non-nullable transient dependencies
    // that are not resolved until cascadeAfterSave() is executed
    cascadeAfterSave( source, persister, entity, anything );
    if ( useIdentityColumn && insert.isEarlyInsert() ) {
      if ( !EntityIdentityInsertAction.class.isInstance( insert ) ) {
        throw new IllegalStateException(
            "Insert should be using an identity column, but action is of unexpected type: " +
                insert.getClass().getName()
        );
      }
      id = ((EntityIdentityInsertAction) insert).getGeneratedId();

      insert.handleNaturalIdPostSaveNotifications( id );
    }

    markInterceptorDirty( entity, persister, source );

    EntityEntry newEntry = source.getPersistenceContext().getEntry( entity );

    if ( newEntry != original ) {
      OgmEntityEntryState ogmEntityState = newEntry.getExtraState( OgmEntityEntryState.class );
      if ( ogmEntityState == null ) {
        newEntry.addExtraState( original.getExtraState( OgmEntityEntryState.class ) );
      }
    }

    return id;
  }
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

    //TODO support "multi table" entities
    final boolean[] tableUpdateNeeded = getTableUpdateNeeded( dirtyFields, hasDirtyCollection );
    final int span = getTableSpan();

    final boolean[] propsToUpdate;
    EntityEntry entry = session.getPersistenceContext().getEntry( object );

    // Ensure that an immutable or non-modifiable entity is not being updated unless it is
    // in the process of being deleted.
    if ( entry == null && ! isMutable() ) {
      throw new IllegalStateException( "Updating immutable entity that is not in session yet!" );
    }
    //we always use a dynamicUpdate model for Infinispan
    if ( (
        //getEntityMetamodel().isDynamicUpdate() &&
        dirtyFields != null ) ) {

      propsToUpdate = getPropertiesToUpdate( dirtyFields, hasDirtyCollection );
      // don't need to check laziness (dirty checking algorithm handles that)
    }
    else if ( ! isModifiableEntity( entry ) ) {
      //TODO does that apply to OGM?
      // We need to generate UPDATE SQL when a non-modifiable entity (e.g., read-only or immutable)
      // needs:
      // - to have references to transient entities set to null before being deleted
      // - to have version incremented do to a "dirty" association
      // If dirtyFields == null, then that means that there are no dirty properties to
      // to be updated; an empty array for the dirty fields needs to be passed to
      // getPropertiesToUpdate() instead of null.
      propsToUpdate = getPropertiesToUpdate(
          ( dirtyFields == null ? ArrayHelper.EMPTY_INT_ARRAY : dirtyFields ),
          hasDirtyCollection
      );
      // don't need to check laziness (dirty checking algorithm handles that)
    }
    else {
      // For the case of dynamic-update="false", or no snapshot, we update all properties
      //TODO handle lazy
      propsToUpdate = getPropertyUpdateability( object );
    }

    final SessionFactoryImplementor factory = getFactory();
    if ( log.isTraceEnabled() ) {
      log.trace( "Updating entity: " + MessageHelper.infoString( this, id, factory ) );
      if ( isVersioned() ) {
        log.trace( "Existing version: " + oldVersion + " -> New version: " + fields[getVersionProperty()] );
      }
    }


    for ( int j = 0; j < span; j++ ) {
      // Now update only the tables with dirty properties (and the table with the version number)
      if ( tableUpdateNeeded[j] ) {
        final EntityKey key = EntityKeyBuilder.fromPersister( this, id, session );
        Tuple resultset = null;

        if ( mightRequireInverseAssociationManagement || usesNonAtomicOptimisticLocking ) {
          resultset = gridDialect.getTuple( key, getTupleContext() );
        }
        else {
          OgmEntityEntryState extraState = entry.getExtraState( OgmEntityEntryState.class );
          if ( extraState != null ) {
            resultset = extraState.getTuple();
          }
          if ( resultset == null ) {
            resultset = gridDialect.getTuple( key, getTupleContext() );
View Full Code Here

  private Object[] getLoadedState(Serializable id, SessionImplementor session) {
    org.hibernate.engine.spi.EntityKey key = session.generateEntityKey( id, this );

    Object entity = session.getPersistenceContext().getEntity( key );
    if ( entity != null ) {
      EntityEntry entry = session.getPersistenceContext().getEntry( entity );
      return entry.getLoadedState();
    }

    return null;
  }
View Full Code Here

  public void setTuple(Tuple tuple) {
    this.tuple = tuple;
  }

  public static OgmEntityEntryState getStateFor(SessionImplementor session, Object object) {
    EntityEntry entityEntry = session.getPersistenceContext().getEntry( object );
    Contracts.assertNotNull( entityEntry, "entityEntry" );

    OgmEntityEntryState ogmEntityState = entityEntry.getExtraState( OgmEntityEntryState.class );
    if ( ogmEntityState == null ) {
      ogmEntityState = new OgmEntityEntryState();
      entityEntry.addExtraState( ogmEntityState );
    }

    return ogmEntityState;
  }
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

    //TODO support "multi table" entities
    final boolean[] tableUpdateNeeded = getTableUpdateNeeded( dirtyFields, hasDirtyCollection );
    final int span = getTableSpan();

    final boolean[] propsToUpdate;
    EntityEntry entry = session.getPersistenceContext().getEntry( object );

    // Ensure that an immutable or non-modifiable entity is not being updated unless it is
    // in the process of being deleted.
    if ( entry == null && ! isMutable() ) {
      throw new IllegalStateException( "Updating immutable entity that is not in session yet!" );
View Full Code Here

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

    final EntityKey key = EntityKeyBuilder.fromPersister( this, id, session );
    final Tuple resultset = gridDialect.getTuple( key, this.getTupleContext() );
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 );
      }

      // 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 = keyType.semiResolve(
            entityEntry.getLoadedValue( foreignKeyPropertyName ),
            session,
            owner
          );
      }

View Full Code Here

TOP

Related Classes of org.hibernate.engine.spi.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.