Package org.hibernate.hql.ast.tree

Examples of org.hibernate.hql.ast.tree.QueryNode


    if ( log.isDebugEnabled() ) {
      log.debug( "processQuery() : " + query.toStringTree() );
    }

    try {
      QueryNode qn = ( QueryNode ) query;

      // Was there an explicit select expression?
      boolean explicitSelect = select != null && select.getNumberOfChildren() > 0;

      if ( !explicitSelect ) {
        // No explicit select expression; render the id and properties
        // projection lists for every persister in the from clause into
        // a single 'token node'.
        //TODO: the only reason we need this stuff now is collection filters,
        //      we should get rid of derived select clause completely!
        createSelectClauseFromFromClause( qn );
      }
      else {
        // Use the explicitly declared select expression; determine the
        // return types indicated by each select token
        useSelectClause( select );
      }

      // After that, process the JOINs.
      // Invoke a delegate to do the work, as this is farily complex.
      JoinProcessor joinProcessor = new JoinProcessor( astFactory, queryTranslatorImpl );
      joinProcessor.processJoins( qn, isSubQuery() );

      // Attach any mapping-defined "ORDER BY" fragments
      Iterator itr = qn.getFromClause().getProjectionList().iterator();
      while ( itr.hasNext() ) {
        final FromElement fromElement = ( FromElement ) itr.next();
//      if ( fromElement.isFetch() && fromElement.isCollectionJoin() ) {
        if ( fromElement.isFetch() && fromElement.getQueryableCollection() != null ) {
          // Does the collection referenced by this FromElement
          // specify an order-by attribute?  If so, attach it to
          // the query's order-by
          if ( fromElement.getQueryableCollection().hasOrdering() ) {
            String orderByFragment = fromElement
                .getQueryableCollection()
                .getSQLOrderByString( fromElement.getCollectionTableAlias() );
            qn.getOrderByClause().addOrderFragment( orderByFragment );
          }
          if ( fromElement.getQueryableCollection().hasManyToManyOrdering() ) {
            String orderByFragment = fromElement.getQueryableCollection()
                .getManyToManyOrderByString( fromElement.getTableAlias() );
            qn.getOrderByClause().addOrderFragment( orderByFragment );
          }
        }
      }
    }
    finally {
View Full Code Here


  public List list(SessionImplementor session, QueryParameters queryParameters)
      throws HibernateException {
    // Delegate to the QueryLoader...
    errorIfDML();
    QueryNode query = ( QueryNode ) sqlAst;
    boolean hasLimit = queryParameters.getRowSelection() != null && queryParameters.getRowSelection().definesLimits();
    boolean needsDistincting = ( query.getSelectClause().isDistinct() || hasLimit ) && containsCollectionFetches();

    QueryParameters queryParametersToUse;
    if ( hasLimit && containsCollectionFetches() ) {
      log.warn( "firstResult/maxResults specified with collection fetch; applying in memory!" );
      RowSelection selection = new RowSelection();
View Full Code Here

    // entire fecthed graph still "points back" to a single
    // root entity for return

    errorIfDML();

    QueryNode query = ( QueryNode ) sqlAst;

    // If there are no collection fetches, then no further checks are needed
    List collectionFetches = query.getFromClause().getCollectionFetches();
    if ( collectionFetches.isEmpty() ) {
      return;
    }

    // A shallow query is ok (although technically there should be no fetching here...)
    if ( isShallowQuery() ) {
      return;
    }

    // Otherwise, we have a non-scalar select with defined collection fetch(es).
    // Make sure that there is only a single root entity in the return (no tuples)
    if ( getReturnTypes().length > 1 ) {
      throw new HibernateException( "cannot scroll with collection fetches and returned tuples" );
    }

    FromElement owner = null;
    Iterator itr = query.getSelectClause().getFromElementsForLoad().iterator();
    while ( itr.hasNext() ) {
      // should be the first, but just to be safe...
      final FromElement fromElement = ( FromElement ) itr.next();
      if ( fromElement.getOrigin() == null ) {
        owner = fromElement;
        break;
      }
    }

    if ( owner == null ) {
      throw new HibernateException( "unable to locate collection fetch(es) owner for scrollability checks" );
    }

    // This is not strictly true.  We actually just need to make sure that
    // it is ordered by root-entity PK and that that order-by comes before
    // any non-root-entity ordering...

    AST primaryOrdering = query.getOrderByClause().getFirstChild();
    if ( primaryOrdering != null ) {
      // TODO : this is a bit dodgy, come up with a better way to check this (plus see above comment)
      String [] idColNames = owner.getQueryable().getIdentifierColumnNames();
      String expectedPrimaryOrderSeq = StringHelper.join(
              ", ",
View Full Code Here

  public List list(SessionImplementor session, QueryParameters queryParameters)
      throws HibernateException {
    // Delegate to the QueryLoader...
    errorIfDML();
    QueryNode query = ( QueryNode ) sqlAst;
    boolean hasLimit = queryParameters.getRowSelection() != null && queryParameters.getRowSelection().definesLimits();
    boolean needsDistincting = ( query.getSelectClause().isDistinct() || hasLimit ) && containsCollectionFetches();

    QueryParameters queryParametersToUse;
    if ( hasLimit && containsCollectionFetches() ) {
      log.warn( "firstResult/maxResults specified with collection fetch; applying in memory!" );
      RowSelection selection = new RowSelection();
View Full Code Here

    // entire fecthed graph still "points back" to a single
    // root entity for return

    errorIfDML();

    QueryNode query = ( QueryNode ) sqlAst;

    // If there are no collection fetches, then no further checks are needed
    List collectionFetches = query.getFromClause().getCollectionFetches();
    if ( collectionFetches.isEmpty() ) {
      return;
    }

    // A shallow query is ok (although technically there should be no fetching here...)
    if ( isShallowQuery() ) {
      return;
    }

    // Otherwise, we have a non-scalar select with defined collection fetch(es).
    // Make sure that there is only a single root entity in the return (no tuples)
    if ( getReturnTypes().length > 1 ) {
      throw new HibernateException( "cannot scroll with collection fetches and returned tuples" );
    }

    FromElement owner = null;
    Iterator itr = query.getSelectClause().getFromElementsForLoad().iterator();
    while ( itr.hasNext() ) {
      // should be the first, but just to be safe...
      final FromElement fromElement = ( FromElement ) itr.next();
      if ( fromElement.getOrigin() == null ) {
        owner = fromElement;
        break;
      }
    }

    if ( owner == null ) {
      throw new HibernateException( "unable to locate collection fetch(es) owner for scrollability checks" );
    }

    // This is not strictly true.  We actually just need to make sure that
    // it is ordered by root-entity PK and that that order-by comes before
    // any non-root-entity ordering...

    AST primaryOrdering = query.getOrderByClause().getFirstChild();
    if ( primaryOrdering != null ) {
      // TODO : this is a bit dodgy, come up with a better way to check this (plus see above comment)
      String [] idColNames = owner.getQueryable().getIdentifierColumnNames();
      String expectedPrimaryOrderSeq = StringHelper.join(
              ", ",
View Full Code Here

    if ( log.isDebugEnabled() ) {
      log.debug( "processQuery() : " + query.toStringTree() );
    }

    try {
      QueryNode qn = ( QueryNode ) query;

      // Was there an explicit select expression?
      boolean explicitSelect = select != null && select.getNumberOfChildren() > 0;

      if ( !explicitSelect ) {
        // No explicit select expression; render the id and properties
        // projection lists for every persister in the from clause into
        // a single 'token node'.
        //TODO: the only reason we need this stuff now is collection filters,
        //      we should get rid of derived select clause completely!
        createSelectClauseFromFromClause( qn );
      }
      else {
        // Use the explicitly declared select expression; determine the
        // return types indicated by each select token
        useSelectClause( select );
      }

      // After that, process the JOINs.
      // Invoke a delegate to do the work, as this is farily complex.
      JoinProcessor joinProcessor = new JoinProcessor( this );
      joinProcessor.processJoins( qn );

      // Attach any mapping-defined "ORDER BY" fragments
      Iterator itr = qn.getFromClause().getProjectionList().iterator();
      while ( itr.hasNext() ) {
        final FromElement fromElement = ( FromElement ) itr.next();
//      if ( fromElement.isFetch() && fromElement.isCollectionJoin() ) {
        if ( fromElement.isFetch() && fromElement.getQueryableCollection() != null ) {
          // Does the collection referenced by this FromElement
          // specify an order-by attribute?  If so, attach it to
          // the query's order-by
          if ( fromElement.getQueryableCollection().hasOrdering() ) {
            String orderByFragment = fromElement
                .getQueryableCollection()
                .getSQLOrderByString( fromElement.getCollectionTableAlias() );
            qn.getOrderByClause().addOrderFragment( orderByFragment );
          }
          if ( fromElement.getQueryableCollection().hasManyToManyOrdering() ) {
            String orderByFragment = fromElement.getQueryableCollection()
                .getManyToManyOrderByString( fromElement.getTableAlias() );
            qn.getOrderByClause().addOrderFragment( orderByFragment );
          }
        }
      }
    }
    finally {
View Full Code Here

  public List list(SessionImplementor session, QueryParameters queryParameters)
      throws HibernateException {
    // Delegate to the QueryLoader...
    errorIfDML();
    QueryNode query = ( QueryNode ) sqlAst;
    boolean hasLimit = queryParameters.getRowSelection() != null && queryParameters.getRowSelection().definesLimits();
    boolean needsDistincting = ( query.getSelectClause().isDistinct() || hasLimit ) && containsCollectionFetches();

    QueryParameters queryParametersToUse;
    if ( hasLimit && containsCollectionFetches() ) {
      log.warn( "firstResult/maxResults specified with collection fetch; applying in memory!" );
      RowSelection selection = new RowSelection();
View Full Code Here

    // entire fecthed graph still "points back" to a single
    // root entity for return

    errorIfDML();

    QueryNode query = ( QueryNode ) sqlAst;

    // If there are no collection fetches, then no further checks are needed
    List collectionFetches = query.getFromClause().getCollectionFetches();
    if ( collectionFetches.isEmpty() ) {
      return;
    }

    // A shallow query is ok (although technically there should be no fetching here...)
    if ( isShallowQuery() ) {
      return;
    }

    // Otherwise, we have a non-scalar select with defined collection fetch(es).
    // Make sure that there is only a single root entity in the return (no tuples)
    if ( getReturnTypes().length > 1 ) {
      throw new HibernateException( "cannot scroll with collection fetches and returned tuples" );
    }

    FromElement owner = null;
    Iterator itr = query.getSelectClause().getFromElementsForLoad().iterator();
    while ( itr.hasNext() ) {
      // should be the first, but just to be safe...
      final FromElement fromElement = ( FromElement ) itr.next();
      if ( fromElement.getOrigin() == null ) {
        owner = fromElement;
        break;
      }
    }

    if ( owner == null ) {
      throw new HibernateException( "unable to locate collection fetch(es) owner for scrollability checks" );
    }

    // This is not strictly true.  We actually just need to make sure that
    // it is ordered by root-entity PK and that that order-by comes before
    // any non-root-entity ordering...

    AST primaryOrdering = query.getOrderByClause().getFirstChild();
    if ( primaryOrdering != null ) {
      // TODO : this is a bit dodgy, come up with a better way to check this (plus see above comment)
      String [] idColNames = owner.getQueryable().getIdentifierColumnNames();
      String expectedPrimaryOrderSeq = StringHelper.join(
              ", ",
View Full Code Here

    if ( log.isDebugEnabled() ) {
      log.debug( "processQuery() : " + query.toStringTree() );
    }

    try {
      QueryNode qn = ( QueryNode ) query;

      // Was there an explicit select expression?
      boolean explicitSelect = select != null && select.getNumberOfChildren() > 0;

      if ( !explicitSelect ) {
        // No explicit select expression; render the id and properties
        // projection lists for every persister in the from clause into
        // a single 'token node'.
        //TODO: the only reason we need this stuff now is collection filters,
        //      we should get rid of derived select clause completely!
        createSelectClauseFromFromClause( qn );
      }
      else {
        // Use the explicitly declared select expression; determine the
        // return types indicated by each select token
        useSelectClause( select );
      }

      // After that, process the JOINs.
      // Invoke a delegate to do the work, as this is farily complex.
      JoinProcessor joinProcessor = new JoinProcessor( this );
      joinProcessor.processJoins( qn );

      // Attach any mapping-defined "ORDER BY" fragments
      Iterator itr = qn.getFromClause().getProjectionList().iterator();
      while ( itr.hasNext() ) {
        final FromElement fromElement = ( FromElement ) itr.next();
//      if ( fromElement.isFetch() && fromElement.isCollectionJoin() ) {
        if ( fromElement.isFetch() && fromElement.getQueryableCollection() != null ) {
          // Does the collection referenced by this FromElement
          // specify an order-by attribute?  If so, attach it to
          // the query's order-by
          if ( fromElement.getQueryableCollection().hasOrdering() ) {
            String orderByFragment = fromElement
                .getQueryableCollection()
                .getSQLOrderByString( fromElement.getCollectionTableAlias() );
            qn.getOrderByClause().addOrderFragment( orderByFragment );
          }
          if ( fromElement.getQueryableCollection().hasManyToManyOrdering() ) {
            String orderByFragment = fromElement.getQueryableCollection()
                .getManyToManyOrderByString( fromElement.getTableAlias() );
            qn.getOrderByClause().addOrderFragment( orderByFragment );
          }
        }
      }
    }
    finally {
View Full Code Here

      // corresponding to the given user alias.  However, the driving table is not
      // (necessarily) the table against which we want to apply locks.  Mainly,
      // the exception case here is joined-subclass hierarchies where we instead
      // want to apply the lock against the root table (for all other strategies,
      // it just happens that driving and root are the same).
      final QueryNode select = ( QueryNode ) queryTranslator.getSqlAST();
      final Lockable drivingPersister = ( Lockable ) select.getFromClause().getFromElement( userAlias ).getQueryable();
      final String sqlAlias = drivingPersister.getRootTableAlias( drivingSqlAlias );
      aliasedLockModes.put( sqlAlias, me.getValue() );
      if ( keyColumnNames != null ) {
        keyColumnNames.put( sqlAlias, drivingPersister.getRootTableIdentifierColumnNames() );
      }
View Full Code Here

TOP

Related Classes of org.hibernate.hql.ast.tree.QueryNode

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.