Package org.hibernate.sql

Examples of org.hibernate.sql.JoinFragment


    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


    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 ) ?
            JoinType.INNER_JOIN : //we can inner join to superclass tables (the row MUST be there)
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 ) ?
          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

        }
      }
    }
    whereString.insert( 0, StringHelper.moveAndToBeginning( filter ) );

    JoinFragment ojf = mergeOuterJoins(associations);
    Select select = new Select( getDialect() )
      .setSelectClause(
        collectionPersister.selectFragment(alias, collectionSuffixes[0] ) +
        selectString(associations)
      )
      .setFromClause( collectionPersister.getTableName(), alias )
      .setWhereClause( whereString.toString()  )
      .setOuterJoins(
        ojf.toFromFragmentString(),
        ojf.toWhereFragmentString()
      );

    select.setOrderByClause( orderBy( associations, mergeOrderings( collectionPersister.getSQLOrderByString(alias), manyToManyOrderBy ) ) );

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

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

        }
      }
    }
    whereString.insert( 0, StringHelper.moveAndToBeginning( filter ) );

    JoinFragment ojf = mergeOuterJoins(associations);
    Select select = new Select( getDialect() )
      .setSelectClause(
        collectionPersister.selectFragment(alias, collectionSuffixes[0] ) +
        selectString(associations)
      )
      .setFromClause( collectionPersister.getTableName(), alias )
      .setWhereClause( whereString.toString()  )
      .setOuterJoins(
        ojf.toFromFragmentString(),
        ojf.toWhereFragmentString()
      );

    select.setOrderByClause( orderBy( associations, mergeOrderings( collectionPersister.getSQLOrderByString(alias), manyToManyOrderBy ) ) );

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

  /**
   * Generate a sequence of <tt>LEFT OUTER JOIN</tt> clauses for the given associations.
   */
  protected final JoinFragment mergeOuterJoins(List associations)
  throws MappingException {
    JoinFragment outerjoin = getDialect().createOuterJoinFragment();
    Iterator iter = associations.iterator();
    OuterJoinableAssociation last = null;
    while ( iter.hasNext() ) {
      OuterJoinableAssociation oj = (OuterJoinableAssociation) iter.next();
      if ( last != null && last.isManyToManyWith( oj ) ) {
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.