Author: stliu
Date: 2011-01-25 00:28:27 -0500 (Tue, 25 Jan 2011)
New Revision: 20882
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/hql/ast/HqlSqlWalker.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/hql/ast/SqlGenerator.java
Log:
JBPAPP-5817 HHH-5843 Avoid useless branches during HQL parsing when trace logging is
disabled
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/hql/ast/HqlSqlWalker.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/hql/ast/HqlSqlWalker.java 2011-01-25
05:15:42 UTC (rev 20881)
+++
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/hql/ast/HqlSqlWalker.java 2011-01-25
05:28:27 UTC (rev 20882)
@@ -113,7 +113,7 @@
*/
public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter,
ParameterBinder.NamedParameterSource {
private static final Logger log = LoggerFactory.getLogger( HqlSqlWalker.class );
-
+ private final boolean trace = log.isTraceEnabled();
private final QueryTranslatorImpl queryTranslatorImpl;
private final HqlParser hqlParser;
private final SessionFactoryHelper sessionFactoryHelper;
@@ -173,13 +173,15 @@
private int traceDepth = 0;
- public void traceIn(String ruleName, AST tree) {
- if ( inputState.guessing > 0 ) {
- return;
+ public void traceIn( String ruleName, AST tree ) {
+ if ( trace ) {
+ if ( inputState.guessing > 0 ) {
+ return;
+ }
+ String prefix = StringHelper.repeat( '-', (traceDepth++ * 2) ) + "->
";
+ String traceText = ruleName + " (" + buildTraceNodeName( tree ) +
")";
+ trace( prefix + traceText );
}
- String prefix = StringHelper.repeat( '-', (traceDepth++ * 2) ) + "->
";
- String traceText = ruleName + " (" + buildTraceNodeName(tree) +
")";
- trace( prefix + traceText );
}
private String buildTraceNodeName(AST tree) {
@@ -188,12 +190,14 @@
: tree.getText() + " [" + printer.getTokenTypeName( tree.getType() ) +
"]";
}
- public void traceOut(String ruleName, AST tree) {
- if ( inputState.guessing > 0 ) {
- return;
+ public void traceOut( String ruleName, AST tree ) {
+ if ( trace ) {
+ if ( inputState.guessing > 0 ) {
+ return;
+ }
+ String prefix = "<-" + StringHelper.repeat( '-', (--traceDepth *
2) ) + " ";
+ trace( prefix + ruleName );
}
- String prefix = "<-" + StringHelper.repeat( '-', (--traceDepth *
2) ) + " ";
- trace( prefix + ruleName );
}
private void trace(String msg) {
@@ -562,7 +566,7 @@
if ( fromElements.size() == 1 ) {
final FromElement fromElement = ( FromElement ) fromElements.get( 0 );
try {
- log.trace( "attempting to resolve property [" + identText + "] as a
non-qualified ref" );
+ if( trace ) log.trace( "attempting to resolve property [" + identText +
"] as a non-qualified ref" );
return fromElement.getPropertyMapping( identText ).toType( identText ) != null;
}
catch( QueryException e ) {
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/hql/ast/SqlGenerator.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/hql/ast/SqlGenerator.java 2011-01-25
05:15:42 UTC (rev 20881)
+++
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/hql/ast/SqlGenerator.java 2011-01-25
05:28:27 UTC (rev 20882)
@@ -57,6 +57,7 @@
*/
public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
private static final Logger log = LoggerFactory.getLogger( SqlGenerator.class );
+ private final boolean trace = log.isTraceEnabled();
private static final ASTPrinter printer = new ASTPrinter( SqlTokenTypes.class, true );
/**
@@ -66,9 +67,9 @@
/**
* all append invocations on the buf should go through this Output instance variable.
- * The value of this variable may be temporarily substitued by sql function processing
code
+ * The value of this variable may be temporarily substituted by sql function processing
code
* to catch generated arguments.
- * This is because sql function templates need arguments as seperate string chunks
+ * This is because sql function templates need arguments as seperated string chunks
* that will be assembled into the target dialect-specific function call.
*/
private SqlWriter writer = new DefaultWriter();
@@ -93,7 +94,7 @@
private int traceDepth = 0;
public void traceIn(String ruleName, AST tree) {
- if ( inputState.guessing > 0 ) {
+ if ( !trace || inputState.guessing > 0 ) {
return;
}
String prefix = StringHelper.repeat( '-', (traceDepth++ * 2) ) + "->
";
@@ -108,7 +109,7 @@
}
public void traceOut(String ruleName, AST tree) {
- if ( inputState.guessing > 0 ) {
+ if ( !trace || inputState.guessing > 0 ) {
return;
}
String prefix = "<-" + StringHelper.repeat( '-', (--traceDepth *
2) ) + " ";