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

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


    }

    // 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.tracev( "Forcing inclusion of extra joins [alias={0}, containsTableAlias={1}]", alias, containsTableAlias );
                        return true;
                    }
                    boolean shallowQuery = walker.isShallowQuery();
                    boolean includeSubclasses = fromElement.isIncludeSubclasses();
                    boolean subQuery = fromClause.isSubQuery();
                    return includeSubclasses && containsTableAlias && !subQuery && !shallowQuery;
          }
            }
      );
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

    // 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 DeleteExecutor( 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 doAfterTransactionCompletion that check, or to simply use the MultiTableUpdateDelegate
        return new MultiTableUpdateExecutor( walker );
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

    return querySpaces;
  }

  @Override
    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

    return fromElement;
  }

  @Override
    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(),
          JoinType.INNER_JOIN,
          persister.getElementColumnNames( fkTableAlias ) );
    }
    join.addCondition( fkTableAlias, keyColumnNames, " = ?" );
    fromElement.setJoinSequence( join );
    fromElement.setFilter( true );
        LOG.debug("createFromFilterElement() : processed filter FROM element.");
    return fromElement;
  }
View Full Code Here

    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() );

    final FromElement fromElement;
    if ( dot.getDataType() != null && dot.getDataType().isComponentType() ) {
      FromElementFactory factory = new FromElementFactory(
          getCurrentFromClause(),
          dot.getLhs().getFromElement(),
          dot.getPropertyPath(),
          alias == null ? null : alias.getText(),
          null,
          false
      );
      fromElement = factory.createComponentJoin( (ComponentType) dot.getDataType() );
    }
    else {
      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 ) {
          LOG.warn( "with-clause expressions do not reference the from-clause element to which the with-clause was associated.  The query may not work as expected..."
              + queryTranslatorImpl.getQueryString() );
        }
      }
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.