Package org.hibernate.hql.ast.util

Examples of org.hibernate.hql.ast.util.SessionFactoryHelper


    Type elementType = queryableCollection.getElementType();
    if ( !elementType.isEntityType() ) {
      throw new IllegalArgumentException( "Cannot create element join for a collection of non-entities!" );
    }
    this.queryableCollection = queryableCollection;
    SessionFactoryHelper sfh = fromClause.getSessionFactoryHelper();
    FromElement destination = null;
    String tableAlias = null;
    EntityPersister entityPersister = queryableCollection.getElementPersister();
    tableAlias = fromClause.getAliasGenerator().createName( entityPersister.getEntityName() );
    String associatedEntityName = entityPersister.getEntityName();
    EntityPersister targetEntityPersister = sfh.requireClassPersister( associatedEntityName );
    // Create the FROM element for the target (the elements of the collection).
    destination = createAndAddFromElement(
        associatedEntityName,
        classAlias,
        targetEntityPersister,
        ( EntityType ) queryableCollection.getElementType(),
        tableAlias
      );
    // If the join is implied, then don't include sub-classes on the element.
    if ( implied ) {
      destination.setIncludeSubclasses( false );
    }
    fromClause.addCollectionJoinFromElementByPath( path, destination );
//    origin.addDestination(destination);
    // Add the query spaces.
    fromClause.getWalker().addQuerySpaces( entityPersister.getQuerySpaces() );

    CollectionType type = queryableCollection.getCollectionType();
    String role = type.getRole();
    String roleAlias = origin.getTableAlias();

    String[] targetColumns = sfh.getCollectionElementColumns( role, roleAlias );
    AssociationType elementAssociationType = sfh.getElementAssociationType( type );

    // Create the join element under the from element.
    int joinType = JoinFragment.INNER_JOIN;
    JoinSequence joinSequence = sfh.createJoinSequence( implied, elementAssociationType, tableAlias, joinType, targetColumns );
    elem = initializeJoin( path, destination, joinSequence, targetColumns, origin, false );
    elem.setUseFromFragment( true )// The associated entity is implied, but it must be included in the FROM.
    elem.setCollectionTableAlias( roleAlias )// The collection alias is the role.
    return elem;
  }
View Full Code Here


          String roleAlias,
          Queryable entityPersister,
          EntityType type,
          int joinType) throws SemanticException {
    FromElement elem;
    SessionFactoryHelper sfh = fromClause.getSessionFactoryHelper();
    if ( inElementsFunction /*implied*/ ) {
      // For implied many-to-many, just add the end join.
      JoinSequence joinSequence = createJoinSequence( roleAlias, joinType );
      elem = createJoin( associatedEntityName, roleAlias, joinSequence, type, true );
    }
    else {
      // For an explicit many-to-many relationship, add a second join from the intermediate
      // (many-to-many) table to the destination table.  Also, make sure that the from element's
      // idea of the destination is the destination table.
      String tableAlias = fromClause.getAliasGenerator().createName( entityPersister.getEntityName() );
      String[] secondJoinColumns = sfh.getCollectionElementColumns( role, roleAlias );
      // Add the second join, the one that ends in the destination table.
      JoinSequence joinSequence = createJoinSequence( roleAlias, joinType );
      joinSequence.addJoin( sfh.getElementAssociationType( collectionType ), tableAlias, joinType, secondJoinColumns );
      elem = createJoin( associatedEntityName, tableAlias, joinSequence, type, false );
      elem.setUseFromFragment( true );
    }
    return elem;
  }
View Full Code Here

    }
    return elem;
  }

  private JoinSequence createJoinSequence(String roleAlias, int joinType) {
    SessionFactoryHelper sessionFactoryHelper = fromClause.getSessionFactoryHelper();
    String[] joinColumns = getColumns();
    if ( collectionType == null ) {
      throw new IllegalStateException( "collectionType is null!" );
    }
    return sessionFactoryHelper.createJoinSequence( implied, collectionType, roleAlias, joinType, joinColumns );
  }
View Full Code Here

      String collectionRole) {
    setASTFactory( new SqlASTFactory( this ) );
    // Initialize the error handling delegate.
    this.parseErrorHandler = new ErrorCounter();
    this.queryTranslatorImpl = qti;
    this.sessionFactoryHelper = new SessionFactoryHelper( sfi );
    this.literalProcessor = new LiteralProcessor( this );
    this.tokenReplacements = tokenReplacements;
    this.collectionFilterRole = collectionRole;
    this.hqlParser = parser;
    this.printer = new ASTPrinter( SqlTokenTypes.class );
View Full Code Here

  throws SemanticException {
    if ( isResolved() ) {
      return;
    }
    FromReferenceNode collectionNode = ( FromReferenceNode ) getFirstChild();
    SessionFactoryHelper sessionFactoryHelper = getSessionFactoryHelper();
    collectionNode.resolveIndex( this );    // Fully resolve the map reference, create implicit joins.

    Type type = collectionNode.getDataType();
    if ( !type.isCollectionType() ) {
      throw new SemanticException( "The [] operator cannot be applied to type " + type.toString() );
    }
    String collectionRole = ( ( CollectionType ) type ).getRole();
    QueryableCollection queryableCollection = sessionFactoryHelper.requireQueryableCollection( collectionRole );
    if ( !queryableCollection.hasIndex() ) {
      throw new QueryException( "unindexed fromElement before []: " + collectionNode.getPath() );
    }

    // Generate the inner join -- The elements need to be joined to the collection they are in.
View Full Code Here

      String collectionRole) {
    setASTFactory( new SqlASTFactory( this ) );
    // Initialize the error handling delegate.
    this.parseErrorHandler = new ErrorCounter();
    this.queryTranslatorImpl = qti;
    this.sessionFactoryHelper = new SessionFactoryHelper( sfi );
    this.literalProcessor = new LiteralProcessor( this );
    this.tokenReplacements = tokenReplacements;
    this.collectionFilterRole = collectionRole;
    this.hqlParser = parser;
    this.printer = new ASTPrinter( SqlTokenTypes.class );
View Full Code Here

  throws SemanticException {
    if ( isResolved() ) {
      return;
    }
    FromReferenceNode collectionNode = ( FromReferenceNode ) getFirstChild();
    SessionFactoryHelper sessionFactoryHelper = getSessionFactoryHelper();
    collectionNode.resolveIndex( this );    // Fully resolve the map reference, create implicit joins.

    Type type = collectionNode.getDataType();
    if ( !type.isCollectionType() ) {
      throw new SemanticException( "The [] operator cannot be applied to type " + type.toString() );
    }
    String collectionRole = ( ( CollectionType ) type ).getRole();
    QueryableCollection queryableCollection = sessionFactoryHelper.requireQueryableCollection( collectionRole );
    if ( !queryableCollection.hasIndex() ) {
      throw new QueryException( "unindexed fromElement before []: " + collectionNode.getPath() );
    }

    // Generate the inner join -- The elements need to be joined to the collection they are in.
View Full Code Here

      String collectionRole) {
    setASTFactory( new SqlASTFactory( this ) );
    // Initialize the error handling delegate.
    this.parseErrorHandler = new ErrorCounter();
    this.queryTranslatorImpl = qti;
    this.sessionFactoryHelper = new SessionFactoryHelper( sfi );
    this.literalProcessor = new LiteralProcessor( this );
    this.tokenReplacements = tokenReplacements;
    this.collectionFilterRole = collectionRole;
    this.hqlParser = parser;
    this.printer = new ASTPrinter( SqlTokenTypes.class );
View Full Code Here

  throws SemanticException {
    if ( isResolved() ) {
      return;
    }
    FromReferenceNode collectionNode = ( FromReferenceNode ) getFirstChild();
    SessionFactoryHelper sessionFactoryHelper = getSessionFactoryHelper();
    collectionNode.resolveIndex( this );    // Fully resolve the map reference, create implicit joins.

    Type type = collectionNode.getDataType();
    if ( !type.isCollectionType() ) {
      throw new SemanticException( "The [] operator cannot be applied to type " + type.toString() );
    }
    String collectionRole = ( ( CollectionType ) type ).getRole();
    QueryableCollection queryableCollection = sessionFactoryHelper.requireQueryableCollection( collectionRole );
    if ( !queryableCollection.hasIndex() ) {
      throw new QueryException( "unindexed fromElement before []: " + collectionNode.getPath() );
    }

    // Generate the inner join -- The elements need to be joined to the collection they are in.
View Full Code Here

      String collectionRole) {
    setASTFactory( new SqlASTFactory( this ) );
    // Initialize the error handling delegate.
    this.parseErrorHandler = new ErrorCounter();
    this.queryTranslatorImpl = qti;
    this.sessionFactoryHelper = new SessionFactoryHelper( sfi );
    this.literalProcessor = new LiteralProcessor( this );
    this.tokenReplacements = tokenReplacements;
    this.collectionFilterRole = collectionRole;
    this.hqlParser = parser;
    this.printer = new ASTPrinter( SqlTokenTypes.class );
View Full Code Here

TOP

Related Classes of org.hibernate.hql.ast.util.SessionFactoryHelper

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.