Show an issue with BasicFormatterImpl

This commit is contained in:
Christian Beikov 2022-03-15 13:30:30 +01:00
parent 41741fb79c
commit 669d23319d
2 changed files with 17 additions and 4 deletions

View File

@ -112,11 +112,16 @@ public class SqlStatementLogger {
@AllowSysOut
public void logStatement(String statement, Formatter formatter) {
if ( logToStdout || LOG.isDebugEnabled() ) {
if ( format ) {
statement = formatter.format( statement );
try {
if ( format ) {
statement = formatter.format( statement );
}
if ( highlight ) {
statement = FormatStyle.HIGHLIGHT.getFormatter().format( statement );
}
}
if ( highlight ) {
statement = FormatStyle.HIGHLIGHT.getFormatter().format( statement );
catch (RuntimeException ex) {
LOG.warn( "Couldn't format statement", ex );
}
}
LOG.debug( statement );

View File

@ -11,6 +11,8 @@ import java.util.StringTokenizer;
import org.junit.Test;
import org.hibernate.engine.jdbc.internal.FormatStyle;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals;
@ -50,6 +52,12 @@ public class BasicFormatterTest extends BaseUnitTestCase {
assertNoLoss( "select group0.[order] as order0 from [Group] group0 where group0.[order]=?1" );
}
@Test
@FailureExpected( jiraKey = "HHH-15125")
public void testProblematic() {
assertNoLoss( "select * from ((select e.id from Entity e union all select e.id from Entity e) union select e.id from Entity e) grp" );
}
private void assertNoLoss(String query) {
String formattedQuery = FormatStyle.BASIC.getFormatter().format( query );
StringTokenizer formatted = new StringTokenizer( formattedQuery, " \t\n\r\f()" );