Package org.hibernate.loader.plan.exec.query.internal

Examples of org.hibernate.loader.plan.exec.query.internal.SelectStatementBuilder


    //    build the needed SQL.
    //   2) Determine how to read information out of the ResultSet resulting from executing the indicated SQL
    //    (the SQL aliases).  ReaderCollector and friends are where this work happens, ultimately
    //    producing a ResultSetProcessor

    final SelectStatementBuilder select = new SelectStatementBuilder( queryProcessor.getSessionFactory().getDialect() );

    // LoadPlan is broken down into 2 high-level pieces that we need to process here.
    //
    // First is the QuerySpaces, which roughly equates to the SQL FROM-clause.  We'll cycle through
    // those first, generating aliases into the AliasContext in addition to writing SQL FROM-clause information
    // into SelectStatementBuilder.  The AliasContext is populated here and the reused while process the SQL
    // SELECT-clause into the SelectStatementBuilder and then again also to build the ResultSetProcessor

    applyRootReturnTableFragments( select );

    if ( shouldApplyRootReturnFilterBeforeKeyRestriction() ) {
      applyRootReturnFilterRestrictions( select );
      // add restrictions...
      // first, the load key restrictions (which entity(s)/collection(s) do we want to load?)
      applyKeyRestriction(
          select,
          getRootTableAlias(),
          keyColumnNames,
          getQueryBuildingParameters().getBatchSize()
      );
    }
    else {
      // add restrictions...
      // first, the load key restrictions (which entity(s)/collection(s) do we want to load?)
      applyKeyRestriction(
          select,
          getRootTableAlias(),
          keyColumnNames,
          getQueryBuildingParameters().getBatchSize()
      );
      applyRootReturnFilterRestrictions( select );
    }


    applyRootReturnWhereJoinRestrictions( select );

    applyRootReturnOrderByFragments( select );
    // then move on to joins...

    applyRootReturnSelectFragments( select );

    queryProcessor.processQuerySpaceJoins( getRootQuerySpace(), select );

    // Next, we process the Returns and Fetches building the SELECT clause and at the same time building
    // Readers for reading the described results out of a SQL ResultSet

    FetchStats fetchStats = null;
    if ( FetchSource.class.isInstance( rootReturn ) ) {
      fetchStats = queryProcessor.processFetches(
          (FetchSource) rootReturn,
          select,
          getReaderCollector()
      );
    }
    else if ( CollectionReturn.class.isInstance( rootReturn ) ) {
      final CollectionReturn collectionReturn = (CollectionReturn) rootReturn;
      if ( collectionReturn.getElementGraph() != null ) {
        fetchStats = queryProcessor.processFetches(
            collectionReturn.getElementGraph(),
            select,
            getReaderCollector()
        );
      }
      // TODO: what about index???
    }

    LoadPlanTreePrinter.INSTANCE.logTree( loadPlan, queryProcessor.getAliasResolutionContext() );

    this.sqlStatement = select.toStatementString();
    this.resultSetProcessor = new ResultSetProcessorImpl(
        loadPlan,
        getReaderCollector().buildRowReader(),
        fetchStats != null && fetchStats.hasSubselectFetches()
    );
View Full Code Here


    //    build the needed SQL.
    //   2) Determine how to read information out of the ResultSet resulting from executing the indicated SQL
    //    (the SQL aliases).  ReaderCollector and friends are where this work happens, ultimately
    //    producing a ResultSetProcessor

    final SelectStatementBuilder select = new SelectStatementBuilder( queryProcessor.getSessionFactory().getDialect() );

    // LoadPlan is broken down into 2 high-level pieces that we need to process here.
    //
    // First is the QuerySpaces, which roughly equates to the SQL FROM-clause.  We'll cycle through
    // those first, generating aliases into the AliasContext in addition to writing SQL FROM-clause information
    // into SelectStatementBuilder.  The AliasContext is populated here and the reused while process the SQL
    // SELECT-clause into the SelectStatementBuilder and then again also to build the ResultSetProcessor

    applyRootReturnTableFragments( select );

    if ( shouldApplyRootReturnFilterBeforeKeyRestriction() ) {
      applyRootReturnFilterRestrictions( select );
      // add restrictions...
      // first, the load key restrictions (which entity(s)/collection(s) do we want to load?)
      applyKeyRestriction(
          select,
          getRootTableAlias(),
          keyColumnNames,
          getQueryBuildingParameters().getBatchSize()
      );
    }
    else {
      // add restrictions...
      // first, the load key restrictions (which entity(s)/collection(s) do we want to load?)
      applyKeyRestriction(
          select,
          getRootTableAlias(),
          keyColumnNames,
          getQueryBuildingParameters().getBatchSize()
      );
      applyRootReturnFilterRestrictions( select );
    }


    applyRootReturnWhereJoinRestrictions( select );

    applyRootReturnOrderByFragments( select );
    // then move on to joins...

    applyRootReturnSelectFragments( select );

    queryProcessor.processQuerySpaceJoins( getRootQuerySpace(), select );

    // Next, we process the Returns and Fetches building the SELECT clause and at the same time building
    // Readers for reading the described results out of a SQL ResultSet

    FetchStats fetchStats = null;
    if ( FetchSource.class.isInstance( rootReturn ) ) {
      fetchStats = queryProcessor.processFetches(
          (FetchSource) rootReturn,
          select,
          getReaderCollector()
      );
    }
    else if ( CollectionReturn.class.isInstance( rootReturn ) ) {
      final CollectionReturn collectionReturn = (CollectionReturn) rootReturn;
      if ( collectionReturn.getElementGraph() != null ) {
        fetchStats = queryProcessor.processFetches(
            collectionReturn.getElementGraph(),
            select,
            getReaderCollector()
        );
      }
      // TODO: what about index???
    }

    LoadPlanTreePrinter.INSTANCE.logTree( loadPlan, queryProcessor.getAliasResolutionContext() );

    this.sqlStatement = select.toStatementString();
    this.resultSetProcessor = new ResultSetProcessorImpl(
        loadPlan,
        getReaderCollector().buildRowReader(),
        fetchStats != null && fetchStats.hasSubselectFetches()
    );
View Full Code Here

      boolean shouldUseOptionalEntityInformation,
      QueryBuildingParameters buildingParameters,
      SessionFactoryImplementor factory) {
    this.loadPlan = loadPlan;

    final SelectStatementBuilder select = new SelectStatementBuilder( factory.getDialect() );
    final EntityReturn rootReturn = Helper.INSTANCE.extractRootReturn( loadPlan, EntityReturn.class );
    final AliasResolutionContext aliasResolutionContext = new AliasResolutionContextImpl( factory );
    final ReaderCollectorImpl readerCollector = new ReaderCollectorImpl();

    final String[] keyColumnNamesToUse = keyColumnNames != null
        ? keyColumnNames
        : ( (Queryable) rootReturn.getEntityPersister() ).getIdentifierColumnNames();

    // apply root entity return specifics
    applyRootReturnSpecifics(
        select,
        keyColumnNamesToUse,
        rootReturn,
        factory,
        buildingParameters,
        aliasResolutionContext
    );
    readerCollector.addReader(
        new EntityReturnReader(
            rootReturn,
            aliasResolutionContext.resolveAliases( rootReturn ),
            new EntityIdentifierReaderImpl(
                rootReturn,
                aliasResolutionContext.resolveAliases( rootReturn ),
                Collections.<EntityReferenceReader>emptyList()
            )
        )
    );

    FetchStats fetchStats = LoadQueryBuilderHelper.applyJoinFetches(
        select,
        factory,
        rootReturn,
        buildingParameters,
        aliasResolutionContext,
        readerCollector
    );

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

TOP

Related Classes of org.hibernate.loader.plan.exec.query.internal.SelectStatementBuilder

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.