Package org.hibernate.sql

Examples of org.hibernate.sql.JoinFragment


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


      final LockOptions lockOptions) throws MappingException {

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

    JoinFragment ojf = mergeOuterJoins( associations );

    Select select = new Select( getDialect() )
        .setLockOptions( lockOptions )
        .setSelectClause(
            projection == null ?
                persister.selectFragment( alias, suffixes[joins] ) + selectString( associations ) :
                projection
        )
        .setFromClause(
            getDialect().appendLockHint( lockOptions, 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) {
    JoinFragment joinFragment = join.toJoinFragment(
        walker.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 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

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

    }

  }

  private void addJoinNodes(QueryNode query, JoinSequence join, FromElement fromElement) {
    JoinFragment joinFragment = join.toJoinFragment(
        walker.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

      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

  public static String createCollectionSubquery(
      JoinSequence joinSequence,
          Map enabledFilters,
          String[] columns) {
    try {
      JoinFragment join = joinSequence.toJoinFragment( enabledFilters, true );
      return new StringBuffer( "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

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.