Merge branch 'HHH-5843' of git://github.com/Sanne/hibernate-core into Sanne-HHH-5843

This commit is contained in:
Hardy Ferentschik 2011-01-19 09:27:21 +01:00
commit 3bf6625ab1
3 changed files with 48 additions and 36 deletions

View File

@ -55,6 +55,7 @@ public final class HqlParser extends HqlBaseParser {
* A logger for this class. * A logger for this class.
*/ */
private static final Logger log = LoggerFactory.getLogger( HqlParser.class ); private static final Logger log = LoggerFactory.getLogger( HqlParser.class );
private final boolean trace = log.isTraceEnabled();
private ParseErrorHandler parseErrorHandler; private ParseErrorHandler parseErrorHandler;
private ASTPrinter printer = getASTPrinter(); private ASTPrinter printer = getASTPrinter();
@ -79,22 +80,25 @@ private HqlParser(TokenStream lexer) {
private int traceDepth = 0; private int traceDepth = 0;
public void traceIn(String ruleName) { public void traceIn(String ruleName) {
if (trace) {
if ( inputState.guessing > 0 ) { if ( inputState.guessing > 0 ) {
return; return;
} }
String prefix = StringHelper.repeat( '-', (traceDepth++ * 2) ) + "-> "; String prefix = StringHelper.repeat( '-', (traceDepth++ * 2) ) + "-> ";
log.trace( prefix + ruleName ); log.trace( prefix + ruleName );
} }
}
public void traceOut(String ruleName) { public void traceOut(String ruleName) {
if (trace) {
if ( inputState.guessing > 0 ) { if ( inputState.guessing > 0 ) {
return; return;
} }
String prefix = "<-" + StringHelper.repeat( '-', (--traceDepth * 2) ) + " "; String prefix = "<-" + StringHelper.repeat( '-', (--traceDepth * 2) ) + " ";
log.trace( prefix + ruleName ); log.trace( prefix + ruleName );
} }
}
public void reportError(RecognitionException e) { public void reportError(RecognitionException e) {
parseErrorHandler.reportError( e ); // Use the delegate. parseErrorHandler.reportError( e ); // Use the delegate.

View File

@ -110,7 +110,7 @@
* Implements methods used by the HQL->SQL tree transform grammar (a.k.a. the second phase). * Implements methods used by the HQL->SQL tree transform grammar (a.k.a. the second phase).
* <ul> * <ul>
* <li>Isolates the Hibernate API-specific code from the ANTLR generated code.</li> * <li>Isolates the Hibernate API-specific code from the ANTLR generated code.</li>
* <li>Handles the SQL framgents generated by the persisters in order to create the SELECT and FROM clauses, * <li>Handles the SQL fragments generated by the persisters in order to create the SELECT and FROM clauses,
* taking into account the joins and projections that are implied by the mappings (persister/queryable).</li> * taking into account the joins and projections that are implied by the mappings (persister/queryable).</li>
* <li>Uses SqlASTFactory to create customized AST nodes.</li> * <li>Uses SqlASTFactory to create customized AST nodes.</li>
* </ul> * </ul>
@ -119,6 +119,7 @@
*/ */
public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, ParameterBinder.NamedParameterSource { public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, ParameterBinder.NamedParameterSource {
private static final Logger log = LoggerFactory.getLogger( HqlSqlWalker.class ); private static final Logger log = LoggerFactory.getLogger( HqlSqlWalker.class );
private final boolean trace = log.isTraceEnabled();
private final QueryTranslatorImpl queryTranslatorImpl; private final QueryTranslatorImpl queryTranslatorImpl;
private final HqlParser hqlParser; private final HqlParser hqlParser;
@ -186,6 +187,7 @@ public HqlSqlWalker(
private int traceDepth = 0; private int traceDepth = 0;
public void traceIn(String ruleName, AST tree) { public void traceIn(String ruleName, AST tree) {
if (trace) {
if ( inputState.guessing > 0 ) { if ( inputState.guessing > 0 ) {
return; return;
} }
@ -193,6 +195,7 @@ public void traceIn(String ruleName, AST tree) {
String traceText = ruleName + " (" + buildTraceNodeName(tree) + ")"; String traceText = ruleName + " (" + buildTraceNodeName(tree) + ")";
log.trace( prefix + traceText ); log.trace( prefix + traceText );
} }
}
private String buildTraceNodeName(AST tree) { private String buildTraceNodeName(AST tree) {
return tree == null return tree == null
@ -201,12 +204,14 @@ private String buildTraceNodeName(AST tree) {
} }
public void traceOut(String ruleName, AST tree) { public void traceOut(String ruleName, AST tree) {
if (trace) {
if ( inputState.guessing > 0 ) { if ( inputState.guessing > 0 ) {
return; return;
} }
String prefix = "<-" + StringHelper.repeat( '-', (--traceDepth * 2) ) + " "; String prefix = "<-" + StringHelper.repeat( '-', (--traceDepth * 2) ) + " ";
log.trace( prefix + ruleName ); log.trace( prefix + ruleName );
} }
}
protected void prepareFromClauseInputTree(AST fromClauseInput) { protected void prepareFromClauseInputTree(AST fromClauseInput) {
@ -583,7 +588,7 @@ protected boolean isNonQualifiedPropertyRef(AST ident) {
if ( fromElements.size() == 1 ) { if ( fromElements.size() == 1 ) {
final FromElement fromElement = ( FromElement ) fromElements.get( 0 ); final FromElement fromElement = ( FromElement ) fromElements.get( 0 );
try { 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; return fromElement.getPropertyMapping( identText ).toType( identText ) != null;
} }
catch( QueryException e ) { catch( QueryException e ) {

View File

@ -33,7 +33,6 @@
import antlr.collections.AST; import antlr.collections.AST;
import org.hibernate.QueryException; import org.hibernate.QueryException;
import org.hibernate.hql.ast.tree.FunctionNode; import org.hibernate.hql.ast.tree.FunctionNode;
import org.hibernate.hql.ast.tree.SqlNode;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.hibernate.util.StringHelper; import org.hibernate.util.StringHelper;
import org.hibernate.param.ParameterSpecification; import org.hibernate.param.ParameterSpecification;
@ -41,7 +40,6 @@
import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.hql.antlr.SqlGeneratorBase; import org.hibernate.hql.antlr.SqlGeneratorBase;
import org.hibernate.hql.antlr.SqlTokenTypes; import org.hibernate.hql.antlr.SqlTokenTypes;
import org.hibernate.hql.ast.tree.MethodNode;
import org.hibernate.hql.ast.tree.FromElement; import org.hibernate.hql.ast.tree.FromElement;
import org.hibernate.hql.ast.tree.Node; import org.hibernate.hql.ast.tree.Node;
import org.hibernate.hql.ast.tree.ParameterNode; import org.hibernate.hql.ast.tree.ParameterNode;
@ -60,14 +58,15 @@
*/ */
public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter { public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
private static final Logger log = LoggerFactory.getLogger( SqlGenerator.class ); private static final Logger log = LoggerFactory.getLogger( SqlGenerator.class );
private final boolean trace = log.isTraceEnabled();
public static boolean REGRESSION_STYLE_CROSS_JOINS = false; public static boolean REGRESSION_STYLE_CROSS_JOINS = false;
/** /**
* all append invocations on the buf should go through this Output instance variable. * 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. * 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 separate string chunks
* that will be assembled into the target dialect-specific function call. * that will be assembled into the target dialect-specific function call.
*/ */
private SqlWriter writer = new DefaultWriter(); private SqlWriter writer = new DefaultWriter();
@ -84,6 +83,7 @@ public class SqlGenerator extends SqlGeneratorBase implements ErrorReporter {
private int traceDepth = 0; private int traceDepth = 0;
public void traceIn(String ruleName, AST tree) { public void traceIn(String ruleName, AST tree) {
if (trace) {
if ( inputState.guessing > 0 ) { if ( inputState.guessing > 0 ) {
return; return;
} }
@ -91,6 +91,7 @@ public void traceIn(String ruleName, AST tree) {
String traceText = ruleName + " (" + buildTraceNodeName(tree) + ")"; String traceText = ruleName + " (" + buildTraceNodeName(tree) + ")";
log.trace( prefix + traceText ); log.trace( prefix + traceText );
} }
}
private String buildTraceNodeName(AST tree) { private String buildTraceNodeName(AST tree) {
return tree == null return tree == null
@ -99,12 +100,14 @@ private String buildTraceNodeName(AST tree) {
} }
public void traceOut(String ruleName, AST tree) { public void traceOut(String ruleName, AST tree) {
if (trace) {
if ( inputState.guessing > 0 ) { if ( inputState.guessing > 0 ) {
return; return;
} }
String prefix = "<-" + StringHelper.repeat( '-', (--traceDepth * 2) ) + " "; String prefix = "<-" + StringHelper.repeat( '-', (--traceDepth * 2) ) + " ";
log.trace( prefix + ruleName ); log.trace( prefix + ruleName );
} }
}
public List getCollectedParameters() { public List getCollectedParameters() {
return collectedParameters; return collectedParameters;