Package org.hibernate.engine.spi

Examples of org.hibernate.engine.spi.EntityKey


      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


      boolean returnProxies,
      ResultTransformer forcedResultTransformer,
      int maxRows,
      List<AfterLoadAction> afterLoadActions) throws SQLException {
    final int entitySpan = getEntityPersisters().length;
    final EntityKey optionalObjectKey = getOptionalObjectKey( queryParameters, session );
    final LockMode[] lockModesArray = getLockModes( queryParameters.getLockOptions() );
    final boolean createSubselects = isSubselectLoadingEnabled();
    final List subselectResultKeys = createSubselects ? new ArrayList() : null;
    final ArrayList hydratedObjects = entitySpan == 0 ? null : new ArrayList( entitySpan * 10 );
    final List results = new ArrayList();
View Full Code Here

      EntityType[] ownerAssociationTypes = getOwnerAssociationTypes();
      for ( int i = 0; i < keys.length; i++ ) {

        int owner = owners[i];
        if ( owner > -1 ) {
          EntityKey ownerKey = keys[owner];
          if ( keys[i] == null && ownerKey != null ) {

            final PersistenceContext persistenceContext = session.getPersistenceContext();

            /*final boolean isPrimaryKey;
View Full Code Here

    final Object[] rowResults = new Object[cols];

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

      Object object = null;
      EntityKey key = keys[i];

      if ( keys[i] == null ) {
        //do nothing
      }
      else {
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 doAfterTransactionCompletion the location the safe way...
      final EntityKey key = session.generateEntityKey( id, this );
      Object entity = session.getPersistenceContext().getEntity( key );
      if ( entity != null ) {
        EntityEntry entry = session.getPersistenceContext().getEntry( entity );
        loadedState = entry.getLoadedState();
      }
View Full Code Here

        try {
          //if there is no resulting row, return null
          if ( !rs.next() ) {
            return null;
          }
          final EntityKey key = session.generateEntityKey( id, this );
          Object owner = session.getPersistenceContext().getEntity( key );
          for ( int i = 0; i < naturalIdPropertyCount; i++ ) {
            snapshot[i] = extractionTypes[i].hydrate( rs, getPropertyAliases( "", naturalIdPropertyIndexes[i] ), session, null );
            if (extractionTypes[i].isEntityType()) {
              snapshot[i] = extractionTypes[i].resolve(snapshot[i], session, owner);
View Full Code Here

  private void scheduleBatchLoadIfNeeded(Serializable id, SessionImplementor session) throws MappingException {
    //cannot batch fetch by unique key (property-ref associations)
    if ( uniqueKeyPropertyName == null && id != null ) {
      final EntityPersister persister = session.getFactory().getEntityPersister( getAssociatedEntityName() );
      if ( persister.isBatchLoadable() ) {
        final EntityKey entityKey = session.generateEntityKey( id, persister );
        if ( !session.getPersistenceContext().containsEntity( entityKey ) ) {
          session.getPersistenceContext().getBatchFetchQueue().addBatchLoadableEntityKey( entityKey );
        }
      }
    }
View Full Code Here

  }

  private Object getReplacement() {
    final SessionImplementor session = getSession();
    if ( isUninitialized() && session != null && session.isOpen()) {
      final EntityKey key = session.generateEntityKey(
          getIdentifier(),
          session.getFactory().getEntityPersister( getEntityName() )
      );
      final Object entity = session.getPersistenceContext().getEntity(key);
      if (entity!=null) setImplementation( entity );
View Full Code Here

    final EntityReferenceProcessingState processingState = context.getProcessingState( entityReference );

    // see if we already have an EntityKey associated with this EntityReference in the processing state.
    // if we do, this should have come from the optional entity identifier...
    final EntityKey entityKey = processingState.getEntityKey();
    if ( entityKey != null ) {
      log.debugf(
          "On call to EntityIdentifierReaderImpl#resolve, EntityKey was already known; " +
              "should only happen on root returns with an optional identifier specified"
      );
View Full Code Here

      handleMissingIdentifier( context );
      return;
    }

    // make sure we have the EntityKey
    final EntityKey entityKey = processingState.getEntityKey();
    if ( entityKey == null ) {
      handleMissingIdentifier( context );
      return;
    }

    // Have we already hydrated this entity's state?
    if ( processingState.getEntityInstance() != null ) {
      return;
    }


    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // In getting here, we know that:
    //     1) We need to hydrate the entity state
    //    2) We have a valid EntityKey for the entity

    // see if we have an existing entry in the session for this EntityKey
    final Object existing = context.getSession().getEntityUsingInterceptor( entityKey );
    if ( existing != null ) {
      // It is previously associated with the Session, perform some checks
      if ( ! entityReference.getEntityPersister().isInstance( existing ) ) {
        throw new WrongClassException(
            "loaded object was of wrong class " + existing.getClass(),
            entityKey.getIdentifier(),
            entityReference.getEntityPersister().getEntityName()
        );
      }
      checkVersion( resultSet, context, entityKey, existing );

      // use the existing association as the hydrated state
      processingState.registerEntityInstance( existing );
      //context.registerHydratedEntity( entityReference, entityKey, existing );
      return;
    }

    // Otherwise, we need to load it from the ResultSet...

    // determine which entity instance to use.  Either the supplied one, or instantiate one
    Object optionalEntityInstance = null;
    if ( isReturn && context.shouldUseOptionalEntityInformation() ) {
      final EntityKey optionalEntityKey = ResultSetProcessorHelper.getOptionalObjectKey(
          context.getQueryParameters(),
          context.getSession()
      );
      if ( optionalEntityKey != null ) {
        if ( optionalEntityKey.equals( entityKey ) ) {
          optionalEntityInstance = context.getQueryParameters().getOptionalObject();
        }
      }
    }
View Full Code Here

TOP

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