Package org.hibernate.sql

Examples of org.hibernate.sql.QueryJoinFragment


  public JoinFragment toJoinFragment(
      Map enabledFilters,
      boolean includeAllSubclassJoins,
      String withClauseFragment,
      String withClauseJoinAlias) throws MappingException {
    final QueryJoinFragment joinFragment = new QueryJoinFragment( factory.getDialect(), useThetaStyle );
    if ( rootJoinable != null ) {
      joinFragment.addCrossJoin( rootJoinable.getTableName(), rootAlias );
      final String filterCondition = rootJoinable.filterFragment( rootAlias, enabledFilters, treatAsDeclarations );
      // JoinProcessor needs to know if the where clause fragment came from a dynamic filter or not so it
      // can put the where clause fragment in the right place in the SQL AST.   'hasFilterCondition' keeps track
      // of that fact.
      joinFragment.setHasFilterCondition( joinFragment.addCondition( filterCondition ) );
      addSubclassJoins( joinFragment, rootAlias, rootJoinable, true, includeAllSubclassJoins, treatAsDeclarations );
    }

    Joinable last = rootJoinable;

    for ( Join join : joins ) {
      // technically the treatAsDeclarations should only apply to rootJoinable or to a single Join,
      // but that is not possible atm given how these JoinSequence and Join objects are built.
      // However, it is generally ok given how the HQL parser builds these JoinSequences (a HQL join
      // results in a JoinSequence with an empty rootJoinable and a single Join).  So we use that here
      // as an assumption
      final String on = join.getAssociationType().getOnCondition( join.getAlias(), factory, enabledFilters, treatAsDeclarations );
      String condition;
      if ( last != null
          && isManyToManyRoot( last )
          && ((QueryableCollection) last).getElementType() == join.getAssociationType() ) {
        // the current join represents the join between a many-to-many association table
        // and its "target" table.  Here we need to apply any additional filters
        // defined specifically on the many-to-many
        final String manyToManyFilter = ( (QueryableCollection) last ).getManyToManyFilterFragment(
            join.getAlias(),
            enabledFilters
        );
        condition = "".equals( manyToManyFilter )
            ? on
            : "".equals( on ) ? manyToManyFilter : on + " and " + manyToManyFilter;
      }
      else {
        condition = on;
      }

      if ( withClauseFragment != null && !isManyToManyRoot( join.joinable )) {
        condition += " and " + withClauseFragment;
      }

      joinFragment.addJoin(
          join.getJoinable().getTableName(),
          join.getAlias(),
          join.getLHSColumns(),
          JoinHelper.getRHSColumnNames( join.getAssociationType(), factory ),
          join.joinType,
          condition
      );

      addSubclassJoins(
          joinFragment,
          join.getAlias(),
          join.getJoinable(),
          join.joinType == JoinType.INNER_JOIN,
          includeAllSubclassJoins,
          // ugh.. this is needed because of how HQL parser (FromElementFactory/SessionFactoryHelper)
          // builds the JoinSequence for HQL joins
          treatAsDeclarations
      );
      last = join.getJoinable();
    }

    if ( next != null ) {
      joinFragment.addFragment( next.toJoinFragment( enabledFilters, includeAllSubclassJoins ) );
    }

    joinFragment.addCondition( conditions.toString() );

    if ( isFromPart ) {
      joinFragment.clearWherePart();
    }

    return joinFragment;
  }
View Full Code Here


  public JoinFragment toJoinFragment(
      Map enabledFilters,
      boolean includeExtraJoins,
      String withClauseFragment,
      String withClauseJoinAlias) throws MappingException {
    final QueryJoinFragment joinFragment = new QueryJoinFragment( factory.getDialect(), useThetaStyle );
    if ( rootJoinable != null ) {
      joinFragment.addCrossJoin( rootJoinable.getTableName(), rootAlias );
      final String filterCondition = rootJoinable.filterFragment( rootAlias, enabledFilters );
      // JoinProcessor needs to know if the where clause fragment came from a dynamic filter or not so it
      // can put the where clause fragment in the right place in the SQL AST.   'hasFilterCondition' keeps track
      // of that fact.
      joinFragment.setHasFilterCondition( joinFragment.addCondition( filterCondition ) );
      if ( includeExtraJoins ) {
        //TODO: not quite sure about the full implications of this!
        addExtraJoins( joinFragment, rootAlias, rootJoinable, true );
      }
    }

    Joinable last = rootJoinable;

    for ( Join join : joins ) {
      final String on = join.getAssociationType().getOnCondition( join.getAlias(), factory, enabledFilters );
      String condition;
      if ( last != null
          && isManyToManyRoot( last )
          && ((QueryableCollection) last).getElementType() == join.getAssociationType() ) {
        // the current join represents the join between a many-to-many association table
        // and its "target" table.  Here we need to apply any additional filters
        // defined specifically on the many-to-many
        final String manyToManyFilter = ( (QueryableCollection) last ).getManyToManyFilterFragment(
            join.getAlias(),
            enabledFilters
        );
        condition = "".equals( manyToManyFilter )
            ? on
            : "".equals( on ) ? manyToManyFilter : on + " and " + manyToManyFilter;
      }
      else {
        condition = on;
      }

      if ( withClauseFragment != null ) {
        condition += " and " + withClauseFragment;
      }

      joinFragment.addJoin(
          join.getJoinable().getTableName(),
          join.getAlias(),
          join.getLHSColumns(),
          JoinHelper.getRHSColumnNames( join.getAssociationType(), factory ),
          join.joinType,
          condition
      );

      //TODO: not quite sure about the full implications of this!
      if ( includeExtraJoins ) {
        addExtraJoins(
            joinFragment,
            join.getAlias(),
            join.getJoinable(),
            join.joinType == JoinType.INNER_JOIN
        );
      }
      last = join.getJoinable();
    }

    if ( next != null ) {
      joinFragment.addFragment( next.toJoinFragment( enabledFilters, includeExtraJoins ) );
    }

    joinFragment.addCondition( conditions.toString() );

    if ( isFromPart ) {
      joinFragment.clearWherePart();
    }

    return joinFragment;
  }
View Full Code Here

  public JoinFragment toJoinFragment(
      Map enabledFilters,
          boolean includeExtraJoins,
          String withClauseFragment,
          String withClauseJoinAlias) throws MappingException {
    QueryJoinFragment joinFragment = new QueryJoinFragment( factory.getDialect(), useThetaStyle );
    if ( rootJoinable != null ) {
      joinFragment.addCrossJoin( rootJoinable.getTableName(), rootAlias );
      String filterCondition = rootJoinable.filterFragment( rootAlias, enabledFilters );
      // JoinProcessor needs to know if the where clause fragment came from a dynamic filter or not so it
      // can put the where clause fragment in the right place in the SQL AST.   'hasFilterCondition' keeps track
      // of that fact.
      joinFragment.setHasFilterCondition( joinFragment.addCondition( filterCondition ) );
      if (includeExtraJoins) { //TODO: not quite sure about the full implications of this!
        addExtraJoins( joinFragment, rootAlias, rootJoinable, true );
      }
    }

    Joinable last = rootJoinable;

    for ( Join join: joins ) {
      String on = join.getAssociationType().getOnCondition( join.getAlias(), factory, enabledFilters );
      String condition = null;
      if ( last != null &&
              isManyToManyRoot( last ) &&
              ( ( QueryableCollection ) last ).getElementType() == join.getAssociationType() ) {
        // the current join represents the join between a many-to-many association table
        // and its "target" table.  Here we need to apply any additional filters
        // defined specifically on the many-to-many
        String manyToManyFilter = ( ( QueryableCollection ) last )
                .getManyToManyFilterFragment( join.getAlias(), enabledFilters );
        condition = "".equals( manyToManyFilter )
            ? on
            : "".equals( on )
                ? manyToManyFilter
                : on + " and " + manyToManyFilter;
      }
      else {
        condition = on;
      }
      if ( withClauseFragment != null ) {
        if ( join.getAlias().equals( withClauseJoinAlias ) ) {
          condition += " and " + withClauseFragment;
        }
      }
      joinFragment.addJoin(
              join.getJoinable().getTableName(),
          join.getAlias(),
          join.getLHSColumns(),
          JoinHelper.getRHSColumnNames( join.getAssociationType(), factory ),
          join.joinType,
          condition
      );
      if (includeExtraJoins) { //TODO: not quite sure about the full implications of this!
        addExtraJoins( joinFragment, join.getAlias(), join.getJoinable(), join.joinType == JoinType.INNER_JOIN );
      }
      last = join.getJoinable();
    }
    if ( next != null ) {
      joinFragment.addFragment( next.toJoinFragment( enabledFilters, includeExtraJoins ) );
    }
    joinFragment.addCondition( conditions.toString() );
    if ( isFromPart ) joinFragment.clearWherePart();
    return joinFragment;
  }
View Full Code Here

  public JoinFragment toJoinFragment(
      Map enabledFilters,
          boolean includeExtraJoins,
          String withClauseFragment,
          String withClauseJoinAlias) throws MappingException {
    QueryJoinFragment joinFragment = new QueryJoinFragment( factory.getDialect(), useThetaStyle );
    if ( rootJoinable != null ) {
      joinFragment.addCrossJoin( rootJoinable.getTableName(), rootAlias );
      String filterCondition = rootJoinable.filterFragment( rootAlias, enabledFilters );
      // JoinProcessor needs to know if the where clause fragment came from a dynamic filter or not so it
      // can put the where clause fragment in the right place in the SQL AST.   'hasFilterCondition' keeps track
      // of that fact.
      joinFragment.setHasFilterCondition( joinFragment.addCondition( filterCondition ) );
      if (includeExtraJoins) { //TODO: not quite sure about the full implications of this!
        addExtraJoins( joinFragment, rootAlias, rootJoinable, true );
      }
    }

    Joinable last = rootJoinable;

    for ( Join join: joins ) {
      String on = join.getAssociationType().getOnCondition( join.getAlias(), factory, enabledFilters );
      String condition = null;
      if ( last != null &&
              isManyToManyRoot( last ) &&
              ( ( QueryableCollection ) last ).getElementType() == join.getAssociationType() ) {
        // the current join represents the join between a many-to-many association table
        // and its "target" table.  Here we need to apply any additional filters
        // defined specifically on the many-to-many
        String manyToManyFilter = ( ( QueryableCollection ) last )
                .getManyToManyFilterFragment( join.getAlias(), enabledFilters );
        condition = "".equals( manyToManyFilter )
            ? on
            : "".equals( on )
                ? manyToManyFilter
                : on + " and " + manyToManyFilter;
      }
      else {
        condition = on;
      }
      if ( withClauseFragment != null ) {
        if ( join.getAlias().equals( withClauseJoinAlias ) ) {
          condition += " and " + withClauseFragment;
        }
      }
      joinFragment.addJoin(
              join.getJoinable().getTableName(),
          join.getAlias(),
          join.getLHSColumns(),
          JoinHelper.getRHSColumnNames( join.getAssociationType(), factory ),
          join.joinType,
          condition
      );
      if (includeExtraJoins) { //TODO: not quite sure about the full implications of this!
        addExtraJoins( joinFragment, join.getAlias(), join.getJoinable(), join.joinType == JoinType.INNER_JOIN );
      }
      last = join.getJoinable();
    }
    if ( next != null ) {
      joinFragment.addFragment( next.toJoinFragment( enabledFilters, includeExtraJoins ) );
    }
    joinFragment.addCondition( conditions.toString() );
    if ( isFromPart ) joinFragment.clearWherePart();
    return joinFragment;
  }
View Full Code Here

  public JoinFragment toJoinFragment(
      Map enabledFilters,
      boolean includeExtraJoins,
      String withClauseFragment,
      String withClauseJoinAlias) throws MappingException {
    final QueryJoinFragment joinFragment = new QueryJoinFragment( factory.getDialect(), useThetaStyle );
    if ( rootJoinable != null ) {
      joinFragment.addCrossJoin( rootJoinable.getTableName(), rootAlias );
      final String filterCondition = rootJoinable.filterFragment( rootAlias, enabledFilters );
      // JoinProcessor needs to know if the where clause fragment came from a dynamic filter or not so it
      // can put the where clause fragment in the right place in the SQL AST.   'hasFilterCondition' keeps track
      // of that fact.
      joinFragment.setHasFilterCondition( joinFragment.addCondition( filterCondition ) );
      if ( includeExtraJoins ) {
        //TODO: not quite sure about the full implications of this!
        addExtraJoins( joinFragment, rootAlias, rootJoinable, true );
      }
    }

    Joinable last = rootJoinable;

    for ( Join join : joins ) {
      final String on = join.getAssociationType().getOnCondition( join.getAlias(), factory, enabledFilters );
      String condition;
      if ( last != null
          && isManyToManyRoot( last )
          && ((QueryableCollection) last).getElementType() == join.getAssociationType() ) {
        // the current join represents the join between a many-to-many association table
        // and its "target" table.  Here we need to apply any additional filters
        // defined specifically on the many-to-many
        final String manyToManyFilter = ( (QueryableCollection) last ).getManyToManyFilterFragment(
            join.getAlias(),
            enabledFilters
        );
        condition = "".equals( manyToManyFilter )
            ? on
            : "".equals( on ) ? manyToManyFilter : on + " and " + manyToManyFilter;
      }
      else {
        condition = on;
      }

      if ( withClauseFragment != null ) {
        if ( join.getAlias().equals( withClauseJoinAlias ) ) {
          condition += " and " + withClauseFragment;
        }
      }

      joinFragment.addJoin(
          join.getJoinable().getTableName(),
          join.getAlias(),
          join.getLHSColumns(),
          JoinHelper.getRHSColumnNames( join.getAssociationType(), factory ),
          join.joinType,
          condition
      );

      //TODO: not quite sure about the full implications of this!
      if ( includeExtraJoins ) {
        addExtraJoins(
            joinFragment,
            join.getAlias(),
            join.getJoinable(),
            join.joinType == JoinType.INNER_JOIN
        );
      }
      last = join.getJoinable();
    }

    if ( next != null ) {
      joinFragment.addFragment( next.toJoinFragment( enabledFilters, includeExtraJoins ) );
    }

    joinFragment.addCondition( conditions.toString() );

    if ( isFromPart ) {
      joinFragment.clearWherePart();
    }

    return joinFragment;
  }
View Full Code Here

  public JoinFragment toJoinFragment(
      Map enabledFilters,
          boolean includeExtraJoins,
          String withClauseFragment,
          String withClauseJoinAlias) throws MappingException {
    QueryJoinFragment joinFragment = new QueryJoinFragment( factory.getDialect(), useThetaStyle );
    if ( rootJoinable != null ) {
      joinFragment.addCrossJoin( rootJoinable.getTableName(), rootAlias );
      String filterCondition = rootJoinable.filterFragment( rootAlias, enabledFilters );
      // JoinProcessor needs to know if the where clause fragment came from a dynamic filter or not so it
      // can put the where clause fragment in the right place in the SQL AST.   'hasFilterCondition' keeps track
      // of that fact.
      joinFragment.setHasFilterCondition( joinFragment.addCondition( filterCondition ) );
      if (includeExtraJoins) { //TODO: not quite sure about the full implications of this!
        addExtraJoins( joinFragment, rootAlias, rootJoinable, true );
      }
    }

    Joinable last = rootJoinable;

    for ( Join join: joins ) {
      String on = join.getAssociationType().getOnCondition( join.getAlias(), factory, enabledFilters );
      String condition = null;
      if ( last != null &&
              isManyToManyRoot( last ) &&
              ( ( QueryableCollection ) last ).getElementType() == join.getAssociationType() ) {
        // the current join represents the join between a many-to-many association table
        // and its "target" table.  Here we need to apply any additional filters
        // defined specifically on the many-to-many
        String manyToManyFilter = ( ( QueryableCollection ) last )
                .getManyToManyFilterFragment( join.getAlias(), enabledFilters );
        condition = "".equals( manyToManyFilter )
            ? on
            : "".equals( on )
                ? manyToManyFilter
                : on + " and " + manyToManyFilter;
      }
      else {
        condition = on;
      }
      if ( withClauseFragment != null ) {
        condition += " and " + withClauseFragment;
      }
      joinFragment.addJoin(
              join.getJoinable().getTableName(),
          join.getAlias(),
          join.getLHSColumns(),
          JoinHelper.getRHSColumnNames( join.getAssociationType(), factory ),
          join.joinType,
          condition
      );
      if (includeExtraJoins) { //TODO: not quite sure about the full implications of this!
        addExtraJoins( joinFragment, join.getAlias(), join.getJoinable(), join.joinType == JoinType.INNER_JOIN );
      }
      last = join.getJoinable();
    }
    if ( next != null ) {
      joinFragment.addFragment( next.toJoinFragment( enabledFilters, includeExtraJoins ) );
    }
    joinFragment.addCondition( conditions.toString() );
    if ( isFromPart ) joinFragment.clearWherePart();
    return joinFragment;
  }
View Full Code Here

TOP

Related Classes of org.hibernate.sql.QueryJoinFragment

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.