Package org.hibernate.hql.ast.tree

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


    // 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;
      }
    }
View Full Code Here


  }

  private StatementExecutor buildAppropriateStatementExecutor(HqlSqlWalker walker) {
    Statement statement = ( Statement ) walker.getAST();
    if ( walker.getStatementType() == HqlSqlTokenTypes.DELETE ) {
      FromElement fromElement = walker.getFinalFromClause().getFromElement();
      Queryable persister = fromElement.getQueryable();
      if ( persister.isMultiTable() ) {
        return new MultiTableDeleteExecutor( walker );
      }
      else {
        return new BasicExecutor( walker, persister );
      }
    }
    else if ( walker.getStatementType() == HqlSqlTokenTypes.UPDATE ) {
      FromElement fromElement = walker.getFinalFromClause().getFromElement();
      Queryable persister = fromElement.getQueryable();
      if ( persister.isMultiTable() ) {
        // even here, if only properties mapped to the "base table" are referenced
        // in the set and where clauses, this could be handled by the BasicDelegate.
        // TODO : decide if it is better performance-wise to perform that check, or to simply use the MultiTableUpdateDelegate
        return new MultiTableUpdateExecutor( walker );
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() ) {
        out( ", " );
      }
      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

  public Set getQuerySpaces() {
    return querySpaces;
  }

  protected AST createFromElement(String path, AST alias, AST propertyFetch) throws SemanticException {
    FromElement fromElement = currentFromClause.addFromElement( path, alias );
    fromElement.setAllPropertyFetch(propertyFetch!=null);
    return fromElement;
  }
View Full Code Here

    fromElement.setAllPropertyFetch(propertyFetch!=null);
    return fromElement;
  }

  protected AST createFromFilterElement(AST filterEntity, AST alias) throws SemanticException {
    FromElement fromElement = currentFromClause.addFromElement( filterEntity.getText(), alias );
    FromClause fromClause = fromElement.getFromClause();
    QueryableCollection persister = sessionFactoryHelper.getCollectionPersister( collectionFilterRole );
    // Get the names of the columns used to link between the collection
    // owner and the collection elements.
    String[] keyColumnNames = persister.getKeyColumnNames();
    String fkTableAlias = persister.isOneToMany()
        ? fromElement.getTableAlias()
        : fromClause.getAliasGenerator().createName( collectionFilterRole );
    JoinSequence join = sessionFactoryHelper.createJoinSequence();
    join.setRoot( persister, fkTableAlias );
    if ( !persister.isOneToMany() ) {
      join.addJoin( ( AssociationType ) persister.getElementType(),
          fromElement.getTableAlias(),
          JoinFragment.INNER_JOIN,
          persister.getElementColumnNames( fkTableAlias ) );
    }
    join.addCondition( fkTableAlias, keyColumnNames, " = ?" );
    fromElement.setJoinSequence( join );
    fromElement.setFilter( true );
    if ( log.isDebugEnabled() ) {
      log.debug( "createFromFilterElement() : processed filter FROM element." );
    }
    return fromElement;
  }
View Full Code Here

    dot.setJoinType( hibernateJoinType )// Tell the dot node about the join type.
    dot.setFetch( fetch );
    // Generate an explicit join for the root dot node.   The implied joins will be collected and passed up
    // to the root dot node.
    dot.resolve( true, false, alias == null ? null : alias.getText() );
    FromElement fromElement = dot.getImpliedJoin();
    fromElement.setAllPropertyFetch(propertyFetch!=null);

    if ( with != null ) {
      if ( fetch ) {
        throw new SemanticException( "with-clause not allowed on fetched associations; use filters" );
      }
View Full Code Here

      String withClauseJoinAlias = visitor.getJoinAlias();
      if ( withClauseJoinAlias == null ) {
        withClauseJoinAlias = fromElement.getCollectionTableAlias();
      }
      else {
        FromElement referencedFromElement = visitor.getReferencedFromElement();
        if ( referencedFromElement != fromElement ) {
          throw new InvalidWithClauseException( "with-clause expressions did not reference from-clause element to which the with-clause was associated" );
        }
      }
View Full Code Here

    currentFromClause = currentFromClause.getParentFromClause();
  }

  protected void lookupAlias(AST aliasRef)
      throws SemanticException {
    FromElement alias = currentFromClause.getFromElement( aliasRef.getText() );
    FromReferenceNode aliasRefNode = ( FromReferenceNode ) aliasRef;
    aliasRefNode.setFromElement( alias );
  }
View Full Code Here

TOP

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