Package org.hibernate.hql.ast.tree

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


  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

      //          2) here we would need to track each comparison individually, along with
      //              the join alias to which it applies and then pass that information
      //              back to the FromElement so it can pass it along to the JoinSequence
      if ( node instanceof DotNode ) {
        DotNode dotNode = ( DotNode ) node;
        FromElement fromElement = dotNode.getFromElement();
        if ( referencedFromElement != null ) {
          if ( fromElement != referencedFromElement ) {
            throw new HibernateException( "with-clause referenced two different from-clause elements" );
          }
        }
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

    }

    // 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

      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

      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

      //          2) here we would need to track each comparison individually, along with
      //              the join alias to which it applies and then pass that information
      //              back to the FromElement so it can pass it along to the JoinSequence
      if ( node instanceof DotNode ) {
        DotNode dotNode = ( DotNode ) node;
        FromElement fromElement = dotNode.getFromElement();
        if ( referencedFromElement != null ) {
          if ( fromElement != referencedFromElement ) {
            throw new HibernateException( "with-clause referenced two different from-clause elements" );
          }
        }
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

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.