Package org.hibernate.engine

Examples of org.hibernate.engine.EntityKey


    EntityPersister subclassPersister = factory.getEntityPersister( entry.getSubclass() );
    Object result = optionalObject == null ?
        session.instantiate( subclassPersister, id ) : optionalObject;

    // make it circular-reference safe
    EntityKey entityKey = new EntityKey( id, subclassPersister, session.getEntityMode() );
    TwoPhaseLoad.addUninitializedCachedEntity(
        entityKey,
        result,
        subclassPersister,
        LockMode.NONE,
View Full Code Here


        log.trace(
            "refreshing transient " +
            MessageHelper.infoString( persister, id, source.getFactory() )
          );
      }
      EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
      if ( source.getPersistenceContext().getEntry(key) != null ) {
        throw new PersistentObjectException(
            "attempted to refresh transient instance when persistent instance was already associated with the Session: " +
            MessageHelper.infoString(persister, id, source.getFactory() )
          );
      }
    }
    else {
      if ( log.isTraceEnabled() ) {
        log.trace(
            "refreshing " +
            MessageHelper.infoString( e.getPersister(), e.getId(), source.getFactory()  )
          );
      }
      if ( !e.isExistsInDatabase() ) {
        throw new HibernateException( "this instance does not yet exist as a row in the database" );
      }

      persister = e.getPersister();
      id = e.getId();
    }

    // cascade the refresh prior to refreshing this entity
    refreshedAlready.put(object, object);
    new Cascade(CascadingAction.REFRESH, Cascade.BEFORE_REFRESH, source)
        .cascade( persister, object, refreshedAlready );

    if ( e != null ) {
      EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
      source.getPersistenceContext().removeEntity(key);
      if ( persister.hasCollections() ) new EvictVisitor( source ).process(object, persister);
    }

    if ( persister.hasCache() ) {
View Full Code Here

              MessageHelper.infoString( persister, id, event.getSession().getFactory() )
      );
    }

    EventSource source = event.getSession();
    EntityKey key = new EntityKey( id, persister, source.getEntityMode() );

    source.getPersistenceContext().checkUniqueness( key, object );

    //get a snapshot
    Object[] values = persister.getPropertyValues( object, source.getEntityMode() );
View Full Code Here

        EntityEntry entry = source.getPersistenceContext().getEntry( entity );
        if ( entry == null ) {
          EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
          Serializable id = persister.getIdentifier( entity, source.getEntityMode() );
          if ( id != null ) {
            EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
            Object managedEntity = source.getPersistenceContext().getEntity( key );
            entry = source.getPersistenceContext().getEntry( managedEntity );
            if ( entry != null ) {
              // we have specialized case of a detached entity from the
              // perspective of the merge operation.  Specifically, we
View Full Code Here

  private boolean existsInDatabase(Object entity, EventSource source, EntityPersister persister) {
    EntityEntry entry = source.getPersistenceContext().getEntry( entity );
    if ( entry == null ) {
      Serializable id = persister.getIdentifier( entity, source.getEntityMode() );
      if ( id != null ) {
        EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
        Object managedEntity = source.getPersistenceContext().getEntity( key );
        entry = source.getPersistenceContext().getEntry( managedEntity );
      }
    }
View Full Code Here

    if ( isImpliedOptimisticLocking ) {
      // need to treat this as if it where optimistic-lock="all" (dirty does *not* make sense);
      // first we need to locate the "loaded" state
      //
      // 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();
      }
View Full Code Here

      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 ) {
View Full Code Here

        );
      }

      final EventSource source = event.getSession();

      EntityKey key = new EntityKey( event.getRequestedId(), persister, source.getEntityMode() );

      source.getPersistenceContext().checkUniqueness( key, entity );

      if ( invokeUpdateLifecycle( entity, persister, source ) ) {
        reassociate( event, event.getObject(), event.getRequestedId(), persister );
View Full Code Here

      // key value upon which to perform the breaking logic.  However,
      // it is also then called from getRowFromResultSet() which is certainly
      // not the most efficient.  But the call here is needed, and there
      // currently is no other way without refactoring of the doQuery()/getRowFromResultSet()
      // methods
      final EntityKey currentKey = getKeyFromResultSet(
          0,
          getEntityPersisters()[0],
          null,
          resultSet,
          session
View Full Code Here

      if ( resultSet.isFirst() ) {
        // don't even bother trying to read any further
        return null;
      }

      EntityKey keyToRead = null;
      // This check is needed since processing leaves the cursor
      // after the last physical row for the current logical row;
      // thus if we are after the last physical row, this might be
      // caused by either:
      //      1) scrolling to the last logical row
      //      2) scrolling past the last logical row
      // In the latter scenario, the previous logical row
      // really is the last logical row.
      //
      // In all other cases, we should process back two
      // logical records (the current logic row, plus the
      // previous logical row).
      if ( resultSet.isAfterLast() && isLogicallyAfterLast ) {
        // position cursor to the last row
        resultSet.last();
        keyToRead = getKeyFromResultSet(
            0,
            getEntityPersisters()[0],
            null,
            resultSet,
            session
          );
      }
      else {
        // Since the result set cursor is always left at the first
        // physical row after the "last processed", we need to jump
        // back one position to get the key value we are interested
        // in skipping
        resultSet.previous();

        // sequentially read the result set in reverse until we recognize
        // a change in the key value.  At that point, we are pointed at
        // the last physical sequential row for the logical row in which
        // we are interested in processing
        boolean firstPass = true;
        final EntityKey lastKey = getKeyFromResultSet(
            0,
            getEntityPersisters()[0],
            null,
            resultSet,
            session
          );
        while ( resultSet.previous() ) {
          EntityKey checkKey = getKeyFromResultSet(
              0,
              getEntityPersisters()[0],
              null,
              resultSet,
              session
            );

          if ( firstPass ) {
            firstPass = false;
            keyToRead = checkKey;
          }

          if ( !lastKey.equals( checkKey ) ) {
            break;
          }
        }

      }

      // Read backwards until we read past the first physical sequential
      // row with the key we are interested in loading
      while ( resultSet.previous() ) {
        EntityKey checkKey = getKeyFromResultSet(
            0,
            getEntityPersisters()[0],
            null,
            resultSet,
            session
View Full Code Here

TOP

Related Classes of org.hibernate.engine.EntityKey

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.