private void generate(AST sqlAst) throws QueryException, RecognitionException { if ( sql == null ) { final SqlGenerator gen = new SqlGenerator( factory ); gen.statement( sqlAst ); sql = gen.getSQL(); if ( LOG.isDebugEnabled() ) { LOG.debugf( "HQL: %s", hql ); LOG.debugf( "SQL: %s", sql ); } gen.getParseErrorHandler().throwQueryException(); if ( collectedParameterSpecifications == null ) { collectedParameterSpecifications = gen.getCollectedParameters(); } else { collectedParameterSpecifications.addAll( gen.getCollectedParameters() ); } } }
@Override public void traceIn(String ruleName, AST tree) { if ( !LOG.isTraceEnabled() ) { return; } if ( inputState.guessing > 0 ) { return; } String prefix = StringHelper.repeat( '-', ( traceDepth++ * 2 ) ) + "-> "; String traceText = ruleName + " (" + buildTraceNodeName( tree ) + ")"; LOG.trace( prefix + traceText ); }
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" ); } } return sqlAssignmentString; }
@Override protected void optionalSpace() { int c = getLastChar(); switch ( c ) { case -1: return; case ' ': return; case ')': return; case '(': return; default: out( " " ); } }
/** * Interprets the {@code WHERE} clause from the user-defined update/delete query * * @param whereClause The user-defined {@code WHERE} clause * * @return The bulk-id-ready {@code WHERE} clause representation */ @SuppressWarnings("unchecked") protected ProcessedWhereClause processWhereClause(AST whereClause) { if ( whereClause.getNumberOfChildren() != 0 ) { // If a where clause was specified in the update/delete query, use it to limit the // ids that will be returned and inserted into the id table... try { SqlGenerator sqlGenerator = new SqlGenerator( sessionFactory ); sqlGenerator.whereClause( whereClause ); String userWhereClause = sqlGenerator.getSQL().substring( 7 ); // strip the " where " List<ParameterSpecification> idSelectParameterSpecifications = sqlGenerator.getCollectedParameters(); return new ProcessedWhereClause( userWhereClause, idSelectParameterSpecifications ); } catch ( RecognitionException e ) { throw new HibernateException( "Unable to generate id select for DML operation", e ); } } else { return ProcessedWhereClause.NO_WHERE_CLAUSE; } }
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? String selectorExpression = gen.getSQL(); joinSequence.addCondition( collectionTableAlias + '.' + indexCols[0] + " = " + selectorExpression ); List<ParameterSpecification> paramSpecs = gen.getCollectedParameters(); if ( paramSpecs != null ) { switch ( paramSpecs.size() ) {
@Override protected void nestedFromFragment(AST d, AST parent) { // check a set of parent/child nodes in the from-clause tree // to determine if a comma is required between them if ( d != null && hasText( d ) ) { if ( parent != null && hasText( parent ) ) { // again, both should be FromElements FromElement left = (FromElement) parent; FromElement right = (FromElement) d; if ( right.getRealOrigin() == left ) { // right represents a joins originating from left... if ( right.getJoinSequence() != null && right.getJoinSequence().isThetaStyle() ) { writeCrossJoinSeparator(); } else { out( " " ); } } else { // not so sure this is even valid subtree. but if it was, it'd // represent two unrelated table references... writeCrossJoinSeparator(); } } out( d ); } }
private void handleWithFragment(FromElement fromElement, AST hqlWithNode) throws SemanticException { try { withClause( hqlWithNode ); AST hqlSqlWithNode = returnAST; if ( LOG.isDebugEnabled() ) { LOG.debug( "handleWithFragment() : " + getASTPrinter().showAsString( hqlSqlWithNode, "-- with clause --" ) ); } WithClauseVisitor visitor = new WithClauseVisitor( fromElement, queryTranslatorImpl ); NodeTraverser traverser = new NodeTraverser( visitor ); traverser.traverseDepthFirst( hqlSqlWithNode ); SqlGenerator sql = new SqlGenerator( getSessionFactoryHelper().getFactory() ); sql.whereExpr( hqlSqlWithNode.getFirstChild() ); fromElement.setWithClauseFragment( "(" + sql.getSQL() + ")" ); } catch (SemanticException e) { throw e; } catch (InvalidWithClauseException e) { throw e; } catch (Exception e) { throw new SemanticException( e.getMessage() ); } }
@Override protected void nestedFromFragment(AST d, AST parent) { // check a set of parent/child nodes in the from-clause tree // to determine if a comma is required between them if ( d != null && hasText( d ) ) { if ( parent != null && hasText( parent ) ) { // again, both should be FromElements FromElement left = ( FromElement ) parent; FromElement right = ( FromElement ) d; if ( right.getRealOrigin() == left ) { // right represents a joins originating from left... if ( right.getJoinSequence() != null && right.getJoinSequence().isThetaStyle() ) { out( ", " ); } else { out( " " ); } } else { // not so sure this is even valid subtree. but if it was, it'd // represent two unrelated table references... out( ", " ); } } out( d ); } } }
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() : "";
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? String selectorExpression = gen.getSQL(); joinSequence.addCondition( collectionTableAlias + '.' + indexCols[0] + " = " + selectorExpression ); List paramSpecs = gen.getCollectedParameters(); if ( paramSpecs != null ) { switch ( paramSpecs.size() ) {
if ( next == null || !hasText( a ) ) { return; while ( right != null && !hasText( right ) ) { right = (FromElement) right.getNextSibling(); if ( !hasText( right ) ) { return; out( " " ); writeCrossJoinSeparator(); out( " " ); writeCrossJoinSeparator();
SqlGenerator sql = new SqlGenerator( getSessionFactoryHelper().getFactory() ); sql.whereExpr( hqlSqlWithNode.getFirstChild() ); fromElement.setWithClauseFragment( withClauseJoinAlias, "(" + sql.getSQL() + ")" );
@Override protected void optionalSpace() { int c = getLastChar(); switch ( c ) { case -1: return; case ' ': return; case ')': return; case '(': return; default: out( " " ); } }
@Override protected void out(AST n) { if ( n instanceof Node ) { out( ( (Node) n ).getRenderText( sessionFactory ) ); } else { super.out( n ); } if ( n instanceof ParameterNode ) { collectedParameters.add( ( (ParameterNode) n ).getHqlParameterSpecification() ); } else if ( n instanceof ParameterContainer ) { if ( ( (ParameterContainer) n ).hasEmbeddedParameters() ) { ParameterSpecification[] specifications = ( (ParameterContainer) n ).getEmbeddedParameters(); if ( specifications != null ) { collectedParameters.addAll( Arrays.asList( specifications ) ); } } } }
@Override protected void nestedFromFragment(AST d, AST parent) { // check a set of parent/child nodes in the from-clause tree // to determine if a comma is required between them if ( d != null && hasText( d ) ) { if ( parent != null && hasText( parent ) ) { // again, both should be FromElements FromElement left = ( FromElement ) parent; FromElement right = ( FromElement ) d; if ( right.getRealOrigin() == left ) { // right represents a joins originating from left... if ( right.getJoinSequence() != null && right.getJoinSequence().isThetaStyle() ) { out( ", " ); } else { out( " " ); } } else { // not so sure this is even valid subtree. but if it was, it'd // represent two unrelated table references... out( ", " ); } } out( d ); } } }
public BasicExecutor(HqlSqlWalker walker, Queryable persister) { this.persister = persister; try { SqlGenerator gen = new SqlGenerator( walker.getSessionFactoryHelper().getFactory() ); gen.statement( walker.getAST() ); sql = gen.getSQL(); gen.getParseErrorHandler().throwQueryException(); parameterSpecifications = gen.getCollectedParameters(); } catch ( RecognitionException e ) { throw QuerySyntaxException.convert( e ); } }
SqlGenerator sqlGenerator = new SqlGenerator( getFactory() ); sqlGenerator.whereClause( whereClause ); userWhereClause = sqlGenerator.getSQL().substring( 7 ); // strip the " where " idSelectParameterSpecifications = sqlGenerator.getCollectedParameters();
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? String selectorExpression = gen.getSQL(); joinSequence.addCondition( collectionTableAlias + '.' + indexCols[0] + " = " + selectorExpression ); List paramSpecs = gen.getCollectedParameters(); if ( paramSpecs != null ) { switch ( paramSpecs.size() ) {