better formatting for 'merge' and 'case'

This commit is contained in:
Gavin 2023-05-31 12:45:52 +02:00 committed by Gavin King
parent 95e6ed1001
commit 37c071fa20
11 changed files with 228 additions and 126 deletions

View File

@ -85,7 +85,7 @@ public class DB2LegacySqlAstTranslator<T extends JdbcOperation> extends Abstract
default:
throw new UnsupportedOperationException( "Can't emulate '" + tableJoin.getJoinType().getText() + "join' in a DB2 recursive query part" );
}
appendSql( COMA_SEPARATOR_CHAR );
appendSql( COMMA_SEPARATOR_CHAR );
renderNamedTableReference( tableJoin.getJoinedTableReference(), LockMode.NONE );
@ -109,7 +109,7 @@ public class DB2LegacySqlAstTranslator<T extends JdbcOperation> extends Abstract
default:
throw new UnsupportedOperationException( "Can't emulate '" + tableGroupJoin.getJoinType().getText() + "join' in a DB2 recursive query part" );
}
appendSql( COMA_SEPARATOR_CHAR );
appendSql( COMMA_SEPARATOR_CHAR );
renderTableGroup( tableGroupJoin.getJoinedGroup(), null, tableGroupJoinCollector );
if ( tableGroupJoin.getPredicate() != null && !tableGroupJoin.getPredicate().isEmpty() ) {

View File

@ -654,7 +654,7 @@ public class OracleLegacySqlAstTranslator<T extends JdbcOperation> extends Abstr
for ( ColumnReference columnReference : columnReferences ) {
appendSql( separator );
columnReference.appendColumnForWrite( this );
separator = COMA_SEPARATOR_CHAR;
separator = COMMA_SEPARATOR_CHAR;
}
appendSql( ")=" );
assignment.getAssignedValue().accept( this );

View File

@ -98,6 +98,10 @@ public interface StatelessSession extends SharedSessionContract {
*/
void delete(String entityName, Object entity);
void upsert(Object entity);
void upsert(String entityName, Object entity);
/**
* Retrieve a row.
*

View File

@ -88,7 +88,7 @@ public class DB2SqlAstTranslator<T extends JdbcOperation> extends AbstractSqlAst
default:
throw new UnsupportedOperationException( "Can't emulate '" + tableJoin.getJoinType().getText() + "join' in a DB2 recursive query part" );
}
appendSql( COMA_SEPARATOR_CHAR );
appendSql( COMMA_SEPARATOR_CHAR );
renderNamedTableReference( tableJoin.getJoinedTableReference(), LockMode.NONE );
@ -112,7 +112,7 @@ public class DB2SqlAstTranslator<T extends JdbcOperation> extends AbstractSqlAst
default:
throw new UnsupportedOperationException( "Can't emulate '" + tableGroupJoin.getJoinType().getText() + "join' in a DB2 recursive query part" );
}
appendSql( COMA_SEPARATOR_CHAR );
appendSql( COMMA_SEPARATOR_CHAR );
renderTableGroup( tableGroupJoin.getJoinedGroup(), null, tableGroupJoinCollector );
if ( tableGroupJoin.getPredicate() != null && !tableGroupJoin.getPredicate().isEmpty() ) {

View File

@ -593,7 +593,7 @@ public class OracleSqlAstTranslator<T extends JdbcOperation> extends SqlAstTrans
for ( ColumnReference columnReference : columnReferences ) {
appendSql( separator );
columnReference.appendColumnForWrite( this );
separator = COMA_SEPARATOR_CHAR;
separator = COMMA_SEPARATOR_CHAR;
}
appendSql( ")=" );
assignment.getAssignedValue().accept( this );

View File

@ -182,7 +182,7 @@ public class CountFunction extends AbstractSqmSelfRenderingFunctionDescriptor {
sqlAppender.appendSql( concatOperator );
sqlAppender.appendSql( "''" );
}
sqlAppender.appendSql( SqlAppender.COMA_SEPARATOR_CHAR );
sqlAppender.appendSql( SqlAppender.COMMA_SEPARATOR_CHAR );
chr.render( sqlAppender, chrArguments, translator );
sqlAppender.appendSql( "),'')," );
chr.render( sqlAppender, chrArguments, translator );
@ -201,7 +201,7 @@ public class CountFunction extends AbstractSqmSelfRenderingFunctionDescriptor {
sqlAppender.appendSql( concatOperator );
sqlAppender.appendSql( "''" );
}
sqlAppender.appendSql( SqlAppender.COMA_SEPARATOR_CHAR );
sqlAppender.appendSql( SqlAppender.COMMA_SEPARATOR_CHAR );
chr.render( sqlAppender, chrArguments, translator );
sqlAppender.appendSql( "),'')," );
chr.render( sqlAppender, chrArguments, translator );

View File

@ -22,7 +22,7 @@ import org.hibernate.internal.util.StringHelper;
public class BasicFormatterImpl implements Formatter {
private static final Set<String> NON_FUNCTION_NAMES = Set.of(
"select", "from", "on", "set", "and", "or", "where", "having", "by"
"select", "from", "on", "set", "and", "or", "where", "having", "by", "using"
);
private static final String INDENT_STRING = " ";
@ -37,12 +37,13 @@ public class BasicFormatterImpl implements Formatter {
boolean beginLine = true;
boolean afterBeginBeforeEnd;
boolean afterByOrSetOrFromOrSelect;
boolean afterOn;
int afterOn;
boolean afterBetween;
boolean afterExtract;
boolean afterInsert;
int inFunction;
int parensSinceSelect;
int valuesParenCount;
private final LinkedList<Integer> parenCounts = new LinkedList<>();
private final LinkedList<Boolean> afterByOrFromOrSelects = new LinkedList<>();
@ -100,15 +101,7 @@ public class BasicFormatterImpl implements Formatter {
break;
case ",":
if ( afterByOrSetOrFromOrSelect && inFunction==0 ) {
commaAfterByOrFromOrSelect();
}
else if ( afterOn && inFunction==0 ) {
commaAfterOn();
}
else {
misc();
}
comma();
break;
case "(":
@ -121,6 +114,7 @@ public class BasicFormatterImpl implements Formatter {
case "select":
select();
break;
case "merge":
case "insert":
case "update":
case "delete":
@ -155,16 +149,13 @@ public class BasicFormatterImpl implements Formatter {
case "group":
case "order":
case "returning":
case "using":
beginNewClause();
break;
case "from":
if ( afterExtract ) {
misc();
afterExtract = false;
from();
break;
}
//else fall through:
case "where":
case "set":
case "having":
@ -186,23 +177,23 @@ public class BasicFormatterImpl implements Formatter {
endCase();
break;
case "and":
if ( afterBetween ) {
misc();
afterBetween = false;
break;
}
//else fall through:
case "or":
case "when":
case "else":
logical();
when();
break;
case "then":
then();
break;
case "and":
and();
break;
case "or":
or();
break;
default:
if ( isWhitespace( token ) ) {
white();
}
else {
misc();
}
@ -216,14 +207,64 @@ public class BasicFormatterImpl implements Formatter {
return result.toString();
}
private void commaAfterOn() {
out();
indent--;
newline();
afterOn = false;
afterByOrSetOrFromOrSelect = true;
private void or() {
logical();
}
private void and() {
if ( afterBetween ) {
misc();
afterBetween = false;
}
else {
logical();
}
}
private void from() {
if ( afterExtract ) {
misc();
afterExtract = false;
}
else {
endNewClause();
}
}
private void comma() {
if ( afterByOrSetOrFromOrSelect && inFunction==0 ) {
commaAfterByOrFromOrSelect();
}
// else if ( afterOn && inFunction==0 ) {
// commaAfterOn();
// }
else {
misc();
}
}
private void then() {
incrementIndent();
newline();
misc();
}
private void when() {
decrementIndent();
newline();
out();
beginLine = false;
afterBeginBeforeEnd = true;
}
// private void commaAfterOn() {
// out();
// decrementIndent();
// newline();
// afterOn = false;
// afterByOrSetOrFromOrSelect = true;
// }
private void commaAfterByOrFromOrSelect() {
out();
newline();
@ -236,13 +277,20 @@ public class BasicFormatterImpl implements Formatter {
}
private void endCase() {
indent--;
afterBeginBeforeEnd = false;
decrementIndent();
logical();
}
private void on() {
indent++;
afterOn = true;
if ( afterOn == 0 ) {
incrementIndent();
}
else if ( afterOn == 1 ) {
// ad hoc, but gives a nice result
decrementIndent();
}
afterOn++;
newline();
out();
beginLine = false;
@ -251,7 +299,9 @@ public class BasicFormatterImpl implements Formatter {
private void beginCase() {
out();
beginLine = false;
indent++;
incrementIndent();
incrementIndent();
afterBeginBeforeEnd = true;
}
private void misc() {
@ -278,7 +328,7 @@ public class BasicFormatterImpl implements Formatter {
}
else {
out();
indent++;
incrementIndent();
beginLine = false;
if ( "update".equals( lcToken ) ) {
newline();
@ -290,8 +340,17 @@ public class BasicFormatterImpl implements Formatter {
}
private void select() {
// if ( parensSinceSelect > 0 ) {
// newline();
// incrementIndent();
// out();
// }
// else {
// out();
// incrementIndent();
// }
out();
indent++;
incrementIndent();
newline();
parenCounts.addLast( parensSinceSelect );
afterByOrFromOrSelects.addLast( afterByOrSetOrFromOrSelect );
@ -300,21 +359,26 @@ public class BasicFormatterImpl implements Formatter {
}
private void out() {
if ( result.charAt( result.length() - 1 ) == ',' ) {
result.append(" ");
}
result.append( token );
}
private void endNewClause() {
if ( !afterBeginBeforeEnd ) {
indent--;
if ( afterOn ) {
indent--;
afterOn = false;
decrementIndent();
if ( afterOn == 1 ) {
decrementIndent();
}
if ( afterOn > 0 ) {
afterOn = 0;
}
newline();
}
out();
if ( !"union".equals( lcToken ) && !"intersect".equals( lcToken ) ) {
indent++;
incrementIndent();
}
newline();
afterBeginBeforeEnd = false;
@ -325,11 +389,13 @@ public class BasicFormatterImpl implements Formatter {
private void beginNewClause() {
if ( !afterBeginBeforeEnd ) {
if ( afterOn ) {
indent--;
afterOn = false;
if ( afterOn == 1 ) {
decrementIndent();
}
indent--;
if ( afterOn > 0 ) {
afterOn = 0;
}
decrementIndent();
newline();
}
out();
@ -339,11 +405,14 @@ public class BasicFormatterImpl implements Formatter {
private void values() {
if ( parensSinceSelect == 0 ) {
indent--;
if ( !afterBeginBeforeEnd ) {
decrementIndent();
}
newline();
out();
indent++;
incrementIndent();
newline();
valuesParenCount = parensSinceSelect + 1;
}
else {
out();
@ -351,19 +420,34 @@ public class BasicFormatterImpl implements Formatter {
}
private void closeParen() {
parensSinceSelect--;
if ( parensSinceSelect < 0 ) {
indent--;
if ( parensSinceSelect == 0 ) {
decrementIndent();
parensSinceSelect = parenCounts.removeLast();
afterByOrSetOrFromOrSelect = afterByOrFromOrSelects.removeLast();
}
else if ( valuesParenCount == parensSinceSelect ) {
valuesParenCount = 0;
if ( afterBeginBeforeEnd ) {
decrementIndent();
}
}
parensSinceSelect--;
if ( inFunction > 0 ) {
// this should come first,
// because we increment
// inFunction for every
// opening paren from the
// first one after the
// function name
inFunction--;
out();
}
else if ( afterOn > 0 ) {
out();
}
else {
if ( !afterByOrSetOrFromOrSelect ) {
indent--;
decrementIndent();
newline();
}
out();
@ -376,13 +460,13 @@ public class BasicFormatterImpl implements Formatter {
inFunction++;
}
beginLine = false;
if ( inFunction > 0 ) {
if ( afterOn > 0 || inFunction > 0 ) {
out();
}
else {
out();
if ( !afterByOrSetOrFromOrSelect ) {
indent++;
incrementIndent();
newline();
beginLine = true;
}
@ -390,6 +474,16 @@ public class BasicFormatterImpl implements Formatter {
parensSinceSelect++;
}
private void incrementIndent() {
indent++;
}
private void decrementIndent() {
if ( indent > 0 ) {
indent--;
}
}
private static boolean isFunctionName(String tok) {
if ( tok == null || tok.length() == 0 ) {
return false;

View File

@ -201,7 +201,7 @@ public class NamedSqmFunctionDescriptor
sqlAppender.appendSql( " within group (order by" );
translator.render( withinGroup.get( 0 ), argumentRenderingMode );
for ( int i = 1; i < withinGroup.size(); i++ ) {
sqlAppender.appendSql( SqlAppender.COMA_SEPARATOR_CHAR );
sqlAppender.appendSql( SqlAppender.COMMA_SEPARATOR_CHAR );
translator.render( withinGroup.get( 0 ), argumentRenderingMode );
}
sqlAppender.appendSql( ')' );

View File

@ -235,7 +235,7 @@ public class PatternRenderer {
sqlAppender.appendSql( " within group (order by" );
translator.render( withinGroup.get( 0 ), argumentRenderingMode );
for ( int i = 1; i < withinGroup.size(); i++ ) {
sqlAppender.appendSql( SqlAppender.COMA_SEPARATOR_CHAR );
sqlAppender.appendSql( SqlAppender.COMMA_SEPARATOR_CHAR );
translator.render( withinGroup.get( 0 ), argumentRenderingMode );
}
sqlAppender.appendSql( ')' );

View File

@ -187,15 +187,19 @@ import org.hibernate.sql.exec.spi.JdbcOperationQueryUpdate;
import org.hibernate.sql.exec.spi.JdbcParameterBinder;
import org.hibernate.sql.exec.spi.JdbcParameterBinding;
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
import org.hibernate.sql.model.MutationOperation;
import org.hibernate.sql.model.ast.ColumnValueParameter;
import org.hibernate.sql.model.ast.ColumnWriteFragment;
import org.hibernate.sql.model.ast.RestrictedTableMutation;
import org.hibernate.sql.model.ast.TableMutation;
import org.hibernate.sql.model.internal.OptionalTableUpdate;
import org.hibernate.sql.model.internal.TableDeleteCustomSql;
import org.hibernate.sql.model.internal.TableDeleteStandard;
import org.hibernate.sql.model.internal.TableInsertCustomSql;
import org.hibernate.sql.model.internal.TableInsertStandard;
import org.hibernate.sql.model.internal.TableUpdateCustomSql;
import org.hibernate.sql.model.internal.TableUpdateStandard;
import org.hibernate.sql.model.jdbc.JdbcMutationOperation;
import org.hibernate.sql.results.internal.SqlSelectionImpl;
import org.hibernate.sql.results.jdbc.spi.JdbcValuesMappingProducer;
import org.hibernate.sql.results.jdbc.spi.JdbcValuesMappingProducerProvider;
@ -1069,7 +1073,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
clauseStack.push( Clause.SET );
for ( Assignment assignment : statement.getAssignments() ) {
appendSql( separator );
separator = COMA_SEPARATOR_CHAR;
separator = COMMA_SEPARATOR_CHAR;
visitSetAssignment( assignment );
}
}
@ -1098,7 +1102,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
for ( ColumnReference columnReference : columnReferences ) {
appendSql( separator );
columnReference.appendColumnForWrite( this, null );
separator = COMA_SEPARATOR_CHAR;
separator = COMMA_SEPARATOR_CHAR;
}
appendSql( ")=" );
assignment.getAssignedValue().accept( this );
@ -1137,7 +1141,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
firstPass = false;
}
else {
appendSql( COMA_SEPARATOR_CHAR );
appendSql( COMMA_SEPARATOR_CHAR );
}
appendSql( targetColumnReference.getColumnExpression() );
@ -1169,7 +1173,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
firstTuple = false;
}
else {
appendSql( COMA_SEPARATOR_CHAR );
appendSql( COMMA_SEPARATOR_CHAR );
}
appendSql( " (" );
boolean firstExpr = true;
@ -1178,7 +1182,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
firstExpr = false;
}
else {
appendSql( COMA_SEPARATOR_CHAR );
appendSql( COMMA_SEPARATOR_CHAR );
}
expression.accept( this );
}
@ -1492,7 +1496,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
for ( int i = 0; i < size; i++ ) {
appendSql( separator );
appendSql( returningColumns.get( i ).getColumnExpression() );
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
}
@ -1560,7 +1564,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
for ( CteStatement cte : cteStatements ) {
appendSql( mainSeparator );
visitCteStatement( cte );
mainSeparator = COMA_SEPARATOR;
mainSeparator = COMMA_SEPARATOR;
topLevelWithClauseIndex = sqlBuffer.length();
}
appendSql( WHITESPACE );
@ -1601,12 +1605,12 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
sqlBuffer.setLength( topLevelWithClauseIndex );
if ( sqlBuffer.charAt( topLevelWithClauseIndex - 1 ) == ')' ) {
// This is the case when there is an existing CTE, so we need a comma for the CTE that are about to render
mainSeparator = COMA_SEPARATOR;
mainSeparator = COMMA_SEPARATOR;
}
for ( CteStatement cte : cteStatements ) {
appendSql( mainSeparator );
visitCteStatement( cte );
mainSeparator = COMA_SEPARATOR;
mainSeparator = COMMA_SEPARATOR;
// Make that the topLevelWithClauseIndex is up-to-date
topLevelWithClauseIndex = sqlBuffer.length();
}
@ -1620,7 +1624,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
for ( CteStatement cte : cteStatements ) {
appendSql( mainSeparator );
visitCteStatement( cte );
mainSeparator = COMA_SEPARATOR;
mainSeparator = COMMA_SEPARATOR;
}
appendSql( WHITESPACE );
}
@ -1677,36 +1681,36 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
for ( String columnExpression : columnExpressions ) {
appendSql( separator );
appendSql( columnExpression );
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
}
else {
for ( CteColumn cteColumn : cte.getCteTable().getCteColumns() ) {
appendSql( separator );
appendSql( cteColumn.getColumnExpression() );
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
}
if ( cte.isRecursive() ) {
if ( !supportsRecursiveSearchClause() ) {
if ( cte.getSearchColumn() != null ) {
appendSql( COMA_SEPARATOR );
appendSql( COMMA_SEPARATOR );
if ( cte.getSearchClauseKind() == CteSearchClauseKind.BREADTH_FIRST ) {
appendSql( determineDepthColumnName( cte ) );
appendSql( COMA_SEPARATOR );
appendSql( COMMA_SEPARATOR );
}
appendSql( cte.getSearchColumn().getColumnExpression() );
}
}
if ( !supportsRecursiveCycleClause() ) {
if ( cte.getCycleMarkColumn() != null ) {
appendSql( COMA_SEPARATOR );
appendSql( COMMA_SEPARATOR );
appendSql( cte.getCycleMarkColumn().getColumnExpression() );
}
}
if ( cte.getCycleMarkColumn() != null && !supportsRecursiveCycleClause()
|| cte.getCyclePathColumn() != null && !supportsRecursiveCycleUsingClause() ) {
appendSql( COMA_SEPARATOR );
appendSql( COMMA_SEPARATOR );
appendSql( determineCyclePathColumnName( cte ) );
}
}
@ -1924,7 +1928,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
}
}
}
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
appendSql( " set " );
appendSql( cte.getSearchColumn().getColumnExpression() );
@ -1945,7 +1949,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
for ( CteColumn cycleColumn : cte.getCycleColumns() ) {
appendSql( separator );
appendSql( cycleColumn.getColumnExpression() );
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
appendSql( " set " );
appendSql( cte.getCycleMarkColumn().getColumnExpression() );
@ -1963,7 +1967,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
protected void renderRecursiveCteVirtualSelections(SelectClause selectClause) {
if ( currentCteStatement != null && currentCteStatement.isRecursive() ) {
if ( currentCteStatement.getSearchColumn() != null && !supportsRecursiveSearchClause() ) {
appendSql( COMA_SEPARATOR );
appendSql( COMMA_SEPARATOR );
if ( supportsRecursiveClauseArrayAndRowEmulation() ) {
emulateSearchClauseOrderWithRowAndArray( selectClause );
}
@ -1973,7 +1977,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
}
if ( !supportsRecursiveCycleClause() || currentCteStatement.getCyclePathColumn() != null && !supportsRecursiveCycleUsingClause() ) {
if ( currentCteStatement.getCycleMarkColumn() != null ) {
appendSql( COMA_SEPARATOR );
appendSql( COMMA_SEPARATOR );
if ( supportsRecursiveClauseArrayAndRowEmulation() ) {
emulateCycleClauseWithRowAndArray( selectClause );
}
@ -2032,7 +2036,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
);
visitColumnReference( depthColumnReference );
appendSql( "+1" );
appendSql( COMA_SEPARATOR );
appendSql( COMMA_SEPARATOR );
appendSql( "row(" );
visitColumnReference( depthColumnReference );
@ -2047,7 +2051,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
.getCteColumns()
.indexOf( searchBySpecification.getCteColumn() );
final SqlSelection sqlSelection = selectClause.getSqlSelections().get( selectionIndex );
appendSql( COMA_SEPARATOR );
appendSql( COMMA_SEPARATOR );
sqlSelection.accept( this );
}
appendSql( ')' );
@ -2081,7 +2085,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
final SqlSelection sqlSelection = selectClause.getSqlSelections().get( selectionIndex );
appendSql( separator );
sqlSelection.accept( this );
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
if ( currentCteStatement.getSearchBySpecifications().size() > 1 ) {
appendSql( CLOSE_PARENTHESIS );
@ -2092,7 +2096,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
else {
if ( currentCteStatement.getSearchClauseKind() == CteSearchClauseKind.BREADTH_FIRST ) {
appendSql( '1' );
appendSql( COMA_SEPARATOR );
appendSql( COMMA_SEPARATOR );
appendSql( "row(0" );
for ( SearchClauseSpecification searchBySpecification : currentCteStatement.getSearchBySpecifications() ) {
@ -2106,7 +2110,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
.getCteColumns()
.indexOf( searchBySpecification.getCteColumn() );
final SqlSelection sqlSelection = selectClause.getSqlSelections().get( selectionIndex );
appendSql( COMA_SEPARATOR );
appendSql( COMMA_SEPARATOR );
sqlSelection.accept( this );
}
appendSql( ')' );
@ -2130,7 +2134,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
final SqlSelection sqlSelection = selectClause.getSqlSelections().get( selectionIndex );
appendSql( separator );
sqlSelection.accept( this );
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
if ( currentCteStatement.getSearchBySpecifications().size() > 1 ) {
appendSql( CLOSE_PARENTHESIS );
@ -2174,7 +2178,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
);
visitColumnReference( depthColumnReference );
appendSql( "+1" );
appendSql( COMA_SEPARATOR );
appendSql( COMMA_SEPARATOR );
arguments.add( lpad( castToString( depthColumnReference ), 10, "0" ) );
arguments.add( nullSeparator );
@ -2250,7 +2254,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
int columnSizeEstimate = 0;
if ( currentCteStatement.getSearchClauseKind() == CteSearchClauseKind.BREADTH_FIRST ) {
appendSql( '1' );
appendSql( COMA_SEPARATOR );
appendSql( COMMA_SEPARATOR );
arguments.add( new QueryLiteral<>( StringHelper.repeat( '0', 10 ), stringType ) );
arguments.add( nullSeparator );
@ -2368,7 +2372,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
appendSql( arrayContainsFunction );
appendSql( OPEN_PARENTHESIS );
visitColumnReference( cyclePathColumnReference );
appendSql( COMA_SEPARATOR );
appendSql( COMMA_SEPARATOR );
}
if ( currentCteStatement.getCycleColumns().size() > 1 ) {
appendSql( "row(" );
@ -2380,7 +2384,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
final SqlSelection sqlSelection = selectClause.getSqlSelections().get( selectionIndex );
appendSql( separator );
sqlSelection.accept( this );
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
appendSql( ')' );
}
@ -2402,7 +2406,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
appendSql( " else " );
currentCteStatement.getNoCycleValue().accept( this );
appendSql( " end" );
appendSql( COMA_SEPARATOR );
appendSql( COMMA_SEPARATOR );
}
// Cycle path
@ -2419,7 +2423,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
final SqlSelection sqlSelection = selectClause.getSqlSelections().get( selectionIndex );
appendSql( separator );
sqlSelection.accept( this );
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
if ( currentCteStatement.getCycleColumns().size() > 1 ) {
appendSql( CLOSE_PARENTHESIS );
@ -2430,7 +2434,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
if ( !supportsRecursiveCycleClause() ) {
// Cycle mark
currentCteStatement.getNoCycleValue().accept( this );
appendSql( COMA_SEPARATOR );
appendSql( COMMA_SEPARATOR );
}
// Cycle path
@ -2446,7 +2450,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
final SqlSelection sqlSelection = selectClause.getSqlSelections().get( selectionIndex );
appendSql( separator );
sqlSelection.accept( this );
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
if ( currentCteStatement.getCycleColumns().size() > 1 ) {
appendSql( CLOSE_PARENTHESIS );
@ -2541,7 +2545,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
appendSql( " else " );
currentCteStatement.getNoCycleValue().accept( this );
appendSql( " end" );
appendSql( COMA_SEPARATOR );
appendSql( COMMA_SEPARATOR );
}
// Remove the wildcard literals
@ -2554,7 +2558,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
if ( !supportsRecursiveCycleClause() ) {
// Cycle mark
currentCteStatement.getNoCycleValue().accept( this );
appendSql( COMA_SEPARATOR );
appendSql( COMMA_SEPARATOR );
}
// Cycle path
@ -3221,7 +3225,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
else {
renderPartitionItem( resolved );
}
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
}
else {
@ -3237,7 +3241,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
renderPartitionItem( resolved );
}
}
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
}
@ -3293,7 +3297,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
for ( SortSpecification sortSpecification : sortSpecifications ) {
appendSql( separator );
visitSortSpecification( sortSpecification );
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
}
finally {
@ -3545,7 +3549,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
for ( SqlSelection lhsExpression : lhsExpressions ) {
appendSql( separator );
lhsExpression.getExpression().accept( this );
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
appendSql( CLOSE_PARENTHESIS );
appendSql( operator.sqlText() );
@ -3682,7 +3686,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
for ( Expression expression : sqlTuple.getExpressions() ) {
appendSql( separator );
visitSortSpecification( expression, sortOrder, nullPrecedence );
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
}
else {
@ -3737,7 +3741,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
appendSql( "1 else 0" );
}
appendSql( " end" );
appendSql( COMA_SEPARATOR_CHAR );
appendSql( COMMA_SEPARATOR_CHAR );
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -4249,7 +4253,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
finally {
clauseStack.pop();
}
appendSql( COMA_SEPARATOR_CHAR );
appendSql( COMMA_SEPARATOR_CHAR );
if ( fetchExpression != null ) {
clauseStack.push( Clause.FETCH );
try {
@ -4395,7 +4399,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
appendSql( alias );
appendSql( ".c" );
appendSql( i );
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
}
appendSql( " from " );
@ -4615,7 +4619,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
appendSql( columnAliases.get( offset ) );
}
offset++;
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
}
else {
@ -4630,7 +4634,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
appendSql( columnAliases.get( offset ) );
}
offset++;
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
parameterRenderingMode = original;
}
@ -4655,7 +4659,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
}
visitSqlSelection( sqlSelection );
parameterRenderingMode = original;
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
}
}
@ -4717,7 +4721,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
protected void renderRowNumberingSelectItems(SelectClause selectClause, QueryPart queryPart) {
final FetchClauseType fetchClauseType = getFetchClauseTypeForRowNumbering( queryPart );
if ( fetchClauseType != null ) {
appendSql( COMA_SEPARATOR_CHAR );
appendSql( COMMA_SEPARATOR_CHAR );
switch ( fetchClauseType ) {
case PERCENT_ONLY:
appendSql( "count(*) over () cnt," );
@ -5151,7 +5155,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
else if ( root.isInitialized() ) {
appendSql( separator );
renderRootTableGroup( root, null );
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
return separator;
}
@ -6294,7 +6298,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
for ( SqlAstNode expression : expressions ) {
appendSql( separator );
expression.accept( this );
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
}
@ -6306,7 +6310,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
for ( Expression e : sqlTuple.getExpressions() ) {
appendSql( separator );
renderSelectExpression( e );
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
}
else if ( expression instanceof Expression ) {
@ -6317,7 +6321,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
appendSql( separator );
expression.accept( this );
}
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
}
@ -6330,7 +6334,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
for ( Expression e : sqlTuple.getExpressions() ) {
appendSql( separator );
renderSelectExpression( e );
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
}
else if ( expression instanceof Expression ) {
@ -6341,7 +6345,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
appendSql( separator );
expression.accept( this );
}
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
append( WHITESPACE );
append( aliasIterator.next() );
}
@ -6877,7 +6881,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
final Expression listExpression = itemAccessor.apply( iterator.next() );
appendSql( separator );
listExpression.accept( this );
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
itemNumber++;
// If we encounter an expression that is not a parameter or literal, we reset the inExprLimit and bindValueMaxCount
// and just render through the in list expressions as they are without padding/splitting
@ -6906,7 +6910,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
final Expression listExpression = iterator.next();
appendSql( separator );
itemAccessor.apply( listExpression ).accept( this );
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
itemNumber++;
}
} while ( iterator.hasNext() );
@ -6917,7 +6921,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
for ( ; itemNumber < bindValueMaxCount; itemNumber++ ) {
appendSql( separator );
lastExpression.accept( this );
separator = COMA_SEPARATOR;
separator = COMMA_SEPARATOR;
}
}
appendSql( CLOSE_PARENTHESIS );
@ -7113,7 +7117,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
appendSql( '1' );
appendSql( order );
for ( int i = 1; i < sqlSelections.size(); i++ ) {
appendSql( COMA_SEPARATOR_CHAR );
appendSql( COMMA_SEPARATOR_CHAR );
appendSql( i + 1 );
appendSql( order );
}

View File

@ -14,8 +14,8 @@ package org.hibernate.sql.ast.spi;
@FunctionalInterface
public interface SqlAppender extends Appendable {
String NO_SEPARATOR = "";
String COMA_SEPARATOR = ",";
char COMA_SEPARATOR_CHAR = ',';
String COMMA_SEPARATOR = ",";
char COMMA_SEPARATOR_CHAR = ',';
char WHITESPACE = ' ';
char OPEN_PARENTHESIS = '(';