Package org.hibernate.hql.internal.ast

Examples of org.hibernate.hql.internal.ast.SqlGenerator


  public BasicExecutor(HqlSqlWalker walker, Queryable persister) {
    this.factory = walker.getSessionFactoryHelper().getFactory();
    this.persister = persister;
    try {
      SqlGenerator gen = new SqlGenerator( factory );
      gen.statement( walker.getAST() );
      sql = gen.getSQL();
      gen.getParseErrorHandler().throwQueryException();
      parameterSpecifications = gen.getCollectedParameters();
    }
    catch ( RecognitionException e ) {
      throw QuerySyntaxException.convert( e );
    }
  }
View Full Code Here


      final DeleteStatement deleteStatement = ( DeleteStatement ) walker.getAST();
     
      final String idSubselectWhere;
      if (deleteStatement.hasWhereClause()) {
        final AST whereClause = deleteStatement.getWhereClause();
        final SqlGenerator gen = new SqlGenerator( factory );
        gen.whereClause( whereClause );
        parameterSpecifications = gen.getCollectedParameters();
        idSubselectWhere = gen.getSQL().length() > 7 ? gen.getSQL() : "";
      }
      else {
        parameterSpecifications = new ArrayList<ParameterSpecification>();
        idSubselectWhere = "";
      }
View Full Code Here

   
    final DeleteStatement deleteStatement = ( DeleteStatement ) walker.getAST();
    final AST whereClause = deleteStatement.getWhereClause();
   
    try {
      final SqlGenerator gen = new SqlGenerator( factory );
      gen.whereClause( whereClause );
      parameterSpecifications = gen.getCollectedParameters();
     
      // If many-to-many, delete the FK row in the collection table.
      for ( Type type : persister.getPropertyTypes() ) {
        if ( type.isCollectionType() ) {
          final CollectionType cType = (CollectionType) type;
          final AbstractCollectionPersister cPersister = (AbstractCollectionPersister) factory
              .getCollectionPersister( cType.getRole() );
          if ( cPersister.isManyToMany() ) {
            if (persister.getIdentifierColumnNames().length > 1
                && !dialect.supportsTuplesInSubqueries()) {
              LOG.warn( "This dialect is unable to cascade the delete into the many-to-many join table" +
                  " when the entity has multiple primary keys.  Either properly setup cascading on" +
                  " the constraints or manually clear the associations prior to deleting the entities." );
            }
            else {
              final String idSubselectWhere = gen.getSQL().length() > 7 ? gen.getSQL() : "";
              final String idSubselect = "(select "
                  + StringHelper.join( ", ", persister.getIdentifierColumnNames() ) + " from "
                  + persister.getTableName() + idSubselectWhere + ")";
              final String where = "(" + StringHelper.join( ", ", cPersister.getKeyColumnNames() )
                  + ") in " + idSubselect;
View Full Code Here

  public BasicExecutor(HqlSqlWalker walker, Queryable persister) {
    this.factory = walker.getSessionFactoryHelper().getFactory();
    this.persister = persister;
    try {
      SqlGenerator gen = new SqlGenerator( factory );
      gen.statement( walker.getAST() );
      sql = gen.getSQL();
      gen.getParseErrorHandler().throwQueryException();
      parameterSpecifications = gen.getCollectedParameters();
    }
    catch ( RecognitionException e ) {
      throw QuerySyntaxException.convert( e );
    }
  }
View Full Code Here

  }

  public String getSqlAssignmentFragment() {
    if ( sqlAssignmentString == null ) {
      try {
        SqlGenerator sqlGenerator = new SqlGenerator( factory );
        sqlGenerator.comparisonExpr( eq, false )// false indicates to not generate parens around the assignment
        sqlAssignmentString = sqlGenerator.getSQL();
      }
      catch( Throwable t ) {
        throw new QueryException( "cannot interpret set-clause assignment" );
      }
    }
View Full Code Here

  public BasicExecutor(HqlSqlWalker walker, Queryable persister) {
        super(walker, null);
    this.persister = persister;
    try {
      SqlGenerator gen = new SqlGenerator( getFactory() );
      gen.statement( walker.getAST() );
      sql = gen.getSQL();
      gen.getParseErrorHandler().throwQueryException();
      parameterSpecifications = gen.getCollectedParameters();
    }
    catch ( RecognitionException e ) {
      throw QuerySyntaxException.convert( e );
    }
  }
View Full Code Here

    JoinSequence joinSequence = fromElement.getJoinSequence();
    String[] indexCols = queryableCollection.getIndexColumnNames();
    if ( indexCols.length != 1 ) {
      throw new QueryException( "composite-index appears in []: " + collectionNode.getPath() );
    }
    SqlGenerator gen = new SqlGenerator( getSessionFactoryHelper().getFactory() );
    try {
      gen.simpleExpr( selector ); //TODO: used to be exprNoParens! was this needed?
    }
    catch ( RecognitionException e ) {
      throw new QueryException( e.getMessage(), e );
    }
    String selectorExpression = gen.getSQL();
    joinSequence.addCondition( collectionTableAlias + '.' + indexCols[0] + " = " + selectorExpression );
    List paramSpecs = gen.getCollectedParameters();
    if ( paramSpecs != null ) {
      switch ( paramSpecs.size() ) {
        case 0 :
          // nothing to do
          break;
View Full Code Here

    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 ) {
View Full Code Here

    JoinSequence joinSequence = fromElement.getJoinSequence();
    String[] indexCols = queryableCollection.getIndexColumnNames();
    if ( indexCols.length != 1 ) {
      throw new QueryException( "composite-index appears in []: " + collectionNode.getPath() );
    }
    SqlGenerator gen = new SqlGenerator( getSessionFactoryHelper().getFactory() );
    try {
      gen.simpleExpr( selector ); //TODO: used to be exprNoParens! was this needed?
    }
    catch ( RecognitionException e ) {
      throw new QueryException( e.getMessage(), e );
    }
    String selectorExpression = gen.getSQL();
    joinSequence.addCondition( collectionTableAlias + '.' + indexCols[0] + " = " + selectorExpression );
    List paramSpecs = gen.getCollectedParameters();
    if ( paramSpecs != null ) {
      switch ( paramSpecs.size() ) {
        case 0 :
          // nothing to do
          break;
View Full Code Here

    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 ) {
View Full Code Here

TOP

Related Classes of org.hibernate.hql.internal.ast.SqlGenerator

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.