Package org.hibernate.sql

Examples of org.hibernate.sql.JoinFragment


      final LockMode lockMode) throws MappingException {

    final int joins = countEntityPersisters( associations );
    suffixes = BasicLoader.generateSuffixes( joins + 1 );

    JoinFragment ojf = mergeOuterJoins( associations );

    Select select = new Select( getDialect() )
        .setLockMode( lockMode )
        .setSelectClause(
            projection == null ?
                persister.selectFragment( alias, suffixes[joins] ) + selectString( associations ) :
                projection
        )
        .setFromClause(
            getDialect().appendLockHint( lockMode, persister.fromTableFragment( alias ) ) +
                persister.fromJoinFragment( alias, true, true )
        )
        .setWhereClause( condition )
        .setOuterJoins(
            ojf.toFromFragmentString(),
            ojf.toWhereFragmentString() + getWhereFragment()
        )
        .setOrderByClause( orderBy( associations, orderBy ) )
        .setGroupByClause( groupBy );

    if ( getFactory().getSettings().isCommentsEnabled() ) {
View Full Code Here


  }

  private void addJoinNodes(QueryNode query, JoinSequence join, FromElement fromElement, boolean inSubquery) {
    // Generate FROM and WHERE fragments for the from element.
    JoinFragment joinFragment = join.toJoinFragment(
        inSubquery ? Collections.EMPTY_MAP : queryTranslatorImpl.getEnabledFilters(),
        fromElement.useFromFragment() || fromElement.isDereferencedBySuperclassOrSubclassProperty(),
        fromElement.getWithClauseFragment(),
        fromElement.getWithClauseJoinAlias()
    );

    String frag = joinFragment.toFromFragmentString();
    String whereFrag = joinFragment.toWhereFragmentString();

    // If the from element represents a JOIN_FRAGMENT and it is
    // a theta-style join, convert its type from JOIN_FRAGMENT
    // to FROM_FRAGMENT
    if ( fromElement.getType() == JOIN_FRAGMENT &&
View Full Code Here

    return join;
  }

  protected JoinFragment createJoin(int[] tableNumbers, String drivingAlias) {
    final String[] keyCols = StringHelper.qualify( drivingAlias, getSubclassTableKeyColumns( tableNumbers[0] ) );
    final JoinFragment jf = getFactory().getDialect().createOuterJoinFragment();
    for ( int i = 1; i < tableNumbers.length; i++ ) { //skip the driving table
      final int j = tableNumbers[i];
      jf.addJoin( getSubclassTableName( j ),
          generateTableAlias( getRootAlias(), j ),
          keyCols,
          getSubclassTableKeyColumns( j ),
          isInverseSubclassTable( j ) || isNullableSubclassTable( j ) ?
          JoinFragment.LEFT_OUTER_JOIN :
View Full Code Here

    final String drivingAlias = generateTableAlias( getRootAlias(), drivingTable ); //we *could* regerate this inside each called method!
    final String where = createWhereByKey( drivingTable, drivingAlias );
    final String from = createFrom( drivingTable, drivingAlias );

    //now render the joins
    JoinFragment jf = createJoin( tableNumbers, drivingAlias );

    //now render the select clause
    SelectFragment selectFragment = createSelect( columnNumbers, formulaNumbers );

    //now tie it all together
    Select select = new Select( getFactory().getDialect() );
    select.setSelectClause( selectFragment.toFragmentString().substring( 2 ) );
    select.setFromClause( from );
    select.setWhereClause( where );
    select.setOuterJoins( jf.toFromFragmentString(), jf.toWhereFragmentString() );
    if ( getFactory().getSettings().isCommentsEnabled() ) {
      select.setComment( "sequential select " + getEntityName() );
    }
    return select.toStatementString();
  }
View Full Code Here

    return false;
  }

  protected JoinFragment createJoin(String name, boolean innerJoin, boolean includeSubclasses) {
    final String[] idCols = StringHelper.qualify( name, getIdentifierColumnNames() ); //all joins join to the pk of the driving table
    final JoinFragment join = getFactory().getDialect().createOuterJoinFragment();
    final int tableSpan = getSubclassTableSpan();
    for ( int j = 1; j < tableSpan; j++ ) { //notice that we skip the first table; it is the driving table!
      final boolean joinIsIncluded = isClassOrSuperclassTable( j ) ||
          ( includeSubclasses && !isSubclassTableSequentialSelect( j ) && !isSubclassTableLazy( j ) );
      if ( joinIsIncluded ) {
        join.addJoin( getSubclassTableName( j ),
            generateTableAlias( name, j ),
            idCols,
            getSubclassTableKeyColumns( j ),
            innerJoin && isClassOrSuperclassTable( j ) && !isInverseTable( j ) && !isNullableTable( j ) ?
            JoinFragment.INNER_JOIN : //we can inner join to superclass tables (the row MUST be there)
View Full Code Here

  public static String createCollectionSubquery(
      JoinSequence joinSequence,
      Map enabledFilters,
      String[] columns) {
    try {
      JoinFragment join = joinSequence.toJoinFragment( enabledFilters, true );
      return "select " + StringHelper.join( ", ", columns )
          + " from " + join.toFromFragmentString().substring( 2 )
          + " where " + join.toWhereFragmentString().substring( 5 );
    }
    catch (MappingException me) {
      throw new QueryException( me );
    }
  }
View Full Code Here

  }

  protected JoinFragment createJoin(String name, boolean innerJoin, boolean includeSubclasses, Set<String> treatAsDeclarations) {
    // IMPL NOTE : all joins join to the pk of the driving table
    final String[] idCols = StringHelper.qualify( name, getIdentifierColumnNames() );
    final JoinFragment join = getFactory().getDialect().createOuterJoinFragment();
    final int tableSpan = getSubclassTableSpan();
    // IMPL NOTE : notice that we skip the first table; it is the driving table!
    for ( int j = 1; j < tableSpan; j++ ) {
      final JoinType joinType = determineSubclassTableJoinType(
          j,
          innerJoin,
          includeSubclasses,
          treatAsDeclarations
      );

      if ( joinType != null && joinType != JoinType.NONE ) {
        join.addJoin(
            getSubclassTableName( j ),
            generateTableAlias( name, j ),
            idCols,
            getSubclassTableKeyColumns( j ),
            joinType
View Full Code Here

  }


  protected JoinFragment createJoin(int[] tableNumbers, String drivingAlias) {
    final String[] keyCols = StringHelper.qualify( drivingAlias, getSubclassTableKeyColumns( tableNumbers[0] ) );
    final JoinFragment jf = getFactory().getDialect().createOuterJoinFragment();
    // IMPL NOTE : notice that we skip the first table; it is the driving table!
    for ( int i = 1; i < tableNumbers.length; i++ ) {
      final int j = tableNumbers[i];
      jf.addJoin( getSubclassTableName( j ),
          generateTableAlias( getRootAlias(), j ),
          keyCols,
          getSubclassTableKeyColumns( j ),
          isInverseSubclassTable( j ) || isNullableSubclassTable( j )
              ? JoinType.LEFT_OUTER_JOIN
View Full Code Here

    final String drivingAlias = generateTableAlias( getRootAlias(), drivingTable ); //we *could* regerate this inside each called method!
    final String where = createWhereByKey( drivingTable, drivingAlias );
    final String from = createFrom( drivingTable, drivingAlias );

    //now render the joins
    JoinFragment jf = createJoin( tableNumbers, drivingAlias );

    //now render the select clause
    SelectFragment selectFragment = createSelect( columnNumbers, formulaNumbers );

    //now tie it all together
    Select select = new Select( getFactory().getDialect() );
    select.setSelectClause( selectFragment.toFragmentString().substring( 2 ) );
    select.setFromClause( from );
    select.setWhereClause( where );
    select.setOuterJoins( jf.toFromFragmentString(), jf.toWhereFragmentString() );
    if ( getFactory().getSettings().isCommentsEnabled() ) {
      select.setComment( "sequential select " + getEntityName() );
    }
    return select.toStatementString();
  }
View Full Code Here

    return factory;
  }

  public void processQuerySpaceJoins(QuerySpace querySpace, SelectStatementBuilder selectStatementBuilder) {
    LOG.debug( "processing queryspace " + querySpace.getUid() );
    final JoinFragment joinFragment = factory.getDialect().createOuterJoinFragment();
    processQuerySpaceJoins( querySpace, joinFragment );

    selectStatementBuilder.setOuterJoins(
        joinFragment.toFromFragmentString(),
        joinFragment.toWhereFragmentString()
    );
  }
View Full Code Here

TOP

Related Classes of org.hibernate.sql.JoinFragment

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.