Package org.hibernate.sql

Examples of org.hibernate.sql.Select


  }

  protected abstract Queryable[] getAffectedQueryables();

  protected String generateIdInsertSelect(Queryable persister, String tableAlias, AST whereClause) {
    Select select = new Select( getFactory().getDialect() );
    SelectFragment selectFragment = new SelectFragment()
        .addColumns( tableAlias, persister.getIdentifierColumnNames(), persister.getIdentifierColumnNames() );
    select.setSelectClause( selectFragment.toFragmentString().substring( 2 ) );

    String rootTableName = persister.getTableName();
    String fromJoinFragment = persister.fromJoinFragment( tableAlias, true, false );
    String whereJoinFragment = persister.whereJoinFragment( tableAlias, true, false );

    select.setFromClause( rootTableName + ' ' + tableAlias + fromJoinFragment );

    if ( whereJoinFragment == null ) {
      whereJoinFragment = "";
    }
    else {
      whereJoinFragment = whereJoinFragment.trim();
      if ( whereJoinFragment.startsWith( "and" ) ) {
        whereJoinFragment = whereJoinFragment.substring( 4 );
      }
    }

    String userWhereClause = "";
    if ( whereClause.getNumberOfChildren() != 0 ) {
      // If a where clause was specified in the update/delete query, use it to limit the
      // returned ids here...
      try {
        SqlGenerator sqlGenerator = new SqlGenerator( getFactory() );
        sqlGenerator.whereClause( whereClause );
        userWhereClause = sqlGenerator.getSQL().substring( 7 )// strip the " where "
        idSelectParameterSpecifications = sqlGenerator.getCollectedParameters();
      }
      catch ( RecognitionException e ) {
        throw new HibernateException( "Unable to generate id select for DML operation", e );
      }
      if ( whereJoinFragment.length() > 0 ) {
        whereJoinFragment += " and ";
      }
    }

    select.setWhereClause( whereJoinFragment + userWhereClause );

    InsertSelect insert = new InsertSelect( getFactory().getDialect() );
    if ( getFactory().getSettings().isCommentsEnabled() ) {
      insert.setComment( "insert-select for " + persister.getEntityName() + " ids" );
    }
View Full Code Here


    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() ) {
      select.setComment( getComment() );
    }
    sql = select.toStatementString();
  }
View Full Code Here

  protected String generateUpdateGeneratedValuesSelectString() {
    return generateGeneratedValuesSelectString( getPropertyUpdateGenerationInclusions() );
  }

  private String generateGeneratedValuesSelectString(ValueInclusion[] inclusions) {
    Select select = new Select( getFactory().getDialect() );

    if ( getFactory().getSettings().isCommentsEnabled() ) {
      select.setComment( "get generated state " + getEntityName() );
    }

    String[] aliasedIdColumns = StringHelper.qualify( getRootAlias(), getIdentifierColumnNames() );

    // Here we render the select column list based on the properties defined as being generated.
    // For partial component generation, we currently just re-select the whole component
    // rather than trying to handle the individual generated portions.
    String selectClause = concretePropertySelectFragment( getRootAlias(), inclusions );
    selectClause = selectClause.substring( 2 );

    String fromClause = fromTableFragment( getRootAlias() ) +
        fromJoinFragment( getRootAlias(), true, false );

    String whereClause = new StringBuffer()
      .append( StringHelper.join( "=? and ", aliasedIdColumns ) )
      .append( "=?" )
      .append( whereJoinFragment( getRootAlias(), true, false ) )
      .toString();

    return select.setSelectClause( selectClause )
        .setFromClause( fromClause )
        .setOuterJoins( "", "" )
        .setWhereClause( whereClause )
        .toStatementString();
  }
View Full Code Here

  protected String generateSnapshotSelectString() {

    //TODO: should we use SELECT .. FOR UPDATE?

    Select select = new Select( getFactory().getDialect() );

    if ( getFactory().getSettings().isCommentsEnabled() ) {
      select.setComment( "get current state " + getEntityName() );
    }

    String[] aliasedIdColumns = StringHelper.qualify( getRootAlias(), getIdentifierColumnNames() );
    String selectClause = StringHelper.join( ", ", aliasedIdColumns ) +
        concretePropertySelectFragment( getRootAlias(), getPropertyUpdateability() );

    String fromClause = fromTableFragment( getRootAlias() ) +
        fromJoinFragment( getRootAlias(), true, false );

    String whereClause = new StringBuffer()
      .append( StringHelper.join( "=? and ",
          aliasedIdColumns ) )
      .append( "=?" )
      .append( whereJoinFragment( getRootAlias(), true, false ) )
      .toString();

    /*if ( isVersioned() ) {
      where.append(" and ")
        .append( getVersionColumnName() )
        .append("=?");
    }*/

    return select.setSelectClause( selectClause )
        .setFromClause( fromClause )
        .setOuterJoins( "", "" )
        .setWhereClause( whereClause )
        .toStatementString();
  }
View Full Code Here

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

      naturalIdMarkers[ naturalIdPropertyIndexes[i] ] = true;
    }

    ///////////////////////////////////////////////////////////////////////
    // TODO : look at perhaps caching this...
    Select select = new Select( getFactory().getDialect() );
    if ( getFactory().getSettings().isCommentsEnabled() ) {
      select.setComment( "get current natural-id state " + getEntityName() );
    }
    select.setSelectClause( concretePropertySelectFragmentSansLeadingComma( getRootAlias(), naturalIdMarkers ) );
    select.setFromClause( fromTableFragment( getRootAlias() ) + fromJoinFragment( getRootAlias(), true, false ) );

    String[] aliasedIdColumns = StringHelper.qualify( getRootAlias(), getIdentifierColumnNames() );
    String whereClause = new StringBuffer()
      .append( StringHelper.join( "=? and ",
          aliasedIdColumns ) )
      .append( "=?" )
      .append( whereJoinFragment( getRootAlias(), true, false ) )
      .toString();

    String sql = select.setOuterJoins( "", "" )
        .setWhereClause( whereClause )
        .toStatementString();
    ///////////////////////////////////////////////////////////////////////

    Object[] snapshot = new Object[ naturalIdPropertyCount ];
View Full Code Here

  }

  protected abstract Queryable[] getAffectedQueryables();

  protected String generateIdInsertSelect(Queryable persister, String tableAlias, AST whereClause) {
    Select select = new Select( getFactory().getDialect() );
    SelectFragment selectFragment = new SelectFragment()
        .addColumns( tableAlias, persister.getIdentifierColumnNames(), persister.getIdentifierColumnNames() );
    select.setSelectClause( selectFragment.toFragmentString().substring( 2 ) );

    String rootTableName = persister.getTableName();
    String fromJoinFragment = persister.fromJoinFragment( tableAlias, true, false );
    String whereJoinFragment = persister.whereJoinFragment( tableAlias, true, false );

    select.setFromClause( rootTableName + ' ' + tableAlias + fromJoinFragment );

    if ( whereJoinFragment == null ) {
      whereJoinFragment = "";
    }
    else {
      whereJoinFragment = whereJoinFragment.trim();
      if ( whereJoinFragment.startsWith( "and" ) ) {
        whereJoinFragment = whereJoinFragment.substring( 4 );
      }
    }

    String userWhereClause = "";
    if ( whereClause.getNumberOfChildren() != 0 ) {
      // If a where clause was specified in the update/delete query, use it to limit the
      // returned ids here...
      try {
        SqlGenerator sqlGenerator = new SqlGenerator( getFactory() );
        sqlGenerator.whereClause( whereClause );
        userWhereClause = sqlGenerator.getSQL().substring( 7 )// strip the " where "
      }
      catch ( RecognitionException e ) {
        throw new HibernateException( "Unable to generate id select for DML operation", e );
      }
      if ( whereJoinFragment.length() > 0 ) {
        whereJoinFragment += " and ";
      }
    }

    select.setWhereClause( whereJoinFragment + userWhereClause );

    InsertSelect insert = new InsertSelect( getFactory().getDialect() );
    if ( getFactory().getSettings().isCommentsEnabled() ) {
      insert.setComment( "insert-select for " + persister.getEntityName() + " ids" );
    }
View Full Code Here

  }

  protected abstract Queryable[] getAffectedQueryables();

  protected String generateIdInsertSelect(Queryable persister, String tableAlias, AST whereClause) {
    Select select = new Select( getFactory().getDialect() );
    SelectFragment selectFragment = new SelectFragment()
        .addColumns( tableAlias, persister.getIdentifierColumnNames(), persister.getIdentifierColumnNames() );
    select.setSelectClause( selectFragment.toFragmentString().substring( 2 ) );

    String rootTableName = persister.getTableName();
    String fromJoinFragment = persister.fromJoinFragment( tableAlias, true, false );
    String whereJoinFragment = persister.whereJoinFragment( tableAlias, true, false );

    select.setFromClause( rootTableName + ' ' + tableAlias + fromJoinFragment );

    if ( whereJoinFragment == null ) {
      whereJoinFragment = "";
    }
    else {
      whereJoinFragment = whereJoinFragment.trim();
      if ( whereJoinFragment.startsWith( "and" ) ) {
        whereJoinFragment = whereJoinFragment.substring( 4 );
      }
    }

    String userWhereClause = "";
    if ( whereClause.getNumberOfChildren() != 0 ) {
      // If a where clause was specified in the update/delete query, use it to limit the
      // returned ids here...
      try {
        SqlGenerator sqlGenerator = new SqlGenerator( getFactory() );
        sqlGenerator.whereClause( whereClause );
        userWhereClause = sqlGenerator.getSQL().substring( 7 )// strip the " where "
        idSelectParameterSpecifications = sqlGenerator.getCollectedParameters();
      }
      catch ( RecognitionException e ) {
        throw new HibernateException( "Unable to generate id select for DML operation", e );
      }
      if ( whereJoinFragment.length() > 0 ) {
        whereJoinFragment += " and ";
      }
    }

    select.setWhereClause( whereJoinFragment + userWhereClause );

    InsertSelect insert = new InsertSelect( getFactory().getDialect() );
    if ( getFactory().getSettings().isCommentsEnabled() ) {
      insert.setComment( "insert-select for " + persister.getEntityName() + " ids" );
    }
View Full Code Here

  }

  protected abstract Queryable[] getAffectedQueryables();

  protected String generateIdInsertSelect(Queryable persister, String tableAlias, AST whereClause) {
    Select select = new Select( getFactory().getDialect() );
    SelectFragment selectFragment = new SelectFragment()
        .addColumns( tableAlias, persister.getIdentifierColumnNames(), persister.getIdentifierColumnNames() );
    select.setSelectClause( selectFragment.toFragmentString().substring( 2 ) );

    String rootTableName = persister.getTableName();
    String fromJoinFragment = persister.fromJoinFragment( tableAlias, true, false );
    String whereJoinFragment = persister.whereJoinFragment( tableAlias, true, false );

    select.setFromClause( rootTableName + ' ' + tableAlias + fromJoinFragment );

    if ( whereJoinFragment == null ) {
      whereJoinFragment = "";
    }
    else {
      whereJoinFragment = whereJoinFragment.trim();
      if ( whereJoinFragment.startsWith( "and" ) ) {
        whereJoinFragment = whereJoinFragment.substring( 4 );
      }
    }

    String userWhereClause = "";
    if ( whereClause.getNumberOfChildren() != 0 ) {
      // If a where clause was specified in the update/delete query, use it to limit the
      // returned ids here...
      try {
        SqlGenerator sqlGenerator = new SqlGenerator( getFactory() );
        sqlGenerator.whereClause( whereClause );
        userWhereClause = sqlGenerator.getSQL().substring( 7 )// strip the " where "
        idSelectParameterSpecifications = sqlGenerator.getCollectedParameters();
      }
      catch ( RecognitionException e ) {
        throw new HibernateException( "Unable to generate id select for DML operation", e );
      }
      if ( whereJoinFragment.length() > 0 ) {
        whereJoinFragment += " and ";
      }
    }

    select.setWhereClause( whereJoinFragment + userWhereClause );

    InsertSelect insert = new InsertSelect( getFactory().getDialect() );
    if ( getFactory().getSettings().isCommentsEnabled() ) {
      insert.setComment( "insert-select for " + persister.getEntityName() + " ids" );
    }
View Full Code Here

      naturalIdMarkers[ naturalIdPropertyIndexes[i] ] = true;
    }

    ///////////////////////////////////////////////////////////////////////
    // TODO : look at perhaps caching this...
    Select select = new Select( getFactory().getDialect() );
    if ( getFactory().getSettings().isCommentsEnabled() ) {
      select.setComment( "get current natural-id state " + getEntityName() );
    }
    select.setSelectClause( concretePropertySelectFragmentSansLeadingComma( getRootAlias(), naturalIdMarkers ) );
    select.setFromClause( fromTableFragment( getRootAlias() ) + fromJoinFragment( getRootAlias(), true, false ) );

    String[] aliasedIdColumns = StringHelper.qualify( getRootAlias(), getIdentifierColumnNames() );
    String whereClause = new StringBuffer()
      .append( StringHelper.join( "=? and ",
          aliasedIdColumns ) )
      .append( "=?" )
      .append( whereJoinFragment( getRootAlias(), true, false ) )
      .toString();

    String sql = select.setOuterJoins( "", "" )
        .setWhereClause( whereClause )
        .toStatementString();
    ///////////////////////////////////////////////////////////////////////

    Object[] snapshot = new Object[ naturalIdPropertyCount ];
View Full Code Here

TOP

Related Classes of org.hibernate.sql.Select

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.