|
From: <hib...@li...> - 2006-06-15 19:58:01
|
Author: ste...@jb...
Date: 2006-06-15 15:57:42 -0400 (Thu, 15 Jun 2006)
New Revision: 10023
Modified:
branches/Branch_3_1/Hibernate3/src/org/hibernate/hql/ast/QueryTranslatorImpl.java
Log:
opened up for subclassing
Modified: branches/Branch_3_1/Hibernate3/src/org/hibernate/hql/ast/QueryTranslatorImpl.java
===================================================================
--- branches/Branch_3_1/Hibernate3/src/org/hibernate/hql/ast/QueryTranslatorImpl.java 2006-06-15 19:41:25 UTC (rev 10022)
+++ branches/Branch_3_1/Hibernate3/src/org/hibernate/hql/ast/QueryTranslatorImpl.java 2006-06-15 19:57:42 UTC (rev 10023)
@@ -33,7 +33,6 @@
import org.hibernate.persister.entity.Queryable;
import org.hibernate.type.Type;
import org.hibernate.util.StringHelper;
-import org.hibernate.util.ArrayHelper;
import java.util.HashMap;
import java.util.Iterator;
@@ -44,9 +43,6 @@
/**
* A QueryTranslator that uses an AST based parser.
- * <br>User: josh
- * <br>Date: Dec 31, 2003
- * <br>Time: 7:50:35 AM
*
* @author Joshua Davis (pg...@so...)
*/
@@ -54,6 +50,8 @@
private static final Log log = LogFactory.getLog( QueryTranslatorImpl.class );
private static final Log AST_LOG = LogFactory.getLog( "org.hibernate.hql.ast.AST" );
+ private static final String HQL_AST_HEADER = "--- HQL AST ---";
+ private static final String SQL_AST_HEADER = "--- SQL AST ---";
private SessionFactoryImplementor factory;
@@ -197,59 +195,72 @@
this.enabledFilters = null; //only needed during compilation phase...
}
- private void generate(AST sqlAst) throws QueryException, RecognitionException {
- if ( sql == null ) {
- SqlGenerator gen = new SqlGenerator(factory);
- gen.statement( sqlAst );
- sql = gen.getSQL();
- if ( log.isDebugEnabled() ) {
- log.debug( "HQL: " + hql );
- log.debug( "SQL: " + sql );
- }
- gen.getParseErrorHandler().throwQueryException();
+ protected HqlParser parse(boolean filter) throws TokenStreamException, RecognitionException {
+ // Parse the query string into an HQL AST.
+ HqlParser parser = constructHqlParserInstance();
+ parser.setFilter( filter );
+
+ if ( log.isDebugEnabled() ) {
+ log.debug( "parse() - HQL: " + hql );
}
+ parser.statement();
+
+ AST hqlAst = parser.getAST();
+
+ showHqlAst( hqlAst );
+
+ parser.getParseErrorHandler().throwQueryException();
+ return parser;
}
- private HqlSqlWalker analyze(HqlParser parser, String collectionRole) throws QueryException, RecognitionException {
- HqlSqlWalker w = new HqlSqlWalker( this, factory, parser, tokenReplacements, collectionRole );
+ protected HqlParser constructHqlParserInstance() {
+ return HqlParser.getInstance( hql );
+ }
+
+ protected HqlSqlWalker analyze(HqlParser parser, String collectionRole) throws QueryException, RecognitionException {
+ HqlSqlWalker w = constructWalkerInstance( parser, collectionRole );
AST hqlAst = parser.getAST();
// Transform the tree.
w.statement( hqlAst );
- if ( AST_LOG.isDebugEnabled() ) {
- ASTPrinter printer = new ASTPrinter( SqlTokenTypes.class );
- AST_LOG.debug( printer.showAsString( w.getAST(), "--- SQL AST ---" ) );
- }
+ showAst( SQL_AST_HEADER, w.getAST(), SqlTokenTypes.class, true );
w.getParseErrorHandler().throwQueryException();
return w;
}
- private HqlParser parse(boolean filter) throws TokenStreamException, RecognitionException {
- // Parse the query string into an HQL AST.
- HqlParser parser = HqlParser.getInstance( hql );
- parser.setFilter( filter );
+ protected HqlSqlWalker constructWalkerInstance(HqlParser parser, String collectionRole) {
+ return new HqlSqlWalker( this, factory, parser, tokenReplacements, collectionRole );
+ }
- if ( log.isDebugEnabled() ) {
- log.debug( "parse() - HQL: " + hql );
+ protected void generate(AST sqlAst) throws QueryException, RecognitionException {
+ if ( sql == null ) {
+ SqlGenerator gen = constructSqlGeneratorInstance();
+ gen.statement( sqlAst );
+ sql = gen.getSQL();
+ if ( log.isDebugEnabled() ) {
+ log.debug( "HQL: " + hql );
+ log.debug( "SQL: " + sql );
+ }
+ gen.getParseErrorHandler().throwQueryException();
}
- parser.statement();
+ }
- AST hqlAst = parser.getAST();
+ protected SqlGenerator constructSqlGeneratorInstance() {
+ return new SqlGenerator( factory );
+ }
- showHqlAst( hqlAst );
-
- parser.getParseErrorHandler().throwQueryException();
- return parser;
+ protected void showHqlAst(AST hqlAst) {
+ showAst( HQL_AST_HEADER, hqlAst, HqlTokenTypes.class, false );
}
- void showHqlAst(AST hqlAst) {
+ protected void showAst(String header, AST ast, Class tokenTypesClass, boolean showNodeClassNames) {
if ( AST_LOG.isDebugEnabled() ) {
- ASTPrinter printer = new ASTPrinter( HqlTokenTypes.class );
- printer.setShowClassNames( false ); // The class names aren't interesting in the first tree.
- AST_LOG.debug( printer.showAsString( hqlAst, "--- HQL AST ---" ) );
+ ASTPrinter printer = new ASTPrinter( tokenTypesClass );
+ printer.setShowClassNames( showNodeClassNames );
+ AST_LOG.debug( printer.showAsString( ast, header ) );
}
}
|