Fix for HHH-11258

This commit is contained in:
Christian Beikov 2016-11-18 10:25:17 +01:00 committed by Steve Ebersole
parent 4d076111a3
commit 801974fa4c
2 changed files with 22 additions and 7 deletions

View File

@ -28,7 +28,7 @@ options {
private StringBuilder buf = new StringBuilder(); private StringBuilder buf = new StringBuilder();
private boolean captureExpression = false; private boolean captureExpression = false;
private StringBuilder expr = new StringBuilder(); protected java.util.List<StringBuilder> exprs = new java.util.ArrayList<StringBuilder>(java.util.Arrays.asList(new StringBuilder()));
protected void out(String s) { protected void out(String s) {
getStringBuilder().append( s ); getStringBuilder().append( s );
@ -75,7 +75,7 @@ options {
} }
protected StringBuilder getStringBuilder() { protected StringBuilder getStringBuilder() {
return captureExpression ? expr : buf; return captureExpression ? exprs.get(exprs.size() - 1) : buf;
} }
protected void nyi(AST n) { protected void nyi(AST n) {
@ -97,16 +97,27 @@ options {
} }
protected void captureExpressionStart() { protected void captureExpressionStart() {
if ( captureExpression ) {
exprs.add( new StringBuilder() );
} else {
captureExpression = true; captureExpression = true;
} }
}
protected void captureExpressionFinish() { protected void captureExpressionFinish() {
// Capturing will only stop when we leave the last capture context
if ( exprs.size() == 1 ) {
captureExpression = false; captureExpression = false;
} }
}
protected String resetCapture() { protected String resetCapture() {
final String expression = expr.toString(); StringBuilder sb = exprs.remove( exprs.size() - 1 );
expr = new StringBuilder(); final String expression = sb.toString();
if ( exprs.isEmpty() ) {
sb.setLength(0);
exprs.add( sb );
}
return expression; return expression;
} }

View File

@ -102,8 +102,12 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
@Override @Override
protected void out(String s) { protected void out(String s) {
if ( exprs.size() > 1 ) {
super.out( s );
} else {
writer.clause( s ); writer.clause( s );
} }
}
@Override @Override
protected void out(AST n) { protected void out(AST n) {