From b9fcc63d843ccb3da9015991240316685f612fa5 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 26 Aug 2020 08:42:46 -0500 Subject: [PATCH] HHH-14152 sql-script.g fix for antlr non deterministic warning - Added "system"-style SqlScriptLogging - Added rule trace logging through SqlScriptLogging --- hibernate-core/src/main/antlr/sql-script.g | 6 ++-- .../tool/schema/ast/SqlScriptLogging.java | 28 +++++++++++++++++++ .../tool/schema/ast/SqlScriptParser.java | 18 ++++++------ .../src/test/resources/log4j.properties | 6 ++-- 4 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/tool/schema/ast/SqlScriptLogging.java diff --git a/hibernate-core/src/main/antlr/sql-script.g b/hibernate-core/src/main/antlr/sql-script.g index 2a2607c027..bc0e3c1ab2 100644 --- a/hibernate-core/src/main/antlr/sql-script.g +++ b/hibernate-core/src/main/antlr/sql-script.g @@ -61,7 +61,7 @@ script ; statement - : { statementStarted(); } (statementPart (afterStatementPartNewline)*)* DELIMITER (newLineToSkip)* { statementEnded(); } + : { statementStarted(); } (statementPart (afterStatementPartNewline)*)* DELIMITER (newLineToSkip)* { statementEnded(); } ; statementPart @@ -76,8 +76,8 @@ quotedString ; afterStatementPartNewline - : NEWLINE { - out(" "); + : n:NEWLINE { + out( " " ); } ; diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/ast/SqlScriptLogging.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/ast/SqlScriptLogging.java new file mode 100644 index 0000000000..d080151024 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/ast/SqlScriptLogging.java @@ -0,0 +1,28 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.tool.schema.ast; + +import org.jboss.logging.Logger; +import org.jboss.logging.annotations.ValidIdRange; + +/** + * @author Steve Ebersole + */ +@ValidIdRange( ) +public class SqlScriptLogging { + public static final String SCRIPT_LOGGER_NAME = "org.hibernate.orm.tooling.schema.script"; + public static final Logger SCRIPT_LOGGER = Logger.getLogger( SCRIPT_LOGGER_NAME ); + + public static final boolean TRACE_ENABLED = SCRIPT_LOGGER.isTraceEnabled(); + public static final boolean DEBUG_ENABLED = SCRIPT_LOGGER.isDebugEnabled(); + + public static final String AST_LOGGER_NAME = SCRIPT_LOGGER_NAME + ".graph"; + public static final Logger AST_LOGGER = Logger.getLogger( AST_LOGGER_NAME ); + + public static final boolean AST_TRACE_ENABLED = AST_LOGGER.isTraceEnabled(); + +} diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/ast/SqlScriptParser.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/ast/SqlScriptParser.java index 5aaca4facb..7089b7257e 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/ast/SqlScriptParser.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/ast/SqlScriptParser.java @@ -14,7 +14,6 @@ import java.util.function.Consumer; import org.hibernate.hql.internal.ast.util.ASTUtil; import org.hibernate.internal.util.StringHelper; -import org.hibernate.tool.schema.SchemaToolingLogging; import antlr.RecognitionException; import antlr.Token; @@ -65,6 +64,7 @@ public class SqlScriptParser extends GeneratedSqlScriptParser { */ @Override protected void out(String text) { + SqlScriptLogging.SCRIPT_LOGGER.tracef( "#out(`%s`) [text]", text ); currentStatementBuffer.append( text ); } @@ -73,13 +73,15 @@ public class SqlScriptParser extends GeneratedSqlScriptParser { */ @Override protected void out(Token token) { + SqlScriptLogging.SCRIPT_LOGGER.tracef( "#out(`%s`) [token]", token.getText() ); + currentStatementBuffer.append( token.getText() ); } @Override protected void statementStarted() { if ( currentStatementBuffer != null ) { - SchemaToolingLogging.LOGGER.debugf( "`#currentStatementBuffer` was not null at `#statementStart`" ); + SqlScriptLogging.SCRIPT_LOGGER.debugf( "`#currentStatementBuffer` was not null at `#statementStart`" ); } currentStatementBuffer = new StringBuilder(); } @@ -90,7 +92,7 @@ public class SqlScriptParser extends GeneratedSqlScriptParser { @Override protected void statementEnded() { final String statementText = currentStatementBuffer.toString().trim(); - SchemaToolingLogging.LOGGER.debugf( "Import statement : %s", statementText ); + SqlScriptLogging.AST_LOGGER.debugf( "Import statement : %s", statementText ); commandConsumer.accept( statementText ); currentStatementBuffer = null; @@ -142,7 +144,7 @@ public class SqlScriptParser extends GeneratedSqlScriptParser { @Override public void reportWarning(String message) { - SchemaToolingLogging.LOGGER.debugf( "SqlScriptParser recognition warning : " + message ); + SqlScriptLogging.SCRIPT_LOGGER.debugf( "SqlScriptParser recognition warning : " + message ); } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -153,7 +155,7 @@ public class SqlScriptParser extends GeneratedSqlScriptParser { @Override public void traceIn(String ruleName) { - if ( ! SchemaToolingLogging.AST_TRACE_ENABLED ) { + if ( ! SqlScriptLogging.AST_TRACE_ENABLED ) { return; } @@ -162,12 +164,12 @@ public class SqlScriptParser extends GeneratedSqlScriptParser { } final String prefix = StringHelper.repeat( '-', ( traceDepth++ * depthIndent ) ); - SchemaToolingLogging.AST_LOGGER.tracef( "%s-> %s", prefix, ruleName ); + SqlScriptLogging.AST_LOGGER.tracef( "%s-> %s", prefix, ruleName ); } @Override public void traceOut(String ruleName) { - if ( ! SchemaToolingLogging.AST_TRACE_ENABLED ) { + if ( ! SqlScriptLogging.AST_TRACE_ENABLED ) { return; } @@ -176,6 +178,6 @@ public class SqlScriptParser extends GeneratedSqlScriptParser { } final String prefix = StringHelper.repeat( '-', ( --traceDepth * depthIndent ) ); - SchemaToolingLogging.AST_LOGGER.tracef( "<-%s %s", prefix, ruleName ); + SqlScriptLogging.AST_LOGGER.tracef( "<-%s %s", prefix, ruleName ); } } diff --git a/hibernate-core/src/test/resources/log4j.properties b/hibernate-core/src/test/resources/log4j.properties index 179eb931df..498bbeddd6 100644 --- a/hibernate-core/src/test/resources/log4j.properties +++ b/hibernate-core/src/test/resources/log4j.properties @@ -19,9 +19,9 @@ log4j.rootLogger=info, stdout log4j.logger.org.hibernate.orm.graph=debug -#log4j.logger.org.hibernate.orm.tooling.schema=trace -## the AST logger gets very verbose at trace -#log4j.logger.org.hibernate.orm.tooling.schema.AST=debug +#log4j.logger.org.hibernate.orm.tooling.schema.script=trace +#log4j.logger.org.hibernate.orm.tooling.schema.script.graph=trace + log4j.logger.org.hibernate.tool.hbm2ddl=trace log4j.logger.org.hibernate.testing.cache=debug