Package org.hibernate.hql.internal.ast.tree

Examples of org.hibernate.hql.internal.ast.tree.FromElement


      case ALIAS_REF: {
        // Notify the FROM element that it is being referenced by the select.
        FromReferenceNode aliasRefNode = ( FromReferenceNode ) node;
        //aliasRefNode.resolve( false, false, aliasRefNode.getText() ); //TODO: is it kosher to do it here?
        aliasRefNode.resolve( false, false ); //TODO: is it kosher to do it here?
        FromElement fromElement = aliasRefNode.getFromElement();
        if ( fromElement != null ) {
          fromElement.setIncludeSubclasses( true );
        }
        break;
      }
      default: {
        break;
View Full Code Here


    protected void beforeSelectClause() throws SemanticException {
    // Turn off includeSubclasses on all FromElements.
    FromClause from = getCurrentFromClause();
    List fromElements = from.getFromElements();
    for ( Iterator iterator = fromElements.iterator(); iterator.hasNext(); ) {
      FromElement fromElement = ( FromElement ) iterator.next();
      fromElement.setIncludeSubclasses( false );
    }
  }
View Full Code Here

      int length = collectionFromElements.size();
      collectionPersisters = new QueryableCollection[length];
      collectionOwners = new int[length];
      collectionSuffixes = new String[length];
      for ( int i=0; i<length; i++ ) {
        FromElement collectionFromElement = (FromElement) collectionFromElements.get(i);
        collectionPersisters[i] = collectionFromElement.getQueryableCollection();
        collectionOwners[i] = fromElementList.indexOf( collectionFromElement.getOrigin() );
//        collectionSuffixes[i] = collectionFromElement.getColumnAliasSuffix();
//        collectionSuffixes[i] = Integer.toString( i ) + "_";
        collectionSuffixes[i] = collectionFromElement.getCollectionSuffix();
      }
    }

    int size = fromElementList.size();
    entityPersisters = new Queryable[size];
    entityEagerPropertyFetches = new boolean[size];
    entityAliases = new String[size];
    sqlAliases = new String[size];
    sqlAliasSuffixes = new String[size];
    includeInSelect = new boolean[size];
    owners = new int[size];
    ownerAssociationTypes = new EntityType[size];

    for ( int i = 0; i < size; i++ ) {
      final FromElement element = ( FromElement ) fromElementList.get( i );
      entityPersisters[i] = ( Queryable ) element.getEntityPersister();

      if ( entityPersisters[i] == null ) {
        throw new IllegalStateException( "No entity persister for " + element.toString() );
      }

      entityEagerPropertyFetches[i] = element.isAllPropertyFetch();
      sqlAliases[i] = element.getTableAlias();
      entityAliases[i] = element.getClassAlias();
      sqlAliasByEntityAlias.put( entityAliases[i], sqlAliases[i] );
      // TODO should we just collect these like with the collections above?
      sqlAliasSuffixes[i] = ( size == 1 ) ? "" : Integer.toString( i ) + "_";
//      sqlAliasSuffixes[i] = element.getColumnAliasSuffix();
      includeInSelect[i] = !element.isFetch();
      if ( includeInSelect[i] ) {
        selectLength++;
      }

      owners[i] = -1; //by default
      if ( element.isFetch() ) {
        if ( element.isCollectionJoin() || element.getQueryableCollection() != null ) {
          // This is now handled earlier in this method.
        }
        else if ( element.getDataType().isEntityType() ) {
          EntityType entityType = ( EntityType ) element.getDataType();
          if ( entityType.isOneToOne() ) {
            owners[i] = fromElementList.indexOf( element.getOrigin() );
          }
          ownerAssociationTypes[i] = entityType;
        }
      }
    }
View Full Code Here

    AST next = a.getNextSibling();
    if ( next == null || !hasText( a ) ) {
      return;
    }

    FromElement left = ( FromElement ) a;
    FromElement right = ( FromElement ) next;

    ///////////////////////////////////////////////////////////////////////
    // HACK ALERT !!!!!!!!!!!!!!!!!!!!!!!!!!!!
    // Attempt to work around "ghost" ImpliedFromElements that occasionally
    // show up between the actual things being joined.  This consistently
    // occurs from index nodes (at least against many-to-many).  Not sure
    // if there are other conditions
    //
    // Essentially, look-ahead to the next FromElement that actually
    // writes something to the SQL
    while ( right != null && !hasText( right ) ) {
      right = ( FromElement ) right.getNextSibling();
    }
    if ( right == null ) {
      return;
    }
    ///////////////////////////////////////////////////////////////////////

    if ( !hasText( right ) ) {
      return;
    }

    if ( right.getRealOrigin() == left ||
         ( right.getRealOrigin() != null && right.getRealOrigin() == left.getRealOrigin() ) ) {
      // right represents a joins originating from left; or
      // both right and left reprersent joins originating from the same FromElement
      if ( right.getJoinSequence() != null && right.getJoinSequence().isThetaStyle() ) {
        writeCrossJoinSeparator();
      }
      else {
        out( " " );
      }
View Full Code Here

    // check a set of parent/child nodes in the from-clause tree
    // to determine if a comma is required between them
    if ( d != null && hasText( d ) ) {
      if ( parent != null && hasText( parent ) ) {
        // again, both should be FromElements
        FromElement left = ( FromElement ) parent;
        FromElement right = ( FromElement ) d;
        if ( right.getRealOrigin() == left ) {
          // right represents a joins originating from left...
          if ( right.getJoinSequence() != null && right.getJoinSequence().isThetaStyle() ) {
            out( ", " );
          }
          else {
            out( " " );
          }
View Full Code Here

    if ( !walker.getSessionFactoryHelper().getFactory().getDialect().supportsTemporaryTables() ) {
      throw new HibernateException( "cannot doAfterTransactionCompletion multi-table deletes using dialect not supporting temp tables" );
    }

    DeleteStatement deleteStatement = ( DeleteStatement ) walker.getAST();
    FromElement fromElement = deleteStatement.getFromClause().getFromElement();
    String bulkTargetAlias = fromElement.getTableAlias();
    this.persister = fromElement.getQueryable();

    this.idInsertSelect = generateIdInsertSelect( persister, bulkTargetAlias, deleteStatement.getWhereClause() );
        LOG.trace("Generated ID-INSERT-SELECT SQL (multi-table delete) : " + idInsertSelect);

    String[] tableNames = persister.getConstraintOrderedTableNameClosure();
View Full Code Here

    if ( !walker.getSessionFactoryHelper().getFactory().getDialect().supportsTemporaryTables() ) {
      throw new HibernateException( "cannot doAfterTransactionCompletion multi-table updates using dialect not supporting temp tables" );
    }

    UpdateStatement updateStatement = ( UpdateStatement ) walker.getAST();
    FromElement fromElement = updateStatement.getFromClause().getFromElement();
    String bulkTargetAlias = fromElement.getTableAlias();
    this.persister = fromElement.getQueryable();

    this.idInsertSelect = generateIdInsertSelect( persister, bulkTargetAlias, updateStatement.getWhereClause() );
        LOG.trace("Generated ID-INSERT-SELECT SQL (multi-table update) : " + idInsertSelect);

    String[] tableNames = persister.getConstraintOrderedTableNameClosure();
View Full Code Here

    AST next = a.getNextSibling();
    if ( next == null || !hasText( a ) ) {
      return;
    }

    FromElement left = ( FromElement ) a;
    FromElement right = ( FromElement ) next;

    ///////////////////////////////////////////////////////////////////////
    // HACK ALERT !!!!!!!!!!!!!!!!!!!!!!!!!!!!
    // Attempt to work around "ghost" ImpliedFromElements that occasionally
    // show up between the actual things being joined.  This consistently
    // occurs from index nodes (at least against many-to-many).  Not sure
    // if there are other conditions
    //
    // Essentially, look-ahead to the next FromElement that actually
    // writes something to the SQL
    while ( right != null && !hasText( right ) ) {
      right = ( FromElement ) right.getNextSibling();
    }
    if ( right == null ) {
      return;
    }
    ///////////////////////////////////////////////////////////////////////

    if ( !hasText( right ) ) {
      return;
    }

    if ( right.getRealOrigin() == left ||
         ( right.getRealOrigin() != null && right.getRealOrigin() == left.getRealOrigin() ) ) {
      // right represents a joins originating from left; or
      // both right and left reprersent joins originating from the same FromElement
      if ( right.getJoinSequence() != null && right.getJoinSequence().isThetaStyle() ) {
        writeCrossJoinSeparator();
      }
      else {
        out( " " );
      }
View Full Code Here

    // check a set of parent/child nodes in the from-clause tree
    // to determine if a comma is required between them
    if ( d != null && hasText( d ) ) {
      if ( parent != null && hasText( parent ) ) {
        // again, both should be FromElements
        FromElement left = ( FromElement ) parent;
        FromElement right = ( FromElement ) d;
        if ( right.getRealOrigin() == left ) {
          // right represents a joins originating from left...
          if ( right.getJoinSequence() != null && right.getJoinSequence().isThetaStyle() ) {
            out( ", " );
          }
          else {
            out( " " );
          }
View Full Code Here

    }

    // Iterate through the alias,JoinSequence pairs and generate SQL token nodes.
    Iterator iter = fromElements.iterator();
    while ( iter.hasNext() ) {
      final FromElement fromElement = ( FromElement ) iter.next();
      JoinSequence join = fromElement.getJoinSequence();
            join.setSelector(new JoinSequence.Selector() {
                public boolean includeSubclasses( String alias ) {
                    // The uber-rule here is that we need to include subclass joins if
                    // the FromElement is in any way dereferenced by a property from
                    // the subclass table; otherwise we end up with column references
                    // qualified by a non-existent table reference in the resulting SQL...
                    boolean containsTableAlias = fromClause.containsTableAlias(alias);
                    if (fromElement.isDereferencedBySubclassProperty()) {
                        // TODO : or should we return 'containsTableAlias'??
                        LOG.trace("Forcing inclusion of extra joins [alias=" + alias + ", containsTableAlias=" + containsTableAlias
                                  + "]");
                        return true;
                    }
                    boolean shallowQuery = walker.isShallowQuery();
                    boolean includeSubclasses = fromElement.isIncludeSubclasses();
                    boolean subQuery = fromClause.isSubQuery();
                    return includeSubclasses && containsTableAlias && !subQuery && !shallowQuery;
          }
            }
      );
View Full Code Here

TOP

Related Classes of org.hibernate.hql.internal.ast.tree.FromElement

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.