fix logging of DDL

the DDL formatter was being applied twice
This commit is contained in:
Gavin 2022-12-18 22:30:45 +01:00 committed by Gavin King
parent ff9a60601c
commit 493818141e
2 changed files with 13 additions and 4 deletions

View File

@ -45,7 +45,7 @@ public class DDLFormatterImpl implements Formatter {
return formatAlterTable( sql ); return formatAlterTable( sql );
} }
else if ( lowerCaseSql.startsWith( "create" ) ) { else if ( lowerCaseSql.startsWith( "create" ) ) {
return sql; return INITIAL_LINE + sql;
} }
else if ( lowerCaseSql.startsWith( "alter table" ) ) { else if ( lowerCaseSql.startsWith( "alter table" ) ) {
return formatAlterTable( sql ); return formatAlterTable( sql );

View File

@ -11,7 +11,7 @@ import java.sql.SQLException;
import java.sql.SQLWarning; import java.sql.SQLWarning;
import java.sql.Statement; import java.sql.Statement;
import org.hibernate.engine.jdbc.internal.DDLFormatterImpl; import org.hibernate.engine.jdbc.internal.FormatStyle;
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper; import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
import org.hibernate.engine.jdbc.spi.SqlStatementLogger; import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreLogging;
@ -65,7 +65,7 @@ public class GenerationTargetToDatabase implements GenerationTarget {
@Override @Override
public void accept(String command) { public void accept(String command) {
getSqlStatementLogger().logStatement( command, DDLFormatterImpl.INSTANCE ); getSqlStatementLogger().logStatement( command, FormatStyle.NONE.getFormatter() );
try { try {
final Statement jdbcStatement = jdbcStatement(); final Statement jdbcStatement = jdbcStatement();
@ -83,12 +83,21 @@ public class GenerationTargetToDatabase implements GenerationTarget {
} }
catch (SQLException e) { catch (SQLException e) {
throw new CommandAcceptanceException( throw new CommandAcceptanceException(
"Error executing DDL \"" + command + "\" via JDBC [" + e.getMessage() + "]", "Error executing DDL \"" + command + "\" via JDBC [" + stripSql(e) + "]",
e e
); );
} }
} }
/**
* Strip repetition of the SQL statement from h2 messages.
*/
private static String stripSql(SQLException e) {
final String message = e.getMessage();
int index = message.indexOf( " SQL statement:" );
return index > 0 ? message.substring( 0, index ) : message;
}
private Statement jdbcStatement() { private Statement jdbcStatement() {
if ( jdbcStatement == null ) { if ( jdbcStatement == null ) {
try { try {