Package org.hibernate.loader.plan2.exec.process.internal

Examples of org.hibernate.loader.plan2.exec.process.internal.EntityReferenceInitializerImpl


//        }
//      }
//    }

    // build an EntityReferenceInitializers for the incoming fetch itself
    readerCollector.add( new EntityReferenceInitializerImpl( fetch, aliases ) );

    // then visit each of our (non-identifier) fetches
    processFetches( fetch, selectStatementBuilder, readerCollector, fetchStats );
  }
View Full Code Here


          return aliases.getEntityElementColumnAliases();
        }
      };
      aliasResolutionContext.registerQuerySpaceAliases( fetch.getQuerySpaceUid(), entityReferenceAliases );
      readerCollector.add(
          new EntityReferenceInitializerImpl(
              (EntityReference) fetch.getElementGraph(),
              entityReferenceAliases
          )
      );
    }
    else {
      final String rhsTableAlias = aliases.getElementTableAlias();

      // select the "collection columns"
      selectStatementBuilder.appendSelectClauseFragment(
          queryableCollection.selectFragment(
              rhsTableAlias,
              aliases.getCollectionColumnAliases().getSuffix()
          )
      );

      if ( fetch.getCollectionPersister().isOneToMany() ) {
        // if the collection elements are entities, select the entity columns as well
        final OuterJoinLoadable elementPersister = (OuterJoinLoadable) queryableCollection.getElementPersister();
        selectStatementBuilder.appendSelectClauseFragment(
            elementPersister.selectFragment(
                aliases.getElementTableAlias(),
                aliases.getEntityElementColumnAliases().getSuffix()
            )
        );
        final EntityReferenceAliases entityReferenceAliases = new EntityReferenceAliases() {
          @Override
          public String getTableAlias() {
            return aliases.getElementTableAlias();
          }

          @Override
          public EntityAliases getColumnAliases() {
            return aliases.getEntityElementColumnAliases();
          }
        };
        aliasResolutionContext.registerQuerySpaceAliases( fetch.getQuerySpaceUid(), entityReferenceAliases );
        readerCollector.add(
            new EntityReferenceInitializerImpl(
                (EntityReference) fetch.getElementGraph(),
                entityReferenceAliases
            )
        );
      }
View Full Code Here

        select,
        readerCollector
    );

    readerCollector.setRootReturnReader( new EntityReturnReader( rootReturn, entityReferenceAliases ) );
    readerCollector.add( new EntityReferenceInitializerImpl( rootReturn, entityReferenceAliases, true ) );

    return fetchStats;
  }
View Full Code Here

        rootReturn,
        select,
        readerCollector
    );

    readerCollector.setRootReturnReader( new EntityReturnReader( rootReturn, entityReferenceAliases ) );
    readerCollector.add( new EntityReferenceInitializerImpl( rootReturn, entityReferenceAliases, true ) );

    return fetchStats;
  }
View Full Code Here

    );

    LoadPlanTreePrinter.INSTANCE.logTree( loadPlan, aliasResolutionContext );

    this.sqlStatement = select.toStatementString();
    this.resultSetProcessor = new ResultSetProcessorImpl(
        loadPlan,
        readerCollector.buildRowReader(),
        fetchStats.hasSubselectFetches()
    );
  }
View Full Code Here

  }

  @Override
  public void hydrateIdentifier(ResultSet resultSet, ResultSetProcessingContextImpl context) throws SQLException {

    final EntityReferenceProcessingState processingState = context.getProcessingState( entityReference );

    // get any previously registered identifier hydrated-state
    Object identifierHydratedForm = processingState.getIdentifierHydratedForm();
    if ( identifierHydratedForm == null ) {
      // if there is none, read it from the result set
      identifierHydratedForm = readIdentifierHydratedState( resultSet, context );

      // broadcast the fact that a hydrated identifier value just became associated with
      // this entity reference
      processingState.registerIdentifierHydratedForm( identifierHydratedForm );
    }
  }
View Full Code Here

  }

  @Override
  public void resolveEntityKey(ResultSet resultSet, ResultSetProcessingContextImpl context) {

    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 [for %s], EntityKey was already known; " +
              "should only happen on root returns with an optional identifier specified"
      );
      return;
    }

    // Look for the hydrated form
    final Object identifierHydratedForm = processingState.getIdentifierHydratedForm();
    if ( identifierHydratedForm == null ) {
      // we need to register the missing identifier, but that happens later after all readers have had a chance
      // to resolve its EntityKey
      return;
    }

    final Type identifierType = entityReference.getEntityPersister().getIdentifierType();
    final Serializable resolvedId = (Serializable) identifierType.resolve(
        identifierHydratedForm,
        context.getSession(),
        null
    );
    if ( resolvedId != null ) {
      processingState.registerEntityKey(
          context.getSession().generateEntityKey( resolvedId, entityReference.getEntityPersister() )
      );
    }
  }
View Full Code Here

    }
  }

  @Override
  public void hydrateEntityState(ResultSet resultSet, ResultSetProcessingContextImpl context) {
    final EntityReferenceProcessingState processingState = context.getProcessingState( entityReference );

    // If there is no identifier for this entity reference for this row, nothing to do
    if ( processingState.isMissingIdentifier() ) {
      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 );
      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();
        }
      }
    }

    final String concreteEntityTypeName = getConcreteEntityTypeName( resultSet, context, entityKey );

    final Object entityInstance = optionalEntityInstance != null
        ? optionalEntityInstance
        : context.getSession().instantiate( concreteEntityTypeName, entityKey.getIdentifier() );

    processingState.registerEntityInstance( entityInstance );

    // need to hydrate it.
    // grab its state from the ResultSet and keep it in the Session
    // (but don't yet initialize the object itself)
    // note that we acquire LockMode.READ even if it was not requested
View Full Code Here

      final EntityType fetchedType = fetch.getFetchedType();
      if ( ! fetchedType.isOneToOne() ) {
        return;
      }

      final EntityReferenceProcessingState fetchOwnerState = context.getOwnerProcessingState( fetch );
      if ( fetchOwnerState == null ) {
        throw new IllegalStateException( "Could not locate fetch owner state" );
      }

      final EntityKey ownerEntityKey = fetchOwnerState.getEntityKey();
      if ( ownerEntityKey != null ) {
        context.getSession().getPersistenceContext().addNullProperty(
            ownerEntityKey,
            fetchedType.getPropertyName()
        );
View Full Code Here

    this.entityReturn = entityReturn;
    this.aliases = aliases;
  }

  public EntityReferenceProcessingState getIdentifierResolutionContext(ResultSetProcessingContext context) {
    final EntityReferenceProcessingState entityReferenceProcessingState = context.getProcessingState( entityReturn );

    if ( entityReferenceProcessingState == null ) {
      throw new AssertionFailure(
          String.format(
              "Could not locate EntityReferenceProcessingState for root entity return [%s (%s)]",
View Full Code Here

TOP

Related Classes of org.hibernate.loader.plan2.exec.process.internal.EntityReferenceInitializerImpl

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.