[hibernate-commits] Hibernate SVN: r16467 - in core/branches/antlr3/src: main/antlr3/org/hibernate/sql/ast/ordering and 36 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Apr 28 12:13:05 EDT 2009


Author: steve.ebersole at jboss.com
Date: 2009-04-28 12:13:04 -0400 (Tue, 28 Apr 2009)
New Revision: 16467

Added:
   core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/
   core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/hql/
   core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/hql/parse/
   core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/hql/parse/HQLLexer.g
   core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/hql/parse/HQLParser.g
   core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/hql/resolve/
   core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/hql/resolve/GeneratedHQLResolver.g
   core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/ordering/
   core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/ordering/OrderByParser.g
   core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/render/
   core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/render/OrderByRenderer.g
   core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/render/SQLRenderer.g-tmp
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/parse/
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/parse/ParserContext.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/parse/ParserContextDefaultImpl.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/HQLResolver.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/HierarchicalPersisterSpaceContext.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/PersisterSpace.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/PersisterSpaceContext.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/PersisterTableExpressionGenerator.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/PropertyPathTerminus.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/ResolutionContext.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/RootPersisterSpaceContext.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/PathResolutionStrategy.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/PathResolutionStrategyStack.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/PathedPropertyReferenceSource.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/AbstractPathResolutionStrategy.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/AbstractUnexpectedPropertyTypeException.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/BasicPathResolutionStrategySupport.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/CollectionExpectedException.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/FromClausePathResolutionStrategy.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/IndexedCollectionExectedException.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/InvalidPropertyJoinException.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/OnFragmentPathResolutionStrategy.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/SelectClausePathResolutionStrategy.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/WithFragmentPathResolutionStrategy.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/ordering/
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/ordering/ColumnMapper.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/ordering/OrderByFragmentParser.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/ordering/OrderByFragmentTranslator.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/ordering/TranslationContext.java
   core/branches/antlr3/src/main/resources/org/hibernate/sql/
   core/branches/antlr3/src/main/resources/org/hibernate/sql/ast/
   core/branches/antlr3/src/main/resources/org/hibernate/sql/ast/template/
   core/branches/antlr3/src/main/resources/org/hibernate/sql/ast/template/GenericSQL.stg
   core/branches/antlr3/src/main/resources/org/hibernate/sql/ast/template/OrderBy.stg
   core/branches/antlr3/src/test/java/org/hibernate/sql/ast/origin/
   core/branches/antlr3/src/test/java/org/hibernate/sql/ast/origin/ordering/
   core/branches/antlr3/src/test/java/org/hibernate/sql/ast/origin/ordering/OrderByParserTest.java
Removed:
   core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/ordering/OrderByParser.g
   core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLLexer.g
   core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLParser.g
   core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/resolve/GeneratedHQLResolver.g
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/ColumnMapper.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentParser.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentTranslator.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/TranslationContext.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/parse/ParserContext.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/parse/ParserContextDefaultImpl.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HQLResolver.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HierarchicalPersisterSpaceContext.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpace.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpaceContext.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableExpressionGenerator.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PropertyPathTerminus.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/ResolutionContext.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/RootPersisterSpaceContext.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathResolutionStrategy.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathResolutionStrategyStack.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathedPropertyReferenceSource.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/AbstractPathResolutionStrategy.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/AbstractUnexpectedPropertyTypeException.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/BasicPathResolutionStrategySupport.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/CollectionExpectedException.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/FromClausePathResolutionStrategy.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/IndexedCollectionExectedException.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/InvalidPropertyJoinException.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/OnFragmentPathResolutionStrategy.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/SelectClausePathResolutionStrategy.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/WithFragmentPathResolutionStrategy.java
   core/branches/antlr3/src/test/java/org/hibernate/sql/ast/ordering/OrderByParserTest.java
Modified:
   core/branches/antlr3/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/Template.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/Table.java
   core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/TreePrinter.java
   core/branches/antlr3/src/test/java/org/hibernate/sql/TemplateTest.java
   core/branches/antlr3/src/test/java/org/hibernate/sql/ast/phase/hql/resolve/TestHQLResolver.java
   core/branches/antlr3/src/test/resources/log4j.properties
Log:
reorg grammars; primary investigation of unified FUNCTION rewriting; code cleanup; basic mapped order-by rendering

Deleted: core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/ordering/OrderByParser.g
===================================================================
--- core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/ordering/OrderByParser.g	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/ordering/OrderByParser.g	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,567 +0,0 @@
-parser grammar OrderByParser;
-
-options {
-	tokenVocab=HQLLexer;
-	output=AST;
-	ASTLabelType=CommonTree;
-}
-
- at parser::header {
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- *
- * Portions of SQL grammar parsing copyright (C) 2003 by Lubos Vnuk.  All rights
- * reserved.  These portions are distributed under license by Red Hat Middleware
- * LLC and are covered by the above LGPL notice.  If you redistribute this material,
- * with or without modification, you must preserve this copyright notice in its
- * entirety.
- */
-package org.hibernate.sql.ast.ordering;
-
-import org.hibernate.sql.Template;
-}
-
- at parser::members {
-    /**
-     * A check to see if the text represents a known function name (in addition to the
-     * set of known {@link #standardFunction "standard"} functions.  This is only needed in the
-     * case of seeing a dot-ident structure which is not followed by a paren; such structures
-     * which are followed by a paren are explicitly assumed to be a function name.
-     *
-     * @param text The text to check as a  function name.
-     *
-     * @return True if the text is a known function name, false otherwise.
-     *
-     * @see #standardFunction
-     */
-    protected boolean isFunctionName(String text) {
-        // by default, assume it is not
-    	return false;
-    }
-
-    /**
-     * A check to see if the text represents a mapped property name.
-     *
-     * @param text The text to check as a property name.
-     *
-     * @return True if the text is a mapped property name, false otherwise.
-     */
-    protected boolean isPropertyName(String text) {
-        // by default, assume it is not
-    	return false;
-    }
-
-    /**
-     * Given a property, resolve it's {@link #COLUMN} or {@link #VECTOR_EXPR} tree.
-     *
-     * @param propertyTree The tree representing the property name.
-     *
-     * @return The column(s) tree.
-     */
-    protected CommonTree buildPropertyColumns(CommonTree propertyTree) {
-        throw new UnsupportedOperationException( "must be overridden!" );
-    }
-
-	private boolean validateSoftKeyword(String text) {
-		return validateLT(1, text);
-	}
-
-	private boolean validateLT(int offset, String text) {
-		String text2Validate = retrieveLT( offset );
-		return text2Validate == null ? false : text2Validate.equalsIgnoreCase( text );
-	}
-
-	private String retrieveLT(int offset) {
-      	if (null == input) {
-      		return null;
-      	}
-		Token token = input.LT(offset);
-		return token == null ? null : token.getText();
-	}
-}
-
-
-// Parser rules ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-
-/**
- * Main recognition rule for this grammar
- */
-orderByFragment :
-    sortSpecification ( COMMA sortSpecification )*
-        -> ^( ORDER_BY sortSpecification+ )
-;
-
-
-/**
- * Reconition rule for what ANSI SQL terms the <tt>sort specification</tt>.  These are the atomic elements of the
- * <tt>ORDER BY</tt> list pieces.
- */
-sortSpecification :
-    sortKey collationSpecification? orderingSpecification?
-        -> ^( SORT_SPEC sortKey collationSpecification? orderingSpecification? )
-;
-
-
-/**
- * Reconition rule for what ANSI SQL terms the <tt>sort key</tt> which is the expression (column, function, etc) upon
- * which to base the sorting.
- */
-sortKey :
-    expression
-;
-
-/**
- * Reconition rule what this grammar recognizes as valid <tt>sort key</tt>.
- */
-expression
-    : QUOTED_IDENTIFIER -> ^( COLUMN[$QUOTED_IDENTIFIER] ALIAS_REF[Template.TEMPLATE] QUOTED_IDENTIFIER[$QUOTED_IDENTIFIER] )
-    // we treat the so-called standard functions differently because they are handled differently by the HQL lexer which we also use here...
-    | standardFunction
-    // not identDotIdentStructure because we dont want QUOTED_IDENTIFIERs is here
-    | ( IDENTIFIER ( DOT IDENTIFIER )* LEFT_PAREN ) => generalFunction
-    // otherwise we fully expect a dot-identifier series, and then we just need to decode the semantic of that structure
-    | identDotIdentStructure
-        -> { ( isFunctionName($identDotIdentStructure.text) ) }?
-              // we have a function with parens (thus no args)
-              ^( GENERAL_FUNCTION_CALL[$identDotIdentStructure.start,$identDotIdentStructure.text] )
-        -> { ( isPropertyName($identDotIdentStructure.text) ) }?
-              // we have a reference to a mapped property
-              { buildPropertyColumns( $identDotIdentStructure.tree ) }
-        -> { ( $identDotIdentStructure.tree.getType() == DOT ) }?
-              // we have a reference to a column which is already qualified
-              identDotIdentStructure
-        ->
-              // we have a reference to a column which is not qualified
-              ^( COLUMN ALIAS_REF[Template.TEMPLATE] IDENTIFIER[$identDotIdentStructure.start,$identDotIdentStructure.text] )
-    ;
-
-fragment
-identifier
-    : IDENTIFIER
-    | QUOTED_IDENTIFIER
-    ;
-
-fragment
-identDotIdentStructure
-    : IDENTIFIER ( DOT^ identifier )*
-    ;
-
-standardFunction
-	:	castFunction
-	|	concatFunction
-	|	substringFunction
-	|	trimFunction
-	|	upperFunction
-	|	lowerFunction
-	|	lengthFunction
-	|	locateFunction
-	|	absFunction
-	|	sqrtFunction
-	|	modFunction
-	|	currentDateFunction
-	|	currentTimeFunction
-	|	currentTimestampFunction
-	|	extractFunction
-	|	positionFunction
-	|	charLengthFunction
-	|	octetLengthFunction
-	|	bitLengthFunction
-	;
-
-castFunction
-	:	cast_keyword^ LEFT_PAREN! expression as_keyword! dataType RIGHT_PAREN!
-	;
-
-fragment
-dataType
-	:	IDENTIFIER
-	;
-
-concatFunction
-	:	concat_keyword^ LEFT_PAREN! expression ( COMMA! expression )+ RIGHT_PAREN!
-	;
-
-substringFunction
-	:	substring_keyword^ LEFT_PAREN! expression COMMA! expression ( COMMA! expression)? RIGHT_PAREN!
-	;
-
-trimFunction
-	:	trim_keyword LEFT_PAREN trimOperands RIGHT_PAREN
-		-> ^(trim_keyword trimOperands)
-	;
-
-fragment
-trimOperands
-options{
-k=2;
-}
- at init {boolean hasSecondExpression = false;}
-	:	trimSpecification from_keyword expression -> ^(trimSpecification STRING_LITERAL[" "] expression)
-	|	trimSpecification expression from_keyword expression -> ^(trimSpecification expression+)
-	|	from_keyword expression -> ^(BOTH STRING_LITERAL[" "] expression)
-	|	cn=expression ( from_keyword expression {hasSecondExpression = true;} )?
-		-> {hasSecondExpression}? ^(BOTH expression+)
-		-> ^(BOTH STRING_LITERAL[" "] $cn)
-	;
-
-fragment
-trimSpecification
-	:	leading_keyword
-	|	trailing_keyword
-	|	both_keyword
-	;
-
-upperFunction
-	:	upper_keyword^ LEFT_PAREN! expression RIGHT_PAREN!
-	;
-
-lowerFunction
-	:	lower_keyword^ LEFT_PAREN! expression RIGHT_PAREN!
-	;
-
-lengthFunction
-	:	length_keyword^ LEFT_PAREN! expression RIGHT_PAREN!
-	;
-
-locateFunction
-	:	locate_keyword^ LEFT_PAREN! expression COMMA! expression ( COMMA! expression )? RIGHT_PAREN!
-	;
-
-absFunction
-	:	abs_keyword^ LEFT_PAREN! expression RIGHT_PAREN!
-	;
-
-sqrtFunction
-	:	sqrt_keyword^ LEFT_PAREN! expression RIGHT_PAREN!
-	;
-
-modFunction
-	:	mod_keyword^ LEFT_PAREN! expression COMMA! expression RIGHT_PAREN!
-	;
-
-currentDateFunction
-	:	current_date_keyword ( LEFT_PAREN! RIGHT_PAREN! )?
-	;
-
-currentTimeFunction
-	:	current_time_keyword ( LEFT_PAREN! RIGHT_PAREN! )?
-	;
-
-currentTimestampFunction
-	:	current_timestamp_keyword ( LEFT_PAREN! RIGHT_PAREN! )?
-	;
-
-extractFunction
-	:	extract_keyword^ LEFT_PAREN! extractField from_keyword! expression RIGHT_PAREN!
-	;
-
-extractField
-	:	datetimeField
-	|	timeZoneField
-	;
-
-datetimeField
-	:	nonSecondDatetimeField
-	|	second_keyword
-	;
-
-nonSecondDatetimeField
-	:	year_keyword
-	|	month_keyword
-	|	day_keyword
-	|	hour_keyword
-	|	minute_keyword
-	;
-
-timeZoneField
-	:	timezone_hour_keyword
-	|	timezone_minute_keyword
-	;
-
-positionFunction
-	:	position_keyword^ LEFT_PAREN! expression in_keyword! expression RIGHT_PAREN!
-	;
-
-charLengthFunction
-	:	character_length_keyword^ LEFT_PAREN! expression RIGHT_PAREN!
-	;
-
-octetLengthFunction
-	:	octet_length_keyword^ LEFT_PAREN! expression RIGHT_PAREN!
-	;
-
-bitLengthFunction
-	:	bit_length_keyword^ LEFT_PAREN! expression RIGHT_PAREN!
-	;
-
-
-generalFunction
-    : generalFunctionName LEFT_PAREN functionArgumentList RIGHT_PAREN
-          -> ^( GENERAL_FUNCTION_CALL[$generalFunctionName.start,$generalFunctionName.text] functionArgumentList )
-    ;
-
-generalFunctionName :
-    IDENTIFIER ( DOT IDENTIFIER )+
-;
-
-/**
- * Recognition rule used to "wrap" all function arguments into a GENERAL_FUNCTION_ARGUMENTS node
- */
-functionArgumentList :
-    functionArgument ( COMMA functionArgument )*
-        -> ^( GENERAL_FUNCTION_ARGUMENTS functionArgument+ )
-;
-
-
-/**
- * Recognized function parameters.
- */
-functionArgument :
-    expression
-    | literal
-;
-
-literal
-	:	numeric_literal
-	|	HEX_LITERAL
-	|	OCTAL_LITERAL
-	|	CHARACTER_LITERAL
-	|	STRING_LITERAL
-	;
-
-numeric_literal
-	:	INTEGER_LITERAL
-	|	DECIMAL_LITERAL
-	|	FLOATING_POINT_LITERAL
-	;
-
-/**
- * Reconition rule for what ANSI SQL terms the <tt>collation specification</tt> used to allow specifying that sorting for
- * the given {@link #sortSpecification} be treated within a specific character-set.
- */
-collationSpecification!
-    : collateKeyword collationName
-        -> COLLATE[$collateKeyword.start,$collationName.text]
-;
-
-collateKeyword :
-    {(validateSoftKeyword("collate"))}?=>  id=IDENTIFIER
-		->	COLLATE[$id]
-;
-
-/**
- * The collation name wrt {@link #collationSpecification}.  Namely, the character-set.
- */
-collationName :
-    IDENTIFIER
-;
-
-/**
- * Reconition rule for what ANSI SQL terms the <tt>ordering specification</tt>; <tt>ASCENDING</tt> or
- * <tt>DESCENDING</tt>.
- */
-orderingSpecification! :
-    ascending_keyword
-        -> ORDER_SPEC[$ascending_keyword.start,"asc"]
-    | descending_keyword
-        -> ORDER_SPEC[$descending_keyword.start,"desc"]
-;
-
-
-// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-// Soft-keyword handling rules
-// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-abs_keyword
-	:	{(validateSoftKeyword("abs"))}?=>  id=IDENTIFIER
-		->	ABS[$id]
-	;
-
-as_keyword
-	:	{(validateSoftKeyword("as"))}?=>  id=IDENTIFIER
-		->	AS[$id]
-	;
-
-ascending_keyword :
-    {(validateSoftKeyword("ascending") || validateSoftKeyword("asc"))}?=>  IDENTIFIER
-;
-
-bit_length_keyword
-	:	{(validateSoftKeyword("bit_length"))}?=>  id=IDENTIFIER
-		->	BIT_LENGTH[$id]
-	;
-
-both_keyword
-	:	{(validateSoftKeyword("both"))}?=>  id=IDENTIFIER
-		->	BOTH[$id]
-	;
-
-cast_keyword
-	:	{(validateSoftKeyword("cast"))}?=>  id=IDENTIFIER
-		->	CAST[$id]
-	;
-
-character_length_keyword
-	:	{(validateSoftKeyword("character_length") || validateSoftKeyword("char_length"))}?=>  id=IDENTIFIER
-		->	CHARACTER_LENGTH[$id]
-	;
-
-concat_keyword
-	:	{(validateSoftKeyword("concat"))}?=>  id=IDENTIFIER
-		->	CONCAT[$id]
-	;
-
-current_date_keyword
-	:	{(validateSoftKeyword("current_date"))}?=>  id=IDENTIFIER
-		->	CURRENT_DATE[$id]
-	;
-
-current_time_keyword
-	:	{(validateSoftKeyword("current_time"))}?=>  id=IDENTIFIER
-		->	CURRENT_TIME[$id]
-	;
-
-current_timestamp_keyword
-	:	{(validateSoftKeyword("current_timestamp"))}?=>  id=IDENTIFIER
-		->	CURRENT_TIMESTAMP[$id]
-	;
-
-day_keyword
-	:	{(validateSoftKeyword("day"))}?=>  id=IDENTIFIER
-		->	DAY[$id]
-	;
-
-descending_keyword :
-    {(validateSoftKeyword("descending") || validateSoftKeyword("desc"))}?=>  IDENTIFIER
-;
-
-extract_keyword
-	:	{(validateSoftKeyword("extract"))}?=>  id=IDENTIFIER
-		->	EXTRACT[$id]
-	;
-
-from_keyword
-	:	{(validateSoftKeyword("from"))}?=>  id=IDENTIFIER
-		->	FROM[$id]
-	;
-
-hour_keyword
-	:	{(validateSoftKeyword("hour"))}?=>  id=IDENTIFIER
-		->	HOUR[$id]
-	;
-
-in_keyword
-	:	{(validateSoftKeyword("in"))}?=>  id=IDENTIFIER
-		->	IN[$id]
-	;
-leading_keyword
-	:	{(validateSoftKeyword("leading"))}?=>  id=IDENTIFIER
-		->	LEADING[$id]
-	;
-
-length_keyword
-	:	{(validateSoftKeyword("length"))}?=>  id=IDENTIFIER
-		->	LENGTH[$id]
-	;
-
-locate_keyword
-	:	{(validateSoftKeyword("locate"))}?=>  id=IDENTIFIER
-		->	LOCATE[$id]
-	;
-
-lower_keyword
-	:	{(validateSoftKeyword("lower"))}?=>  id=IDENTIFIER
-		->	LOWER[$id]
-	;
-
-minute_keyword
-	:	{(validateSoftKeyword("minute"))}?=>  id=IDENTIFIER
-		->	MINUTE[$id]
-	;
-
-mod_keyword
-	:	{(validateSoftKeyword("mod"))}?=>  id=IDENTIFIER
-		->	MOD[$id]
-	;
-
-month_keyword
-	:	{(validateSoftKeyword("month"))}?=>  id=IDENTIFIER
-		->	MONTH[$id]
-	;
-
-octet_length_keyword
-	:	{(validateSoftKeyword("octet_length"))}?=>  id=IDENTIFIER
-		->	OCTET_LENGTH[$id]
-	;
-
-position_keyword
-	:	{(validateSoftKeyword("position"))}?=>  id=IDENTIFIER
-		->	POSITION[$id]
-	;
-
-second_keyword
-	:	{(validateSoftKeyword("second"))}?=>  id=IDENTIFIER
-		->	SECOND[$id]
-	;
-
-sqrt_keyword
-	:	{(validateSoftKeyword("sqrt"))}?=>  id=IDENTIFIER
-		->	SQRT[$id]
-	;
-
-substring_keyword
-	:	{(validateSoftKeyword("substring"))}?=>  id=IDENTIFIER
-		->	SUBSTRING[$id]
-	;
-
-timezone_hour_keyword
-	:	{(validateSoftKeyword("timezone_hour"))}?=>  id=IDENTIFIER
-		->	TIMEZONE_HOUR[$id]
-	;
-
-timezone_minute_keyword
-	:	{(validateSoftKeyword("timezone_minute"))}?=>  id=IDENTIFIER
-		->	TIMEZONE_MINUTE[$id]
-	;
-
-trailing_keyword
-	:	{(validateSoftKeyword("trailing"))}?=>  id=IDENTIFIER
-		->	TRAILING[$id]
-	;
-
-trim_keyword
-	:	{(validateSoftKeyword("trim"))}?=>  id=IDENTIFIER
-		->	TRIM[$id]
-	;
-
-upper_keyword
-	:	{(validateSoftKeyword("upper"))}?=>  id=IDENTIFIER
-		->	UPPER[$id]
-	;
-
-year_keyword
-	:	{(validateSoftKeyword("year"))}?=>  id=IDENTIFIER
-		->	YEAR[$id]
-	;
-

Copied: core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/hql/parse/HQLLexer.g (from rev 16466, core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLLexer.g)
===================================================================
--- core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/hql/parse/HQLLexer.g	                        (rev 0)
+++ core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/hql/parse/HQLLexer.g	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,368 @@
+lexer grammar HQLLexer;
+
+tokens {
+//GENERIC SQL TOKENS
+	TABLE;
+	COLUMN;
+	COLUMN_LIST;
+
+//VIRTUAL TOKENS
+	ALIAS_NAME;
+	ALIAS_REF;
+	BETWEEN_LIST;
+	COLLATE;
+	COLLECTION_EXPRESSION;
+	DOT_CLASS;
+	DYNAMIC_INSTANTIATION_ARG;
+	DYNAMIC_INSTANTIATION;
+	ENTITY_NAME;
+	ENTITY_PERSISTER_REF;
+	FILTER;
+	FUNCTION;
+//	GENERAL_FUNCTION_CALL;
+//	GENERAL_FUNCTION_ARGUMENTS;
+	GROUPING_VALUE;
+	IN_LIST;
+	INSERTABILITY_SPEC;
+	IS_NOT_EMPTY;
+	IS_NOT_NULL;
+	IS_NULL;
+	JAVA_CONSTANT;
+	JPA_PARAM;
+	NAMED_PARAM;
+	NOT_BETWEEN;
+	NOT_IN;
+	NOT_LIKE;
+	NOT_MEMBER_OF;
+	ORDER_SPEC;
+	PATH;
+	PERSISTER_JOIN;
+	PERSISTER_SPACE;
+	PROP_FETCH;
+	PROPERTY_JOIN;
+	PROPERTY_REFERENCE;
+	QUALIFIED_JOIN;
+	QUERY_SPEC;
+	QUERY;
+	SEARCHED_CASE;
+	SELECT_FROM;
+	SELECT_ITEM;
+	SELECT_LIST;
+	SIMPLE_CASE;
+	SORT_SPEC;
+	SUB_QUERY;
+	UNARY_MINUS;
+	UNARY_PLUS;
+	VECTOR_EXPR;
+	VERSIONED_VALUE;
+
+//SOFT KEYWORDS
+	ABS;
+	ALL;
+	AND;
+	ANY;
+	AS;
+	AVG;
+	BETWEEN;
+	BIT_LENGTH;
+	BOTH;
+	CAST;
+	CHARACTER_LENGTH;
+	CLASS;
+	COALESCE;
+	CONCAT;
+	COUNT;
+	CROSS;
+	CURRENT_DATE;
+	CURRENT_TIME;
+	CURRENT_TIMESTAMP;
+	DAY;
+	DELETE;
+	DISTINCT;
+	ELEMENTS;
+	ELSE;
+	END;
+	ESCAPE;
+	EXCEPT;
+	EXISTS;
+	EXTRACT;
+	FETCH;
+	FROM;
+	FULL;
+	GROUP_BY;
+	HAVING;
+	HOUR;
+	IN;
+	INDEX;
+	INDICES;
+	INNER;
+	INSERT;
+	INTERSECT;
+	INTO;
+	IS_EMPTY;
+	IS;
+	JOIN;
+	LEADING;
+	LEFT;
+	LENGTH;
+	LIKE;
+	LOCATE;
+	LOWER;
+	MAX;
+	MAXELEMENT;
+	MAXINDEX;
+	MEMBER_OF;
+	MIN;
+	MINELEMENT;
+	MININDEX;
+	MINUTE;
+	MOD;
+	MONTH;
+	NEW;
+	NOT;
+	NULLIF;
+	OCTET_LENGTH;
+	ON;
+	OR;
+	ORDER_BY;
+	OUTER;
+	POSITION;
+	PROPERTIES;
+	RIGHT;
+	SECOND;
+	SELECT;
+	SET;
+	SIZE;
+	SOME;
+	SQRT;
+	SUBSTRING;
+	SUM;
+	THEN;
+	TIMEZONE_HOUR;
+	TIMEZONE_MINUTE;
+	TRAILING;
+	TRIM;
+	UNION;
+	UPDATE;
+	UPPER;
+	VERSIONED;
+	WHEN;
+	WHERE;
+	WITH;
+	YEAR;
+}
+
+ at header {
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ *
+ * Portions of SQL grammar parsing copyright (C) 2003 by Lubos Vnuk.  All rights
+ * reserved.  These portions are distributed under license by Red Hat Middleware
+ * LLC and are covered by the above LGPL notice.  If you redistribute this material,
+ * with or without modification, you must preserve this copyright notice in its
+ * entirety.
+ */
+package org.hibernate.sql.ast.origin.hql.parse;
+}
+
+WS      :       (	' '
+                |	'\t'
+                |	'\f'
+                |	EOL
+                )+
+                { $channel=HIDDEN; }
+        ;
+
+fragment
+EOL 	:	     
+   		(       ( '\r\n' )=> '\r\n'  // Evil DOS
+                |       '\r'    // Macintosh
+                |       '\n'    // Unix (the right way)
+                )
+        ;
+
+HEX_LITERAL : '0' ('x'|'X') HEX_DIGIT+ INTEGER_TYPE_SUFFIX? ;
+
+INTEGER_LITERAL : ('0' | '1'..'9' '0'..'9'*) ;
+
+DECIMAL_LITERAL : ('0' | '1'..'9' '0'..'9'*) INTEGER_TYPE_SUFFIX ;
+
+OCTAL_LITERAL : '0' ('0'..'7')+ INTEGER_TYPE_SUFFIX? ;
+
+fragment
+HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;
+
+fragment
+INTEGER_TYPE_SUFFIX : ('l'|'L') ;
+
+FLOATING_POINT_LITERAL
+    :   ('0'..'9')+ '.' ('0'..'9')* EXPONENT? FLOAT_TYPE_SUFFIX?
+    |   '.' ('0'..'9')+ EXPONENT? FLOAT_TYPE_SUFFIX?
+    |   ('0'..'9')+ EXPONENT FLOAT_TYPE_SUFFIX?
+    |   ('0'..'9')+ FLOAT_TYPE_SUFFIX
+    ;
+
+fragment
+EXPONENT : ('e'|'E') ('+'|'-')? ('0'..'9')+ ;
+
+fragment
+FLOAT_TYPE_SUFFIX : ('f'|'F'|'d'|'D') ;
+
+CHARACTER_LITERAL
+    :   '\'' ( ESCAPE_SEQUENCE | ~('\''|'\\') ) '\''
+    ;
+
+STRING_LITERAL
+    :  '"' ( ESCAPE_SEQUENCE | ~('\\'|'"') )* '"'
+    |  ('\'' ( ESCAPE_SEQUENCE | ~('\\'|'\'') )* '\'')+
+    ;
+
+fragment
+ESCAPE_SEQUENCE
+    :   '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
+    |   UNICODE_ESCAPE
+    |   OCTAL_ESCAPE
+    ;
+
+fragment
+OCTAL_ESCAPE
+    :   '\\' ('0'..'3') ('0'..'7') ('0'..'7')
+    |   '\\' ('0'..'7') ('0'..'7')
+    |   '\\' ('0'..'7')
+    ;
+
+fragment
+UNICODE_ESCAPE
+    :   '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
+    ;
+
+TRUE
+	:	'true'
+	;	
+
+FALSE
+	:	'false'
+	;
+
+NULL
+	:	'null'
+	;
+
+EQUALS
+	:	'='
+	;
+
+SEMICOLON
+	:	';'
+	;
+
+COLON
+	:	':'
+	;
+
+NOT_EQUAL
+	:	'!='
+	|	'^='
+	|	'<>'
+	;
+
+PIPE
+	:	'|'
+	;
+
+DOUBLE_PIPE
+	:	'||'
+	;
+
+PARAM	:	'?'
+	;
+
+GREATER
+	:	'>'
+	;
+
+GREATER_EQUAL
+	:	'>='
+	;
+
+LESS
+	:	'<'
+	;
+
+LESS_EQUAL
+	:	'<='
+	;
+
+ARROW
+	:	'->'
+	;
+
+IDENTIFIER
+	:	('a'..'z'|'A'..'Z'|'_'|'$'|'\u0080'..'\ufffe')('a'..'z'|'A'..'Z'|'_'|'$'|'0'..'9'|'\u0080'..'\ufffe')*
+	;
+
+QUOTED_IDENTIFIER
+    : '`' ( ESCAPE_SEQUENCE | ~('\\'|'`') )* '`'
+    ;
+
+LEFT_PAREN
+        :	'('
+        ;
+
+RIGHT_PAREN
+        :	')'
+        ;
+
+LEFT_SQUARE
+        :	'['
+        ;
+
+RIGHT_SQUARE
+        :	']'
+        ;        
+
+COMMA	:	','
+	;
+	
+DOT	:	'.'
+	;
+
+PLUS	:	'+'
+	;
+
+MINUS	:	'-'
+	;
+
+ASTERISK
+	:	'*'	
+	;
+
+SOLIDUS	:	'/'	
+	;
+
+PERCENT	:	'%'	
+	;
+
+AMPERSAND
+	:	'&'	
+	;
\ No newline at end of file


Property changes on: core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/hql/parse/HQLLexer.g
___________________________________________________________________
Name: svn:eol-style
   + native

Copied: core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/hql/parse/HQLParser.g (from rev 16466, core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLParser.g)
===================================================================
--- core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/hql/parse/HQLParser.g	                        (rev 0)
+++ core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/hql/parse/HQLParser.g	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,1479 @@
+parser grammar HQLParser;
+
+options {
+	tokenVocab=HQLLexer;
+	output=AST;
+}
+
+ at parser::header {
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ *
+ * Portions of SQL grammar parsing copyright (C) 2003 by Lubos Vnuk.  All rights
+ * reserved.  These portions are distributed under license by Red Hat Middleware
+ * LLC and are covered by the above LGPL notice.  If you redistribute this material,
+ * with or without modification, you must preserve this copyright notice in its
+ * entirety.
+ */
+package org.hibernate.sql.ast.origin.hql.parse;
+
+import java.util.LinkedList;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Iterator;
+import org.hibernate.sql.ast.tree.EntityNameTree;
+}
+
+ at parser::members {
+	private Stack enableParameterUsage = new Stack();
+	private ParserContext context = new ParserContextDefaultImpl();
+    private List errorMessages = new LinkedList();
+
+	public void setParserContext(ParserContext context){
+		this.context = context;
+	}
+
+	private boolean validateSoftKeyword(String text) {
+		return validateLT(1, text);
+	}
+
+	private boolean validateLT(int offset, String text) {
+		String text2Validate = retrieveLT( offset );
+		return text2Validate == null ? false : text2Validate.equalsIgnoreCase( text );
+	}
+
+	private String retrieveLT(int offset) {
+      	if (null == input) {
+      		return null;
+      	}
+		Token token = input.LT(offset);
+		return token == null ? null : token.getText();
+	}
+
+	public boolean hasErrors() {
+	    return errorMessages.size() > 0;
+	}
+	
+	public List getErrorMessages() {
+	   return errorMessages;
+	}
+
+    public void reportError(RecognitionException e) {
+        errorMessages.add(
+                generateError(
+                    getRuleInvocationStack( e, this.getClass().getName() ),
+                    this.getTokenNames(),
+                    e
+                )
+        );
+        super.reportError( e );
+    }
+
+    private String generateError(
+            List invocationStack,
+            String[] tokenNames,
+            RecognitionException e) {
+        String localization = invocationStack + ": line " + e.line + ":" + e.charPositionInLine + " ";
+        return generateError(localization, tokenNames, e);
+    }
+
+    private String generateError(
+            String localization,
+            String[] tokenNames,
+            RecognitionException e) {
+        String message = "";
+        if ( e instanceof MismatchedTokenException ) {
+            MismatchedTokenException mte = (MismatchedTokenException)e;
+            String tokenName = "<unknown>";
+            if (mte.expecting == Token.EOF) {
+                tokenName = "EOF";
+            }
+            else {
+                if (tokenNames != null) {
+                    tokenName = tokenNames[mte.expecting];
+                }
+            }
+            message = localization + "mismatched token: " + e.token + "; expecting type " + tokenName;
+        }
+        else if (e instanceof MismatchedTreeNodeException) {
+            MismatchedTreeNodeException mtne = (MismatchedTreeNodeException)e;
+            String tokenName = "<unknown>";
+            if (mtne.expecting == Token.EOF) {
+                tokenName = "EOF";
+            }
+            else {
+                tokenName = tokenNames[mtne.expecting];
+            }
+            message = localization + "mismatched tree node: " + mtne.node + "; expecting type " + tokenName;
+        }
+        else if (e instanceof NoViableAltException) {
+            NoViableAltException nvae = (NoViableAltException)e;
+            message = localization + "state " + nvae.stateNumber + " (decision=" + nvae.decisionNumber
+                      + ") no viable alt; token=" + e.token;
+        }
+        else if (e instanceof EarlyExitException) {
+            EarlyExitException eee = (EarlyExitException)e;
+            message = localization + "required (...)+ loop (decision=" + eee.decisionNumber + ") did not match anything; token="
+                      + e.token;
+        }
+        else if (e instanceof MismatchedSetException) {
+            MismatchedSetException mse = (MismatchedSetException)e;
+            message = localization + "mismatched token: " + e.token + "; expecting set " + mse.expecting;
+        }
+        else if (e instanceof MismatchedNotSetException) {
+            MismatchedNotSetException mse = (MismatchedNotSetException)e;
+            message = localization + "mismatched token: " + e.token + "; expecting set " + mse.expecting;
+        }
+        else if (e instanceof FailedPredicateException) {
+            FailedPredicateException fpe = (FailedPredicateException)e;
+            message = localization + "rule " + fpe.ruleName + " failed predicate: {" + fpe.predicateText + "}?";
+        }
+        return message;
+    }
+    
+    private List extractEntityNames(String entityName) throws RecognitionException {
+    	List implementors = context.getEntityImplementors(entityName);
+    	if (implementors == null){
+    		throw new RecognitionException( );
+    	}
+    	return implementors;
+    }
+    
+	private Tree generatePersisterSpacesTree(List persistenceSpaces) {
+	    List persisterSpaceList = new ArrayList();
+	    for ( Iterator iterator = persistenceSpaces.iterator(); iterator.hasNext(); ) {
+			Tree persistenceSpaceData = (Tree) iterator.next();
+			if ( persistenceSpaceData.getType() == PERSISTER_JOIN
+			        || persistenceSpaceData.getType() == PROPERTY_JOIN ) {
+				adaptor.addChild(persisterSpaceList.get(persisterSpaceList.size() - 1), persistenceSpaceData);
+			}
+			else {
+			    Object persistenceSpaceTree = (Object)adaptor.nil();
+			    persistenceSpaceTree = adaptor.becomeRoot((Object)adaptor.create(PERSISTER_SPACE, "PERSISTER_SPACE"), persistenceSpaceTree);
+			    adaptor.addChild(persistenceSpaceTree, persistenceSpaceData);
+			    persisterSpaceList.add(persistenceSpaceTree);
+			}
+		}
+	    Tree resultTree = (Tree) adaptor.nil();
+	    for ( Iterator iterator = persisterSpaceList.iterator(); iterator.hasNext(); ) {
+			Object persistenceElement = (Object) iterator.next();
+			adaptor.addChild(resultTree, persistenceElement);
+		}
+
+		return resultTree;
+	}
+
+	private Tree generateUpdateStatementTree(
+	        Object updateKey,
+			Object entityName,
+			Object aliasClause,
+			Object setClause,
+			Object whereClause) {
+		Tree result = new CommonTree();
+		EntityNameTree entityNameTree = (EntityNameTree) entityName;
+		for (int i = 0; i < entityNameTree.getEntityCount(); i++) {
+			Tree updateRoot = new CommonTree( (CommonTree) updateKey );
+			updateRoot.addChild( new EntityNameTree( entityNameTree, entityNameTree.getEntityName(i) ) );
+			if ( aliasClause != null ) {
+				updateRoot.addChild( (Tree) aliasClause );
+			}
+			updateRoot.addChild( (Tree) setClause );
+
+			if (whereClause != null) {
+				updateRoot.addChild( (Tree) whereClause );
+			}
+			result.addChild(updateRoot);
+		}
+		return result;
+	}
+
+	private Tree generateDeleteStatementTree(
+	        Object deleteKey,
+			Object entityName,
+			Object aliasClause,
+			Object whereClause) {
+		Tree result = new CommonTree();
+		EntityNameTree entityNameTree = (EntityNameTree) entityName;
+		for ( int i = 0; i < entityNameTree.getEntityCount(); i++ ) {
+			Tree deleteRoot = new CommonTree( (CommonTree) deleteKey );
+			deleteRoot.addChild( new EntityNameTree( entityNameTree, entityNameTree.getEntityName(i) ) );
+
+			if (aliasClause != null) {
+				deleteRoot.addChild((Tree) aliasClause);
+			}
+
+			if (whereClause != null) {
+				deleteRoot.addChild((Tree) whereClause);
+			}
+
+			result.addChild(deleteRoot);
+		}
+		return result;
+	}
+	
+	private Tree generateSelecFromTree(Object selectClause, Object fromClause, List aliasList){
+		Tree result = new CommonTree(new CommonToken(SELECT_FROM, "SELECT_FROM"));
+		Tree selectTree = null;
+		result.addChild((Tree) fromClause);
+		if (selectClause == null && aliasList != null && aliasList.size() > 0) {
+			selectTree = new CommonTree(new CommonToken(SELECT, "SELECT"));
+			Tree selectList = new CommonTree(new CommonToken(SELECT_LIST, "SELECT_LIST"));
+			for (Iterator iterator = aliasList.iterator(); iterator
+					.hasNext();) {
+				String aliasName = (String) iterator.next();
+				Tree selectElement = new CommonTree(new CommonToken(SELECT_ITEM, "SELECT_ITEM"));
+				Tree aliasElement = new CommonTree(new CommonToken(ALIAS_REF, aliasName));
+				selectElement.addChild(aliasElement);
+				selectList.addChild(selectElement);
+			}
+			selectTree.addChild(selectList);
+		}
+		else {
+			selectTree = (Tree) selectClause;
+		}
+		result.addChild(selectTree);
+		return result;
+	}
+}
+
+filterStatement[String collectionRole]
+ at init	{ if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
+ at after	{ enableParameterUsage.pop(); }
+	:	selectClause? from_key? whereClause? ( groupByClause havingClause?)? orderByClause?
+		-> ^(QUERY ^(QUERY_SPEC["filter-query-spec"] FILTER[$collectionRole] 
+				selectClause? from_key? whereClause? ( groupByClause havingClause?)? orderByClause?))
+	//TODO throw an exception here when using from
+	;
+
+statement
+ at init	{ if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
+ at after	{ enableParameterUsage.pop(); }
+	:	updateStatement
+	|	deleteStatement
+	|	insertStatement
+	|	selectStatement
+	;
+
+updateStatement
+scope{
+	boolean generateVersionedField;
+}	:	udpate_key
+		(versioned_key {$updateStatement::generateVersionedField = true;})? 
+			from_key? entityName aliasClause[true] setClause whereClause?
+		-> {	generateUpdateStatementTree($udpate_key.tree, $entityName.tree, $aliasClause.tree, $setClause.tree, $whereClause.tree )	}
+	;
+
+//TODO: check what is necessary to generate at versioned field
+setClause
+	:	set_key assignment (COMMA assignment)*
+		-> {$updateStatement::generateVersionedField}? ^(set_key assignment+ ^(EQUALS VERSIONED_VALUE STRING_LITERAL))
+		-> ^(set_key assignment+)
+	;
+
+assignment
+	:	assignmentField EQUALS^ concatenation
+	;
+
+assignmentField
+	:	dotIdentifierPath -> ^(PROPERTY_REFERENCE dotIdentifierPath)
+	;
+
+deleteStatement
+	:	delete_key from_key? entityName aliasClause[true] whereClause?
+		-> {	generateDeleteStatementTree($delete_key.tree, $entityName.tree, $aliasClause.tree, $whereClause.tree )	}
+	;
+
+insertStatement
+	:	insert_key^ 
+		intoClause selectStatement
+	;
+
+//TODO: Generate an exception when try to use a polimorfic entity at INTO clause
+intoClause
+	:	into_key entityName insertabilitySpecification
+		-> ^(into_key entityName ALIAS_NAME[context.buildUniqueImplicitAlias()] insertabilitySpecification)
+	;
+
+insertabilitySpecification
+	:	LEFT_PAREN insertablePropertySpecification ( COMMA insertablePropertySpecification )* RIGHT_PAREN
+		-> ^(INSERTABILITY_SPEC insertablePropertySpecification+ )
+	;
+
+insertablePropertySpecification
+	:	dotIdentifierPath -> ^(PROPERTY_REFERENCE dotIdentifierPath)
+	;
+
+selectStatement
+	:	queryExpression orderByClause?
+		-> ^(QUERY queryExpression orderByClause?)
+	;
+
+//Think about the exception generation where Polimorfic queris are used inside a Mix of results (union, intersect and except) 
+queryExpression
+	:	querySpec ( ( union_key^ | intersect_key^ | except_key^ ) all_key? querySpec )*
+	;
+
+querySpec
+	:	selectFrom whereClause? ( groupByClause havingClause? )?
+		-> ^(QUERY_SPEC selectFrom whereClause? groupByClause? havingClause?)
+	;
+
+groupByClause
+	:	group_by_key^ groupingSpecification
+	;
+
+havingClause
+	:	having_key^ logicalExpression
+	;
+
+groupingSpecification
+	:	groupingValue ( COMMA! groupingValue )*
+	;
+
+groupingValue
+	:	concatenation collationSpecification?
+		-> ^(GROUPING_VALUE concatenation collationSpecification?)
+	;
+
+whereClause
+	:	where_key^ logicalExpression
+	;
+
+selectFrom
+	:	sc=selectClause? fc=fromClause
+		-> { generateSelecFromTree($sc.tree, $fc.tree, $fc.aliasList)}
+	;
+
+subQuery
+ at init	{ if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
+ at after	{ enableParameterUsage.pop(); }
+	:	queryExpression
+		-> ^(SUB_QUERY ^(QUERY queryExpression))
+	;
+
+fromClause returns [List aliasList]
+scope{
+	List aliases;
+}
+ at init	{	$fromClause::aliases = new ArrayList();	}
+ at after	{	$aliasList = $fromClause::aliases;	}
+	:	from_key^ 
+			persisterSpaces
+	;
+
+persisterSpaces
+	:	ps+=persisterSpace ( COMMA ps+=persisterSpace )*
+		-> {generatePersisterSpacesTree($ps)}
+	;
+
+persisterSpace
+	:	persisterSpaceRoot ( qualifiedJoin | crossJoin )*
+	;
+
+crossJoin
+	:	cross_key join_key mainEntityPersisterReference
+		-> ^(PERSISTER_JOIN[$join_key.start,"persister-join"] cross_key mainEntityPersisterReference) 
+	;
+
+qualifiedJoin
+ at init	{ boolean isEntityReference = false; boolean hasFetch = false; List entityNames = null; }
+ at after	{ if (!hasFetch) $fromClause::aliases.add(((Tree)$ac.tree).getText()); }
+	:	nonCrossJoinType join_key (fetch_key {hasFetch = true;})? path ac=aliasClause[true]
+	(	on_key 
+	{	isEntityReference = true;
+		entityNames = extractEntityNames($path.text);	} 
+		logicalExpression 
+	|	propertyFetch? withClause?
+	)
+	-> {isEntityReference}? ^(PERSISTER_JOIN[$join_key.start,"persister-join"] nonCrossJoinType ^(ENTITY_PERSISTER_REF ENTITY_NAME<EntityNameTree>[$path.start, $path.text, entityNames] aliasClause?) ^(on_key logicalExpression))
+	-> ^(PROPERTY_JOIN[$join_key.start, "property-join"] nonCrossJoinType fetch_key? aliasClause? propertyFetch? ^(PROPERTY_REFERENCE path) withClause?)
+	;
+
+withClause
+	:	with_key^ logicalExpression
+	;
+
+nonCrossJoinType
+	:	inner_key
+	|	outerJoinType outer_key?
+	|	-> INNER
+	;
+
+outerJoinType
+	:	left_key
+	|	right_key
+	|	full_key
+	;
+
+persisterSpaceRoot
+options{
+backtrack=true;
+}	:	mainEntityPersisterReference
+	|	jpaCollectionReference
+	|	hibernateLegacySyntax
+	;
+
+mainEntityPersisterReference
+ at after	{ $fromClause::aliases.add(((Tree)$ac.tree).getText()); }
+	:	entityName ac=aliasClause[true] propertyFetch?
+		-> ^(ENTITY_PERSISTER_REF entityName aliasClause? propertyFetch?)
+	;
+
+propertyFetch
+	:	fetch_key all_key properties_key
+		-> PROP_FETCH[$fetch_key.start, "property-fetch"]
+	;
+
+hibernateLegacySyntax returns [boolean isPropertyJoin]
+ at init {$isPropertyJoin = false;}
+ at after	{ $fromClause::aliases.add(((Tree)$ad.tree).getText()); }
+	:	ad=aliasDeclaration in_key
+	(	class_key entityName -> ^(ENTITY_PERSISTER_REF entityName aliasDeclaration) 
+	|	collectionExpression {$isPropertyJoin = true;} -> ^(PROPERTY_JOIN INNER[$in_key.start, "inner legacy"] aliasDeclaration collectionExpression)
+	)
+	;
+
+jpaCollectionReference
+ at after	{ $fromClause::aliases.add(((Tree)$ac.tree).getText()); }
+	:	in_key LEFT_PAREN propertyReference RIGHT_PAREN ac=aliasClause[true]
+		-> ^(PROPERTY_JOIN INNER[$in_key.start, "inner"] aliasClause? propertyReference) 
+	;
+
+selectClause
+	:	select_key^ distinct_key? rootSelectExpression 
+	;
+
+rootSelectExpression
+	:	rootDynamicInstantiation
+	|	jpaSelectObjectSyntax
+	|	explicitSelectList
+	;
+
+explicitSelectList
+	:	explicitSelectItem ( COMMA explicitSelectItem )*
+		-> ^(SELECT_LIST explicitSelectItem+)
+	;
+
+explicitSelectItem
+	:	selectExpression
+	;
+
+selectExpression
+ at init	{ if (state.backtracking == 0) enableParameterUsage.push(Boolean.FALSE); }
+ at after	{ enableParameterUsage.pop(); }
+//PARAMETERS CAN'T BE USED -> This verification should be scoped
+	:	expression aliasClause[false]
+		-> ^(SELECT_ITEM expression aliasClause?)
+	;
+
+aliasClause[boolean generateAlias]
+options{
+    k=2;
+}	:	-> {$generateAlias}? ALIAS_NAME[context.buildUniqueImplicitAlias()]
+		->
+	|	aliasDeclaration
+	|	as_key! aliasDeclaration
+	;
+
+aliasDeclaration
+	:	IDENTIFIER -> ALIAS_NAME[$IDENTIFIER]
+	;
+
+aliasReference
+	:	IDENTIFIER -> ALIAS_REF[$IDENTIFIER] 
+	;
+
+rootDynamicInstantiation
+	:	new_key dynamicInstantiationTarget LEFT_PAREN dynamicInstantiationArgs RIGHT_PAREN
+		-> ^(SELECT_ITEM ^(DYNAMIC_INSTANTIATION[$dynamicInstantiationTarget.start, $dynamicInstantiationTarget.text] dynamicInstantiationArgs))
+	;
+
+dynamicInstantiationTarget
+	:	dotIdentifierPath
+	;
+
+dynamicInstantiationArgs
+	:	dynamicInstantiationArg ( COMMA! dynamicInstantiationArg )*
+	;
+
+dynamicInstantiationArg
+	:	selectExpression -> ^(DYNAMIC_INSTANTIATION_ARG selectExpression)
+	|	rootDynamicInstantiation -> ^(DYNAMIC_INSTANTIATION_ARG rootDynamicInstantiation)
+	;
+
+jpaSelectObjectSyntax
+	:	object_key LEFT_PAREN aliasReference RIGHT_PAREN
+		-> ^(SELECT_ITEM aliasReference) 
+	;
+
+orderByClause
+	:	order_by_key^ sortSpecification ( COMMA! sortSpecification )*
+	;
+
+sortSpecification
+ at init{boolean generateOmmitedElement = true;}
+	:	sortKey collationSpecification? (orderingSpecification {generateOmmitedElement = false;})?
+		-> {generateOmmitedElement}? ^(SORT_SPEC sortKey collationSpecification? ORDER_SPEC["asc"])
+		-> ^(SORT_SPEC sortKey collationSpecification? orderingSpecification?)
+	;
+
+sortKey
+ at init	{ if (state.backtracking == 0) enableParameterUsage.push(Boolean.FALSE); }
+ at after	{ enableParameterUsage.pop(); }
+//PARAMETERS CAN'T BE USED -> This verification should be scoped
+	:	concatenation
+	;
+
+collationSpecification
+	:	collate_key collateName
+	->	COLLATE[$collateName.start, $collateName.text]
+	;
+
+collateName
+	:	dotIdentifierPath
+	;
+
+orderingSpecification
+	:	ascending_key -> ORDER_SPEC[$ascending_key.start, "asc"]
+	|	descending_key -> ORDER_SPEC[$descending_key.start, "desc"]
+	;
+
+logicalExpression
+	:	expression
+	;
+
+expression
+	:	logicalOrExpression
+	;
+
+logicalOrExpression
+	:	logicalAndExpression ( or_key^ logicalAndExpression )*
+	;
+
+logicalAndExpression
+	:	negatedExpression ( and_key^ negatedExpression )*
+	;
+
+negatedExpression
+	:	not_key^ negatedExpression
+	|	equalityExpression
+	;
+
+equalityExpression
+ at init{ boolean isNull = false; boolean isNegated = false;}
+	:	(relationalExpression -> relationalExpression) 
+	(	is_key (not_key {isNegated = true;})? (NULL {isNull = true;}|empty_key)
+		-> {isNull && isNegated}? ^(IS_NOT_NULL[$not_key.start, "is not null"] $equalityExpression)
+		-> {isNull && !isNegated}? ^(IS_NULL[$NULL, "is null"] $equalityExpression)
+		-> {!isNull && isNegated}? ^(IS_NOT_EMPTY $equalityExpression)
+		-> ^(IS_EMPTY $equalityExpression)
+	|	( op=EQUALS | op=NOT_EQUAL ) relationalExpression
+		-> ^($op $equalityExpression relationalExpression)
+	)*
+	;
+
+relationalExpression
+ at init {boolean isNegated = false;} 
+	:	(concatenation -> concatenation)
+	( 
+	(	( op=LESS | op=GREATER | op=LESS_EQUAL | op=GREATER_EQUAL ) additiveExpression
+			-> ^($op $relationalExpression additiveExpression) 
+		)+
+	|  (not_key {isNegated = true;} )?
+		(	in_key inList
+			-> {isNegated}? ^(NOT_IN[$not_key.start, "not in"] $relationalExpression inList)
+			-> ^(in_key $relationalExpression inList) 
+		|	between_key betweenList
+			-> {isNegated}? ^(NOT_BETWEEN[$not_key.start, "not between"] $relationalExpression betweenList)
+			-> ^(between_key $relationalExpression betweenList)
+		|	like_key concatenation likeEscape?
+			-> {isNegated}? ^(NOT_LIKE[$not_key.start, "not like"] $relationalExpression concatenation likeEscape?) 
+			-> ^(like_key $relationalExpression concatenation likeEscape?)
+		|	member_of_key path
+			-> {isNegated}? ^(NOT_MEMBER_OF[$not_key.start, "not member of"] $relationalExpression ^(PATH path))
+			-> ^(member_of_key $relationalExpression ^(PATH path))
+		)
+	)?
+	;
+
+likeEscape
+	:	escape_key^ concatenation
+	;
+
+inList
+	:	collectionExpression
+		-> ^(IN_LIST collectionExpression)
+	|	LEFT_PAREN ( {((validateSoftKeyword("select")|validateSoftKeyword("from")))}?=> subQuery | concatenation (COMMA concatenation)* ) RIGHT_PAREN
+		-> ^(IN_LIST concatenation* subQuery?)
+	;
+
+betweenList
+	:	concatenation and_key concatenation
+		-> ^(BETWEEN_LIST concatenation+)
+	;
+
+concatenation
+	:	additiveExpression (DOUBLE_PIPE^ {enableParameterUsage.push(Boolean.TRUE);} additiveExpression { enableParameterUsage.pop(); })*
+	;
+
+additiveExpression
+	:	multiplyExpression ( ( PLUS^ | MINUS^ ) {enableParameterUsage.push(Boolean.TRUE);} multiplyExpression { enableParameterUsage.pop(); })*
+	;
+
+multiplyExpression
+	:	unaryExpression ( ( ASTERISK^ | SOLIDUS^ ) {enableParameterUsage.push(Boolean.TRUE);} unaryExpression { enableParameterUsage.pop(); })*
+	;
+
+unaryExpression
+	:	MINUS unaryExpression -> ^(UNARY_MINUS[$MINUS] unaryExpression)
+	|	PLUS unaryExpression -> ^(UNARY_PLUS[$PLUS] unaryExpression)
+	|	caseExpression
+	|	quantifiedExpression
+	|	standardFunction
+	|	setFunction
+	|	collectionFunction
+	|	collectionExpression
+	|	atom
+	;
+
+caseExpression
+ at init	{ if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
+ at after	{ enableParameterUsage.pop(); }
+	:	caseAbbreviation
+	|	caseSpecification
+	;
+
+caseAbbreviation
+	:	nullif_key^ LEFT_PAREN! concatenation COMMA! concatenation RIGHT_PAREN!
+	|	coalesce_key^ LEFT_PAREN! concatenation (COMMA! concatenation)* RIGHT_PAREN!
+	;
+
+caseSpecification
+options{
+backtrack=true;
+}	:	simpleCase
+	|	searchedCase
+	;
+
+simpleCase
+	:	case_key concatenation simpleCaseWhenClause+ elseClause? end_key
+	->	^(SIMPLE_CASE[$case_key.start, $case_key.text] concatenation simpleCaseWhenClause+ elseClause?)
+	;
+
+simpleCaseWhenClause
+	:	when_key^ concatenation then_key! concatenation
+	;
+
+elseClause
+	:	else_key^ concatenation
+	;
+
+searchedCase
+	:	case_key searchedWhenClause+ elseClause? end_key
+	->	^(SEARCHED_CASE[$case_key.start, $case_key.text] searchedWhenClause+ elseClause?)
+	;
+
+searchedWhenClause
+	:	when_key^ logicalExpression then_key! concatenation
+	;
+
+quantifiedExpression
+	:	( some_key^ | exists_key^ | all_key^ | any_key^ ) 
+	(	collectionExpression
+	|	aliasReference
+	|	LEFT_PAREN! subQuery RIGHT_PAREN!
+	)
+	;
+
+standardFunction
+ at init	{ if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
+ at after	{ enableParameterUsage.pop(); }
+	:	castFunction
+	|	concatFunction
+	|	substringFunction
+	|	trimFunction
+	|	upperFunction
+	|	lowerFunction
+	|	lengthFunction
+	|	locateFunction
+	|	absFunction
+	|	sqrtFunction
+	|	modFunction
+	|	sizeFunction
+	|	indexFunction
+	|	currentDateFunction
+	|	currentTimeFunction
+	|	currentTimestampFunction
+	|	extractFunction
+	|	positionFunction
+	|	charLengthFunction
+	|	octetLengthFunction
+	|	bitLengthFunction
+	;
+
+castFunction
+	:	cast_key^ LEFT_PAREN! concatenation as_key! dataType RIGHT_PAREN!
+	;
+
+concatFunction
+	:	concat_key^ LEFT_PAREN! concatenation ( COMMA! concatenation )+ RIGHT_PAREN!
+	;
+
+substringFunction
+	:	substring_key^ LEFT_PAREN! concatenation COMMA! concatenation ( COMMA! concatenation)? RIGHT_PAREN!
+	;
+
+trimFunction
+	:	trim_key LEFT_PAREN trimOperands RIGHT_PAREN
+		-> ^(trim_key trimOperands)
+	;
+
+trimOperands
+options{
+k=2;
+}
+ at init {boolean hasSecondExpression = false;}
+	:	trimSpecification from_key concatenation -> ^(trimSpecification STRING_LITERAL[" "] concatenation)
+	|	trimSpecification concatenation from_key concatenation -> ^(trimSpecification concatenation+)
+	|	from_key concatenation -> ^(BOTH STRING_LITERAL[" "] concatenation)
+	|	cn=concatenation ( from_key concatenation {hasSecondExpression = true;} )?
+		-> {hasSecondExpression}? ^(BOTH concatenation+)
+		-> ^(BOTH STRING_LITERAL[" "] $cn)
+	;
+
+trimSpecification
+	:	leading_key
+	|	trailing_key
+	|	both_key
+	;
+
+upperFunction
+	:	upper_key^ LEFT_PAREN! concatenation RIGHT_PAREN!
+	;
+
+lowerFunction
+	:	lower_key^ LEFT_PAREN! concatenation RIGHT_PAREN!
+	;
+
+lengthFunction
+	:	length_key^ LEFT_PAREN! concatenation RIGHT_PAREN!
+	;
+
+locateFunction
+	:	locate_key^ LEFT_PAREN! concatenation COMMA! concatenation ( COMMA! concatenation )? RIGHT_PAREN!
+	;
+
+absFunction
+	:	abs_key^ LEFT_PAREN! concatenation RIGHT_PAREN!
+	;
+
+sqrtFunction
+	:	sqrt_key^ LEFT_PAREN! concatenation RIGHT_PAREN!
+	;
+
+modFunction
+	:	mod_key^ LEFT_PAREN! concatenation COMMA! concatenation RIGHT_PAREN!
+	;
+
+sizeFunction
+	:	size_key^ LEFT_PAREN! propertyReference RIGHT_PAREN!
+	;
+
+indexFunction
+	:	index_key^ LEFT_PAREN! aliasReference RIGHT_PAREN!
+	;
+
+currentDateFunction
+	:	current_date_key ( LEFT_PAREN! RIGHT_PAREN! )?
+	;
+
+currentTimeFunction
+	:	current_time_key ( LEFT_PAREN! RIGHT_PAREN! )?
+	;
+
+currentTimestampFunction
+	:	current_timestamp_key ( LEFT_PAREN! RIGHT_PAREN! )?
+	;
+
+extractFunction
+	:	extract_key^ LEFT_PAREN! extractField from_key! concatenation RIGHT_PAREN!
+	;
+
+extractField
+	:	datetimeField
+	|	timeZoneField
+	;
+
+datetimeField
+	:	nonSecondDatetimeField
+	|	second_key
+	;
+
+nonSecondDatetimeField
+	:	year_key
+	|	month_key
+	|	day_key
+	|	hour_key
+	|	minute_key
+	;
+
+timeZoneField
+	:	timezone_hour_key
+	|	timezone_minute_key
+	;
+
+positionFunction
+	:	position_key^ LEFT_PAREN! concatenation in_key! concatenation RIGHT_PAREN!
+	;
+
+charLengthFunction
+	:	character_length_key^ LEFT_PAREN! concatenation RIGHT_PAREN!
+	;
+
+octetLengthFunction
+	:	octet_length_key^ LEFT_PAREN! concatenation RIGHT_PAREN!
+	;
+
+bitLengthFunction
+	:	bit_length_key^ LEFT_PAREN! concatenation RIGHT_PAREN!
+	;
+
+setFunction
+ at init	{ boolean generateOmmitedElement = true; if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
+ at after	{ enableParameterUsage.pop(); }
+	:	( sum_key^ | avg_key^ | max_key^ | min_key^ ) LEFT_PAREN! additiveExpression RIGHT_PAREN!
+	|	count_key LEFT_PAREN ( ASTERISK {generateOmmitedElement = false;} | ( ( (distinct_key | all_key) {generateOmmitedElement = false;} )? countFunctionArguments ) ) RIGHT_PAREN
+		-> {generateOmmitedElement}? ^(count_key ASTERISK? ALL countFunctionArguments?)
+		-> ^(count_key ASTERISK? distinct_key? all_key? countFunctionArguments?)
+	;
+
+countFunctionArguments
+ at init { int type = -1;}
+	:	propertyReference
+	|	collectionExpression
+	|	numeric_literal
+	;
+
+collectionFunction
+ at init	{ if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
+ at after	{ enableParameterUsage.pop(); }
+	:	( maxelement_key^ | maxindex_key^ | minelement_key^ | minindex_key^ ) LEFT_PAREN! propertyReference RIGHT_PAREN!
+	;
+
+collectionExpression
+	:	(elements_key^|indices_key^) LEFT_PAREN! propertyReference RIGHT_PAREN!
+	;
+
+atom
+ at init { int type = -1;}
+	:	identPrimary
+	    //TODO  if ends with:
+	    //  .class -> class type
+	    //  if contains "()" it is a function call 
+	    //  if it is constantReference (using context)
+	    //  otherwise it will be a generic element to be resolved on the next phase (1st tree walker)
+	    -> {type == 0}? ^(DOT_CLASS identPrimary)
+	    -> {type == 3}? ^(FUNCTION[$identPrimary.start,$identPrimary.text])
+	    -> {type == 4}? ^(JAVA_CONSTANT identPrimary) //-> here will have 2 strutctures element and the constant
+	    -> ^(PATH identPrimary)
+	|	constant
+	|	parameterSpecification { if (enableParameterUsage.peek().equals(Boolean.FALSE)) throw new RecognitionException( ); }
+	//validate using Scopes if it is enabled or not to use parameterSpecification.. if not generate an exception 
+	|	LEFT_PAREN! ({((validateSoftKeyword("select")|validateSoftKeyword("from")))}?=> subQuery|expressionOrVector) RIGHT_PAREN!
+	;
+
+parameterSpecification
+ at init {boolean isJpaParam = false;}
+	:	COLON IDENTIFIER -> NAMED_PARAM[$IDENTIFIER]
+	|	PARAM (INTEGER_LITERAL {isJpaParam = true;})?
+		-> {isJpaParam}? JPA_PARAM[$INTEGER_LITERAL]
+		-> PARAM	
+	;
+
+expressionOrVector
+ at init {boolean isVectorExp = false;}
+	:	expression (vectorExpr {isVectorExp = true;})?
+		-> {isVectorExp}? ^(VECTOR_EXPR expression vectorExpr) 
+		-> expression
+	;
+
+vectorExpr
+ at init	{ if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
+ at after	{ enableParameterUsage.pop(); }
+	:	COMMA! expression (COMMA! expression)*
+	;
+
+identPrimary
+	: 	IDENTIFIER
+		(	DOT^ IDENTIFIER
+		|	LEFT_SQUARE^ expression RIGHT_SQUARE!
+		|	LEFT_SQUARE^ RIGHT_SQUARE!
+		|	LEFT_PAREN^ exprList RIGHT_PAREN!
+		)*
+	;
+
+exprList
+ at init	{ if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
+ at after	{ enableParameterUsage.pop(); }
+	:	expression? (COMMA! expression)*
+	;
+
+constant
+	:	literal
+	|	NULL
+	|	TRUE
+	|	FALSE
+	;
+
+literal
+	:	numeric_literal
+	|	HEX_LITERAL
+	|	OCTAL_LITERAL
+	|	CHARACTER_LITERAL
+	|	STRING_LITERAL
+	;
+
+numeric_literal
+	:	INTEGER_LITERAL
+	|	DECIMAL_LITERAL
+	|	FLOATING_POINT_LITERAL
+	;
+
+entityName
+ at init	{ List entityNames = null; }
+	:	dotIdentifierPath
+	{	entityNames = extractEntityNames($dotIdentifierPath.text);	}
+	//here the polimorfic entities should be resolved... to:
+	   // 1. to place inside the ENTITY_NAME Token all its possible values, otherwise it would be much difficult to return to the place that should explit the sentence 
+	   // 2. enable exception geration when not supported (union, insert)
+		-> ENTITY_NAME<EntityNameTree>[$dotIdentifierPath.start, $dotIdentifierPath.text, entityNames]
+	;
+
+propertyReference
+	:	path
+		-> ^(PROPERTY_REFERENCE path)
+	;
+
+dataType
+	:	IDENTIFIER
+	;
+
+dotIdentifierPath
+	:	IDENTIFIER 
+		(	DOT^ IDENTIFIER		)*
+	;
+
+path
+	:	IDENTIFIER 
+		(	DOT^ IDENTIFIER
+		|	LEFT_SQUARE^ expression RIGHT_SQUARE!
+		|	LEFT_SQUARE^ RIGHT_SQUARE!
+		)*
+	;
+
+class_key
+	:	{(validateSoftKeyword("class"))}?=>  id=IDENTIFIER
+		->	CLASS[$id]
+	;
+
+new_key
+	:	{(validateSoftKeyword("new"))}?=>  id=IDENTIFIER
+		->	NEW[$id]
+	;
+
+else_key
+	:	{(validateSoftKeyword("else"))}?=>  id=IDENTIFIER
+		->	ELSE[$id]
+	;
+
+object_key
+	:	{(validateSoftKeyword("object"))}?=>  id=IDENTIFIER
+	;
+
+case_key
+	:	{(validateSoftKeyword("case"))}?=>  IDENTIFIER
+	;
+
+current_date_key
+	:	{(validateSoftKeyword("current_date"))}?=>  id=IDENTIFIER
+		->	CURRENT_DATE[$id]
+	;
+
+current_time_key
+	:	{(validateSoftKeyword("current_time"))}?=>  id=IDENTIFIER
+		->	CURRENT_TIME[$id]
+	;
+
+current_timestamp_key
+	:	{(validateSoftKeyword("current_timestamp"))}?=>  id=IDENTIFIER
+		->	CURRENT_TIMESTAMP[$id]
+	;
+
+timezone_hour_key
+	:	{(validateSoftKeyword("timezone_hour"))}?=>  id=IDENTIFIER
+		->	TIMEZONE_HOUR[$id]
+	;
+
+timezone_minute_key
+	:	{(validateSoftKeyword("timezone_minute"))}?=>  id=IDENTIFIER
+		->	TIMEZONE_MINUTE[$id]
+	;
+
+character_length_key
+	:	{(validateSoftKeyword("character_length") || validateSoftKeyword("char_length"))}?=>  id=IDENTIFIER
+		->	CHARACTER_LENGTH[$id]
+	;
+
+octet_length_key
+	:	{(validateSoftKeyword("octet_length"))}?=>  id=IDENTIFIER
+		->	OCTET_LENGTH[$id]
+	;
+
+bit_length_key
+	:	{(validateSoftKeyword("bit_length"))}?=>  id=IDENTIFIER
+		->	BIT_LENGTH[$id]
+	;
+
+extract_key
+	:	{(validateSoftKeyword("extract"))}?=>  id=IDENTIFIER
+		->	EXTRACT[$id]
+	;
+
+second_key
+	:	{(validateSoftKeyword("second"))}?=>  id=IDENTIFIER
+		->	SECOND[$id]
+	;
+
+year_key
+	:	{(validateSoftKeyword("year"))}?=>  id=IDENTIFIER
+		->	YEAR[$id]
+	;
+
+month_key
+	:	{(validateSoftKeyword("month"))}?=>  id=IDENTIFIER
+		->	MONTH[$id]
+	;
+
+day_key
+	:	{(validateSoftKeyword("day"))}?=>  id=IDENTIFIER
+		->	DAY[$id]
+	;
+
+hour_key
+	:	{(validateSoftKeyword("hour"))}?=>  id=IDENTIFIER
+		->	HOUR[$id]
+	;
+
+minute_key
+	:	{(validateSoftKeyword("minute"))}?=>  id=IDENTIFIER
+		->	MINUTE[$id]
+	;
+
+position_key
+	:	{(validateSoftKeyword("position"))}?=>  id=IDENTIFIER
+		->	POSITION[$id]
+	;
+
+sum_key
+	:	{(validateSoftKeyword("sum"))}?=>  id=IDENTIFIER
+		->	SUM[$id]
+	;
+
+avg_key
+	:	{(validateSoftKeyword("avg"))}?=>  id=IDENTIFIER
+		->	AVG[$id]
+	;
+
+max_key
+	:	{(validateSoftKeyword("max"))}?=>  id=IDENTIFIER
+		->	MAX[$id]
+	;
+
+min_key
+	:	{(validateSoftKeyword("min"))}?=>  id=IDENTIFIER
+		->	MIN[$id]
+	;
+
+count_key
+	:	{(validateSoftKeyword("count"))}?=>  id=IDENTIFIER
+		->	COUNT[$id]
+	;
+
+maxelement_key
+	:	{(validateSoftKeyword("maxelement"))}?=>  id=IDENTIFIER
+		->	MAXELEMENT[$id]
+	;
+
+maxindex_key
+	:	{(validateSoftKeyword("maxindex"))}?=>  id=IDENTIFIER
+		->	MAXINDEX[$id]
+	;
+
+minelement_key
+	:	{(validateSoftKeyword("minelement"))}?=>  id=IDENTIFIER
+		->	MINELEMENT[$id]
+	;
+
+minindex_key
+	:	{(validateSoftKeyword("minindex"))}?=>  id=IDENTIFIER
+		->	MININDEX[$id]
+	;
+
+locate_key
+	:	{(validateSoftKeyword("locate"))}?=>  id=IDENTIFIER
+		->	LOCATE[$id]
+	;
+
+abs_key
+	:	{(validateSoftKeyword("abs"))}?=>  id=IDENTIFIER
+		->	ABS[$id]
+	;
+
+sqrt_key
+	:	{(validateSoftKeyword("sqrt"))}?=>  id=IDENTIFIER
+		->	SQRT[$id]
+	;
+
+mod_key
+	:	{(validateSoftKeyword("mod"))}?=>  id=IDENTIFIER
+		->	MOD[$id]
+	;
+
+size_key
+	:	{(validateSoftKeyword("size"))}?=>  id=IDENTIFIER
+		->	SIZE[$id]
+	;
+
+index_key
+	:	{(validateSoftKeyword("index"))}?=>  id=IDENTIFIER
+		->	INDEX[$id]
+	;
+
+leading_key
+	:	{(validateSoftKeyword("leading"))}?=>  id=IDENTIFIER
+		->	LEADING[$id]
+	;
+
+trailing_key
+	:	{(validateSoftKeyword("trailing"))}?=>  id=IDENTIFIER
+		->	TRAILING[$id]
+	;
+
+upper_key
+	:	{(validateSoftKeyword("upper"))}?=>  id=IDENTIFIER
+		->	UPPER[$id]
+	;
+
+lower_key
+	:	{(validateSoftKeyword("lower"))}?=>  id=IDENTIFIER
+		->	LOWER[$id]
+	;
+
+length_key
+	:	{(validateSoftKeyword("length"))}?=>  id=IDENTIFIER
+		->	LENGTH[$id]
+	;
+
+both_key
+	:	{(validateSoftKeyword("both"))}?=>  id=IDENTIFIER
+		->	BOTH[$id]
+	;
+
+trim_key
+	:	{(validateSoftKeyword("trim"))}?=>  id=IDENTIFIER
+		->	TRIM[$id]
+	;
+	
+substring_key
+	:	{(validateSoftKeyword("substring"))}?=>  id=IDENTIFIER
+		->	SUBSTRING[$id]
+	;
+
+concat_key
+	:	{(validateSoftKeyword("concat"))}?=>  id=IDENTIFIER
+		->	CONCAT[$id]
+	;
+
+cast_key
+	:	{(validateSoftKeyword("cast"))}?=>  id=IDENTIFIER
+		->	CAST[$id]
+	;
+
+any_key
+	:	{(validateSoftKeyword("any"))}?=>  id=IDENTIFIER
+		->	ANY[$id]
+	;
+
+exists_key
+	:	{(validateSoftKeyword("exists"))}?=>  id=IDENTIFIER
+		->	EXISTS[$id]
+	;
+
+some_key
+	:	{(validateSoftKeyword("some"))}?=>  id=IDENTIFIER
+		->	SOME[$id]
+	;
+
+then_key
+	:	{(validateSoftKeyword("then"))}?=>  id=IDENTIFIER
+		->	THEN[$id]
+	;
+
+end_key
+	:	{(validateSoftKeyword("end"))}?=>  id=IDENTIFIER
+		->	END[$id]
+	;
+
+
+when_key
+	:	{(validateSoftKeyword("when"))}?=>  id=IDENTIFIER
+		->	WHEN[$id]
+	;
+
+nullif_key
+	:	{(validateSoftKeyword("nullif"))}?=>  id=IDENTIFIER
+		->	NULLIF[$id]
+	;
+
+coalesce_key
+	:	{(validateSoftKeyword("coalesce"))}?=>  id=IDENTIFIER
+		->	COALESCE[$id]
+	;
+
+escape_key
+	:	{(validateSoftKeyword("escape"))}?=>  id=IDENTIFIER
+		->	ESCAPE[$id]
+	;
+
+like_key
+	:	{(validateSoftKeyword("like"))}?=>  id=IDENTIFIER
+		->	LIKE[$id]
+	;
+
+between_key
+	:	{(validateSoftKeyword("between"))}?=>  id=IDENTIFIER
+		->	BETWEEN[$id]
+	;
+
+member_of_key
+ at init{
+	String text = "";
+}	:	{(validateSoftKeyword("member") && validateLT(2, "of"))}?=>  id=IDENTIFIER IDENTIFIER {text = $text;}
+		->	MEMBER_OF[$id]
+	;
+
+empty_key
+	:	{(validateSoftKeyword("empty"))}?=>  id=IDENTIFIER
+	;
+
+is_key	:	{(validateSoftKeyword("is"))}?=>  id=IDENTIFIER
+		->	IS[$id]
+	;
+
+or_key	:	{(validateSoftKeyword("or"))}?=>  id=IDENTIFIER
+		->	OR[$id]
+	;
+
+and_key	:	{(validateSoftKeyword("and"))}?=>  id=IDENTIFIER
+		->	AND[$id]
+	;
+
+not_key	:	{(validateSoftKeyword("not"))}?=>  id=IDENTIFIER
+		->	NOT[$id]
+	;
+
+set_key
+	:	{(validateSoftKeyword("set"))}?=>  id=IDENTIFIER
+		->	SET[$id]
+	;
+
+versioned_key
+	:	{(validateSoftKeyword("versioned"))}?=>  id=IDENTIFIER
+		->	VERSIONED[$id]
+	;
+
+udpate_key
+	:	{(validateSoftKeyword("update"))}?=>  id=IDENTIFIER
+		->	UPDATE[$id]
+	;
+
+delete_key
+	:	{(validateSoftKeyword("delete"))}?=>  id=IDENTIFIER
+		->	DELETE[$id]
+	;
+
+insert_key
+	:	{(validateSoftKeyword("insert"))}?=>  id=IDENTIFIER
+		->	INSERT[$id]
+	;
+
+into_key
+	:	{(validateSoftKeyword("into"))}?=>  id=IDENTIFIER
+		->	INTO[$id]
+	;
+
+having_key
+	:	{(validateSoftKeyword("having"))}?=>  id=IDENTIFIER
+		->	HAVING[$id]
+	;
+
+with_key
+	:	{(validateSoftKeyword("with"))}?=>  id=IDENTIFIER
+		->	WITH[$id]
+	;
+
+on_key
+	:	{(validateSoftKeyword("on"))}?=>  id=IDENTIFIER
+		->	ON[$id]
+	;
+
+indices_key
+	:	{(validateSoftKeyword("indices"))}?=>  id=IDENTIFIER
+		->	INDICES[$id]
+	;
+
+cross_key
+	:	{(validateSoftKeyword("cross"))}?=>  id=IDENTIFIER
+		->	CROSS[$id]
+	;
+
+join_key
+	:	{(validateSoftKeyword("join"))}?=>  id=IDENTIFIER
+		->	JOIN[$id]
+	;
+
+inner_key
+	:	{(validateSoftKeyword("inner"))}?=>  id=IDENTIFIER
+		->	INNER[$id]
+	;
+
+outer_key
+	:	{(validateSoftKeyword("outer"))}?=>  id=IDENTIFIER
+		->	OUTER[$id]
+	;
+
+left_key
+	:	{(validateSoftKeyword("left"))}?=>  id=IDENTIFIER
+		->	LEFT[$id]
+	;
+
+right_key
+	:	{(validateSoftKeyword("right"))}?=>  id=IDENTIFIER
+		->	RIGHT[$id]
+	;
+
+full_key
+	:	{(validateSoftKeyword("full"))}?=>  id=IDENTIFIER
+		->	FULL[$id]
+	;
+
+elements_key
+	:	{(validateSoftKeyword("elements"))}?=>  id=IDENTIFIER
+		->	ELEMENTS[$id]
+	;
+
+properties_key
+	:	{(validateSoftKeyword("properties"))}?=>  id=IDENTIFIER
+		->	PROPERTIES[$id]
+	;
+
+fetch_key
+	:	{(validateSoftKeyword("fetch"))}?=>  id=IDENTIFIER
+		->	FETCH[$id]
+	;
+
+in_key
+	:	{(validateSoftKeyword("in"))}?=>  id=IDENTIFIER
+		->	IN[$id]
+	;
+
+as_key
+	:	{(validateSoftKeyword("as"))}?=>  id=IDENTIFIER
+		->	AS[$id]
+	;
+
+where_key
+	:	{(validateSoftKeyword("where"))}?=>  id=IDENTIFIER
+		->	WHERE[$id]
+	;
+
+select_key
+	:	{(validateSoftKeyword("select"))}?=>  id=IDENTIFIER
+		->	SELECT[$id]
+	;
+
+distinct_key
+	:	{(validateSoftKeyword("distinct"))}?=>  id=IDENTIFIER
+		->	DISTINCT[$id]
+	;
+
+union_key
+	:	{(validateSoftKeyword("union"))}?=>  id=IDENTIFIER
+		->	UNION[$id]
+	;
+
+intersect_key
+	:	{(validateSoftKeyword("intersect"))}?=>  id=IDENTIFIER
+		->	INTERSECT[$id]
+	;
+
+except_key
+	:	{(validateSoftKeyword("except"))}?=>  id=IDENTIFIER
+		->	EXCEPT[$id]
+	;
+
+all_key
+	:	{(validateSoftKeyword("all"))}?=>  id=IDENTIFIER
+		->	ALL[$id]
+	;
+
+ascending_key
+	:	{(validateSoftKeyword("ascending") || validateSoftKeyword("asc"))}?=>  IDENTIFIER
+	;
+
+descending_key
+	:	{(validateSoftKeyword("descending") || validateSoftKeyword("desc"))}?=>  IDENTIFIER
+	;
+
+collate_key
+	:	{(validateSoftKeyword("collate"))}?=>  IDENTIFIER
+	;
+
+order_by_key
+ at init{
+	String text = "";
+}	:	{(validateSoftKeyword("order") && validateLT(2, "by"))}?=>  id=IDENTIFIER IDENTIFIER {text = $text;}
+		->	ORDER_BY[$id]
+	;
+
+group_by_key
+ at init{
+	String text = "";
+}	:	{(validateSoftKeyword("group") && validateLT(2, "by"))}?=>  id=IDENTIFIER IDENTIFIER {text = $text;}
+		->	GROUP_BY[$id]
+	;
+
+from_key
+	:	{(validateSoftKeyword("from"))}?=>  id=IDENTIFIER
+        	->	FROM[$id]
+	;
\ No newline at end of file


Property changes on: core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/hql/parse/HQLParser.g
___________________________________________________________________
Name: svn:eol-style
   + native

Copied: core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/hql/resolve/GeneratedHQLResolver.g (from rev 16466, core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/resolve/GeneratedHQLResolver.g)
===================================================================
--- core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/hql/resolve/GeneratedHQLResolver.g	                        (rev 0)
+++ core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/hql/resolve/GeneratedHQLResolver.g	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,636 @@
+tree grammar GeneratedHQLResolver;
+
+options{
+	output=AST;
+	rewrite=true;
+	tokenVocab=HQLLexer;
+	ASTLabelType=CommonTree;
+	TokenLabelType=CommonToken;
+}
+
+ at header {
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ *
+ * Portions of SQL grammar parsing copyright (C) 2003 by Lubos Vnuk.  All rights
+ * reserved.  These portions are distributed under license by Red Hat Middleware
+ * LLC and are covered by the above LGPL notice.  If you redistribute this material,
+ * with or without modification, you must preserve this copyright notice in its
+ * entirety.
+ */
+package org.hibernate.sql.ast.origin.hql.resolve;
+
+import org.antlr.runtime.tree.CommonTree;
+import org.hibernate.sql.ast.common.JoinType;
+import org.hibernate.sql.ast.origin.hql.resolve.path.PathedPropertyReferenceSource;
+}
+
+ at members {
+    protected void registerPersisterSpace(Tree entityName, Tree alias) {
+        throw new UnsupportedOperationException( "must be overridden!" );
+    }
+    
+	protected boolean isUnqualifiedPropertyReference() {
+        throw new UnsupportedOperationException( "must be overridden!" );
+	}	
+
+	protected PathedPropertyReferenceSource normalizeUnqualifiedPropertyReference(Tree property) {
+        throw new UnsupportedOperationException( "must be overridden!" );
+	}
+	
+	protected boolean isPersisterReferenceAlias() {
+        throw new UnsupportedOperationException( "must be overridden!" );
+    }
+
+    protected PathedPropertyReferenceSource normalizeUnqualifiedRoot(Tree identifier382) {
+        throw new UnsupportedOperationException( "must be overridden!" );
+	}
+
+	protected PathedPropertyReferenceSource normalizeQualifiedRoot(Tree identifier381) {
+        throw new UnsupportedOperationException( "must be overridden!" );
+	}
+
+    protected PathedPropertyReferenceSource normalizePropertyPathIntermediary(
+            PathedPropertyReferenceSource source,
+            Tree propertyName) {
+        throw new UnsupportedOperationException( "must be overridden!" );
+	}
+
+    protected PathedPropertyReferenceSource normalizeIntermediateIndexOperation(
+            PathedPropertyReferenceSource propertyReferenceSource,
+            Tree collectionProperty,
+			Tree selector) {
+        throw new UnsupportedOperationException( "must be overridden!" );
+	}
+
+    protected void normalizeTerminalIndexOperation(
+            PathedPropertyReferenceSource propertyReferenceSource,
+            Tree collectionProperty,
+			Tree selector ) {
+        throw new UnsupportedOperationException( "must be overridden!" );
+    }
+
+    protected PathedPropertyReferenceSource normalizeUnqualifiedPropertyReferenceSource(Tree identifier394) {
+        throw new UnsupportedOperationException( "must be overridden!" );
+	}
+
+    protected Tree normalizePropertyPathTerminus(PathedPropertyReferenceSource source, Tree propertyNameNode) {
+        throw new UnsupportedOperationException( "must be overridden!" );
+    }
+
+	protected void pushFromStrategy(
+	        JoinType joinType,
+			Tree assosiationFetchTree,
+			Tree propertyFetchTree,
+			Tree alias) {
+        throw new UnsupportedOperationException( "must be overridden!" );
+	}
+	
+	protected void pushSelectStrategy() {
+        throw new UnsupportedOperationException( "must be overridden!" );
+	}
+
+	protected void popStrategy(){
+        throw new UnsupportedOperationException( "must be overridden!" );
+	}	
+}
+
+filterStatement[String collectionRole]
+	:	^(QUERY ^(QUERY_SPEC FILTER 
+				selectClause? whereClause? ( groupByClause havingClause?)? orderByClause?))
+	;
+
+statement
+	:	updateStatementSet
+	|	deleteStatementSet
+	|	insertStatementSet
+	|	queryStatementSet
+	;
+
+updateStatementSet
+	:	updateStatement+
+	;
+
+updateStatement
+	:	^(UPDATE entityName ^(SET assignment+) whereClause?)
+	;
+
+assignment
+	:	^(EQUALS propertyReference valueExpression)
+	|	^(EQUALS VERSIONED_VALUE STRING_LITERAL)
+	;
+
+deleteStatementSet
+	:	deleteStatement+
+	;
+
+deleteStatement
+	:	^(DELETE entityName whereClause?)
+	;
+
+insertStatementSet
+	:	insertStatement+
+	;
+
+insertStatement
+	:	^(INSERT intoClause queryStatementSet)
+	;
+
+intoClause
+	:	^(INTO entityName ^(INSERTABILITY_SPEC propertyReference+ ) )
+	;
+
+queryStatementSet
+	:	queryStatement+
+	;
+
+queryStatement
+	:	^(QUERY queryExpression orderByClause?)
+	;
+
+queryExpression
+	:	^(UNION ALL? queryExpression queryExpression)
+	|	^(INTERSECT ALL? queryExpression queryExpression)
+	|	^(EXCEPT ALL? queryExpression queryExpression)
+	|	querySpec	
+	;
+
+querySpec
+	:	^(QUERY_SPEC selectFrom whereClause? groupByClause? havingClause?)
+	;
+
+whereClause
+	:	^(WHERE searchCondition)
+	;
+
+groupByClause
+	:	^(GROUP_BY groupingValue+)
+	;
+
+groupingValue
+	:	^(GROUPING_VALUE valueExpression COLLATE?)
+	;
+
+havingClause
+	:	^(HAVING searchCondition)
+	;
+
+selectFrom
+	:	^(SELECT_FROM fromClause selectClause)
+	;
+
+fromClause
+	:	^(FROM persisterSpaces+)
+	;
+
+persisterSpaces
+	:	^(PERSISTER_SPACE persisterSpace)
+	;
+
+persisterSpace
+	:	persisterSpaceRoot joins*
+	;
+
+persisterSpaceRoot
+	:	^(ENTITY_PERSISTER_REF entityName PROP_FETCH?)
+	;
+
+joins
+	:	^(PROPERTY_JOIN jt=joinType ft=FETCH? an=ALIAS_NAME pf=PROP_FETCH? 
+		{	pushFromStrategy($jt.joinType, $ft, $pf, $an );	}	
+		(collectionExpression|propertyReference) withClause?)
+		{	popStrategy();	}
+	|	^(PERSISTER_JOIN joinType persisterSpaceRoot onClause?)
+	;
+
+withClause
+	:	^(WITH searchCondition)
+	;
+
+onClause
+	:	^(ON searchCondition)
+	;
+
+joinType returns [JoinType joinType]
+	:	CROSS {	$joinType = JoinType.CROSS;	}
+	|	INNER {	$joinType = JoinType.INNER;	}
+	|	(LEFT {	$joinType = JoinType.LEFT;	} |	RIGHT {	$joinType = JoinType.RIGHT;	} | FULL {	$joinType = JoinType.FULL;	}) OUTER?
+	;
+
+selectClause
+ at init	{	if (state.backtracking == 0) pushSelectStrategy();	}
+ at after	{	popStrategy();	}
+	:	^(SELECT DISTINCT? rootSelectExpression) 
+	;
+
+rootSelectExpression
+	:	^(SELECT_LIST rootSelectExpression+)
+	|	^(SELECT_ITEM rootSelectExpression)
+	|	^(DYNAMIC_INSTANTIATION rootSelectExpression+)
+	|	^(DYNAMIC_INSTANTIATION_ARG rootSelectExpression)
+	|	valueExpression ALIAS_NAME?
+	;
+
+orderByClause
+	:	^(ORDER_BY sortSpecification+)
+	;
+
+sortSpecification
+	:	^(SORT_SPEC valueExpression COLLATE? ORDER_SPEC)
+	;
+
+searchCondition
+	:	^( OR searchCondition searchCondition )
+	|	^( AND searchCondition searchCondition )
+	|	^( NOT searchCondition )
+	|	predicate
+	;
+
+predicate
+	:	^( EQUALS rowValueConstructor comparativePredicateValue )
+	|	^( NOT_EQUAL rowValueConstructor comparativePredicateValue )
+	|	^( LESS rowValueConstructor comparativePredicateValue )
+	|	^( LESS_EQUAL rowValueConstructor comparativePredicateValue )
+	|	^( GREATER rowValueConstructor comparativePredicateValue )
+	|	^( GREATER_EQUAL rowValueConstructor comparativePredicateValue )
+	|	^( IS_NULL rowValueConstructor )
+	|	^( IS_NOT_NULL rowValueConstructor )
+	|	^( LIKE valueExpression valueExpression escapeSpecification? )
+	|	^( NOT_LIKE valueExpression valueExpression escapeSpecification? )
+	|	^( BETWEEN rowValueConstructor betweenList )
+	|	^( NOT_BETWEEN rowValueConstructor betweenList )
+	|	^( IN rowValueConstructor inPredicateValue )
+	|	^( NOT_IN rowValueConstructor inPredicateValue )
+	|	^( MEMBER_OF rowValueConstructor rowValueConstructor )
+	|	^( NOT_MEMBER_OF rowValueConstructor rowValueConstructor  )
+	|	^( IS_EMPTY rowValueConstructor )
+	|	^( IS_NOT_EMPTY rowValueConstructor )
+	|	rowValueConstructor
+	;
+
+betweenList
+	:	^( BETWEEN_LIST rowValueConstructor rowValueConstructor )
+	;	
+
+comparativePredicateValue
+	:	rowValueConstructor
+	;
+
+rowValueConstructor
+	:	valueExpression
+	;
+
+escapeSpecification
+	:	^(ESCAPE characterValueExpression)
+	;
+
+inPredicateValue
+	:	^(IN_LIST valueExpression+)
+	;
+
+numericValueExpression
+	:	valueExpression
+	;
+
+characterValueExpression
+	:	valueExpression
+	;
+
+datetimeValueExpression
+	:	valueExpression
+	;
+
+valueExpression
+	:	^( DOUBLE_PIPE characterValueExpression+ )
+	|	^( UNARY_MINUS numericValueExpression )
+	|	^( UNARY_PLUS numericValueExpression )
+	|	^( PLUS valueExpression valueExpression )
+	|	^( MINUS valueExpression valueExpression )
+	|	^( ASTERISK numericValueExpression numericValueExpression )
+	|	^( SOLIDUS numericValueExpression numericValueExpression )
+	|	^( EXISTS rowValueConstructor)
+    |	^( SOME valueExpression )
+    |	^( ALL valueExpression )
+    |	^( ANY valueExpression )
+	|	^( VECTOR_EXPR valueExpression+) // or a tuples or ^(AND or IN statement 
+	|	valueExpressionPrimary
+	;
+
+valueExpressionPrimary
+	:	caseExpression
+	|	function
+	|	collectionFunction
+	|	collectionExpression
+	|	constant
+	|	parameter
+	|	propertyReference
+	|	^(SUB_QUERY queryStatementSet)
+	|	ALIAS_REF //ID COLUMN, full property column list 
+	|	^(DOT_CLASS path) // crazy
+	|	^(JAVA_CONSTANT path) //It will generate at SQL a parameter element (?) -> 'cos we do not need to care about char escaping
+	|	^(PATH propertyReferencePath)
+	;
+
+caseExpression
+	:	^(NULLIF valueExpression valueExpression)
+	|	^(COALESCE valueExpression valueExpression*)
+	|	^(SIMPLE_CASE valueExpression simpleCaseWhenClause+ elseClause?)
+	|	^(SEARCHED_CASE searchedWhenClause+ elseClause?)
+	;
+
+simpleCaseWhenClause
+	:	^(WHEN valueExpression valueExpression)
+	;
+
+searchedWhenClause
+	:	^(WHEN searchCondition valueExpression)
+	;
+
+elseClause
+	:	^(ELSE valueExpression)
+	;
+
+function
+	: setFunction
+	| standardFunction
+	;
+
+setFunction
+	:	^(SUM numericValueExpression)
+	|	^(AVG numericValueExpression)
+	|	^(MAX numericValueExpression)
+	|	^(MIN numericValueExpression)
+	|	^(COUNT (ASTERISK | (DISTINCT|ALL) countFunctionArguments))
+	;
+
+standardFunction
+	: functionFunction
+	| castFunction
+	|	concatFunction
+	|	substringFunction
+	|	trimFunction
+	|	upperFunction
+	|	lowerFunction
+	|	lengthFunction
+	|	locateFunction
+	|	absFunction
+	|	sqrtFunction
+	|	modFunction
+	|	sizeFunction
+	|	indexFunction
+	|	currentDateFunction
+	|	currentTimeFunction
+	|	currentTimestampFunction
+	|	extractFunction
+	|	positionFunction
+	|	charLengthFunction
+	|	octetLengthFunction
+	|	bitLengthFunction
+	;
+
+functionFunction
+    : ^( FUNCTION valueExpression* )
+    ;
+
+castFunction
+	: ^(CAST valueExpression IDENTIFIER)
+	// todo : -> ^( FUNCTION[$CAST.start,"cast"] valueExpression "as" IDENTIFIER )
+	;
+
+concatFunction
+	:	^(CONCAT valueExpression+)
+	;
+
+substringFunction
+	:	^(SUBSTRING characterValueExpression numericValueExpression numericValueExpression?)
+	;
+
+trimFunction
+	:	^(TRIM trimOperands)
+	;
+
+trimOperands
+	:	^((LEADING|TRAILING|BOTH) characterValueExpression characterValueExpression)
+	;
+
+upperFunction
+	:	^(UPPER characterValueExpression)
+	;
+
+lowerFunction
+	:	^(LOWER characterValueExpression)
+	;
+
+lengthFunction
+	:	^(LENGTH characterValueExpression)
+	;
+
+locateFunction
+	:	^(LOCATE characterValueExpression characterValueExpression numericValueExpression?)
+	;
+
+absFunction
+	:	^(ABS numericValueExpression)
+	;
+
+sqrtFunction
+	:	^(SQRT numericValueExpression)
+	;
+
+modFunction
+	:	^(MOD numericValueExpression numericValueExpression)
+	;
+
+sizeFunction
+	:	^(SIZE propertyReference)
+	;
+
+indexFunction
+	:	^(INDEX ALIAS_REF)
+	;
+
+currentDateFunction
+	:	CURRENT_DATE
+	;
+
+currentTimeFunction
+	:	CURRENT_TIME
+	;
+
+currentTimestampFunction
+	:	CURRENT_TIMESTAMP
+	;
+
+extractFunction
+	:	^(EXTRACT extractField datetimeValueExpression)
+	;
+
+extractField
+	:	datetimeField
+	|	timeZoneField
+	;
+
+datetimeField
+	:	YEAR
+	|	MONTH
+	|	DAY
+	|	HOUR
+	|	MINUTE
+	|	SECOND
+	;
+
+timeZoneField
+	:	TIMEZONE_HOUR
+	|	TIMEZONE_MINUTE
+	;
+
+positionFunction
+	:	^(POSITION characterValueExpression characterValueExpression)
+	;
+
+charLengthFunction
+	:	^(CHARACTER_LENGTH characterValueExpression)
+	;
+
+octetLengthFunction
+	:	^(OCTET_LENGTH characterValueExpression)	
+	;
+
+bitLengthFunction
+	:	^(BIT_LENGTH characterValueExpression)
+	;
+
+
+countFunctionArguments
+	:	collectionExpression
+	|	propertyReference
+	|	numeric_literal
+	;
+
+collectionFunction
+	:	^((MAXELEMENT|MAXINDEX|MINELEMENT|MININDEX) collectionPropertyReference)
+		//it will generate a SELECT MAX (m.column) form Table xxx -> it is realted to Hibernate mappings to Table->Map
+	;
+
+collectionPropertyReference
+	:	propertyReference
+	;
+
+collectionExpression
+	:	^(ELEMENTS propertyReference) //it will generate a SELECT m.column form Table xxx -> it is realted to Hibernate mappings to Table->Map
+	|	^(INDICES propertyReference)
+	;
+
+parameter
+	:	NAMED_PARAM
+	|	JPA_PARAM
+	|	PARAM
+	;
+
+constant
+	:	literal
+	|	NULL
+	|	TRUE
+	|	FALSE
+	;
+
+literal
+	:	numeric_literal
+	|	HEX_LITERAL
+	|	OCTAL_LITERAL
+	|	CHARACTER_LITERAL
+	|	STRING_LITERAL
+	;
+
+numeric_literal
+	:	INTEGER_LITERAL
+	|	DECIMAL_LITERAL
+	|	FLOATING_POINT_LITERAL
+	;
+
+entityName
+	:	ENTITY_NAME ALIAS_NAME
+	{	registerPersisterSpace($ENTITY_NAME, $ALIAS_NAME);	}
+	;
+
+propertyReference
+	:	^(PROPERTY_REFERENCE propertyReferencePath)
+	;
+
+propertyReferencePath
+	: 	{isUnqualifiedPropertyReference()}? unqualifiedPropertyReference
+	|	pathedPropertyReference
+    |	terminalIndexOperation
+	;
+
+unqualifiedPropertyReference returns [PathedPropertyReferenceSource propertyReferenceSource]
+	:	IDENTIFIER
+	{	$propertyReferenceSource = normalizeUnqualifiedPropertyReference( $IDENTIFIER ); }
+	;
+
+pathedPropertyReference
+	:	^(DOT pathedPropertyReferenceSource IDENTIFIER)
+	{	normalizePropertyPathTerminus( $pathedPropertyReferenceSource.propertyReferenceSource, $IDENTIFIER );	}
+	;
+
+pathedPropertyReferenceSource returns [PathedPropertyReferenceSource propertyReferenceSource]
+	:	{(isPersisterReferenceAlias())}?=> IDENTIFIER { $propertyReferenceSource = normalizeQualifiedRoot( $IDENTIFIER ); }
+    |	{(isUnqualifiedPropertyReference())}?=> IDENTIFIER { $propertyReferenceSource = normalizeUnqualifiedRoot( $IDENTIFIER ); }
+    |	intermediatePathedPropertyReference { $propertyReferenceSource = $intermediatePathedPropertyReference.propertyReferenceSource; }
+    |	intermediateIndexOperation { $propertyReferenceSource = $intermediateIndexOperation.propertyReferenceSource; }
+    ;
+
+intermediatePathedPropertyReference returns [PathedPropertyReferenceSource propertyReferenceSource]
+	:	^(DOT source=pathedPropertyReferenceSource IDENTIFIER )
+	{	$propertyReferenceSource = normalizePropertyPathIntermediary( $pathedPropertyReferenceSource.propertyReferenceSource, $IDENTIFIER );	}
+	;
+
+intermediateIndexOperation returns [PathedPropertyReferenceSource propertyReferenceSource]
+	:	^( LEFT_SQUARE indexOperationSource indexSelector ) 
+	{	$propertyReferenceSource = normalizeIntermediateIndexOperation( $indexOperationSource.propertyReferenceSource, $indexOperationSource.collectionProperty, $indexSelector.tree );	}
+	;
+
+terminalIndexOperation
+	:	^( LEFT_SQUARE indexOperationSource indexSelector ) 
+	{	normalizeTerminalIndexOperation( $indexOperationSource.propertyReferenceSource, $indexOperationSource.collectionProperty, $indexSelector.tree );	}
+	;
+
+indexOperationSource returns [PathedPropertyReferenceSource propertyReferenceSource, Tree collectionProperty]
+	:	^(DOT pathedPropertyReferenceSource IDENTIFIER )
+	{	$propertyReferenceSource = $pathedPropertyReferenceSource.propertyReferenceSource;
+		$collectionProperty = $IDENTIFIER;	}
+    |	{(isUnqualifiedPropertyReference())}?=> IDENTIFIER
+    {	$propertyReferenceSource = normalizeUnqualifiedPropertyReferenceSource( $IDENTIFIER );
+    	$collectionProperty = $IDENTIFIER;	}
+	;
+
+indexSelector
+	:	valueExpression
+	;
+
+path
+	: 	IDENTIFIER
+	|	^(DOT path path )
+	|	^(LEFT_SQUARE path valueExpression* )
+	|	^(LEFT_PAREN path valueExpression* )
+	;


Property changes on: core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/hql/resolve/GeneratedHQLResolver.g
___________________________________________________________________
Name: svn:eol-style
   + native

Copied: core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/ordering/OrderByParser.g (from rev 16437, core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/ordering/OrderByParser.g)
===================================================================
--- core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/ordering/OrderByParser.g	                        (rev 0)
+++ core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/origin/ordering/OrderByParser.g	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,565 @@
+parser grammar OrderByParser;
+
+options {
+	tokenVocab=HQLLexer;
+	output=AST;
+	ASTLabelType=CommonTree;
+}
+
+ at parser::header {
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ *
+ * Portions of SQL grammar parsing copyright (C) 2003 by Lubos Vnuk.  All rights
+ * reserved.  These portions are distributed under license by Red Hat Middleware
+ * LLC and are covered by the above LGPL notice.  If you redistribute this material,
+ * with or without modification, you must preserve this copyright notice in its
+ * entirety.
+ */
+package org.hibernate.sql.ast.origin.ordering;
+
+import org.hibernate.sql.Template;
+}
+
+ at parser::members {
+    /**
+     * A check to see if the text represents a known function name (in addition to the
+     * set of known {@link #standardFunction "standard"} functions.  This is only needed in the
+     * case of seeing a dot-ident structure which is not followed by a paren; such structures
+     * which are followed by a paren are explicitly assumed to be a function name.
+     *
+     * @param text The text to check as a  function name.
+     *
+     * @return True if the text is a known function name, false otherwise.
+     *
+     * @see #standardFunction
+     */
+    protected boolean isFunctionName(String text) {
+        // by default, assume it is not
+    	return false;
+    }
+
+    /**
+     * A check to see if the text represents a mapped property name.
+     *
+     * @param text The text to check as a property name.
+     *
+     * @return True if the text is a mapped property name, false otherwise.
+     */
+    protected boolean isPropertyName(String text) {
+        // by default, assume it is not
+    	return false;
+    }
+
+    /**
+     * Given a property, resolve it's {@link #COLUMN} or {@link #VECTOR_EXPR} tree.
+     *
+     * @param propertyTree The tree representing the property name.
+     *
+     * @return The column(s) tree.
+     */
+    protected CommonTree buildPropertyColumns(CommonTree propertyTree) {
+        throw new UnsupportedOperationException( "must be overridden!" );
+    }
+
+	private boolean validateSoftKeyword(String text) {
+		return validateLT(1, text);
+	}
+
+	private boolean validateLT(int offset, String text) {
+		String text2Validate = retrieveLT( offset );
+		return text2Validate == null ? false : text2Validate.equalsIgnoreCase( text );
+	}
+
+	private String retrieveLT(int offset) {
+      	if (null == input) {
+      		return null;
+      	}
+		Token token = input.LT(offset);
+		return token == null ? null : token.getText();
+	}
+}
+
+
+// Parser rules ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+
+/**
+ * Main recognition rule for this grammar
+ */
+orderByFragment :
+    sortSpecification ( COMMA sortSpecification )*
+        -> ^( ORDER_BY sortSpecification+ )
+;
+
+
+/**
+ * Reconition rule for what ANSI SQL terms the <tt>sort specification</tt>.  These are the atomic elements of the
+ * <tt>ORDER BY</tt> list pieces.
+ */
+sortSpecification :
+    sortKey collationSpecification? orderingSpecification?
+        -> ^( SORT_SPEC sortKey collationSpecification? orderingSpecification? )
+;
+
+
+/**
+ * Reconition rule for what ANSI SQL terms the <tt>sort key</tt> which is the expression (column, function, etc) upon
+ * which to base the sorting.
+ */
+sortKey :
+    expression
+;
+
+/**
+ * Reconition rule what this grammar recognizes as valid <tt>sort key</tt>.
+ */
+expression
+    : QUOTED_IDENTIFIER -> ^( COLUMN[$QUOTED_IDENTIFIER] ALIAS_REF[Template.TEMPLATE] QUOTED_IDENTIFIER[$QUOTED_IDENTIFIER] )
+    // we treat the so-called standard functions differently because they are handled differently by the HQL lexer which we also use here...
+    | standardFunction
+    // not identDotIdentStructure because we dont want QUOTED_IDENTIFIERs is here
+    | ( IDENTIFIER ( DOT IDENTIFIER )* LEFT_PAREN ) => generalFunction
+    // otherwise we fully expect a dot-identifier series, and then we just need to decode the semantic of that structure
+    | identDotIdentStructure
+        -> { ( isFunctionName($identDotIdentStructure.text) ) }?
+              // we have a function with parens (thus no args)
+              ^( FUNCTION[$identDotIdentStructure.start,$identDotIdentStructure.text] )
+        -> { ( isPropertyName($identDotIdentStructure.text) ) }?
+              // we have a reference to a mapped property
+              { buildPropertyColumns( $identDotIdentStructure.tree ) }
+        -> { ( $identDotIdentStructure.tree.getType() == DOT ) }?
+              // we have a reference to a column which is already qualified
+              identDotIdentStructure
+        ->
+              // we have a reference to a column which is not qualified
+              ^( COLUMN ALIAS_REF[Template.TEMPLATE] IDENTIFIER[$identDotIdentStructure.start,$identDotIdentStructure.text] )
+    ;
+
+fragment
+identifier
+    : IDENTIFIER
+    | QUOTED_IDENTIFIER
+    ;
+
+fragment
+identDotIdentStructure
+    : IDENTIFIER ( DOT^ identifier )*
+    ;
+
+standardFunction
+	:	castFunction
+	|	concatFunction
+	|	substringFunction
+	|	trimFunction
+	|	upperFunction
+	|	lowerFunction
+	|	lengthFunction
+	|	locateFunction
+	|	absFunction
+	|	sqrtFunction
+	|	modFunction
+	|	currentDateFunction
+	|	currentTimeFunction
+	|	currentTimestampFunction
+	|	extractFunction
+	|	positionFunction
+	|	charLengthFunction
+	|	octetLengthFunction
+	|	bitLengthFunction
+	;
+
+castFunction
+	: cast_keyword LEFT_PAREN expression as_keyword dataType RIGHT_PAREN
+	    -> ^( FUNCTION[$cast_keyword.start,$cast_keyword.text] expression as_keyword dataType )
+	;
+
+fragment
+dataType
+	:	IDENTIFIER
+	;
+
+concatFunction
+	: concat_keyword LEFT_PAREN expression ( COMMA expression )+ RIGHT_PAREN
+	    -> ^( FUNCTION[$concat_keyword.start,$concat_keyword.text] expression+ )
+	;
+
+substringFunction
+	: substring_keyword LEFT_PAREN expression COMMA expression ( COMMA expression)? RIGHT_PAREN
+	    -> ^( FUNCTION[$substring_keyword.start,$substring_keyword.text] expression+ )
+	;
+
+trimFunction
+	: trim_keyword LEFT_PAREN trimOperands RIGHT_PAREN
+	    -> ^( FUNCTION[$trim_keyword.start,$trim_keyword.text] trimOperands )
+	;
+
+fragment
+trimOperands
+options{
+k=2;
+}
+ at init {boolean hasSecondExpression = false;}
+	:	trimSpecification from_keyword expression -> ^(trimSpecification STRING_LITERAL[" "] expression)
+	|	trimSpecification expression from_keyword expression -> ^(trimSpecification expression+)
+	|	from_keyword expression -> ^(BOTH STRING_LITERAL[" "] expression)
+	|	cn=expression ( from_keyword expression {hasSecondExpression = true;} )?
+		-> {hasSecondExpression}? ^(BOTH expression+)
+		-> ^(BOTH STRING_LITERAL[" "] $cn)
+	;
+
+fragment
+trimSpecification
+	:	leading_keyword
+	|	trailing_keyword
+	|	both_keyword
+	;
+
+upperFunction
+	: upper_keyword LEFT_PAREN expression RIGHT_PAREN
+	    -> ^( FUNCTION[$upper_keyword.start,$upper_keyword.text] expression )
+	;
+
+lowerFunction
+	: lower_keyword LEFT_PAREN expression RIGHT_PAREN
+	    -> ^( FUNCTION[$lower_keyword.start,$lower_keyword.text] expression )
+	;
+
+lengthFunction
+	: length_keyword LEFT_PAREN expression RIGHT_PAREN
+	    -> ^( FUNCTION[$length_keyword.start,$length_keyword.text] expression )
+	;
+
+locateFunction
+	: locate_keyword LEFT_PAREN expression COMMA expression ( COMMA expression )? RIGHT_PAREN
+	    -> ^( FUNCTION[$locate_keyword.start,$locate_keyword.text] expression+ )
+	;
+
+absFunction
+	:	abs_keyword^ LEFT_PAREN! expression RIGHT_PAREN!
+	;
+
+sqrtFunction
+	:	sqrt_keyword^ LEFT_PAREN! expression RIGHT_PAREN!
+	;
+
+modFunction
+	:	mod_keyword^ LEFT_PAREN! expression COMMA! expression RIGHT_PAREN!
+	;
+
+currentDateFunction
+	:	current_date_keyword ( LEFT_PAREN! RIGHT_PAREN! )?
+	;
+
+currentTimeFunction
+	:	current_time_keyword ( LEFT_PAREN! RIGHT_PAREN! )?
+	;
+
+currentTimestampFunction
+	:	current_timestamp_keyword ( LEFT_PAREN! RIGHT_PAREN! )?
+	;
+
+extractFunction
+	:	extract_keyword^ LEFT_PAREN! extractField from_keyword! expression RIGHT_PAREN!
+	;
+
+extractField
+	:	datetimeField
+	|	timeZoneField
+	;
+
+datetimeField
+	:	nonSecondDatetimeField
+	|	second_keyword
+	;
+
+nonSecondDatetimeField
+	:	year_keyword
+	|	month_keyword
+	|	day_keyword
+	|	hour_keyword
+	|	minute_keyword
+	;
+
+timeZoneField
+	:	timezone_hour_keyword
+	|	timezone_minute_keyword
+	;
+
+positionFunction
+	:	position_keyword^ LEFT_PAREN! expression in_keyword! expression RIGHT_PAREN!
+	;
+
+charLengthFunction
+	:	character_length_keyword^ LEFT_PAREN! expression RIGHT_PAREN!
+	;
+
+octetLengthFunction
+	:	octet_length_keyword^ LEFT_PAREN! expression RIGHT_PAREN!
+	;
+
+bitLengthFunction
+	:	bit_length_keyword^ LEFT_PAREN! expression RIGHT_PAREN!
+	;
+
+
+generalFunction
+    : generalFunctionName LEFT_PAREN functionArgument ( COMMA functionArgument )* RIGHT_PAREN
+          -> ^( FUNCTION[$generalFunctionName.start,$generalFunctionName.text] functionArgument+ )
+    ;
+
+generalFunctionName :
+    IDENTIFIER ( DOT IDENTIFIER )+
+;
+
+/**
+ * Recognized function parameters.
+ */
+functionArgument :
+    expression
+    | literal
+;
+
+literal
+	:	numeric_literal
+	|	HEX_LITERAL
+	|	OCTAL_LITERAL
+	|	CHARACTER_LITERAL
+	|	STRING_LITERAL
+	;
+
+numeric_literal
+	:	INTEGER_LITERAL
+	|	DECIMAL_LITERAL
+	|	FLOATING_POINT_LITERAL
+	;
+
+/**
+ * Reconition rule for what ANSI SQL terms the <tt>collation specification</tt> used to allow specifying that sorting for
+ * the given {@link #sortSpecification} be treated within a specific character-set.
+ */
+collationSpecification!
+    : collateKeyword collationName
+        -> COLLATE[$collateKeyword.start,$collationName.text]
+;
+
+collateKeyword :
+    {(validateSoftKeyword("collate"))}?=>  id=IDENTIFIER
+		->	COLLATE[$id]
+;
+
+/**
+ * The collation name wrt {@link #collationSpecification}.  Namely, the character-set.
+ */
+collationName :
+    IDENTIFIER
+;
+
+/**
+ * Reconition rule for what ANSI SQL terms the <tt>ordering specification</tt>; <tt>ASCENDING</tt> or
+ * <tt>DESCENDING</tt>.
+ */
+orderingSpecification! :
+    ascending_keyword
+        -> ORDER_SPEC[$ascending_keyword.start,$ascending_keyword.text]
+    | descending_keyword
+        -> ORDER_SPEC[$descending_keyword.start,$descending_keyword.text]
+;
+
+
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// Soft-keyword handling rules
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+abs_keyword
+	:	{(validateSoftKeyword("abs"))}?=>  id=IDENTIFIER
+		->	ABS[$id]
+	;
+
+as_keyword
+	:	{(validateSoftKeyword("as"))}?=>  id=IDENTIFIER
+		->	AS[$id]
+	;
+
+ascending_keyword :
+    {(validateSoftKeyword("ascending") || validateSoftKeyword("asc"))}?=>  IDENTIFIER
+;
+
+bit_length_keyword
+	:	{(validateSoftKeyword("bit_length"))}?=>  id=IDENTIFIER
+		->	BIT_LENGTH[$id]
+	;
+
+both_keyword
+	:	{(validateSoftKeyword("both"))}?=>  id=IDENTIFIER
+		->	BOTH[$id]
+	;
+
+cast_keyword
+	:	{(validateSoftKeyword("cast"))}?=>  id=IDENTIFIER
+		->	CAST[$id]
+	;
+
+character_length_keyword
+	:	{(validateSoftKeyword("character_length") || validateSoftKeyword("char_length"))}?=>  id=IDENTIFIER
+		->	CHARACTER_LENGTH[$id]
+	;
+
+concat_keyword
+	:	{(validateSoftKeyword("concat"))}?=>  id=IDENTIFIER
+		->	CONCAT[$id]
+	;
+
+current_date_keyword
+	:	{(validateSoftKeyword("current_date"))}?=>  id=IDENTIFIER
+		->	CURRENT_DATE[$id]
+	;
+
+current_time_keyword
+	:	{(validateSoftKeyword("current_time"))}?=>  id=IDENTIFIER
+		->	CURRENT_TIME[$id]
+	;
+
+current_timestamp_keyword
+	:	{(validateSoftKeyword("current_timestamp"))}?=>  id=IDENTIFIER
+		->	CURRENT_TIMESTAMP[$id]
+	;
+
+day_keyword
+	:	{(validateSoftKeyword("day"))}?=>  id=IDENTIFIER
+		->	DAY[$id]
+	;
+
+descending_keyword :
+    {(validateSoftKeyword("descending") || validateSoftKeyword("desc"))}?=>  IDENTIFIER
+;
+
+extract_keyword
+	:	{(validateSoftKeyword("extract"))}?=>  id=IDENTIFIER
+		->	EXTRACT[$id]
+	;
+
+from_keyword
+	:	{(validateSoftKeyword("from"))}?=>  id=IDENTIFIER
+		->	FROM[$id]
+	;
+
+hour_keyword
+	:	{(validateSoftKeyword("hour"))}?=>  id=IDENTIFIER
+		->	HOUR[$id]
+	;
+
+in_keyword
+	:	{(validateSoftKeyword("in"))}?=>  id=IDENTIFIER
+		->	IN[$id]
+	;
+leading_keyword
+	:	{(validateSoftKeyword("leading"))}?=>  id=IDENTIFIER
+		->	LEADING[$id]
+	;
+
+length_keyword
+	:	{(validateSoftKeyword("length"))}?=>  id=IDENTIFIER
+		->	LENGTH[$id]
+	;
+
+locate_keyword
+	:	{(validateSoftKeyword("locate"))}?=>  id=IDENTIFIER
+		->	LOCATE[$id]
+	;
+
+lower_keyword
+	:	{(validateSoftKeyword("lower"))}?=>  id=IDENTIFIER
+		->	LOWER[$id]
+	;
+
+minute_keyword
+	:	{(validateSoftKeyword("minute"))}?=>  id=IDENTIFIER
+		->	MINUTE[$id]
+	;
+
+mod_keyword
+	:	{(validateSoftKeyword("mod"))}?=>  id=IDENTIFIER
+		->	MOD[$id]
+	;
+
+month_keyword
+	:	{(validateSoftKeyword("month"))}?=>  id=IDENTIFIER
+		->	MONTH[$id]
+	;
+
+octet_length_keyword
+	:	{(validateSoftKeyword("octet_length"))}?=>  id=IDENTIFIER
+		->	OCTET_LENGTH[$id]
+	;
+
+position_keyword
+	:	{(validateSoftKeyword("position"))}?=>  id=IDENTIFIER
+		->	POSITION[$id]
+	;
+
+second_keyword
+	:	{(validateSoftKeyword("second"))}?=>  id=IDENTIFIER
+		->	SECOND[$id]
+	;
+
+sqrt_keyword
+	:	{(validateSoftKeyword("sqrt"))}?=>  id=IDENTIFIER
+		->	SQRT[$id]
+	;
+
+substring_keyword
+	:	{(validateSoftKeyword("substring"))}?=>  id=IDENTIFIER
+		->	SUBSTRING[$id]
+	;
+
+timezone_hour_keyword
+	:	{(validateSoftKeyword("timezone_hour"))}?=>  id=IDENTIFIER
+		->	TIMEZONE_HOUR[$id]
+	;
+
+timezone_minute_keyword
+	:	{(validateSoftKeyword("timezone_minute"))}?=>  id=IDENTIFIER
+		->	TIMEZONE_MINUTE[$id]
+	;
+
+trailing_keyword
+	:	{(validateSoftKeyword("trailing"))}?=>  id=IDENTIFIER
+		->	TRAILING[$id]
+	;
+
+trim_keyword
+	:	{(validateSoftKeyword("trim"))}?=>  id=IDENTIFIER
+		->	TRIM[$id]
+	;
+
+upper_keyword
+	:	{(validateSoftKeyword("upper"))}?=>  id=IDENTIFIER
+		->	UPPER[$id]
+	;
+
+year_keyword
+	:	{(validateSoftKeyword("year"))}?=>  id=IDENTIFIER
+		->	YEAR[$id]
+	;
+

Deleted: core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLLexer.g
===================================================================
--- core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLLexer.g	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLLexer.g	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,367 +0,0 @@
-lexer grammar HQLLexer;
-
-tokens {
-//GENERIC SQL TOKENS
-	TABLE;
-	COLUMN;
-	COLUMN_LIST;
-
-//VIRTUAL TOKENS
-	ALIAS_NAME;
-	ALIAS_REF;
-	BETWEEN_LIST;
-	COLLATE;
-	COLLECTION_EXPRESSION;
-	DOT_CLASS;
-	DYNAMIC_INSTANTIATION_ARG;
-	DYNAMIC_INSTANTIATION;
-	ENTITY_NAME;
-	ENTITY_PERSISTER_REF;
-	FILTER;
-	GENERAL_FUNCTION_CALL;
-	GENERAL_FUNCTION_ARGUMENTS;
-	GROUPING_VALUE;
-	IN_LIST;
-	INSERTABILITY_SPEC;
-	IS_NOT_EMPTY;
-	IS_NOT_NULL;
-	IS_NULL;
-	JAVA_CONSTANT;
-	JPA_PARAM;
-	NAMED_PARAM;
-	NOT_BETWEEN;
-	NOT_IN;
-	NOT_LIKE;
-	NOT_MEMBER_OF;
-	ORDER_SPEC;
-	PATH;
-	PERSISTER_JOIN;
-	PERSISTER_SPACE;
-	PROP_FETCH;
-	PROPERTY_JOIN;
-	PROPERTY_REFERENCE;
-	QUALIFIED_JOIN;
-	QUERY_SPEC;
-	QUERY;
-	SEARCHED_CASE;
-	SELECT_FROM;
-	SELECT_ITEM;
-	SELECT_LIST;
-	SIMPLE_CASE;
-	SORT_SPEC;
-	SUB_QUERY;
-	UNARY_MINUS;
-	UNARY_PLUS;
-	VECTOR_EXPR;
-	VERSIONED_VALUE;
-
-//SOFT KEYWORDS
-	ABS;
-	ALL;
-	AND;
-	ANY;
-	AS;
-	AVG;
-	BETWEEN;
-	BIT_LENGTH;
-	BOTH;
-	CAST;
-	CHARACTER_LENGTH;
-	CLASS;
-	COALESCE;
-	CONCAT;
-	COUNT;
-	CROSS;
-	CURRENT_DATE;
-	CURRENT_TIME;
-	CURRENT_TIMESTAMP;
-	DAY;
-	DELETE;
-	DISTINCT;
-	ELEMENTS;
-	ELSE;
-	END;
-	ESCAPE;
-	EXCEPT;
-	EXISTS;
-	EXTRACT;
-	FETCH;
-	FROM;
-	FULL;
-	GROUP_BY;
-	HAVING;
-	HOUR;
-	IN;
-	INDEX;
-	INDICES;
-	INNER;
-	INSERT;
-	INTERSECT;
-	INTO;
-	IS_EMPTY;
-	IS;
-	JOIN;
-	LEADING;
-	LEFT;
-	LENGTH;
-	LIKE;
-	LOCATE;
-	LOWER;
-	MAX;
-	MAXELEMENT;
-	MAXINDEX;
-	MEMBER_OF;
-	MIN;
-	MINELEMENT;
-	MININDEX;
-	MINUTE;
-	MOD;
-	MONTH;
-	NEW;
-	NOT;
-	NULLIF;
-	OCTET_LENGTH;
-	ON;
-	OR;
-	ORDER_BY;
-	OUTER;
-	POSITION;
-	PROPERTIES;
-	RIGHT;
-	SECOND;
-	SELECT;
-	SET;
-	SIZE;
-	SOME;
-	SQRT;
-	SUBSTRING;
-	SUM;
-	THEN;
-	TIMEZONE_HOUR;
-	TIMEZONE_MINUTE;
-	TRAILING;
-	TRIM;
-	UNION;
-	UPDATE;
-	UPPER;
-	VERSIONED;
-	WHEN;
-	WHERE;
-	WITH;
-	YEAR;
-}
-
- at header {
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- *
- * Portions of SQL grammar parsing copyright (C) 2003 by Lubos Vnuk.  All rights
- * reserved.  These portions are distributed under license by Red Hat Middleware
- * LLC and are covered by the above LGPL notice.  If you redistribute this material,
- * with or without modification, you must preserve this copyright notice in its
- * entirety.
- */
-package org.hibernate.sql.ast.phase.hql.parse;
-}
-
-WS      :       (	' '
-                |	'\t'
-                |	'\f'
-                |	EOL
-                )+
-                { $channel=HIDDEN; }
-        ;
-
-fragment
-EOL 	:	     
-   		(       ( '\r\n' )=> '\r\n'  // Evil DOS
-                |       '\r'    // Macintosh
-                |       '\n'    // Unix (the right way)
-                )
-        ;
-
-HEX_LITERAL : '0' ('x'|'X') HEX_DIGIT+ INTEGER_TYPE_SUFFIX? ;
-
-INTEGER_LITERAL : ('0' | '1'..'9' '0'..'9'*) ;
-
-DECIMAL_LITERAL : ('0' | '1'..'9' '0'..'9'*) INTEGER_TYPE_SUFFIX ;
-
-OCTAL_LITERAL : '0' ('0'..'7')+ INTEGER_TYPE_SUFFIX? ;
-
-fragment
-HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;
-
-fragment
-INTEGER_TYPE_SUFFIX : ('l'|'L') ;
-
-FLOATING_POINT_LITERAL
-    :   ('0'..'9')+ '.' ('0'..'9')* EXPONENT? FLOAT_TYPE_SUFFIX?
-    |   '.' ('0'..'9')+ EXPONENT? FLOAT_TYPE_SUFFIX?
-    |   ('0'..'9')+ EXPONENT FLOAT_TYPE_SUFFIX?
-    |   ('0'..'9')+ FLOAT_TYPE_SUFFIX
-    ;
-
-fragment
-EXPONENT : ('e'|'E') ('+'|'-')? ('0'..'9')+ ;
-
-fragment
-FLOAT_TYPE_SUFFIX : ('f'|'F'|'d'|'D') ;
-
-CHARACTER_LITERAL
-    :   '\'' ( ESCAPE_SEQUENCE | ~('\''|'\\') ) '\''
-    ;
-
-STRING_LITERAL
-    :  '"' ( ESCAPE_SEQUENCE | ~('\\'|'"') )* '"'
-    |  ('\'' ( ESCAPE_SEQUENCE | ~('\\'|'\'') )* '\'')+
-    ;
-
-fragment
-ESCAPE_SEQUENCE
-    :   '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
-    |   UNICODE_ESCAPE
-    |   OCTAL_ESCAPE
-    ;
-
-fragment
-OCTAL_ESCAPE
-    :   '\\' ('0'..'3') ('0'..'7') ('0'..'7')
-    |   '\\' ('0'..'7') ('0'..'7')
-    |   '\\' ('0'..'7')
-    ;
-
-fragment
-UNICODE_ESCAPE
-    :   '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
-    ;
-
-TRUE
-	:	'true'
-	;	
-
-FALSE
-	:	'false'
-	;
-
-NULL
-	:	'null'
-	;
-
-EQUALS
-	:	'='
-	;
-
-SEMICOLON
-	:	';'
-	;
-
-COLON
-	:	':'
-	;
-
-NOT_EQUAL
-	:	'!='
-	|	'^='
-	|	'<>'
-	;
-
-PIPE
-	:	'|'
-	;
-
-DOUBLE_PIPE
-	:	'||'
-	;
-
-PARAM	:	'?'
-	;
-
-GREATER
-	:	'>'
-	;
-
-GREATER_EQUAL
-	:	'>='
-	;
-
-LESS
-	:	'<'
-	;
-
-LESS_EQUAL
-	:	'<='
-	;
-
-ARROW
-	:	'->'
-	;
-
-IDENTIFIER
-	:	('a'..'z'|'A'..'Z'|'_'|'$'|'\u0080'..'\ufffe')('a'..'z'|'A'..'Z'|'_'|'$'|'0'..'9'|'\u0080'..'\ufffe')*
-	;
-
-QUOTED_IDENTIFIER
-    : '`' ( ESCAPE_SEQUENCE | ~('\\'|'`') )* '`'
-    ;
-
-LEFT_PAREN
-        :	'('
-        ;
-
-RIGHT_PAREN
-        :	')'
-        ;
-
-LEFT_SQUARE
-        :	'['
-        ;
-
-RIGHT_SQUARE
-        :	']'
-        ;        
-
-COMMA	:	','
-	;
-	
-DOT	:	'.'
-	;
-
-PLUS	:	'+'
-	;
-
-MINUS	:	'-'
-	;
-
-ASTERISK
-	:	'*'	
-	;
-
-SOLIDUS	:	'/'	
-	;
-
-PERCENT	:	'%'	
-	;
-
-AMPERSAND
-	:	'&'	
-	;
\ No newline at end of file

Deleted: core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLParser.g
===================================================================
--- core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLParser.g	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/parse/HQLParser.g	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,1469 +0,0 @@
-parser grammar HQLParser;
-
-options {
-	tokenVocab=HQLLexer;
-	output=AST;
-}
-
- at parser::header {
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- *
- * Portions of SQL grammar parsing copyright (C) 2003 by Lubos Vnuk.  All rights
- * reserved.  These portions are distributed under license by Red Hat Middleware
- * LLC and are covered by the above LGPL notice.  If you redistribute this material,
- * with or without modification, you must preserve this copyright notice in its
- * entirety.
- */
-package org.hibernate.sql.ast.phase.hql.parse;
-
-import java.util.LinkedList;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.Iterator;
-import org.hibernate.sql.ast.tree.EntityNameTree;
-}
-
- at parser::members {
-	private Stack enableParameterUsage = new Stack();
-	private ParserContext context = new ParserContextDefaultImpl();
-    private List errorMessages = new LinkedList();
-
-	public void setParserContext(ParserContext context){
-		this.context = context;
-	}
-
-	private boolean validateIdentifierKey(String text) {
-		return validateLT(1, text);
-	}
-	
-	private boolean validateLT(int LTNumber, String text) {
-		String text2Validate = retrieveLT( LTNumber );
-		return text2Validate == null ? false : text2Validate.equalsIgnoreCase(text);
-	}
-
-	private String retrieveLT(int LTNumber) {
-      		if (null == input)
-			return null;
-		if (null == input.LT(LTNumber))
-			return null;
-		if (null == input.LT(LTNumber).getText())
-			return null;
-	
-		return input.LT(LTNumber).getText();
-	}
-
-	public boolean hasErrors(){
-	   if ( errorMessages.size() > 0 ) {
-	       return true;
-       }
-       return false;
-	}
-	
-	public List getErrorMessages(){
-	   return errorMessages;
-	}
-
-    public void reportError( RecognitionException e ) {
-        errorMessages.add(generateError(getRuleInvocationStack(e, this.getClass().getName()), this.getTokenNames(), e));
-        super.reportError(e);
-    }
-
-    private String generateError( List invocationStack,
-                                String[] tokenNames,
-                                RecognitionException e ) {
-        String localization = invocationStack + ": line " + e.line + ":" + e.charPositionInLine + " ";
-        return generateError(localization, tokenNames, e);
-    }
-
-    private String generateError( String localization,
-                                String[] tokenNames,
-                                RecognitionException e ) {
-        String message = "";
-        if (e instanceof MismatchedTokenException) {
-            MismatchedTokenException mte = (MismatchedTokenException)e;
-            String tokenName = "<unknown>";
-            if (mte.expecting == Token.EOF) {
-                tokenName = "EOF";
-            } else {
-                if (tokenNames != null) {
-                    tokenName = tokenNames[mte.expecting];
-                }
-            }
-            message = localization + "mismatched token: " + e.token + "; expecting type " + tokenName;
-        } else if (e instanceof MismatchedTreeNodeException) {
-            MismatchedTreeNodeException mtne = (MismatchedTreeNodeException)e;
-            String tokenName = "<unknown>";
-            if (mtne.expecting == Token.EOF) {
-                tokenName = "EOF";
-            } else {
-                tokenName = tokenNames[mtne.expecting];
-            }
-            message = localization + "mismatched tree node: " + mtne.node + "; expecting type " + tokenName;
-        } else if (e instanceof NoViableAltException) {
-            NoViableAltException nvae = (NoViableAltException)e;
-            message = localization + "state " + nvae.stateNumber + " (decision=" + nvae.decisionNumber
-                      + ") no viable alt; token=" + e.token;
-        } else if (e instanceof EarlyExitException) {
-            EarlyExitException eee = (EarlyExitException)e;
-            message = localization + "required (...)+ loop (decision=" + eee.decisionNumber + ") did not match anything; token="
-                      + e.token;
-        } else if (e instanceof MismatchedSetException) {
-            MismatchedSetException mse = (MismatchedSetException)e;
-            message = localization + "mismatched token: " + e.token + "; expecting set " + mse.expecting;
-        } else if (e instanceof MismatchedNotSetException) {
-            MismatchedNotSetException mse = (MismatchedNotSetException)e;
-            message = localization + "mismatched token: " + e.token + "; expecting set " + mse.expecting;
-        } else if (e instanceof FailedPredicateException) {
-            FailedPredicateException fpe = (FailedPredicateException)e;
-            message = localization + "rule " + fpe.ruleName + " failed predicate: {" + fpe.predicateText + "}?";
-        }
-        
-        return message;
-    }
-    
-    private List extractEntityNames(String entityName) throws RecognitionException {
-    	List implementors = context.getEntityImplementors(entityName);
-    	if (implementors == null){
-    		throw new RecognitionException( );
-    	}
-    	return implementors;
-    }
-    
-	private Tree generatePersisterSpacesTree(List persistenceSpaces) {
-	    List persisterSpaceList = new ArrayList();
-	    for (Iterator iterator = persistenceSpaces.iterator(); iterator
-				.hasNext();) {
-			Tree persistenceSpaceData = (Tree) iterator.next();
-			if (persistenceSpaceData.getType() == PERSISTER_JOIN || persistenceSpaceData.getType() == PROPERTY_JOIN){
-				adaptor.addChild(persisterSpaceList.get(persisterSpaceList.size() - 1), persistenceSpaceData);
-			} else {
-			    Object persistenceSpaceTree = (Object)adaptor.nil();
-			    persistenceSpaceTree = adaptor.becomeRoot((Object)adaptor.create(PERSISTER_SPACE, "PERSISTER_SPACE"), persistenceSpaceTree);
-			    adaptor.addChild(persistenceSpaceTree, persistenceSpaceData);
-			    persisterSpaceList.add(persistenceSpaceTree);
-			}
-		}
-	    Tree resultTree = (Tree) adaptor.nil();
-	    for (Iterator iterator = persisterSpaceList.iterator(); iterator
-				.hasNext();) {
-			Object persistenceElement = (Object) iterator.next();
-			adaptor.addChild(resultTree, persistenceElement);
-		}
-
-		return resultTree;
-	}
-
-	private Tree generateUpdateStatementTree(Object updateKey,
-			Object entityName, Object aliasClause, Object setClause,
-			Object whereClause) {
-		Tree result = new CommonTree();
-		EntityNameTree entityNameTree = (EntityNameTree) entityName;
-		for (int i = 0; i < entityNameTree.getEntityCount(); i++) {
-			Tree updateRoot = new CommonTree((CommonTree) updateKey);
-
-			updateRoot.addChild(new EntityNameTree(entityNameTree,
-					entityNameTree.getEntityName(i)));
-
-			if (aliasClause != null) {
-				updateRoot.addChild((Tree) aliasClause);
-			}
-			updateRoot.addChild((Tree) setClause);
-
-			if (whereClause != null) {
-				updateRoot.addChild((Tree) whereClause);
-			}
-
-			result.addChild(updateRoot);
-		}
-		return result;
-	}
-
-	private Tree generateDeleteStatementTree(Object deleteKey,
-			Object entityName, Object aliasClause, Object whereClause) {
-		Tree result = new CommonTree();
-		EntityNameTree entityNameTree = (EntityNameTree) entityName;
-		for (int i = 0; i < entityNameTree.getEntityCount(); i++) {
-			Tree deleteRoot = new CommonTree((CommonTree) deleteKey);
-
-			deleteRoot.addChild(new EntityNameTree(entityNameTree,
-					entityNameTree.getEntityName(i)));
-
-			if (aliasClause != null) {
-				deleteRoot.addChild((Tree) aliasClause);
-			}
-
-			if (whereClause != null) {
-				deleteRoot.addChild((Tree) whereClause);
-			}
-
-			result.addChild(deleteRoot);
-		}
-		return result;
-	}
-	
-	private Tree generateSelecFromTree(Object selectClause, Object fromClause, List aliasList){
-		Tree result = new CommonTree(new CommonToken(SELECT_FROM, "SELECT_FROM"));
-		Tree selectTree = null;
-		result.addChild((Tree) fromClause);
-		if (selectClause == null && aliasList != null && aliasList.size() > 0) {
-			selectTree = new CommonTree(new CommonToken(SELECT, "SELECT"));
-			Tree selectList = new CommonTree(new CommonToken(SELECT_LIST, "SELECT_LIST"));
-			for (Iterator iterator = aliasList.iterator(); iterator
-					.hasNext();) {
-				String aliasName = (String) iterator.next();
-				Tree selectElement = new CommonTree(new CommonToken(SELECT_ITEM, "SELECT_ITEM"));
-				Tree aliasElement = new CommonTree(new CommonToken(ALIAS_REF, aliasName));
-				selectElement.addChild(aliasElement);
-				selectList.addChild(selectElement);
-			}
-			selectTree.addChild(selectList);
-		} else {
-			selectTree = (Tree) selectClause;
-		}
-		result.addChild(selectTree);
-		return result;
-	}
-}
-
-filterStatement[String collectionRole]
- at init	{ if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
- at after	{ enableParameterUsage.pop(); }
-	:	selectClause? from_key? whereClause? ( groupByClause havingClause?)? orderByClause?
-		-> ^(QUERY ^(QUERY_SPEC["filter-query-spec"] FILTER[$collectionRole] 
-				selectClause? from_key? whereClause? ( groupByClause havingClause?)? orderByClause?))
-	//TODO throw an exception here when using from
-	;
-
-statement
- at init	{ if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
- at after	{ enableParameterUsage.pop(); }
-	:	updateStatement
-	|	deleteStatement
-	|	insertStatement
-	|	selectStatement
-	;
-
-updateStatement
-scope{
-	boolean generateVersionedField;
-}	:	udpate_key
-		(versioned_key {$updateStatement::generateVersionedField = true;})? 
-			from_key? entityName aliasClause[true] setClause whereClause?
-		-> {	generateUpdateStatementTree($udpate_key.tree, $entityName.tree, $aliasClause.tree, $setClause.tree, $whereClause.tree )	}
-	;
-
-//TODO: check what is necessary to generate at versioned field
-setClause
-	:	set_key assignment (COMMA assignment)*
-		-> {$updateStatement::generateVersionedField}? ^(set_key assignment+ ^(EQUALS VERSIONED_VALUE STRING_LITERAL))
-		-> ^(set_key assignment+)
-	;
-
-assignment
-	:	assignmentField EQUALS^ concatenation
-	;
-
-assignmentField
-	:	dotIdentifierPath -> ^(PROPERTY_REFERENCE dotIdentifierPath)
-	;
-
-deleteStatement
-	:	delete_key from_key? entityName aliasClause[true] whereClause?
-		-> {	generateDeleteStatementTree($delete_key.tree, $entityName.tree, $aliasClause.tree, $whereClause.tree )	}
-	;
-
-insertStatement
-	:	insert_key^ 
-		intoClause selectStatement
-	;
-
-//TODO: Generate an exception when try to use a polimorfic entity at INTO clause
-intoClause
-	:	into_key entityName insertabilitySpecification
-		-> ^(into_key entityName ALIAS_NAME[context.buildUniqueImplicitAlias()] insertabilitySpecification)
-	;
-
-insertabilitySpecification
-	:	LEFT_PAREN insertablePropertySpecification ( COMMA insertablePropertySpecification )* RIGHT_PAREN
-		-> ^(INSERTABILITY_SPEC insertablePropertySpecification+ )
-	;
-
-insertablePropertySpecification
-	:	dotIdentifierPath -> ^(PROPERTY_REFERENCE dotIdentifierPath)
-	;
-
-selectStatement
-	:	queryExpression orderByClause?
-		-> ^(QUERY queryExpression orderByClause?)
-	;
-
-//Think about the exception generation where Polimorfic queris are used inside a Mix of results (union, intersect and except) 
-queryExpression
-	:	querySpec ( ( union_key^ | intersect_key^ | except_key^ ) all_key? querySpec )*
-	;
-
-querySpec
-	:	selectFrom whereClause? ( groupByClause havingClause? )?
-		-> ^(QUERY_SPEC selectFrom whereClause? groupByClause? havingClause?)
-	;
-
-groupByClause
-	:	group_by_key^ groupingSpecification
-	;
-
-havingClause
-	:	having_key^ logicalExpression
-	;
-
-groupingSpecification
-	:	groupingValue ( COMMA! groupingValue )*
-	;
-
-groupingValue
-	:	concatenation collationSpecification?
-		-> ^(GROUPING_VALUE concatenation collationSpecification?)
-	;
-
-whereClause
-	:	where_key^ logicalExpression
-	;
-
-selectFrom
-	:	sc=selectClause? fc=fromClause
-		-> { generateSelecFromTree($sc.tree, $fc.tree, $fc.aliasList)}
-	;
-
-subQuery
- at init	{ if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
- at after	{ enableParameterUsage.pop(); }
-	:	queryExpression
-		-> ^(SUB_QUERY ^(QUERY queryExpression))
-	;
-
-fromClause returns [List aliasList]
-scope{
-	List aliases;
-}
- at init	{	$fromClause::aliases = new ArrayList();	}
- at after	{	$aliasList = $fromClause::aliases;	}
-	:	from_key^ 
-			persisterSpaces
-	;
-
-persisterSpaces
-	:	ps+=persisterSpace ( COMMA ps+=persisterSpace )*
-		-> {generatePersisterSpacesTree($ps)}
-	;
-
-persisterSpace
-	:	persisterSpaceRoot ( qualifiedJoin | crossJoin )*
-	;
-
-crossJoin
-	:	cross_key join_key mainEntityPersisterReference
-		-> ^(PERSISTER_JOIN[$join_key.start,"persister-join"] cross_key mainEntityPersisterReference) 
-	;
-
-qualifiedJoin
- at init	{ boolean isEntityReference = false; boolean hasFetch = false; List entityNames = null; }
- at after	{ if (!hasFetch) $fromClause::aliases.add(((Tree)$ac.tree).getText()); }
-	:	nonCrossJoinType join_key (fetch_key {hasFetch = true;})? path ac=aliasClause[true]
-	(	on_key 
-	{	isEntityReference = true;
-		entityNames = extractEntityNames($path.text);	} 
-		logicalExpression 
-	|	propertyFetch? withClause?
-	)
-	-> {isEntityReference}? ^(PERSISTER_JOIN[$join_key.start,"persister-join"] nonCrossJoinType ^(ENTITY_PERSISTER_REF ENTITY_NAME<EntityNameTree>[$path.start, $path.text, entityNames] aliasClause?) ^(on_key logicalExpression))
-	-> ^(PROPERTY_JOIN[$join_key.start, "property-join"] nonCrossJoinType fetch_key? aliasClause? propertyFetch? ^(PROPERTY_REFERENCE path) withClause?)
-	;
-
-withClause
-	:	with_key^ logicalExpression
-	;
-
-nonCrossJoinType
-	:	inner_key
-	|	outerJoinType outer_key?
-	|	-> INNER
-	;
-
-outerJoinType
-	:	left_key
-	|	right_key
-	|	full_key
-	;
-
-persisterSpaceRoot
-options{
-backtrack=true;
-}	:	mainEntityPersisterReference
-	|	jpaCollectionReference
-	|	hibernateLegacySyntax
-	;
-
-mainEntityPersisterReference
- at after	{ $fromClause::aliases.add(((Tree)$ac.tree).getText()); }
-	:	entityName ac=aliasClause[true] propertyFetch?
-		-> ^(ENTITY_PERSISTER_REF entityName aliasClause? propertyFetch?)
-	;
-
-propertyFetch
-	:	fetch_key all_key properties_key
-		-> PROP_FETCH[$fetch_key.start, "property-fetch"]
-	;
-
-hibernateLegacySyntax returns [boolean isPropertyJoin]
- at init {$isPropertyJoin = false;}
- at after	{ $fromClause::aliases.add(((Tree)$ad.tree).getText()); }
-	:	ad=aliasDeclaration in_key
-	(	class_key entityName -> ^(ENTITY_PERSISTER_REF entityName aliasDeclaration) 
-	|	collectionExpression {$isPropertyJoin = true;} -> ^(PROPERTY_JOIN INNER[$in_key.start, "inner legacy"] aliasDeclaration collectionExpression)
-	)
-	;
-
-jpaCollectionReference
- at after	{ $fromClause::aliases.add(((Tree)$ac.tree).getText()); }
-	:	in_key LEFT_PAREN propertyReference RIGHT_PAREN ac=aliasClause[true]
-		-> ^(PROPERTY_JOIN INNER[$in_key.start, "inner"] aliasClause? propertyReference) 
-	;
-
-selectClause
-	:	select_key^ distinct_key? rootSelectExpression 
-	;
-
-rootSelectExpression
-	:	rootDynamicInstantiation
-	|	jpaSelectObjectSyntax
-	|	explicitSelectList
-	;
-
-explicitSelectList
-	:	explicitSelectItem ( COMMA explicitSelectItem )*
-		-> ^(SELECT_LIST explicitSelectItem+)
-	;
-
-explicitSelectItem
-	:	selectExpression
-	;
-
-selectExpression
- at init	{ if (state.backtracking == 0) enableParameterUsage.push(Boolean.FALSE); }
- at after	{ enableParameterUsage.pop(); }
-//PARAMETERS CAN'T BE USED -> This verification should be scoped
-	:	expression aliasClause[false]
-		-> ^(SELECT_ITEM expression aliasClause?)
-	;
-
-aliasClause[boolean generateAlias]
-options{
-    k=2;
-}	:	-> {$generateAlias}? ALIAS_NAME[context.buildUniqueImplicitAlias()]
-		->
-	|	aliasDeclaration
-	|	as_key! aliasDeclaration
-	;
-
-aliasDeclaration
-	:	IDENTIFIER -> ALIAS_NAME[$IDENTIFIER]
-	;
-
-aliasReference
-	:	IDENTIFIER -> ALIAS_REF[$IDENTIFIER] 
-	;
-
-rootDynamicInstantiation
-	:	new_key dynamicInstantiationTarget LEFT_PAREN dynamicInstantiationArgs RIGHT_PAREN
-		-> ^(SELECT_ITEM ^(DYNAMIC_INSTANTIATION[$dynamicInstantiationTarget.start, $dynamicInstantiationTarget.text] dynamicInstantiationArgs))
-	;
-
-dynamicInstantiationTarget
-	:	dotIdentifierPath
-	;
-
-dynamicInstantiationArgs
-	:	dynamicInstantiationArg ( COMMA! dynamicInstantiationArg )*
-	;
-
-dynamicInstantiationArg
-	:	selectExpression -> ^(DYNAMIC_INSTANTIATION_ARG selectExpression)
-	|	rootDynamicInstantiation -> ^(DYNAMIC_INSTANTIATION_ARG rootDynamicInstantiation)
-	;
-
-jpaSelectObjectSyntax
-	:	object_key LEFT_PAREN aliasReference RIGHT_PAREN
-		-> ^(SELECT_ITEM aliasReference) 
-	;
-
-orderByClause
-	:	order_by_key^ sortSpecification ( COMMA! sortSpecification )*
-	;
-
-sortSpecification
- at init{boolean generateOmmitedElement = true;}
-	:	sortKey collationSpecification? (orderingSpecification {generateOmmitedElement = false;})?
-		-> {generateOmmitedElement}? ^(SORT_SPEC sortKey collationSpecification? ORDER_SPEC["asc"])
-		-> ^(SORT_SPEC sortKey collationSpecification? orderingSpecification?)
-	;
-
-sortKey
- at init	{ if (state.backtracking == 0) enableParameterUsage.push(Boolean.FALSE); }
- at after	{ enableParameterUsage.pop(); }
-//PARAMETERS CAN'T BE USED -> This verification should be scoped
-	:	concatenation
-	;
-
-collationSpecification
-	:	collate_key collateName
-	->	COLLATE[$collateName.start, $collateName.text]
-	;
-
-collateName
-	:	dotIdentifierPath
-	;
-
-orderingSpecification
-	:	ascending_key -> ORDER_SPEC[$ascending_key.start, "asc"]
-	|	descending_key -> ORDER_SPEC[$descending_key.start, "desc"]
-	;
-
-logicalExpression
-	:	expression
-	;
-
-expression
-	:	logicalOrExpression
-	;
-
-logicalOrExpression
-	:	logicalAndExpression ( or_key^ logicalAndExpression )*
-	;
-
-logicalAndExpression
-	:	negatedExpression ( and_key^ negatedExpression )*
-	;
-
-negatedExpression
-	:	not_key^ negatedExpression
-	|	equalityExpression
-	;
-
-equalityExpression
- at init{ boolean isNull = false; boolean isNegated = false;}
-	:	(relationalExpression -> relationalExpression) 
-	(	is_key (not_key {isNegated = true;})? (NULL {isNull = true;}|empty_key)
-		-> {isNull && isNegated}? ^(IS_NOT_NULL[$not_key.start, "is not null"] $equalityExpression)
-		-> {isNull && !isNegated}? ^(IS_NULL[$NULL, "is null"] $equalityExpression)
-		-> {!isNull && isNegated}? ^(IS_NOT_EMPTY $equalityExpression)
-		-> ^(IS_EMPTY $equalityExpression)
-	|	( op=EQUALS | op=NOT_EQUAL ) relationalExpression
-		-> ^($op $equalityExpression relationalExpression)
-	)*
-	;
-
-relationalExpression
- at init {boolean isNegated = false;} 
-	:	(concatenation -> concatenation)
-	( 
-	(	( op=LESS | op=GREATER | op=LESS_EQUAL | op=GREATER_EQUAL ) additiveExpression
-			-> ^($op $relationalExpression additiveExpression) 
-		)+
-	|  (not_key {isNegated = true;} )?
-		(	in_key inList
-			-> {isNegated}? ^(NOT_IN[$not_key.start, "not in"] $relationalExpression inList)
-			-> ^(in_key $relationalExpression inList) 
-		|	between_key betweenList
-			-> {isNegated}? ^(NOT_BETWEEN[$not_key.start, "not between"] $relationalExpression betweenList)
-			-> ^(between_key $relationalExpression betweenList)
-		|	like_key concatenation likeEscape?
-			-> {isNegated}? ^(NOT_LIKE[$not_key.start, "not like"] $relationalExpression concatenation likeEscape?) 
-			-> ^(like_key $relationalExpression concatenation likeEscape?)
-		|	member_of_key path
-			-> {isNegated}? ^(NOT_MEMBER_OF[$not_key.start, "not member of"] $relationalExpression ^(PATH path))
-			-> ^(member_of_key $relationalExpression ^(PATH path))
-		)
-	)?
-	;
-
-likeEscape
-	:	escape_key^ concatenation
-	;
-
-inList
-	:	collectionExpression
-		-> ^(IN_LIST collectionExpression)
-	|	LEFT_PAREN ( {((validateIdentifierKey("select")|validateIdentifierKey("from")))}?=> subQuery | concatenation (COMMA concatenation)* ) RIGHT_PAREN
-		-> ^(IN_LIST concatenation* subQuery?)
-	;
-
-betweenList
-	:	concatenation and_key concatenation
-		-> ^(BETWEEN_LIST concatenation+)
-	;
-
-concatenation
-	:	additiveExpression (DOUBLE_PIPE^ {enableParameterUsage.push(Boolean.TRUE);} additiveExpression { enableParameterUsage.pop(); })*
-	;
-
-additiveExpression
-	:	multiplyExpression ( ( PLUS^ | MINUS^ ) {enableParameterUsage.push(Boolean.TRUE);} multiplyExpression { enableParameterUsage.pop(); })*
-	;
-
-multiplyExpression
-	:	unaryExpression ( ( ASTERISK^ | SOLIDUS^ ) {enableParameterUsage.push(Boolean.TRUE);} unaryExpression { enableParameterUsage.pop(); })*
-	;
-
-unaryExpression
-	:	MINUS unaryExpression -> ^(UNARY_MINUS[$MINUS] unaryExpression)
-	|	PLUS unaryExpression -> ^(UNARY_PLUS[$PLUS] unaryExpression)
-	|	caseExpression
-	|	quantifiedExpression
-	|	standardFunction
-	|	setFunction
-	|	collectionFunction
-	|	collectionExpression
-	|	atom
-	;
-
-caseExpression
- at init	{ if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
- at after	{ enableParameterUsage.pop(); }
-	:	caseAbbreviation
-	|	caseSpecification
-	;
-
-caseAbbreviation
-	:	nullif_key^ LEFT_PAREN! concatenation COMMA! concatenation RIGHT_PAREN!
-	|	coalesce_key^ LEFT_PAREN! concatenation (COMMA! concatenation)* RIGHT_PAREN!
-	;
-
-caseSpecification
-options{
-backtrack=true;
-}	:	simpleCase
-	|	searchedCase
-	;
-
-simpleCase
-	:	case_key concatenation simpleCaseWhenClause+ elseClause? end_key
-	->	^(SIMPLE_CASE[$case_key.start, $case_key.text] concatenation simpleCaseWhenClause+ elseClause?)
-	;
-
-simpleCaseWhenClause
-	:	when_key^ concatenation then_key! concatenation
-	;
-
-elseClause
-	:	else_key^ concatenation
-	;
-
-searchedCase
-	:	case_key searchedWhenClause+ elseClause? end_key
-	->	^(SEARCHED_CASE[$case_key.start, $case_key.text] searchedWhenClause+ elseClause?)
-	;
-
-searchedWhenClause
-	:	when_key^ logicalExpression then_key! concatenation
-	;
-
-quantifiedExpression
-	:	( some_key^ | exists_key^ | all_key^ | any_key^ ) 
-	(	collectionExpression
-	|	aliasReference
-	|	LEFT_PAREN! subQuery RIGHT_PAREN!
-	)
-	;
-
-standardFunction
- at init	{ if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
- at after	{ enableParameterUsage.pop(); }
-	:	castFunction
-	|	concatFunction
-	|	substringFunction
-	|	trimFunction
-	|	upperFunction
-	|	lowerFunction
-	|	lengthFunction
-	|	locateFunction
-	|	absFunction
-	|	sqrtFunction
-	|	modFunction
-	|	sizeFunction
-	|	indexFunction
-	|	currentDateFunction
-	|	currentTimeFunction
-	|	currentTimestampFunction
-	|	extractFunction
-	|	positionFunction
-	|	charLengthFunction
-	|	octetLengthFunction
-	|	bitLengthFunction
-	;
-
-castFunction
-	:	cast_key^ LEFT_PAREN! concatenation as_key! dataType RIGHT_PAREN!
-	;
-
-concatFunction
-	:	concat_key^ LEFT_PAREN! concatenation ( COMMA! concatenation )+ RIGHT_PAREN!
-	;
-
-substringFunction
-	:	substring_key^ LEFT_PAREN! concatenation COMMA! concatenation ( COMMA! concatenation)? RIGHT_PAREN!
-	;
-
-trimFunction
-	:	trim_key LEFT_PAREN trimOperands RIGHT_PAREN
-		-> ^(trim_key trimOperands)
-	;
-
-trimOperands
-options{
-k=2;
-}
- at init {boolean hasSecondExpression = false;}
-	:	trimSpecification from_key concatenation -> ^(trimSpecification STRING_LITERAL[" "] concatenation)
-	|	trimSpecification concatenation from_key concatenation -> ^(trimSpecification concatenation+)
-	|	from_key concatenation -> ^(BOTH STRING_LITERAL[" "] concatenation)
-	|	cn=concatenation ( from_key concatenation {hasSecondExpression = true;} )?
-		-> {hasSecondExpression}? ^(BOTH concatenation+)
-		-> ^(BOTH STRING_LITERAL[" "] $cn)
-	;
-
-trimSpecification
-	:	leading_key
-	|	trailing_key
-	|	both_key
-	;
-
-upperFunction
-	:	upper_key^ LEFT_PAREN! concatenation RIGHT_PAREN!
-	;
-
-lowerFunction
-	:	lower_key^ LEFT_PAREN! concatenation RIGHT_PAREN!
-	;
-
-lengthFunction
-	:	length_key^ LEFT_PAREN! concatenation RIGHT_PAREN!
-	;
-
-locateFunction
-	:	locate_key^ LEFT_PAREN! concatenation COMMA! concatenation ( COMMA! concatenation )? RIGHT_PAREN!
-	;
-
-absFunction
-	:	abs_key^ LEFT_PAREN! concatenation RIGHT_PAREN!
-	;
-
-sqrtFunction
-	:	sqrt_key^ LEFT_PAREN! concatenation RIGHT_PAREN!
-	;
-
-modFunction
-	:	mod_key^ LEFT_PAREN! concatenation COMMA! concatenation RIGHT_PAREN!
-	;
-
-sizeFunction
-	:	size_key^ LEFT_PAREN! propertyReference RIGHT_PAREN!
-	;
-
-indexFunction
-	:	index_key^ LEFT_PAREN! aliasReference RIGHT_PAREN!
-	;
-
-currentDateFunction
-	:	current_date_key ( LEFT_PAREN! RIGHT_PAREN! )?
-	;
-
-currentTimeFunction
-	:	current_time_key ( LEFT_PAREN! RIGHT_PAREN! )?
-	;
-
-currentTimestampFunction
-	:	current_timestamp_key ( LEFT_PAREN! RIGHT_PAREN! )?
-	;
-
-extractFunction
-	:	extract_key^ LEFT_PAREN! extractField from_key! concatenation RIGHT_PAREN!
-	;
-
-extractField
-	:	datetimeField
-	|	timeZoneField
-	;
-
-datetimeField
-	:	nonSecondDatetimeField
-	|	second_key
-	;
-
-nonSecondDatetimeField
-	:	year_key
-	|	month_key
-	|	day_key
-	|	hour_key
-	|	minute_key
-	;
-
-timeZoneField
-	:	timezone_hour_key
-	|	timezone_minute_key
-	;
-
-positionFunction
-	:	position_key^ LEFT_PAREN! concatenation in_key! concatenation RIGHT_PAREN!
-	;
-
-charLengthFunction
-	:	character_length_key^ LEFT_PAREN! concatenation RIGHT_PAREN!
-	;
-
-octetLengthFunction
-	:	octet_length_key^ LEFT_PAREN! concatenation RIGHT_PAREN!
-	;
-
-bitLengthFunction
-	:	bit_length_key^ LEFT_PAREN! concatenation RIGHT_PAREN!
-	;
-
-setFunction
- at init	{ boolean generateOmmitedElement = true; if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
- at after	{ enableParameterUsage.pop(); }
-	:	( sum_key^ | avg_key^ | max_key^ | min_key^ ) LEFT_PAREN! additiveExpression RIGHT_PAREN!
-	|	count_key LEFT_PAREN ( ASTERISK {generateOmmitedElement = false;} | ( ( (distinct_key | all_key) {generateOmmitedElement = false;} )? countFunctionArguments ) ) RIGHT_PAREN
-		-> {generateOmmitedElement}? ^(count_key ASTERISK? ALL countFunctionArguments?)
-		-> ^(count_key ASTERISK? distinct_key? all_key? countFunctionArguments?)
-	;
-
-countFunctionArguments
- at init { int type = -1;}
-	:	propertyReference
-	|	collectionExpression
-	|	numeric_literal
-	;
-
-collectionFunction
- at init	{ if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
- at after	{ enableParameterUsage.pop(); }
-	:	( maxelement_key^ | maxindex_key^ | minelement_key^ | minindex_key^ ) LEFT_PAREN! propertyReference RIGHT_PAREN!
-	;
-
-collectionExpression
-	:	(elements_key^|indices_key^) LEFT_PAREN! propertyReference RIGHT_PAREN!
-	;
-
-atom
- at init { int type = -1;}
-	:	identPrimary
-	    //TODO  if ends with:
-	    //  .class -> class type
-	    //  if contains "()" it is a function call 
-	    //  if it is constantReference (using context)
-	    //  otherwise it will be a generic element to be resolved on the next phase (1st tree walker)
-	    -> {type == 0}? ^(DOT_CLASS identPrimary)
-	    -> {type == 3}? ^(GENERAL_FUNCTION_CALL identPrimary)
-	    -> {type == 4}? ^(JAVA_CONSTANT identPrimary) //-> here will have 2 strutctures element and the constant
-	    -> ^(PATH identPrimary)
-	|	constant
-	|	parameterSpecification { if (enableParameterUsage.peek().equals(Boolean.FALSE)) throw new RecognitionException( ); }
-	//validate using Scopes if it is enabled or not to use parameterSpecification.. if not generate an exception 
-	|	LEFT_PAREN! ({((validateIdentifierKey("select")|validateIdentifierKey("from")))}?=> subQuery|expressionOrVector) RIGHT_PAREN!
-	;
-
-parameterSpecification
- at init {boolean isJpaParam = false;}
-	:	COLON IDENTIFIER -> NAMED_PARAM[$IDENTIFIER]
-	|	PARAM (INTEGER_LITERAL {isJpaParam = true;})?
-		-> {isJpaParam}? JPA_PARAM[$INTEGER_LITERAL]
-		-> PARAM	
-	;
-
-expressionOrVector
- at init {boolean isVectorExp = false;}
-	:	expression (vectorExpr {isVectorExp = true;})?
-		-> {isVectorExp}? ^(VECTOR_EXPR expression vectorExpr) 
-		-> expression
-	;
-
-vectorExpr
- at init	{ if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
- at after	{ enableParameterUsage.pop(); }
-	:	COMMA! expression (COMMA! expression)*
-	;
-
-identPrimary
-	: 	IDENTIFIER
-		(	DOT^ IDENTIFIER
-		|	LEFT_SQUARE^ expression RIGHT_SQUARE!
-		|	LEFT_SQUARE^ RIGHT_SQUARE!
-		|	LEFT_PAREN^ exprList RIGHT_PAREN!
-		)*
-	;
-
-exprList
- at init	{ if (state.backtracking == 0) enableParameterUsage.push(Boolean.TRUE); }
- at after	{ enableParameterUsage.pop(); }
-	:	expression? (COMMA! expression)*
-	;
-
-constant
-	:	literal
-	|	NULL
-	|	TRUE
-	|	FALSE
-	;
-
-literal
-	:	numeric_literal
-	|	HEX_LITERAL
-	|	OCTAL_LITERAL
-	|	CHARACTER_LITERAL
-	|	STRING_LITERAL
-	;
-
-numeric_literal
-	:	INTEGER_LITERAL
-	|	DECIMAL_LITERAL
-	|	FLOATING_POINT_LITERAL
-	;
-
-entityName
- at init	{ List entityNames = null; }
-	:	dotIdentifierPath
-	{	entityNames = extractEntityNames($dotIdentifierPath.text);	}
-	//here the polimorfic entities should be resolved... to:
-	   // 1. to place inside the ENTITY_NAME Token all its possible values, otherwise it would be much difficult to return to the place that should explit the sentence 
-	   // 2. enable exception geration when not supported (union, insert)
-		-> ENTITY_NAME<EntityNameTree>[$dotIdentifierPath.start, $dotIdentifierPath.text, entityNames]
-	;
-
-propertyReference
-	:	path
-		-> ^(PROPERTY_REFERENCE path)
-	;
-
-dataType
-	:	IDENTIFIER
-	;
-
-dotIdentifierPath
-	:	IDENTIFIER 
-		(	DOT^ IDENTIFIER		)*
-	;
-
-path
-	:	IDENTIFIER 
-		(	DOT^ IDENTIFIER
-		|	LEFT_SQUARE^ expression RIGHT_SQUARE!
-		|	LEFT_SQUARE^ RIGHT_SQUARE!
-		)*
-	;
-
-class_key
-	:	{(validateIdentifierKey("class"))}?=>  id=IDENTIFIER
-		->	CLASS[$id]
-	;
-
-new_key
-	:	{(validateIdentifierKey("new"))}?=>  id=IDENTIFIER
-		->	NEW[$id]
-	;
-
-else_key
-	:	{(validateIdentifierKey("else"))}?=>  id=IDENTIFIER
-		->	ELSE[$id]
-	;
-
-object_key
-	:	{(validateIdentifierKey("object"))}?=>  id=IDENTIFIER
-	;
-
-case_key
-	:	{(validateIdentifierKey("case"))}?=>  IDENTIFIER
-	;
-
-current_date_key
-	:	{(validateIdentifierKey("current_date"))}?=>  id=IDENTIFIER
-		->	CURRENT_DATE[$id]
-	;
-
-current_time_key
-	:	{(validateIdentifierKey("current_time"))}?=>  id=IDENTIFIER
-		->	CURRENT_TIME[$id]
-	;
-
-current_timestamp_key
-	:	{(validateIdentifierKey("current_timestamp"))}?=>  id=IDENTIFIER
-		->	CURRENT_TIMESTAMP[$id]
-	;
-
-timezone_hour_key
-	:	{(validateIdentifierKey("timezone_hour"))}?=>  id=IDENTIFIER
-		->	TIMEZONE_HOUR[$id]
-	;
-
-timezone_minute_key
-	:	{(validateIdentifierKey("timezone_minute"))}?=>  id=IDENTIFIER
-		->	TIMEZONE_MINUTE[$id]
-	;
-
-character_length_key
-	:	{(validateIdentifierKey("character_length") || validateIdentifierKey("char_length"))}?=>  id=IDENTIFIER
-		->	CHARACTER_LENGTH[$id]
-	;
-
-octet_length_key
-	:	{(validateIdentifierKey("octet_length"))}?=>  id=IDENTIFIER
-		->	OCTET_LENGTH[$id]
-	;
-
-bit_length_key
-	:	{(validateIdentifierKey("bit_length"))}?=>  id=IDENTIFIER
-		->	BIT_LENGTH[$id]
-	;
-
-extract_key
-	:	{(validateIdentifierKey("extract"))}?=>  id=IDENTIFIER
-		->	EXTRACT[$id]
-	;
-
-second_key
-	:	{(validateIdentifierKey("second"))}?=>  id=IDENTIFIER
-		->	SECOND[$id]
-	;
-
-year_key
-	:	{(validateIdentifierKey("year"))}?=>  id=IDENTIFIER
-		->	YEAR[$id]
-	;
-
-month_key
-	:	{(validateIdentifierKey("month"))}?=>  id=IDENTIFIER
-		->	MONTH[$id]
-	;
-
-day_key
-	:	{(validateIdentifierKey("day"))}?=>  id=IDENTIFIER
-		->	DAY[$id]
-	;
-
-hour_key
-	:	{(validateIdentifierKey("hour"))}?=>  id=IDENTIFIER
-		->	HOUR[$id]
-	;
-
-minute_key
-	:	{(validateIdentifierKey("minute"))}?=>  id=IDENTIFIER
-		->	MINUTE[$id]
-	;
-
-position_key
-	:	{(validateIdentifierKey("position"))}?=>  id=IDENTIFIER
-		->	POSITION[$id]
-	;
-
-sum_key
-	:	{(validateIdentifierKey("sum"))}?=>  id=IDENTIFIER
-		->	SUM[$id]
-	;
-
-avg_key
-	:	{(validateIdentifierKey("avg"))}?=>  id=IDENTIFIER
-		->	AVG[$id]
-	;
-
-max_key
-	:	{(validateIdentifierKey("max"))}?=>  id=IDENTIFIER
-		->	MAX[$id]
-	;
-
-min_key
-	:	{(validateIdentifierKey("min"))}?=>  id=IDENTIFIER
-		->	MIN[$id]
-	;
-
-count_key
-	:	{(validateIdentifierKey("count"))}?=>  id=IDENTIFIER
-		->	COUNT[$id]
-	;
-
-maxelement_key
-	:	{(validateIdentifierKey("maxelement"))}?=>  id=IDENTIFIER
-		->	MAXELEMENT[$id]
-	;
-
-maxindex_key
-	:	{(validateIdentifierKey("maxindex"))}?=>  id=IDENTIFIER
-		->	MAXINDEX[$id]
-	;
-
-minelement_key
-	:	{(validateIdentifierKey("minelement"))}?=>  id=IDENTIFIER
-		->	MINELEMENT[$id]
-	;
-
-minindex_key
-	:	{(validateIdentifierKey("minindex"))}?=>  id=IDENTIFIER
-		->	MININDEX[$id]
-	;
-
-locate_key
-	:	{(validateIdentifierKey("locate"))}?=>  id=IDENTIFIER
-		->	LOCATE[$id]
-	;
-
-abs_key
-	:	{(validateIdentifierKey("abs"))}?=>  id=IDENTIFIER
-		->	ABS[$id]
-	;
-
-sqrt_key
-	:	{(validateIdentifierKey("sqrt"))}?=>  id=IDENTIFIER
-		->	SQRT[$id]
-	;
-
-mod_key
-	:	{(validateIdentifierKey("mod"))}?=>  id=IDENTIFIER
-		->	MOD[$id]
-	;
-
-size_key
-	:	{(validateIdentifierKey("size"))}?=>  id=IDENTIFIER
-		->	SIZE[$id]
-	;
-
-index_key
-	:	{(validateIdentifierKey("index"))}?=>  id=IDENTIFIER
-		->	INDEX[$id]
-	;
-
-leading_key
-	:	{(validateIdentifierKey("leading"))}?=>  id=IDENTIFIER
-		->	LEADING[$id]
-	;
-
-trailing_key
-	:	{(validateIdentifierKey("trailing"))}?=>  id=IDENTIFIER
-		->	TRAILING[$id]
-	;
-
-upper_key
-	:	{(validateIdentifierKey("upper"))}?=>  id=IDENTIFIER
-		->	UPPER[$id]
-	;
-
-lower_key
-	:	{(validateIdentifierKey("lower"))}?=>  id=IDENTIFIER
-		->	LOWER[$id]
-	;
-
-length_key
-	:	{(validateIdentifierKey("length"))}?=>  id=IDENTIFIER
-		->	LENGTH[$id]
-	;
-
-both_key
-	:	{(validateIdentifierKey("both"))}?=>  id=IDENTIFIER
-		->	BOTH[$id]
-	;
-
-trim_key
-	:	{(validateIdentifierKey("trim"))}?=>  id=IDENTIFIER
-		->	TRIM[$id]
-	;
-	
-substring_key
-	:	{(validateIdentifierKey("substring"))}?=>  id=IDENTIFIER
-		->	SUBSTRING[$id]
-	;
-
-concat_key
-	:	{(validateIdentifierKey("concat"))}?=>  id=IDENTIFIER
-		->	CONCAT[$id]
-	;
-
-cast_key
-	:	{(validateIdentifierKey("cast"))}?=>  id=IDENTIFIER
-		->	CAST[$id]
-	;
-
-any_key
-	:	{(validateIdentifierKey("any"))}?=>  id=IDENTIFIER
-		->	ANY[$id]
-	;
-
-exists_key
-	:	{(validateIdentifierKey("exists"))}?=>  id=IDENTIFIER
-		->	EXISTS[$id]
-	;
-
-some_key
-	:	{(validateIdentifierKey("some"))}?=>  id=IDENTIFIER
-		->	SOME[$id]
-	;
-
-then_key
-	:	{(validateIdentifierKey("then"))}?=>  id=IDENTIFIER
-		->	THEN[$id]
-	;
-
-end_key
-	:	{(validateIdentifierKey("end"))}?=>  id=IDENTIFIER
-		->	END[$id]
-	;
-
-
-when_key
-	:	{(validateIdentifierKey("when"))}?=>  id=IDENTIFIER
-		->	WHEN[$id]
-	;
-
-nullif_key
-	:	{(validateIdentifierKey("nullif"))}?=>  id=IDENTIFIER
-		->	NULLIF[$id]
-	;
-
-coalesce_key
-	:	{(validateIdentifierKey("coalesce"))}?=>  id=IDENTIFIER
-		->	COALESCE[$id]
-	;
-
-escape_key
-	:	{(validateIdentifierKey("escape"))}?=>  id=IDENTIFIER
-		->	ESCAPE[$id]
-	;
-
-like_key
-	:	{(validateIdentifierKey("like"))}?=>  id=IDENTIFIER
-		->	LIKE[$id]
-	;
-
-between_key
-	:	{(validateIdentifierKey("between"))}?=>  id=IDENTIFIER
-		->	BETWEEN[$id]
-	;
-
-member_of_key
- at init{
-	String text = "";
-}	:	{(validateIdentifierKey("member") && validateLT(2, "of"))}?=>  id=IDENTIFIER IDENTIFIER {text = $text;}
-		->	MEMBER_OF[$id]
-	;
-
-empty_key
-	:	{(validateIdentifierKey("empty"))}?=>  id=IDENTIFIER
-	;
-
-is_key	:	{(validateIdentifierKey("is"))}?=>  id=IDENTIFIER
-		->	IS[$id]
-	;
-
-or_key	:	{(validateIdentifierKey("or"))}?=>  id=IDENTIFIER
-		->	OR[$id]
-	;
-
-and_key	:	{(validateIdentifierKey("and"))}?=>  id=IDENTIFIER
-		->	AND[$id]
-	;
-
-not_key	:	{(validateIdentifierKey("not"))}?=>  id=IDENTIFIER
-		->	NOT[$id]
-	;
-
-set_key
-	:	{(validateIdentifierKey("set"))}?=>  id=IDENTIFIER
-		->	SET[$id]
-	;
-
-versioned_key
-	:	{(validateIdentifierKey("versioned"))}?=>  id=IDENTIFIER
-		->	VERSIONED[$id]
-	;
-
-udpate_key
-	:	{(validateIdentifierKey("update"))}?=>  id=IDENTIFIER
-		->	UPDATE[$id]
-	;
-
-delete_key
-	:	{(validateIdentifierKey("delete"))}?=>  id=IDENTIFIER
-		->	DELETE[$id]
-	;
-
-insert_key
-	:	{(validateIdentifierKey("insert"))}?=>  id=IDENTIFIER
-		->	INSERT[$id]
-	;
-
-into_key
-	:	{(validateIdentifierKey("into"))}?=>  id=IDENTIFIER
-		->	INTO[$id]
-	;
-
-having_key
-	:	{(validateIdentifierKey("having"))}?=>  id=IDENTIFIER
-		->	HAVING[$id]
-	;
-
-with_key
-	:	{(validateIdentifierKey("with"))}?=>  id=IDENTIFIER
-		->	WITH[$id]
-	;
-
-on_key
-	:	{(validateIdentifierKey("on"))}?=>  id=IDENTIFIER
-		->	ON[$id]
-	;
-
-indices_key
-	:	{(validateIdentifierKey("indices"))}?=>  id=IDENTIFIER
-		->	INDICES[$id]
-	;
-
-cross_key
-	:	{(validateIdentifierKey("cross"))}?=>  id=IDENTIFIER
-		->	CROSS[$id]
-	;
-
-join_key
-	:	{(validateIdentifierKey("join"))}?=>  id=IDENTIFIER
-		->	JOIN[$id]
-	;
-
-inner_key
-	:	{(validateIdentifierKey("inner"))}?=>  id=IDENTIFIER
-		->	INNER[$id]
-	;
-
-outer_key
-	:	{(validateIdentifierKey("outer"))}?=>  id=IDENTIFIER
-		->	OUTER[$id]
-	;
-
-left_key
-	:	{(validateIdentifierKey("left"))}?=>  id=IDENTIFIER
-		->	LEFT[$id]
-	;
-
-right_key
-	:	{(validateIdentifierKey("right"))}?=>  id=IDENTIFIER
-		->	RIGHT[$id]
-	;
-
-full_key
-	:	{(validateIdentifierKey("full"))}?=>  id=IDENTIFIER
-		->	FULL[$id]
-	;
-
-elements_key
-	:	{(validateIdentifierKey("elements"))}?=>  id=IDENTIFIER
-		->	ELEMENTS[$id]
-	;
-
-properties_key
-	:	{(validateIdentifierKey("properties"))}?=>  id=IDENTIFIER
-		->	PROPERTIES[$id]
-	;
-
-fetch_key
-	:	{(validateIdentifierKey("fetch"))}?=>  id=IDENTIFIER
-		->	FETCH[$id]
-	;
-
-in_key
-	:	{(validateIdentifierKey("in"))}?=>  id=IDENTIFIER
-		->	IN[$id]
-	;
-
-as_key
-	:	{(validateIdentifierKey("as"))}?=>  id=IDENTIFIER
-		->	AS[$id]
-	;
-
-where_key
-	:	{(validateIdentifierKey("where"))}?=>  id=IDENTIFIER
-		->	WHERE[$id]
-	;
-
-select_key
-	:	{(validateIdentifierKey("select"))}?=>  id=IDENTIFIER
-		->	SELECT[$id]
-	;
-
-distinct_key
-	:	{(validateIdentifierKey("distinct"))}?=>  id=IDENTIFIER
-		->	DISTINCT[$id]
-	;
-
-union_key
-	:	{(validateIdentifierKey("union"))}?=>  id=IDENTIFIER
-		->	UNION[$id]
-	;
-
-intersect_key
-	:	{(validateIdentifierKey("intersect"))}?=>  id=IDENTIFIER
-		->	INTERSECT[$id]
-	;
-
-except_key
-	:	{(validateIdentifierKey("except"))}?=>  id=IDENTIFIER
-		->	EXCEPT[$id]
-	;
-
-all_key
-	:	{(validateIdentifierKey("all"))}?=>  id=IDENTIFIER
-		->	ALL[$id]
-	;
-
-ascending_key
-	:	{(validateIdentifierKey("ascending") || validateIdentifierKey("asc"))}?=>  IDENTIFIER
-	;
-
-descending_key
-	:	{(validateIdentifierKey("descending") || validateIdentifierKey("desc"))}?=>  IDENTIFIER
-	;
-
-collate_key
-	:	{(validateIdentifierKey("collate"))}?=>  IDENTIFIER
-	;
-
-order_by_key
- at init{
-	String text = "";
-}	:	{(validateIdentifierKey("order") && validateLT(2, "by"))}?=>  id=IDENTIFIER IDENTIFIER {text = $text;}
-		->	ORDER_BY[$id]
-	;
-
-group_by_key
- at init{
-	String text = "";
-}	:	{(validateIdentifierKey("group") && validateLT(2, "by"))}?=>  id=IDENTIFIER IDENTIFIER {text = $text;}
-		->	GROUP_BY[$id]
-	;
-
-from_key
-	:	{(validateIdentifierKey("from"))}?=>  id=IDENTIFIER
-        	->	FROM[$id]
-	;
\ No newline at end of file

Deleted: core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/resolve/GeneratedHQLResolver.g
===================================================================
--- core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/resolve/GeneratedHQLResolver.g	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/phase/hql/resolve/GeneratedHQLResolver.g	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,625 +0,0 @@
-tree grammar GeneratedHQLResolver;
-
-options{
-	output=AST;
-	rewrite=true;
-	tokenVocab=HQLLexer;
-	ASTLabelType=CommonTree;
-	TokenLabelType=CommonToken;
-}
-
- at header {
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- *
- * Portions of SQL grammar parsing copyright (C) 2003 by Lubos Vnuk.  All rights
- * reserved.  These portions are distributed under license by Red Hat Middleware
- * LLC and are covered by the above LGPL notice.  If you redistribute this material,
- * with or without modification, you must preserve this copyright notice in its
- * entirety.
- */
-package org.hibernate.sql.ast.phase.hql.resolve;
-
-import org.antlr.runtime.tree.CommonTree;
-import org.hibernate.sql.ast.common.JoinType;
-import org.hibernate.sql.ast.phase.hql.resolve.path.PathedPropertyReferenceSource;
-}
-
- at members{
-    protected void registerPersisterSpace(Tree entityName,
-                                       Tree alias) {
-        throw new UnsupportedOperationException( "must be overridden!" );
-    }
-    
-	protected boolean isUnqualifiedPropertyReference() {
-        throw new UnsupportedOperationException( "must be overridden!" );
-	}	
-
-	protected PathedPropertyReferenceSource normalizeUnqualifiedPropertyReference(Tree property) {
-        throw new UnsupportedOperationException( "must be overridden!" );
-	}
-	
-	protected boolean isPersisterReferenceAlias() {
-        throw new UnsupportedOperationException( "must be overridden!" );
-    }
-
-    protected PathedPropertyReferenceSource normalizeUnqualifiedRoot( Tree identifier382 ) {
-        throw new UnsupportedOperationException( "must be overridden!" );
-	}
-
-	protected PathedPropertyReferenceSource normalizeQualifiedRoot( Tree identifier381 ) {
-        throw new UnsupportedOperationException( "must be overridden!" );
-	}
-
-    protected PathedPropertyReferenceSource normalizePropertyPathIntermediary( PathedPropertyReferenceSource source, Tree propertyName ) {
-        throw new UnsupportedOperationException( "must be overridden!" );
-	}
-
-    protected PathedPropertyReferenceSource normalizeIntermediateIndexOperation( PathedPropertyReferenceSource propertyReferenceSource, Tree collectionProperty,
-			Tree selector ) {
-        throw new UnsupportedOperationException( "must be overridden!" );
-	}
-
-    protected void normalizeTerminalIndexOperation( PathedPropertyReferenceSource propertyReferenceSource, Tree collectionProperty,
-			Tree selector ) {
-        throw new UnsupportedOperationException( "must be overridden!" );
-    }
-
-    protected PathedPropertyReferenceSource normalizeUnqualifiedPropertyReferenceSource(
-			Tree identifier394 ) {
-        throw new UnsupportedOperationException( "must be overridden!" );
-	}
-
-    protected Tree normalizePropertyPathTerminus(PathedPropertyReferenceSource source, Tree propertyNameNode) {
-        throw new UnsupportedOperationException( "must be overridden!" );
-    }
-
-	protected void pushFromStrategy( JoinType joinType,
-			Tree assosiationFetchTree, Tree propertyFetchTree,
-			Tree alias ) {
-        throw new UnsupportedOperationException( "must be overridden!" );
-	}
-	
-	protected void pushSelectStrategy() {
-        throw new UnsupportedOperationException( "must be overridden!" );
-	}
-	
-
-	protected void popStrategy(){
-        throw new UnsupportedOperationException( "must be overridden!" );
-	}	
-}
-
-filterStatement[String collectionRole]
-	:	^(QUERY ^(QUERY_SPEC FILTER 
-				selectClause? whereClause? ( groupByClause havingClause?)? orderByClause?))
-	;
-
-statement
-	:	updateStatementSet
-	|	deleteStatementSet
-	|	insertStatementSet
-	|	queryStatementSet
-	;
-
-updateStatementSet
-	:	updateStatement+
-	;
-
-updateStatement
-	:	^(UPDATE entityName ^(SET assignment+) whereClause?)
-	;
-
-assignment
-	:	^(EQUALS propertyReference valueExpression)
-	|	^(EQUALS VERSIONED_VALUE STRING_LITERAL)
-	;
-
-deleteStatementSet
-	:	deleteStatement+
-	;
-
-deleteStatement
-	:	^(DELETE entityName whereClause?)
-	;
-
-insertStatementSet
-	:	insertStatement+
-	;
-
-insertStatement
-	:	^(INSERT intoClause queryStatementSet)
-	;
-
-intoClause
-	:	^(INTO entityName ^(INSERTABILITY_SPEC propertyReference+ ) )
-	;
-
-queryStatementSet
-	:	queryStatement+
-	;
-
-queryStatement
-	:	^(QUERY queryExpression orderByClause?)
-	;
-
-queryExpression
-	:	^(UNION ALL? queryExpression queryExpression)
-	|	^(INTERSECT ALL? queryExpression queryExpression)
-	|	^(EXCEPT ALL? queryExpression queryExpression)
-	|	querySpec	
-	;
-
-querySpec
-	:	^(QUERY_SPEC selectFrom whereClause? groupByClause? havingClause?)
-	;
-
-whereClause
-	:	^(WHERE searchCondition)
-	;
-
-groupByClause
-	:	^(GROUP_BY groupingValue+)
-	;
-
-groupingValue
-	:	^(GROUPING_VALUE valueExpression COLLATE?)
-	;
-
-havingClause
-	:	^(HAVING searchCondition)
-	;
-
-selectFrom
-	:	^(SELECT_FROM fromClause selectClause)
-	;
-
-fromClause
-	:	^(FROM persisterSpaces+)
-	;
-
-persisterSpaces
-	:	^(PERSISTER_SPACE persisterSpace)
-	;
-
-persisterSpace
-	:	persisterSpaceRoot joins*
-	;
-
-persisterSpaceRoot
-	:	^(ENTITY_PERSISTER_REF entityName PROP_FETCH?)
-	;
-
-joins
-	:	^(PROPERTY_JOIN jt=joinType ft=FETCH? an=ALIAS_NAME pf=PROP_FETCH? 
-		{	pushFromStrategy($jt.joinType, $ft, $pf, $an );	}	
-		(collectionExpression|propertyReference) withClause?)
-		{	popStrategy();	}
-	|	^(PERSISTER_JOIN joinType persisterSpaceRoot onClause?)
-	;
-
-withClause
-	:	^(WITH searchCondition)
-	;
-
-onClause
-	:	^(ON searchCondition)
-	;
-
-joinType returns [JoinType joinType]
-	:	CROSS {	$joinType = JoinType.CROSS;	}
-	|	INNER {	$joinType = JoinType.INNER;	}
-	|	(LEFT {	$joinType = JoinType.LEFT;	} |	RIGHT {	$joinType = JoinType.RIGHT;	} | FULL {	$joinType = JoinType.FULL;	}) OUTER?
-	;
-
-selectClause
- at init	{	if (state.backtracking == 0) pushSelectStrategy();	}
- at after	{	popStrategy();	}
-	:	^(SELECT DISTINCT? rootSelectExpression) 
-	;
-
-rootSelectExpression
-	:	^(SELECT_LIST rootSelectExpression+)
-	|	^(SELECT_ITEM rootSelectExpression)
-	|	^(DYNAMIC_INSTANTIATION rootSelectExpression+)
-	|	^(DYNAMIC_INSTANTIATION_ARG rootSelectExpression)
-	|	valueExpression ALIAS_NAME?
-	;
-
-orderByClause
-	:	^(ORDER_BY sortSpecification+)
-	;
-
-sortSpecification
-	:	^(SORT_SPEC valueExpression COLLATE? ORDER_SPEC)
-	;
-
-searchCondition
-	:	^( OR searchCondition searchCondition )
-	|	^( AND searchCondition searchCondition )
-	|	^( NOT searchCondition )
-	|	predicate
-	;
-
-predicate
-	:	^( EQUALS rowValueConstructor comparativePredicateValue )
-	|	^( NOT_EQUAL rowValueConstructor comparativePredicateValue )
-	|	^( LESS rowValueConstructor comparativePredicateValue )
-	|	^( LESS_EQUAL rowValueConstructor comparativePredicateValue )
-	|	^( GREATER rowValueConstructor comparativePredicateValue )
-	|	^( GREATER_EQUAL rowValueConstructor comparativePredicateValue )
-	|	^( IS_NULL rowValueConstructor )
-	|	^( IS_NOT_NULL rowValueConstructor )
-	|	^( LIKE valueExpression valueExpression escapeSpecification? )
-	|	^( NOT_LIKE valueExpression valueExpression escapeSpecification? )
-	|	^( BETWEEN rowValueConstructor betweenList )
-	|	^( NOT_BETWEEN rowValueConstructor betweenList )
-	|	^( IN rowValueConstructor inPredicateValue )
-	|	^( NOT_IN rowValueConstructor inPredicateValue )
-	|	^( MEMBER_OF rowValueConstructor rowValueConstructor )
-	|	^( NOT_MEMBER_OF rowValueConstructor rowValueConstructor  )
-	|	^( IS_EMPTY rowValueConstructor )
-	|	^( IS_NOT_EMPTY rowValueConstructor )
-	|	rowValueConstructor
-	;
-
-betweenList
-	:	^( BETWEEN_LIST rowValueConstructor rowValueConstructor )
-	;	
-
-comparativePredicateValue
-	:	rowValueConstructor
-	;
-
-rowValueConstructor
-	:	valueExpression
-	;
-
-escapeSpecification
-	:	^(ESCAPE characterValueExpression)
-	;
-
-inPredicateValue
-	:	^(IN_LIST valueExpression+)
-	;
-
-numericValueExpression
-	:	valueExpression
-	;
-
-characterValueExpression
-	:	valueExpression
-	;
-
-datetimeValueExpression
-	:	valueExpression
-	;
-
-valueExpression
-	:	^( DOUBLE_PIPE characterValueExpression+ )
-	|	^( UNARY_MINUS numericValueExpression )
-	|	^( UNARY_PLUS numericValueExpression )
-	|	^( PLUS valueExpression valueExpression )
-	|	^( MINUS valueExpression valueExpression )
-	|	^( ASTERISK numericValueExpression numericValueExpression )
-	|	^( SOLIDUS numericValueExpression numericValueExpression )
-	|	^( EXISTS rowValueConstructor)
-    |	^( SOME valueExpression )
-    |	^( ALL valueExpression )
-    |	^( ANY valueExpression )
-	|	^( VECTOR_EXPR valueExpression+) // or a tuples or ^(AND or IN statement 
-	|	valueExpressionPrimary
-	;
-
-valueExpressionPrimary
-	:	caseExpression
-	|	function
-	|	collectionFunction
-	|	collectionExpression
-	|	constant
-	|	parameter
-	|	propertyReference
-	|	^(SUB_QUERY queryStatementSet)
-	|	ALIAS_REF //ID COLUMN, full property column list 
-	|	^(DOT_CLASS path) // crazy 
-	|	^(GENERAL_FUNCTION_CALL path)
-	|	^(JAVA_CONSTANT path) //It will generate at SQL a parameter element (?) -> 'cos we do not need to care about char escaping
-	|	^(PATH propertyReferencePath)
-	;
-
-caseExpression
-	:	^(NULLIF valueExpression valueExpression)
-	|	^(COALESCE valueExpression valueExpression*)
-	|	^(SIMPLE_CASE valueExpression simpleCaseWhenClause+ elseClause?)
-	|	^(SEARCHED_CASE searchedWhenClause+ elseClause?)
-	;
-
-simpleCaseWhenClause
-	:	^(WHEN valueExpression valueExpression)
-	;
-
-searchedWhenClause
-	:	^(WHEN searchCondition valueExpression)
-	;
-
-elseClause
-	:	^(ELSE valueExpression)
-	;
-
-function
-	:	standardFunction
-	|	setFunction
-	;
-
-standardFunction
-	:	castFunction
-	|	concatFunction
-	|	substringFunction
-	|	trimFunction
-	|	upperFunction
-	|	lowerFunction
-	|	lengthFunction
-	|	locateFunction
-	|	absFunction
-	|	sqrtFunction
-	|	modFunction
-	|	sizeFunction
-	|	indexFunction
-	|	currentDateFunction
-	|	currentTimeFunction
-	|	currentTimestampFunction
-	|	extractFunction
-	|	positionFunction
-	|	charLengthFunction
-	|	octetLengthFunction
-	|	bitLengthFunction
-	;
-
-castFunction
-	:	^(CAST valueExpression IDENTIFIER)
-	;
-
-concatFunction
-	:	^(CONCAT valueExpression+)
-	;
-
-substringFunction
-	:	^(SUBSTRING characterValueExpression numericValueExpression numericValueExpression?)
-	;
-
-trimFunction
-	:	^(TRIM trimOperands)
-	;
-
-trimOperands
-	:	^((LEADING|TRAILING|BOTH) characterValueExpression characterValueExpression)
-	;
-
-upperFunction
-	:	^(UPPER characterValueExpression)
-	;
-
-lowerFunction
-	:	^(LOWER characterValueExpression)
-	;
-
-lengthFunction
-	:	^(LENGTH characterValueExpression)
-	;
-
-locateFunction
-	:	^(LOCATE characterValueExpression characterValueExpression numericValueExpression?)
-	;
-
-absFunction
-	:	^(ABS numericValueExpression)
-	;
-
-sqrtFunction
-	:	^(SQRT numericValueExpression)
-	;
-
-modFunction
-	:	^(MOD numericValueExpression numericValueExpression)
-	;
-
-sizeFunction
-	:	^(SIZE propertyReference)
-	;
-
-indexFunction
-	:	^(INDEX ALIAS_REF)
-	;
-
-currentDateFunction
-	:	CURRENT_DATE
-	;
-
-currentTimeFunction
-	:	CURRENT_TIME
-	;
-
-currentTimestampFunction
-	:	CURRENT_TIMESTAMP
-	;
-
-extractFunction
-	:	^(EXTRACT extractField datetimeValueExpression)
-	;
-
-extractField
-	:	datetimeField
-	|	timeZoneField
-	;
-
-datetimeField
-	:	YEAR
-	|	MONTH
-	|	DAY
-	|	HOUR
-	|	MINUTE
-	|	SECOND
-	;
-
-timeZoneField
-	:	TIMEZONE_HOUR
-	|	TIMEZONE_MINUTE
-	;
-
-positionFunction
-	:	^(POSITION characterValueExpression characterValueExpression)
-	;
-
-charLengthFunction
-	:	^(CHARACTER_LENGTH characterValueExpression)
-	;
-
-octetLengthFunction
-	:	^(OCTET_LENGTH characterValueExpression)	
-	;
-
-bitLengthFunction
-	:	^(BIT_LENGTH characterValueExpression)
-	;
-
-setFunction
-	:	^(SUM numericValueExpression)
-	|	^(AVG numericValueExpression)
-	|	^(MAX numericValueExpression)
-	|	^(MIN numericValueExpression)
-	|	^(COUNT (ASTERISK | (DISTINCT|ALL) countFunctionArguments))
-	;
-
-countFunctionArguments
-	:	collectionExpression
-	|	propertyReference
-	|	numeric_literal
-	;
-
-collectionFunction
-	:	^((MAXELEMENT|MAXINDEX|MINELEMENT|MININDEX) collectionPropertyReference)
-		//it will generate a SELECT MAX (m.column) form Table xxx -> it is realted to Hibernate mappings to Table->Map
-	;
-
-collectionPropertyReference
-	:	propertyReference
-	;
-
-collectionExpression
-	:	^(ELEMENTS propertyReference) //it will generate a SELECT m.column form Table xxx -> it is realted to Hibernate mappings to Table->Map
-	|	^(INDICES propertyReference)
-	;
-
-parameter
-	:	NAMED_PARAM
-	|	JPA_PARAM
-	|	PARAM
-	;
-
-constant
-	:	literal
-	|	NULL
-	|	TRUE
-	|	FALSE
-	;
-
-literal
-	:	numeric_literal
-	|	HEX_LITERAL
-	|	OCTAL_LITERAL
-	|	CHARACTER_LITERAL
-	|	STRING_LITERAL
-	;
-
-numeric_literal
-	:	INTEGER_LITERAL
-	|	DECIMAL_LITERAL
-	|	FLOATING_POINT_LITERAL
-	;
-
-entityName
-	:	ENTITY_NAME ALIAS_NAME
-	{	registerPersisterSpace($ENTITY_NAME, $ALIAS_NAME);	}
-	;
-
-propertyReference
-	:	^(PROPERTY_REFERENCE propertyReferencePath)
-	;
-
-propertyReferencePath
-	: 	{isUnqualifiedPropertyReference()}? unqualifiedPropertyReference
-	|	pathedPropertyReference
-    |	terminalIndexOperation
-	;
-
-unqualifiedPropertyReference returns [PathedPropertyReferenceSource propertyReferenceSource]
-	:	IDENTIFIER
-	{	$propertyReferenceSource = normalizeUnqualifiedPropertyReference( $IDENTIFIER ); }
-	;
-
-pathedPropertyReference
-	:	^(DOT pathedPropertyReferenceSource IDENTIFIER)
-	{	normalizePropertyPathTerminus( $pathedPropertyReferenceSource.propertyReferenceSource, $IDENTIFIER );	}
-	;
-
-pathedPropertyReferenceSource returns [PathedPropertyReferenceSource propertyReferenceSource]
-	:	{(isPersisterReferenceAlias())}?=> IDENTIFIER { $propertyReferenceSource = normalizeQualifiedRoot( $IDENTIFIER ); }
-    |	{(isUnqualifiedPropertyReference())}?=> IDENTIFIER { $propertyReferenceSource = normalizeUnqualifiedRoot( $IDENTIFIER ); }
-    |	intermediatePathedPropertyReference { $propertyReferenceSource = $intermediatePathedPropertyReference.propertyReferenceSource; }
-    |	intermediateIndexOperation { $propertyReferenceSource = $intermediateIndexOperation.propertyReferenceSource; }
-    ;
-
-intermediatePathedPropertyReference returns [PathedPropertyReferenceSource propertyReferenceSource]
-	:	^(DOT source=pathedPropertyReferenceSource IDENTIFIER )
-	{	$propertyReferenceSource = normalizePropertyPathIntermediary( $pathedPropertyReferenceSource.propertyReferenceSource, $IDENTIFIER );	}
-	;
-
-intermediateIndexOperation returns [PathedPropertyReferenceSource propertyReferenceSource]
-	:	^( LEFT_SQUARE indexOperationSource indexSelector ) 
-	{	$propertyReferenceSource = normalizeIntermediateIndexOperation( $indexOperationSource.propertyReferenceSource, $indexOperationSource.collectionProperty, $indexSelector.tree );	}
-	;
-
-terminalIndexOperation
-	:	^( LEFT_SQUARE indexOperationSource indexSelector ) 
-	{	normalizeTerminalIndexOperation( $indexOperationSource.propertyReferenceSource, $indexOperationSource.collectionProperty, $indexSelector.tree );	}
-	;
-
-indexOperationSource returns [PathedPropertyReferenceSource propertyReferenceSource, Tree collectionProperty]
-	:	^(DOT pathedPropertyReferenceSource IDENTIFIER )
-	{	$propertyReferenceSource = $pathedPropertyReferenceSource.propertyReferenceSource;
-		$collectionProperty = $IDENTIFIER;	}
-    |	{(isUnqualifiedPropertyReference())}?=> IDENTIFIER
-    {	$propertyReferenceSource = normalizeUnqualifiedPropertyReferenceSource( $IDENTIFIER );
-    	$collectionProperty = $IDENTIFIER;	}
-	;
-
-indexSelector
-	:	valueExpression
-	;
-
-path
-	: 	IDENTIFIER
-	|	^(DOT path path )
-	|	^(LEFT_SQUARE path valueExpression* )
-	|	^(LEFT_PAREN path valueExpression* )
-	;

Added: core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/render/OrderByRenderer.g
===================================================================
--- core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/render/OrderByRenderer.g	                        (rev 0)
+++ core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/render/OrderByRenderer.g	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,227 @@
+tree grammar OrderByRenderer;
+
+options{
+	output=template;
+	tokenVocab=HQLLexer;
+	ASTLabelType=CommonTree;
+	TokenLabelType=CommonToken;
+}
+
+ at header {
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ *
+ * Portions of SQL grammar parsing copyright (C) 2003 by Lubos Vnuk.  All rights
+ * reserved.  These portions are distributed under license by Red Hat Middleware
+ * LLC and are covered by the above LGPL notice.  If you redistribute this material,
+ * with or without modification, you must preserve this copyright notice in its
+ * entirety.
+ */
+package org.hibernate.sql.ast.render;
+}
+
+// todo : merge with 'full sql rendering' grammar
+//    this is currently just a temporary subset grammar limited to the needs of mapping-defined order-by fragments
+
+orderByClause
+    : ^( ORDER_BY sortSpecs+=sortSpecification+ )
+        ->  orderByClause( sortSpecifications={$sortSpecs} )
+    ;
+
+sortSpecification
+    : ^( SORT_SPEC sortKey COLLATE? ORDER_SPEC? )
+        ->  sortSpecification(
+                    sortKey={$sortKey.st},
+                    collationSpecification={$COLLATE.text},
+                    orderingSpecification={$ORDER_SPEC.text}
+            )
+    ;
+
+sortKey
+    : expression
+    ;
+
+expression
+    : column
+    | function
+    ;
+
+column
+    : ^( COLUMN ALIAS_REF identifier )
+        -> column( qualifier={$ALIAS_REF.text}, name={$identifier.text} )
+    ;
+
+identifier
+    : IDENTIFIER
+    | QUOTED_IDENTIFIER
+    ;
+
+function
+    : functionFunction
+//	| castFunction
+//	| concatFunction
+//	| substringFunction
+//	| trimFunction
+//	| upperFunction
+//	| lowerFunction
+//	| lengthFunction
+//	| locateFunction
+	| absFunction
+	| sqrtFunction
+	| modFunction
+	| currentDateFunction
+	| currentTimeFunction
+	| currentTimestampFunction
+	| extractFunction
+	| positionFunction
+	| charLengthFunction
+	| octetLengthFunction
+	| bitLengthFunction
+    ;
+
+functionFunction
+    : ^( FUNCTION args+=functionArgument* )
+        -> basicFunction( name={$FUNCTION.text}, args={$args} )
+    ;
+
+functionArgument
+    : expression
+    | literal
+;
+
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// rewritten in parser as ^( FUNCTION ... ) structures
+//castFunction
+//	: ^( CAST valueExpression IDENTIFIER )
+//	;
+//
+//concatFunction
+//	: ^( CONCAT valueExpression+ )
+//	;
+//
+//substringFunction
+//	:	^(SUBSTRING characterValueExpression numericValueExpression numericValueExpression?)
+//	;
+//
+//trimFunction
+//	:	^(TRIM trimOperands)
+//	;
+//
+//trimOperands
+//	:	^((LEADING|TRAILING|BOTH) characterValueExpression characterValueExpression)
+//	;
+//
+//upperFunction
+//	:	^(UPPER characterValueExpression)
+//	;
+//
+//lowerFunction
+//	:	^(LOWER characterValueExpression)
+//	;
+//
+//lengthFunction
+//	:	^(LENGTH characterValueExpression)
+//	;
+//
+//locateFunction
+//	:	^(LOCATE characterValueExpression characterValueExpression numericValueExpression?)
+//	;
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+absFunction
+	:	^( ABS expression )
+	;
+
+sqrtFunction
+	:	^(SQRT expression)
+	;
+
+modFunction
+	:	^(MOD expression expression)
+	;
+
+currentDateFunction
+	:	CURRENT_DATE
+	;
+
+currentTimeFunction
+	:	CURRENT_TIME
+	;
+
+currentTimestampFunction
+	:	CURRENT_TIMESTAMP
+	;
+
+extractFunction
+	:	^(EXTRACT extractField expression)
+	;
+
+extractField
+	:	datetimeField
+	|	timeZoneField
+	;
+
+datetimeField
+	:	YEAR
+	|	MONTH
+	|	DAY
+	|	HOUR
+	|	MINUTE
+	|	SECOND
+	;
+
+timeZoneField
+	:	TIMEZONE_HOUR
+	|	TIMEZONE_MINUTE
+	;
+
+positionFunction
+	:	^(POSITION expression expression)
+	;
+
+charLengthFunction
+	:	^(CHARACTER_LENGTH expression)
+	;
+
+octetLengthFunction
+	:	^(OCTET_LENGTH expression)
+	;
+
+bitLengthFunction
+	:	^(BIT_LENGTH expression)
+	;
+
+literal
+	:	numeric_literal
+	|	HEX_LITERAL
+	|	OCTAL_LITERAL
+	|	CHARACTER_LITERAL
+	|	STRING_LITERAL
+	;
+
+numeric_literal
+	:	INTEGER_LITERAL
+	|	DECIMAL_LITERAL
+	|	FLOATING_POINT_LITERAL
+	;
+

Added: core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/render/SQLRenderer.g-tmp
===================================================================
--- core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/render/SQLRenderer.g-tmp	                        (rev 0)
+++ core/branches/antlr3/src/main/antlr3/org/hibernate/sql/ast/render/SQLRenderer.g-tmp	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,178 @@
+tree grammar SQLRenderer;
+
+options{
+	output=template;
+	tokenVocab=HQL;
+}
+
+ at header {
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ *
+ * Portions of SQL grammar parsing copyright (C) 2003 by Lubos Vnuk.  All rights
+ * reserved.  These portions are distributed under license by Red Hat Middleware
+ * LLC and are covered by the above LGPL notice.  If you redistribute this material,
+ * with or without modification, you must preserve this copyright notice in its
+ * entirety.
+ */
+package org.hibernate.sql.ast.render;
+}
+
+orderByClause
+    : ^( ORDER_BY sortSpecs+=sortSpecification+ )
+        ->  orderByClause( sortSpecifications={$sortSpecs} )
+    ;
+
+orderByFragment
+    : ^( ORDER_BY sortSpecs+=sortSpecification+ )
+        ->  orderByFragment( sortSpecifications={$sortSpecs} )
+    ;
+
+sortSpecification
+    : ^( SORT_SPEC sortKey collationSpecification? orderingSpecification? )
+        ->  sortSpecification(
+                    sortKey={$sortKey.st},
+                    collationSpecification={$collationSpecification.st},
+                    orderingSpecification={$orderingSpecification.st}
+            )
+    ;
+
+sortKey
+    : valueExpression
+    ;
+
+
+valueExpression
+    : numericValueExpression
+
+     |     <string value expression>
+     |     <datetime value expression>
+     |     <interval value expression>
+     |     <boolean value expression>
+     |     <user-defined type value expression>
+     |     <row value expression>
+     |     <reference value expression>
+     |     <collection value expression>
+    ;
+
+numericValueExpression
+    : term
+    |     <numeric value expression> <plus sign> <term>
+     |     <numeric value expression> <minus sign> <term>
+    ;
+
+term
+    : factor
+    | ^( ASTERISK term factor )
+    | ^( SOLIDUS term factor )
+
+factor
+    :
+    ;
+
+  <factor>    ::=   [ <sign> ] <numeric primary>
+
+numericPrimary
+    : valueExpressionPrimary
+    | numericValyeFunction
+    ;
+
+valueExpressionPrimary
+    : parenthesizedValueExpression
+    | <nonparenthesized value expression primary>
+    ;
+
+parenthesizedValueExpression
+    : ^( VECTOR_EXPR valueExpression )
+    ;
+
+nonparenthesizedValueExpressionPrimary
+    :
+         <unsigned value specification>
+     |     <column reference>
+     |     <set function specification>
+     |     <scalar subquery>
+     |     <case expression>
+     |     <cast specification>
+     |     <subtype treatment>
+     |     <attribute or method reference>
+     |     <reference resolution>
+     |     <collection value constructor>
+     |     <routine invocation>
+     |     <field reference>
+     |     <element reference>
+     |     <method invocation>
+     |     <static method invocation>
+     |     <new specification>
+    ;
+
+unsignedValueSpecification
+    : unsignedLiteral
+    | <general value specification>
+    ;
+
+unsignedLiteral
+    : unsignedNumericLiteral
+    | generalLiteral
+    ;
+
+generalValueSpecification
+    :
+    ;
+
+unsignedNumericLiteral
+	:	INTEGER_LITERAL
+	|	DECIMAL_LITERAL
+	|	FLOATING_POINT_LITERAL
+    ;
+
+generalLiteral
+    : STRING_LITERAL
+    | CHARACTER_LITERAL
+    | HEX_LITERAL
+    | OCTAL_LITERAL
+    | booleanLiteral
+    | dateTimeLiteral
+    | intervalLiteral
+
+     |     <national character string literal>
+     |     <bit string literal>
+     |     <hex string literal>
+     |     <binary string literal>
+     |     <datetime literal>
+     |     <interval literal>
+     |     <boolean literal>
+    ;
+
+booleanLiteral
+    : TRUE
+    | FALSE
+    ;
+
+dateTimeLiteral
+    :
+    ;
+
+intervalLiteral
+    :
+    ;

Modified: core/branches/antlr3/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -80,7 +80,7 @@
 import org.hibernate.sql.SelectFragment;
 import org.hibernate.sql.SimpleSelect;
 import org.hibernate.sql.Template;
-import org.hibernate.sql.ast.ordering.ColumnMapper;
+import org.hibernate.sql.ast.origin.ordering.ColumnMapper;
 import org.hibernate.type.AbstractComponentType;
 import org.hibernate.type.CollectionType;
 import org.hibernate.type.EntityType;

Modified: core/branches/antlr3/src/main/java/org/hibernate/sql/Template.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/Template.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/Template.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -30,9 +30,9 @@
 import org.hibernate.dialect.Dialect;
 import org.hibernate.dialect.function.SQLFunctionRegistry;
 import org.hibernate.util.StringHelper;
-import org.hibernate.sql.ast.ordering.ColumnMapper;
-import org.hibernate.sql.ast.ordering.TranslationContext;
-import org.hibernate.sql.ast.ordering.OrderByFragmentTranslator;
+import org.hibernate.sql.ast.origin.ordering.ColumnMapper;
+import org.hibernate.sql.ast.origin.ordering.TranslationContext;
+import org.hibernate.sql.ast.origin.ordering.OrderByFragmentTranslator;
 import org.hibernate.engine.SessionFactoryImplementor;
 
 /**

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/ColumnMapper.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/ColumnMapper.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/ColumnMapper.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,46 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- *
- */
-package org.hibernate.sql.ast.ordering;
-
-import org.hibernate.HibernateException;
-
-/**
- * Contract for mapping a (an assumed) property reference to its columns.
- *
- * @author Steve Ebersole
- */
-public interface ColumnMapper {
-	/**
-	 * Resolve the property reference to its underlying columns.
-	 *
-	 * @param reference The property reference name.
-	 *
-	 * @return The underlying columns, or null if the property reference is unknown.
-	 *
-	 * @throws HibernateException Generally indicates that the property reference is unkown; interpretation is the
-	 * same as a null return.
-	 */
-	public String[] map(String reference) throws HibernateException;
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentParser.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentParser.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentParser.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,109 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- *
- */
-package org.hibernate.sql.ast.ordering;
-
-import org.antlr.runtime.TokenStream;
-import org.antlr.runtime.tree.CommonTree;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.hibernate.sql.ast.common.HibernateTree;
-import org.hibernate.sql.Template;
-
-/**
- * Extension of the Antlr-generated parser for the purpose of adding our custom parsing behavior.
- *
- * @author Steve Ebersole
- */
-public class OrderByFragmentParser extends OrderByParser {
-	private static final Logger log = LoggerFactory.getLogger( OrderByFragmentParser.class );
-	private final TranslationContext context;
-
-	private final String openQuoteChar;
-	private final String closeQuoteChar;
-
-	public OrderByFragmentParser(TokenStream lexer, TranslationContext context) {
-		super( lexer );
-		this.context = context;
-
-		this.openQuoteChar = Character.toString( context.getDialect().openQuote() );
-		this.closeQuoteChar = Character.toString( context.getDialect().closeQuote() );
-	}
-
-	@Override
-	protected boolean isFunctionName(String text) {
-		log.trace( "Checking function name [" + text + "]" );
-		return context.getSqlFunctionRegistry().hasFunction( text );
-	}
-
-	@Override
-	protected boolean isPropertyName(String text) {
-		log.trace( "Checking property name [" + text + "]" );
-		try {
-			return context.getColumnMapper().map( text ) != null;
-		}
-		catch ( Throwable t ) {
-			return false;
-		}
-	}
-
-	@Override
-	protected CommonTree buildPropertyColumns(CommonTree propertyTree) {
-		final String text = extractPropertyName( propertyTree );
-		String[] columns = context.getColumnMapper().map( text );
-		if ( columns.length == 1 ) {
-			return buildColumn( columns[0] );
-		}
-		else {
-			HibernateTree vector = new HibernateTree( VECTOR_EXPR );
-			for ( String column : columns ) {
-				vector.addChild( buildColumn( column ) );
-			}
-			return vector;
-		}
-	}
-
-	private CommonTree buildColumn(String columnName) {
-		// ugh
-		HibernateTree columnNameNode;
-		if ( columnName.startsWith( openQuoteChar ) && columnName.endsWith( closeQuoteChar ) ) {
-			columnName = columnName.substring( 1, columnName.length() - 1 );
-			columnNameNode = new HibernateTree( QUOTED_IDENTIFIER, columnName );
-		}
-		else {
-			columnNameNode = new HibernateTree( IDENTIFIER, columnName );
-		}
-
-		HibernateTree tree = new HibernateTree( COLUMN );
-		tree.addChild( new HibernateTree( ALIAS_REF, Template.TEMPLATE ) );
-		tree.addChild( columnNameNode );
-
-		return tree;
-	}
-
-	private String extractPropertyName(CommonTree propertyTree) {
-		return propertyTree.getText();
-	}
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentTranslator.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentTranslator.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentTranslator.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,91 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- *
- */
-package org.hibernate.sql.ast.ordering;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.hibernate.HibernateException;
-import org.hibernate.sql.ast.util.TreePrinter;
-import org.hibernate.sql.ast.phase.hql.parse.HQLLexer;
-
-import org.antlr.runtime.ANTLRStringStream;
-import org.antlr.runtime.CommonTokenStream;
-import org.antlr.runtime.tree.Tree;
-
-/**
- * A translator which coordinates translation of an <tt>order-by</tt> mapping.
- *
- * @author Steve Ebersole
- */
-public class OrderByFragmentTranslator {
-	private static final Logger log = LoggerFactory.getLogger( OrderByFragmentTranslator.class );
-
-	public final TranslationContext context;
-
-	public OrderByFragmentTranslator(TranslationContext context) {
-		this.context = context;
-	}
-
-	/**
-	 * The main contract, performing the translation.
-	 *
-	 * @param fragment The <tt>order-by</tt> mapping fragment to be translated.
-	 *
-	 * @return The translated fragment.
-	 */
-	public String render(String fragment) {
-		HQLLexer lexer = new HQLLexer( new ANTLRStringStream( fragment ) );
-		OrderByFragmentParser parser = new OrderByFragmentParser( new CommonTokenStream( lexer ), context );
-		try {
-            Tree tree = ( Tree ) parser.orderByFragment().getTree();
-
-            if ( log.isTraceEnabled() ) {
-                TreePrinter printer = new TreePrinter( OrderByParser.class );
-                log.trace( printer.renderAsString( tree, "--- {order-by fragment} ---" ) );
-            }
-		}
-		catch ( HibernateException e ) {
-			throw e;
-		}
-		catch ( Throwable t ) {
-			throw new HibernateException( "Unable to parse order-by fragment", t );
-		}
-
-//		OrderByFragmentRenderer renderer = new OrderByFragmentRenderer();
-//		try {
-//			renderer.orderByFragment( parser.getAST() );
-//		}
-//		catch ( HibernateException e ) {
-//			throw e;
-//		}
-//		catch ( Throwable t ) {
-//			throw new HibernateException( "Unable to render parsed order-by fragment", t );
-//		}
-//
-//		return renderer.getRenderedFragment();
-        return null;
-	}
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/TranslationContext.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/TranslationContext.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/TranslationContext.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,64 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- *
- */
-package org.hibernate.sql.ast.ordering;
-
-import org.hibernate.engine.SessionFactoryImplementor;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.function.SQLFunctionRegistry;
-
-/**
- * Contract for contextual information required to perform translation.
-*
-* @author Steve Ebersole
-*/
-public interface TranslationContext {
-	/**
-	 * Retrieves the <tt>session factory</tt> for this context.
-	 *
-	 * @return The <tt>session factory</tt>
-	 */
-	public SessionFactoryImplementor getSessionFactory();
-
-	/**
-	 * Retrieves the <tt>dialect</tt> for this context.
-	 *
-	 * @return The <tt>dialect</tt>
-	 */
-	public Dialect getDialect();
-
-	/**
-	 * Retrieves the <tt>SQL function registry/tt> for this context.
-	 *
-	 * @return The SQL function registry.
-	 */
-	public SQLFunctionRegistry getSqlFunctionRegistry();
-
-	/**
-	 * Retrieves the <tt>column mapper</tt> for this context.
-	 *
-	 * @return The <tt>column mapper</tt>
-	 */
-	public ColumnMapper getColumnMapper();
-}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/parse/ParserContext.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/parse/ParserContext.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/parse/ParserContext.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/parse/ParserContext.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,14 @@
+package org.hibernate.sql.ast.origin.hql.parse;
+
+import java.util.List;
+
+public interface ParserContext {
+
+	public boolean isJavaConstant(String text);
+
+	public boolean isEntityName(String text);
+
+	public List getEntityImplementors(String text);
+	
+	public String buildUniqueImplicitAlias();
+}


Property changes on: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/parse/ParserContext.java
___________________________________________________________________
Name: svn:eol-style
   + native

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/parse/ParserContextDefaultImpl.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/parse/ParserContextDefaultImpl.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/parse/ParserContextDefaultImpl.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/parse/ParserContextDefaultImpl.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,30 @@
+package org.hibernate.sql.ast.origin.hql.parse;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hibernate.sql.ast.alias.ImplicitAliasGenerator;
+
+public class ParserContextDefaultImpl implements ParserContext {
+
+	private final ImplicitAliasGenerator implicitAliasGenerator = new ImplicitAliasGenerator(); 
+	
+	public List getEntityImplementors(String text) {
+		List implementors = new ArrayList();
+		implementors.add(text);
+		return implementors;
+	}
+
+	public boolean isEntityName(String text) {
+		return true;
+	}
+
+	public boolean isJavaConstant(String text) {
+		return false;
+	}
+
+	public String buildUniqueImplicitAlias() {
+		return implicitAliasGenerator.buildUniqueImplicitAlias();
+	}
+
+}


Property changes on: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/parse/ParserContextDefaultImpl.java
___________________________________________________________________
Name: svn:eol-style
   + native

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/HQLResolver.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HQLResolver.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/HQLResolver.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/HQLResolver.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,242 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+package org.hibernate.sql.ast.origin.hql.resolve;
+
+import org.antlr.runtime.RecognizerSharedState;
+import org.antlr.runtime.tree.CommonTree;
+import org.antlr.runtime.tree.Tree;
+import org.antlr.runtime.tree.TreeNodeStream;
+
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.persister.entity.Queryable;
+import org.hibernate.sql.ast.alias.DefaultTableAliasGenerator;
+import org.hibernate.sql.ast.alias.TableAliasGenerator;
+import org.hibernate.sql.ast.common.HibernateTree;
+import org.hibernate.sql.ast.common.JoinType;
+import org.hibernate.sql.ast.origin.hql.parse.HQLLexer;
+import org.hibernate.sql.ast.origin.hql.resolve.path.PathResolutionStrategy;
+import org.hibernate.sql.ast.origin.hql.resolve.path.PathResolutionStrategyStack;
+import org.hibernate.sql.ast.origin.hql.resolve.path.PathedPropertyReferenceSource;
+import org.hibernate.sql.ast.origin.hql.resolve.path.impl.BasicPathResolutionStrategySupport;
+import org.hibernate.sql.ast.origin.hql.resolve.path.impl.FromClausePathResolutionStrategy;
+import org.hibernate.sql.ast.origin.hql.resolve.path.impl.SelectClausePathResolutionStrategy;
+import org.hibernate.sql.ast.tree.Table;
+import org.hibernate.sql.ast.tree.Table.EntityTableSpace;
+import org.hibernate.sql.ast.util.TreePrinter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HQLResolver extends GeneratedHQLResolver implements ResolutionContext {
+	private static final Logger log = LoggerFactory.getLogger( HQLResolver.class );
+
+	private final SessionFactoryImplementor sessionFactory;
+	private final PersisterSpaceContext persisterSpaceContext;
+	private final DefaultTableAliasGenerator defaultTableAliasGenerator;
+	private final PathResolutionStrategyStack pathResolutionStrategyStack;
+	private final TreePrinter printer;
+
+	private boolean isProcessingFunction = false;
+
+	public HQLResolver(TreeNodeStream input, SessionFactoryImplementor sessionFactory) {
+		this( input, new RecognizerSharedState(), sessionFactory );
+	}
+
+	public HQLResolver(TreeNodeStream input, RecognizerSharedState state, SessionFactoryImplementor sessionFactory) {
+		super( input, state );
+		this.sessionFactory = sessionFactory;
+		this.persisterSpaceContext = new RootPersisterSpaceContext();
+		this.defaultTableAliasGenerator = new DefaultTableAliasGenerator( sessionFactory.getDialect() );
+		this.printer = new TreePrinter( HQLLexer.class );
+		this.pathResolutionStrategyStack = new PathResolutionStrategyStack();
+		this.pathResolutionStrategyStack.push( new BasicPathResolutionStrategySupport( this ) );
+	}
+
+	protected void registerPersisterSpace(Tree entityName, Tree alias) {
+		String entityPersisterName = sessionFactory.getImportedClassName( entityName.getText() );
+		Queryable entityPersister = ( Queryable ) sessionFactory.getEntityPersister( entityPersisterName );
+
+		TableAliasGenerator.TableAliasRoot tableAliasRoot = getTableAliasGenerator()
+				.generateSqlAliasRoot( entityPersister, alias.getText() );
+		EntityTableSpace tableSpace = new Table.EntityTableSpace( entityPersister, tableAliasRoot );
+		registerPersisterSpace( tableSpace.getPersisterSpace() );
+	}
+
+	public PersisterSpaceContext getCurrentPersisterSpaceContext() {
+		return persisterSpaceContext;
+	}
+
+	public SessionFactoryImplementor getSessionFactoryImplementor() {
+		return sessionFactory;
+	}
+
+	public TableAliasGenerator getTableAliasGenerator() {
+		return defaultTableAliasGenerator;
+	}
+
+	public TreePrinter getTreePrinter() {
+		return printer;
+	}
+
+	public boolean isCurrentlyProcessingFunction() {
+		return isProcessingFunction;
+	}
+
+	public PathResolutionStrategyStack getPathResolutionStrategyStack() {
+		return pathResolutionStrategyStack;
+	}
+
+	public PathResolutionStrategy getCurrentPathResolutionStrategy() {
+		return pathResolutionStrategyStack.getCurrent();
+	}
+
+	public void registerAssociationFetch(PersisterSpace persisterSpace) {
+		throw new UnsupportedOperationException( "must be implemented!" );
+	}
+
+	public void registerPropertyFetch(PersisterSpace persisterSpace) {
+		throw new UnsupportedOperationException( "must be implemented!" );
+	}
+
+	protected void pushFromStrategy(
+			JoinType joinType,
+			Tree associationFetch,
+			Tree propertyFetch,
+			Tree alias) {
+		boolean associationFetching = associationFetch != null;
+		boolean propertyFetching = propertyFetch != null;
+		pathResolutionStrategyStack.push(
+				new FromClausePathResolutionStrategy(
+						this,
+						joinType,
+						associationFetching,
+						propertyFetching,
+						alias.getText()
+				)
+		);
+	}
+
+	protected void pushSelectStrategy() {
+		pathResolutionStrategyStack.push( new SelectClausePathResolutionStrategy( this ) );
+	}
+
+	protected void popStrategy() {
+		pathResolutionStrategyStack.pop();
+	}
+
+	private void registerPersisterSpace(PersisterSpace persisterSpace) {
+		persisterSpaceContext.registerPersisterSpace( persisterSpace );
+	}
+
+	protected boolean isUnqualifiedPropertyReference() {
+		return locateOwningPersisterAlias( ( Tree ) input.LT( 1 ) ) != null;
+	}
+
+	protected String locateOwningPersisterAlias(Tree property) {
+		PersisterSpace persisterReference = getCurrentPersisterSpaceContext()
+				.locatePersisterSpaceExposingProperty( property.getText() );
+		return persisterReference == null ? null : persisterReference.getSourceAlias();
+	}
+
+	protected boolean isPersisterReferenceAlias() {
+		Tree alias = ( Tree ) input.LT( 1 );
+		log.trace(
+				"Checking [" + textOrNull( alias )
+						+ "] as persister-ref alias"
+		);
+		return getCurrentPersisterSpaceContext().isContainedAlias( alias.getText() );
+	}
+
+	protected PathedPropertyReferenceSource normalizeUnqualifiedPropertyReference(Tree property) {
+		return getCurrentPathResolutionStrategy().handleRoot(
+				getCurrentPersisterSpaceContext().locatePersisterSpaceExposingProperty( property.getText() )
+		);
+	}
+
+	protected PathedPropertyReferenceSource normalizeUnqualifiedRoot(Tree propertyName) {
+		log.debug( "normalizing path expression root as unqualified property [" + textOrNull( propertyName ) + "]" );
+		PathedPropertyReferenceSource root = getCurrentPathResolutionStrategy().handleRoot(
+				getCurrentPersisterSpaceContext().locatePersisterSpaceExposingProperty( propertyName.getText() )
+		);
+		return root.handleIntermediatePathPart( propertyName.getText() );
+	}
+
+	protected PathedPropertyReferenceSource normalizeQualifiedRoot(Tree alias) {
+		log.debug( "normalizing path expression root as alias [" + alias.getText() + "]" );
+		return getCurrentPathResolutionStrategy().handleRoot(
+				getCurrentPersisterSpaceContext().locatePersisterSpaceByAlias( alias.getText() )
+		);
+	}
+
+	protected Tree normalizePropertyPathTerminus(PathedPropertyReferenceSource source, Tree propertyNameNode) {
+		log.trace( "normalizing terminal path expression [" + textOrNull( propertyNameNode ) + "]" );
+		return getCurrentPathResolutionStrategy().handleTerminalPathPart( source, propertyNameNode.getText() );
+	}
+
+	protected PathedPropertyReferenceSource normalizePropertyPathIntermediary(
+			PathedPropertyReferenceSource source,
+			Tree propertyName) {
+		log.trace( "normalizing intermediate path expression [" + textOrNull( propertyName ) + "]" );
+		return getCurrentPathResolutionStrategy().handleIntermediatePathPart( source, propertyName.getText() );
+	}
+
+	protected PathedPropertyReferenceSource normalizeUnqualifiedPropertyReferenceSource(Tree propertyName) {
+		return getCurrentPathResolutionStrategy().handleRoot(
+				getCurrentPersisterSpaceContext().locatePersisterSpaceExposingProperty( propertyName.getText() )
+		);
+	}
+
+	protected PathedPropertyReferenceSource normalizeIntermediateIndexOperation(
+			PathedPropertyReferenceSource collectionSource,
+			Tree collectionProperty,
+			Tree selector) {
+		log.trace( "normalizing intermediate index access [" + textOrNull( collectionProperty ) + "]" );
+		return getCurrentPathResolutionStrategy().handleIntermediateIndexAccess(
+				collectionSource,
+				collectionProperty.getText(),
+				new HibernateTree( ( CommonTree ) selector )
+		);
+	}
+
+	protected void normalizeTerminalIndexOperation(
+			PathedPropertyReferenceSource collectionSource,
+			Tree collectionProperty,
+			Tree selector) {
+		log.trace( "normalizing terminal index access [" + textOrNull( collectionProperty ) + "]" );
+		getCurrentPathResolutionStrategy().handleTerminalIndexAccess(
+				collectionSource, collectionProperty.getText(),
+				new HibernateTree( ( CommonTree ) selector )
+		);
+	}
+
+	private String textOrNull(Tree tree) {
+		return tree == null ? null : tree.getText();
+	}
+
+}
\ No newline at end of file


Property changes on: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/HQLResolver.java
___________________________________________________________________
Name: svn:eol-style
   + native

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/HierarchicalPersisterSpaceContext.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HierarchicalPersisterSpaceContext.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/HierarchicalPersisterSpaceContext.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/HierarchicalPersisterSpaceContext.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,103 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+package org.hibernate.sql.ast.origin.hql.resolve;
+
+/**
+ * Defines a hierarchical representation of a persister reference context.
+ * <p/>
+ * Generally speaking this notion should really only hold for SELECT statements.  Does not make sense for
+ * INSERT or UPDATE or DELETE statements to have a parent, as that would mean they are being used as in a subqquery
+ * (certainly, however, it makes sense for these to *be the parent* context...).
+ *
+ * @author Steve Ebersole
+ */
+public class HierarchicalPersisterSpaceContext extends RootPersisterSpaceContext {
+	private final PersisterSpaceContext parent;
+
+	public HierarchicalPersisterSpaceContext(PersisterSpaceContext parent) {
+		super();
+		if ( parent == null ) {
+			throw new IllegalArgumentException( "Parent PersisterSpaceContext cannot be null!" );
+		}
+		this.parent = parent;
+	}
+
+	/**
+	 * Get the parent context of this context.
+	 *
+	 * @return Our parent context.
+	 */
+	public PersisterSpaceContext getParent() {
+		return parent;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 * <p/>
+	 * Overriden to project the lookup to our parent if not found locally.
+	 */
+	public boolean isContainedAlias(String alias) {
+		return super.isContainedAlias( alias ) || getParent().isContainedAlias( alias );
+	}
+
+	/**
+	 * {@inheritDoc}
+	 * <p/>
+	 * Overriden to project the lookup to our parent if not found locally.
+	 */
+	public boolean isContainedExposedProperty(String propertyName) {
+		return super.isContainedExposedProperty( propertyName ) || getParent().isContainedExposedProperty( propertyName );
+	}
+
+	/**
+	 * {@inheritDoc}
+	 * <p/>
+	 * Overriden to project the lookup to our parent if not found locally.
+	 */
+	public PersisterSpace locatePersisterSpaceByAlias(String alias) {
+		PersisterSpace persisterSpace = super.locatePersisterSpaceByAlias( alias );
+		if ( persisterSpace == null ) {
+			persisterSpace = getParent().locatePersisterSpaceByAlias( alias );
+		}
+		return persisterSpace;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 * <p/>
+	 * Overriden to project the lookup to our parent if not found locally.
+	 */
+	public PersisterSpace locatePersisterSpaceExposingProperty(String propertyName) {
+		PersisterSpace persisterSpace = super.locatePersisterSpaceExposingProperty( propertyName );
+		if ( persisterSpace == null ) {
+			persisterSpace = getParent().locatePersisterSpaceExposingProperty( propertyName );
+		}
+		return persisterSpace;
+	}
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/PersisterSpace.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpace.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/PersisterSpace.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/PersisterSpace.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,70 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+package org.hibernate.sql.ast.origin.hql.resolve;
+
+import org.hibernate.type.Type;
+import org.hibernate.sql.ast.tree.Table;
+
+/**
+ *
+ * @author Steve Ebersole
+ */
+public interface PersisterSpace {
+	/**
+	 * Retrieve the corresponding alias from the input (HQL, etc).
+	 *
+	 * @return The source alias.
+	 */
+	public String getSourceAlias();
+
+	/**
+	 * Retrieve the name of the underlying persister.
+	 *
+	 * @return The persister name.
+	 */
+	public String getName();
+
+	/**
+	 * Retrieve the short (unqualified) version of the persister name.
+	 * <p/>
+	 * Useful for alias basing.
+	 *
+	 * @return The persister short name.
+	 */
+	public String getShortName();
+
+	public Table.TableSpace getTableSpace();
+
+	public boolean containsProperty(String propertyName);
+
+	public Type getPropertyType(String propertyName);
+
+	public Table locateReusablePropertyJoinedTable(String propertyName);
+	public void registerReusablePropertyJoinedTable(String propertyName, Table table);
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/PersisterSpaceContext.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpaceContext.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/PersisterSpaceContext.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/PersisterSpaceContext.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,76 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+package org.hibernate.sql.ast.origin.hql.resolve;
+
+/**
+ * The contract for defining a scoping for references to persisters.
+ *
+ * @author Steve Ebersole
+ */
+public interface PersisterSpaceContext {
+	/**
+	 * Does the given text represent an alias for a persister within this context?
+	 *
+	 * @param text The potential persister alias.
+	 * @return True if given text is a persister alias; false otherwise.
+	 */
+	public boolean isContainedAlias(String text);
+
+	/**
+	 * Does the given text represent a property exposed from a persister in this context?
+	 *
+	 * @param text The potential property name.
+	 * @return True if a persister in this context exposes such a property; false otherwise.
+	 */
+	public boolean isContainedExposedProperty(String text);
+
+	/**
+	 * Locate a {@link PersisterSpace} by alias.
+	 *
+	 * @param alias The alias by which to locate the persister space.
+	 * @return The persister reference, or null.
+	 */
+	public PersisterSpace locatePersisterSpaceByAlias(String alias);
+
+	/**
+	 * Locate a {@link PersisterSpace} in this context defined by a persister which exposes the
+	 * specified property.
+	 *
+	 * @param propertyName The name of the property.
+	 * @return The persister space, or null.
+	 */
+	public PersisterSpace locatePersisterSpaceExposingProperty(String propertyName);
+
+	/**
+	 * Registers a persister space in this context.
+	 *
+	 * @param persisterSpace The persister reference to register.
+	 */
+	public void registerPersisterSpace(PersisterSpace persisterSpace);
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/PersisterTableExpressionGenerator.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableExpressionGenerator.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/PersisterTableExpressionGenerator.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/PersisterTableExpressionGenerator.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,219 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+package org.hibernate.sql.ast.origin.hql.resolve;
+
+import org.hibernate.persister.MappedTableMetadata;
+import org.hibernate.persister.collection.QueryableCollection;
+import org.hibernate.persister.entity.Queryable;
+import org.hibernate.sql.ast.alias.TableAliasGenerator;
+import org.hibernate.sql.ast.common.HibernateTree;
+import org.hibernate.sql.ast.tree.Table;
+import org.hibernate.sql.ast.util.TreePrinter;
+import org.hibernate.sql.ast.origin.hql.parse.HQLLexer;
+
+/**
+ * Generate table expressions for persisters.
+ * <p/>
+ * NOTE : temporary, until such time as we are able to have the persisters themselves return these structures.
+ *
+ * @author Steve Ebersole
+ */
+public abstract class PersisterTableExpressionGenerator {
+	/**
+	 * Generate the table expression for the given entity persister.
+	 *
+	 * @param persister The entity persister.
+	 * @param aliasRoot The alias root for SQL alias generation.
+	 * @param tableSpace The table space to which any generated table references need to belong.
+	 *
+	 * @return The generated table expression (could be simply the root table in a joined table structure).
+	 */
+	public static Table generateTableExpression(
+			Queryable persister,
+			TableAliasGenerator.TableAliasRoot aliasRoot,
+			Table.EntityTableSpace tableSpace) {
+		MappedTableMetadata tableMetadata = persister.getMappedTableMetadata();
+
+		final String drivingTableName = tableMetadata.getDrivingTableName();
+		final String[] drivingTableJoinColumns = tableMetadata.getIdentifierColumnNames();
+		final String drivingTableAlias = aliasRoot.generate( 0 );
+		final Table drivingTable = generateTableReference( drivingTableName, drivingTableAlias, tableSpace );
+
+		int suffix = 0;
+
+		for ( MappedTableMetadata.JoinedTable joinedTable : tableMetadata.getJoinedTables() ) {
+			final String joinTableAlias = aliasRoot.generate( ++suffix );
+			final Table table = generateTableReference( joinedTable.getName(), joinTableAlias, tableSpace );
+
+			final HibernateTree join = new HibernateTree( HQLLexer.JOIN, "join" );
+			drivingTable.addChild( join );
+			if ( joinedTable.useInnerJoin() ) {
+				join.addChild( new HibernateTree( HQLLexer.INNER, "inner" ) );
+			}
+			else {
+				join.addChild( new HibernateTree( HQLLexer.LEFT, "left outer" ) );
+			}
+			join.addChild( table );
+
+			final HibernateTree on = new HibernateTree( HQLLexer.ON, "on" );
+			join.addChild( on );
+			final HibernateTree joinCondition = generateJoinCorrelation(
+					drivingTableAlias,
+					drivingTableJoinColumns,
+					joinTableAlias,
+					joinedTable.getKeyColumns()
+			);
+			on.addChild( joinCondition );
+		}
+
+		// todo : temporary...
+		System.out.println(
+				new TreePrinter( HQLLexer.class ).renderAsString( drivingTable, "Generated table space" )
+		);
+
+		return drivingTable;
+	}
+
+	/**
+	 * Generate the table expression for the given collection persister.
+	 *
+	 * @param collectionPersister The collection persister
+	 * @param aliasRoot The alias root for SQL alias generation.
+	 * @param tableSpace The table space to which any generated table references need to belong.
+	 *
+	 * @return The generated table expression (could be simply the root table in a joined table structure).
+	 */
+	public static Table generateTableExpression(
+			QueryableCollection collectionPersister,
+			TableAliasGenerator.TableAliasRoot aliasRoot,
+			Table.CollectionTableSpace tableSpace) {
+		if ( collectionPersister.isOneToMany() ) {
+			Table table = generateTableExpression(
+					( Queryable ) collectionPersister.getElementPersister(),
+					aliasRoot,
+					tableSpace.getEntityElementTableSpace()
+			);
+			tableSpace.setCollectionTable( table );
+			return table;
+		}
+		else {
+			Table associationTable = generateTableReference(
+					collectionPersister.getTableName(),
+					aliasRoot.generateCollectionTableAlias(),
+					tableSpace
+			);
+			tableSpace.setCollectionTable( associationTable );
+
+			if ( collectionPersister.isManyToMany() ) {
+				Queryable elementPersister = ( Queryable ) collectionPersister.getElementPersister();
+				Table drivingTable = generateTableExpression(
+						elementPersister,
+						aliasRoot,
+						tableSpace.getEntityElementTableSpace()
+				);
+
+				final HibernateTree join = new HibernateTree( HQLLexer.JOIN );
+				associationTable.addChild( join );
+				join.addChild( new HibernateTree( HQLLexer.LEFT, "left outer" ) );
+				join.addChild( drivingTable );
+
+				String[] entityFkColumnNames = collectionPersister.getElementColumnNames();
+				String[] entityPkColumnNames = elementPersister.getKeyColumnNames();
+
+				final HibernateTree on = new HibernateTree( HQLLexer.ON );
+				join.addChild( on );
+				final HibernateTree joinCondition = generateJoinCorrelation(
+						associationTable.getAliasText(),
+						entityFkColumnNames,
+						drivingTable.getAliasText(),
+						entityPkColumnNames
+				);
+				on.addChild( joinCondition );
+			}
+			return associationTable;
+		}
+	}
+
+	private static Table generateTableReference(String tableName, String tableAlias, Table.TableSpace tableSpace) {
+		return new Table( tableName, tableAlias, tableSpace );
+	}
+
+	/**
+	 * Creates a join correlation subtree (AST representing all the conditions on which the join occurs).
+	 *
+	 * @param lhsAlias The alias for the left-hand side (LHS) of the join
+	 * @param lhsColumns The LHS columns
+	 * @param rhsAlias The alias for the right-hand side (RHS) of the join
+	 * @param rhsColumns The RHS columns
+	 *
+	 * @return The join correlation AST.
+	 */
+	public static HibernateTree generateJoinCorrelation(
+			String lhsAlias,
+			String[] lhsColumns,
+			String rhsAlias,
+			String[] rhsColumns) {
+		HibernateTree correlation = generateJoinCorrelation( lhsAlias, lhsColumns[0], rhsAlias, rhsColumns[0] );
+		if ( lhsColumns.length > 1 ) {
+			for ( int i = 1; i < lhsColumns.length; i++ ) {
+				HibernateTree previous = correlation;
+				correlation = new HibernateTree( HQLLexer.AND, "and" );
+				correlation.addChild( previous );
+				correlation.addChild( generateJoinCorrelation( lhsAlias, lhsColumns[i], rhsAlias, rhsColumns[i] ) );
+			}
+		}
+		return correlation;
+	}
+
+	/**
+	 * Creates a join correlation subtree.  The difference here is that we have just a single column on each side.
+	 *
+	 * @param lhsAlias The alias for the left-hand side (LHS) of the join
+	 * @param lhsColumn The LHS column
+	 * @param rhsAlias The alias for the right-hand side (RHS) of the join
+	 * @param rhsColumn The RHS column
+	 *
+	 * @return The join correlation AST.
+	 */
+	public static HibernateTree generateJoinCorrelation(String lhsAlias, String lhsColumn, String rhsAlias, String rhsColumn) {
+		HibernateTree lhs = new HibernateTree( HQLLexer.COLUMN );
+		lhs.addChild( new HibernateTree( HQLLexer.ALIAS_REF, lhsAlias ) );
+		lhs.addChild( new HibernateTree( HQLLexer.IDENTIFIER, lhsColumn ) );
+
+		HibernateTree rhs = new HibernateTree( HQLLexer.COLUMN );
+		rhs.addChild( new HibernateTree( HQLLexer.ALIAS_REF, rhsAlias ) );
+		rhs.addChild( new HibernateTree( HQLLexer.IDENTIFIER, rhsColumn ) );
+
+		HibernateTree correlation = new HibernateTree( HQLLexer.EQUALS, "=" );
+		correlation.addChild( lhs );
+		correlation.addChild( rhs );
+
+		return correlation;
+	}
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/PropertyPathTerminus.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PropertyPathTerminus.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/PropertyPathTerminus.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/PropertyPathTerminus.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,40 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+
+package org.hibernate.sql.ast.origin.hql.resolve;
+
+import org.hibernate.sql.ast.common.HibernateTree;
+
+/**
+ * Represents the terminal part of a property path.
+ *
+ * @author Steve Ebersole
+ */
+public abstract class PropertyPathTerminus extends HibernateTree {
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/ResolutionContext.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/ResolutionContext.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/ResolutionContext.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/ResolutionContext.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,94 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+
+package org.hibernate.sql.ast.origin.hql.resolve;
+
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.sql.ast.alias.TableAliasGenerator;
+import org.hibernate.sql.ast.origin.hql.resolve.path.PathResolutionStrategy;
+import org.hibernate.sql.ast.util.TreePrinter;
+
+/**
+ * todo : javadocs
+ *
+ * @author Steve Ebersole
+ */
+public interface ResolutionContext {
+
+	/**
+	 * The session factory available for this context.  Providing, for example, mapping information.
+	 *
+	 * @return The session factory.
+	 */
+	public SessionFactoryImplementor getSessionFactoryImplementor();
+
+	/**
+	 * The current {@link PersisterSpaceContext} for this context.  The {@link PersisterSpaceContext}
+	 * can change in relation to subqueries and such.  See {@link PersisterSpaceContext} docs for more info.
+	 *
+	 * @return The current {@link PersisterSpaceContext} for this resolution context.
+	 */
+	public PersisterSpaceContext getCurrentPersisterSpaceContext();
+
+//	/**
+//	 * The builder of {@link PersisterReference} instances for this context.
+//	 *
+//	 * @return The {@link PersisterReference} builder.
+//	 */
+//	public PersisterReferenceBuilder getPersisterReferenceBuilder();
+//
+//	/**
+//	 * The builder of {@link Join} instances pertaining to property joins for this context.
+//	 *
+//	 * @return The property {@link Join} builder.
+//	 */
+//	public PropertyJoinBuilder getPropertyJoinBuilder();
+
+	/**
+	 * The tree printer available for this context.
+	 *
+	 * @return The tree printer.
+	 */
+	public TreePrinter getTreePrinter();
+
+	public TableAliasGenerator getTableAliasGenerator();
+
+	/**
+	 * Is this context currently processing a function?
+	 *
+	 * @return True or false.
+	 */
+	public boolean isCurrentlyProcessingFunction();
+
+	public PathResolutionStrategy getCurrentPathResolutionStrategy();
+
+	public void registerAssociationFetch(PersisterSpace persisterSpace);
+
+	public void registerPropertyFetch(PersisterSpace persisterSpace);
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/RootPersisterSpaceContext.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/RootPersisterSpaceContext.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/RootPersisterSpaceContext.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/RootPersisterSpaceContext.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,107 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+
+package org.hibernate.sql.ast.origin.hql.resolve;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.QueryException;
+
+/**
+ * Defines the contract for implementors of a "context" or a "scope" for references to persisters.  Generally speaking,
+ * this maps to the notion of a FROM clause in a SELECT statement.  However, DML operations also have a notion of a
+ * persister reference.  This, then, acts as the abstraction of these grouped references to persisters.
+ *
+ * @author Steve Ebersole
+ */
+public class RootPersisterSpaceContext implements PersisterSpaceContext {
+	private static final Logger log = LoggerFactory.getLogger( RootPersisterSpaceContext.class );
+
+	private List<PersisterSpace> persisterSpaces = new ArrayList<PersisterSpace>();
+	private Map<String,PersisterSpace> aliasXref = new HashMap<String,PersisterSpace>();
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public void registerPersisterSpace(PersisterSpace persisterSpace) {
+		if ( persisterSpace.getSourceAlias() == null ) {
+			throw new IllegalArgumentException( "unexpected null persister-reference alias" );
+		}
+		persisterSpaces.add( persisterSpace );
+		aliasXref.put( persisterSpace.getSourceAlias(), persisterSpace );
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean isContainedAlias(String alias) {
+		return aliasXref.containsKey( alias );
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean isContainedExposedProperty(String propertyName) {
+		// a matching alias always takes precedence...
+		return ( ! isContainedAlias( propertyName ) ) && locatePersisterSpaceExposingProperty( propertyName ) != null;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public PersisterSpace locatePersisterSpaceByAlias(String alias) {
+		log.trace( "attempting to resolve [" + alias + "] as persister space alias" );
+		return aliasXref.get( alias );
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public PersisterSpace locatePersisterSpaceExposingProperty(String propertyName) {
+		log.trace( "attempting to resolve [" + propertyName + "] as unqualified property" );
+		PersisterSpace match = null;
+		for ( PersisterSpace persisterSpace : persisterSpaces ) {
+			if ( persisterSpace.containsProperty( propertyName ) ) {
+				if ( match != null ) {
+					// todo : better exception type
+					throw new QueryException( "multiple persisters contained property [" + propertyName + "]" );
+				}
+				match = persisterSpace;
+			}
+		}
+		return match;
+	}
+
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/PathResolutionStrategy.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathResolutionStrategy.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/PathResolutionStrategy.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/PathResolutionStrategy.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,94 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+
+package org.hibernate.sql.ast.origin.hql.resolve.path;
+
+import org.hibernate.sql.ast.origin.hql.resolve.PersisterSpace;
+import org.hibernate.sql.ast.common.HibernateTree;
+
+/**
+ * Applies a strategy pattern to the manner in which path expressions are normalized, allowing contextual pluggability
+ * of the implicit-join and index-access handling rules...
+ *
+ * @author Steve Ebersole
+ */
+public interface PathResolutionStrategy {
+	/**
+	 * Handle the root of the pathed property reference.
+	 *
+	 * @param persisterReference The root of the path.
+	 *
+	 * @return The source representation of the path root.
+	 */
+	public PathedPropertyReferenceSource handleRoot(PersisterSpace persisterReference);
+
+	/**
+	 * Handle an intermeidary path part.
+	 *
+	 * @param source The source of the property reference.
+	 * @param pathPart The current property path part.
+	 *
+	 * @return The new source for further property part handling.
+	 */
+	public PathedPropertyReferenceSource handleIntermediatePathPart(PathedPropertyReferenceSource source, String pathPart);
+
+	/**
+	 * Handle the terminal path part.
+	 *
+	 * @param source The source of the property reference.
+	 * @param pathPart The current (and terminal/last) path part.
+	 *
+	 * @return The terminal property reference indicated by the overall path.
+	 */
+	public HibernateTree handleTerminalPathPart(PathedPropertyReferenceSource source, String pathPart);
+
+	/**
+	 * Handle an index access operation (a.b[selector] for example).  In this particular case the index access
+	 * is further dereferenced (it is intermediate).
+	 *
+	 * @param source The source of the property reference.
+	 * @param pathPart The current property path part, here specifically naming the collection property
+	 * @param selector The index selection expression
+	 *
+	 * @return The new source for further property part handling.
+	 */
+	public PathedPropertyReferenceSource handleIntermediateIndexAccess(PathedPropertyReferenceSource source, String pathPart, HibernateTree selector);
+
+	/**
+	 * Handle an index access operation (a.b[selector] for example).  In this particular case the index access
+	 * is the terminus of the path expression.
+	 *
+	 * @param source The source of the property reference.
+	 * @param pathPart The current property path part, here specifically naming the collection property
+	 * @param selector The index selection expression
+	 *
+	 * @return The terminal property reference indicated by the overall path.
+	 */
+	public HibernateTree handleTerminalIndexAccess(PathedPropertyReferenceSource source, String pathPart, HibernateTree selector);
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/PathResolutionStrategyStack.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathResolutionStrategyStack.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/PathResolutionStrategyStack.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/PathResolutionStrategyStack.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,53 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+
+package org.hibernate.sql.ast.origin.hql.resolve.path;
+
+import java.util.LinkedList;
+
+/**
+ * Provides a stack of {@link PathResolutionStrategy} instances.
+ *
+ * @author Steve Ebersole
+ */
+public class PathResolutionStrategyStack {
+	private LinkedList<PathResolutionStrategy> stack = new LinkedList<PathResolutionStrategy>();
+
+	public void push(PathResolutionStrategy handler) {
+		stack.addFirst( handler );
+	}
+
+	public PathResolutionStrategy pop() {
+		return stack.removeFirst();
+	}
+
+	public PathResolutionStrategy getCurrent() {
+		return stack.getFirst();
+	}
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/PathedPropertyReferenceSource.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathedPropertyReferenceSource.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/PathedPropertyReferenceSource.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/PathedPropertyReferenceSource.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,90 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+package org.hibernate.sql.ast.origin.hql.resolve.path;
+
+import org.antlr.runtime.tree.Tree;
+
+import org.hibernate.sql.ast.common.HibernateTree;
+
+/**
+ * The contract for representing the non-terminal parts of a property path expression
+ * <p/>
+ * NOTE : extends AST so the grammar can more easily handle it, not because it will actually end up in the syntax
+ * tree (it will not).
+ *
+ * @author Steve Ebersole
+ */
+public interface PathedPropertyReferenceSource extends Tree {
+	/**
+	 * Return the path which led to this source.
+	 *
+	 * @return The origination path.
+	 */
+	public String getOriginationPath();
+
+	/**
+	 * Handle an intermediate path part reference.
+	 *
+	 * @param name The name for the path part to handle.
+	 *
+	 * @return An appropriate source representation of said intermeidate path part.
+	 */
+	public PathedPropertyReferenceSource handleIntermediatePathPart(String name);
+
+	/**
+	 * Handle the terminal path reference.
+	 *
+	 * @param name The name of the terminal path part.
+	 *
+	 * @return The property reference terminus.
+	 */
+	public HibernateTree handleTerminalPathPart(String name);
+
+	/**
+	 * Handle an index access operation (a.b[selector] for example).  In this particular case the index access
+	 * is further dereferenced (it is intermediate).
+	 *
+	 * @param collectionPropertyName The name of the collection property to which the index operator applies
+	 * @param selector The index selection expression
+	 *
+	 * @return An appropriate source representation of said intermeidate path part.
+	 */
+	public PathedPropertyReferenceSource handleIntermediateIndexAccess(String collectionPropertyName, HibernateTree selector);
+
+	/**
+	 * Handle an index access operation (a.b[selector] for example).  In this particular case the index access
+	 * is the terminus of the path expression.
+	 * 
+	 * @param collectionPropertyName The name of the collection property to which the index operator applies
+	 * @param selector The index selection expression
+	 *
+	 * @return The property reference terminus.
+	 */
+	public HibernateTree handleTerminalIndexAccess(String collectionPropertyName, HibernateTree selector);
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/AbstractPathResolutionStrategy.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/AbstractPathResolutionStrategy.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/AbstractPathResolutionStrategy.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/AbstractPathResolutionStrategy.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,610 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+package org.hibernate.sql.ast.origin.hql.resolve.path.impl;
+
+import org.antlr.runtime.Token;
+import org.hibernate.QueryException;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.persister.collection.QueryableCollection;
+import org.hibernate.persister.entity.Queryable;
+import org.hibernate.sql.ast.alias.TableAliasGenerator;
+import org.hibernate.sql.ast.common.HibernateToken;
+import org.hibernate.sql.ast.common.HibernateTree;
+import org.hibernate.sql.ast.origin.hql.resolve.PersisterSpace;
+import org.hibernate.sql.ast.origin.hql.resolve.PersisterTableExpressionGenerator;
+import org.hibernate.sql.ast.origin.hql.resolve.ResolutionContext;
+import org.hibernate.sql.ast.origin.hql.resolve.path.PathedPropertyReferenceSource;
+import org.hibernate.sql.ast.origin.hql.resolve.path.PathResolutionStrategy;
+import org.hibernate.sql.ast.origin.hql.parse.HQLLexer;
+import org.hibernate.sql.ast.tree.Table;
+import org.hibernate.sql.ast.util.DisplayableNode;
+import org.hibernate.sql.ast.util.TreePrinter;
+import org.hibernate.type.CollectionType;
+import org.hibernate.type.ComponentType;
+import org.hibernate.type.EntityType;
+import org.hibernate.type.Type;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract implementation of {@link org.hibernate.sql.ast.origin.hql.resolve.path.PathResolutionStrategy} providing convenience methods to actual
+ * {@link PathResolutionStrategy} implementors.
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractPathResolutionStrategy implements PathResolutionStrategy {
+	private static final Logger log = LoggerFactory.getLogger( AbstractPathResolutionStrategy.class );
+
+	private final ResolutionContext resolutionContext;
+	private String pathThusFar = null;
+
+	protected AbstractPathResolutionStrategy(ResolutionContext resolutionContext) {
+		this.resolutionContext = resolutionContext;
+	}
+
+	// reolution context ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	/**
+	 * Getter for property 'resolutionContext'.
+	 *
+	 * @return Value for property 'resolutionContext'.
+	 */
+	protected ResolutionContext resolutionContext() {
+		return resolutionContext;
+	}
+
+	protected final HibernateTree createNode(int type, String text) {
+		return new HibernateTree(type, text);
+	}
+
+	/**
+	 * Getter for property 'sessionFactoryImplementor'.
+	 *
+	 * @return Value for property 'sessionFactoryImplementor'.
+	 */
+	protected final SessionFactoryImplementor getSessionFactoryImplementor() {
+		return resolutionContext().getSessionFactoryImplementor();
+	}
+
+	/**
+	 * Getter for property 'ASTPrinter'.
+	 *
+	 * @return Value for property 'ASTPrinter'.
+	 */
+	protected final TreePrinter getTreePrinter() {
+		return resolutionContext().getTreePrinter();
+	}
+
+
+	// path ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	protected void initializePathSoFar(String root) {
+		pathThusFar = root;
+	}
+
+	/**
+	 * Getter for property 'pathThusFar'.
+	 *
+	 * @return Value for property 'pathThusFar'.
+	 */
+	public String getPathThusFar() {
+		return pathThusFar;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public final PathedPropertyReferenceSource handleRoot(PersisterSpace persisterSpace) {
+		initializePathSoFar( persisterSpace.getSourceAlias() );
+		log.trace( "handling root path source [" + pathThusFar + "]" );
+		return internalHandleRoot( persisterSpace );
+	}
+
+	/**
+	 * Hook for subclasses to process the path root.
+	 *
+	 * @param persisterSpace The persister defining the source root.
+	 * @return The appropriate property path source implementation.
+	 */
+	protected abstract PathedPropertyReferenceSource internalHandleRoot(PersisterSpace persisterSpace);
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public final PathedPropertyReferenceSource handleIntermediatePathPart(PathedPropertyReferenceSource source, String pathPart) {
+		pathThusFar = ( pathThusFar == null ) ? pathPart : pathThusFar + "." + pathPart;
+		log.trace( "handling intermediate path source [" + pathThusFar + "]" );
+		return internalResolveIntermediatePathPart( source, pathPart );
+	}
+
+	/**
+	 * Hook for subclasses to process an intermediate part of the path.
+	 *
+	 * @param source The source from which pathPart originates.
+	 * @param pathPart The name of the path part to be processed.
+	 * @return The appropriate property path source implementation.
+	 */
+	protected PathedPropertyReferenceSource internalResolveIntermediatePathPart(PathedPropertyReferenceSource source, String pathPart) {
+		return source.handleIntermediatePathPart( pathPart );
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public final HibernateTree handleTerminalPathPart(PathedPropertyReferenceSource source, String pathPart) {
+		pathThusFar = ( pathThusFar == null ) ? pathPart : pathThusFar + "." + pathPart;
+		log.trace( "handling terminal path part [" + pathThusFar + "]" );
+		try {
+			return internalResolveTerminalPathPart( source, pathPart );
+		}
+		finally {
+			pathThusFar = null;
+		}
+	}
+
+	/**
+	 * Hook for subclasses to process the terminal (or ending) part of a path.
+	 *
+	 * @param source The source from which pathPart originates.
+	 * @param pathPart The name of the path part to be processed.
+	 * @return a node representing the normalized property path.
+	 */
+	protected HibernateTree internalResolveTerminalPathPart(PathedPropertyReferenceSource source, String pathPart) {
+		return source.handleTerminalPathPart( pathPart );
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public final PathedPropertyReferenceSource handleIntermediateIndexAccess(PathedPropertyReferenceSource source, String pathPart, HibernateTree selector) {
+		pathThusFar = ( ( pathThusFar == null ) ? pathPart : pathThusFar + "." + pathPart ) + "[]";
+		log.trace( "handling intermediate index access [" + pathThusFar + "]" );
+		try {
+			return internalHandleIntermediateIndexAccess( source, pathPart, selector );
+		}
+		finally {
+			pathThusFar = null;
+		}
+	}
+
+	/**
+	 * Hook for subclasses to process an index access as an intermediate property path.
+	 *
+	 * @param source The source from which pathPart originates.
+	 * @param pathPart The name of the path part to be processed.
+	 * @param selector The index selector to be appliedto the indexed collection
+	 *
+	 * @return The appropriate property path source implementation.
+	 */
+	protected PathedPropertyReferenceSource internalHandleIntermediateIndexAccess(PathedPropertyReferenceSource source, String pathPart, HibernateTree selector) {
+		return source.handleIntermediateIndexAccess( pathPart, selector );
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public final HibernateTree handleTerminalIndexAccess(PathedPropertyReferenceSource source, String pathPart, HibernateTree selector) {
+		pathThusFar = ( ( pathThusFar == null ) ? pathPart : pathThusFar + "." + pathPart ) + "[]";
+		log.trace( "handling terminal index access [" + pathThusFar + "]" );
+		try {
+			return internalHandleTerminalIndexAccess( source, pathPart, selector );
+		}
+		finally {
+			pathThusFar = null;
+		}
+	}
+
+	/**
+	 * Hook for subclasses to process an index access as the terminus of a property path.
+	 *
+	 * @param source The source from which pathPart originates.
+	 * @param pathPart The name of the path part to be processed.
+	 * @param selector The index selector to be appliedto the indexed collection
+	 *
+	 * @return a node representing the normalized property path.
+	 */
+	protected HibernateTree internalHandleTerminalIndexAccess(PathedPropertyReferenceSource source, String pathPart, HibernateTree selector) {
+		return source.handleTerminalIndexAccess( pathPart, selector );
+	}
+
+	/**
+	 * Convenience method to locate the index of a component sub-property.  The returned index is relative to
+	 * {@link ComponentType#getPropertyNames}.
+	 *
+	 * @param componentType The component type mapping.
+	 * @param subPropertyName The sub-property name.
+	 * @return The index.
+	 */
+	protected static int locateComponentPropertyIndex(ComponentType componentType, String subPropertyName) {
+		String[] componentPropertyNames = componentType.getPropertyNames();
+		for ( int i = 0; i < componentPropertyNames.length; i++ ) {
+			if ( componentPropertyNames[i].equals( subPropertyName ) ) {
+				return i;
+			}
+		}
+		throw new QueryException( "could not locate component property [" + subPropertyName + "]" );
+	}
+
+	/**
+	 * Hook to allow subclasses to disallow implicit join.
+	 *
+	 * @param origin The persister-reference which is the origin of the property
+	 * @param property The property resulting in a join.
+	 */
+	protected void validateJoinCreation(PersisterSpace origin, String property) {
+		log.debug( "creating path expression implied join [" + origin.getSourceAlias() + "].[" + property + "]" );
+	}
+
+	/**
+	 * Hook to allow subclasses to define the type of join to use for an implciit join.
+	 * <p/>
+	 * The default is to use an {@link HQLLexer#INNER} join.
+	 *
+	 * @return The join type node.
+	 */
+	protected HibernateTree buildJoinTypeNode() {
+		return createNode( HQLLexer.INNER, "inner" );
+	}
+
+	/**
+	 * Does this strategy allows property joins to be reused?
+	 *
+	 * @return True/false.
+	 */
+	protected boolean areJoinsReusable() {
+		return true;
+	}
+
+	/**
+	 * Locate (if property joins are reusable) or build an appropriate joined table.
+	 *
+	 * @param lhs The join lhs, which is the origin of the property.
+	 * @param propertyName The name of the property
+	 * @param alias The alias, if any, to apply to the generated RHS persister reference.
+	 * @param propertyFetching Should property fetching be applied to the generated RHS?
+	 * @param associationFetching Did this property join specify association fetching (join fetch)?
+	 * @return The appropriate join.
+	 */
+	protected final Table locateOrBuildPropertyJoinedTable(
+			PersisterSpace lhs,
+			String propertyName,
+			String alias,
+			boolean propertyFetching,
+			boolean associationFetching) {
+		Table joinedTable = null;
+		if ( areJoinsReusable() ) {
+			joinedTable = lhs.locateReusablePropertyJoinedTable( propertyName );
+		}
+
+		if ( joinedTable == null ) {
+			joinedTable = buildPropertyJoinedTable( lhs, propertyName, alias, propertyFetching, associationFetching );
+			if ( areJoinsReusable() ) {
+				lhs.registerReusablePropertyJoinedTable( propertyName, joinedTable );
+			}
+		}
+
+		return joinedTable;
+	}
+
+	/**
+	 * Build a property joined table
+	 *
+	 * @param lhs The join's left-hand-side persister-reference
+	 * @param propertyName The property name.
+	 * @param alias The alias to apply to the rhs of the join
+	 * @param propertyFetching should property fetching be applied to the joined persister?
+	 * @param associationFetching Should the association making up the property join also be fetched?
+	 *
+	 * @return The right-hand-side persister-reference.
+	 */
+	protected Table buildPropertyJoinedTable(
+			PersisterSpace lhs,
+			String propertyName,
+			String alias,
+			boolean propertyFetching,
+			boolean associationFetching) {
+		validateJoinCreation( lhs, propertyName );
+		Table joinedTable;
+		Type propertyType = lhs.getPropertyType( propertyName );
+		if ( propertyType.isEntityType() ) {
+			EntityType entityType = ( EntityType ) propertyType;
+			Queryable entityPersister = ( Queryable ) getSessionFactoryImplementor()
+					.getEntityPersister( entityType.getAssociatedEntityName( getSessionFactoryImplementor() ) );
+			joinedTable = createJoin( lhs, entityPersister, alias );
+		}
+		else if ( propertyType.isCollectionType() ) {
+			CollectionType collectionType = ( CollectionType ) propertyType;
+			QueryableCollection collectionPersister = ( QueryableCollection ) getSessionFactoryImplementor()
+					.getCollectionPersister( collectionType.getRole() );
+			joinedTable = createJoin( lhs, collectionPersister, alias, null );
+		}
+		else {
+			throw new InvalidPropertyJoinException( getPathThusFar(), lhs.getName(), propertyName );
+		}
+
+		if ( propertyFetching ) {
+			resolutionContext().registerPropertyFetch( joinedTable.getTableSpace().getPersisterSpace() );
+		}
+		if ( associationFetching ) {
+			resolutionContext.registerAssociationFetch( joinedTable.getTableSpace().getPersisterSpace() );
+		}
+
+		return joinedTable;
+	}
+
+	/**
+	 * Generate a column list (tree w/ token type {@link HQLLexer#COLUMN_LIST} for the columns making up the given
+	 * property.
+	 *
+	 * @param origin The persister-space from which the property originates.
+	 * @param propertyName The name of the property being referenced.
+	 *
+	 * @return The column list.
+	 */
+	protected final HibernateTree generatePropertyColumnList(PersisterSpace origin, String propertyName) {
+		HibernateTree columnList = new HibernateTree( HQLLexer.COLUMN_LIST );
+		Table containingTable = origin.getTableSpace().getContainingTable( propertyName );
+		for ( String columnName : origin.getTableSpace().getPropertyColumnNames( propertyName ) ) {
+			final HibernateTree column = new HibernateTree( HQLLexer.COLUMN );
+			columnList.addChild( column );
+			column.addChild( new HibernateTree( HQLLexer.ALIAS_REF, containingTable.getAliasText() ) );
+			column.addChild( new HibernateTree( HQLLexer.IDENTIFIER, columnName ) );
+		}
+		return columnList;
+	}
+
+
+	// source impl support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	public abstract class AbstractPathedPropertyReferenceSource
+			extends HibernateTree
+			implements PathedPropertyReferenceSource, DisplayableNode {
+		private final String originationPath;
+
+		/**
+		 * Constructs a new AbstractPathedPropertyReferenceSource.
+		 */
+		protected AbstractPathedPropertyReferenceSource() {
+			this( getPathThusFar() );
+		}
+
+		protected AbstractPathedPropertyReferenceSource(Token token) {
+			this( token, getPathThusFar() );
+		}
+
+		protected AbstractPathedPropertyReferenceSource(String originationPath) {
+			super( new HibernateToken( HQLLexer.IDENTIFIER, originationPath ) );
+			this.originationPath = originationPath;
+		}
+
+		protected AbstractPathedPropertyReferenceSource(Token token, String originationPath) {
+			super( token );
+			this.originationPath = originationPath;
+		}
+
+		public HibernateTree handleTerminalIndexAccess(PersisterSpace lhs, String collectionPropertyName, HibernateTree selector) {
+			Table joinedCollectionTable = createIndexAccessJoin( lhs, collectionPropertyName, selector );
+
+			// in general we need the collection element column list
+			QueryableCollection collectionPersister = resolveCollectionPersister( lhs, collectionPropertyName );
+			HibernateTree columnList = new HibernateTree( HQLLexer.COLUMN_LIST );
+			for ( String columnName : collectionPersister.getElementColumnNames() ) {
+				final HibernateTree column = new HibernateTree( HQLLexer.COLUMN );
+				column.addChild( new HibernateTree( HQLLexer.ALIAS_REF, joinedCollectionTable.getAliasText() ) );
+				column.addChild( new HibernateTree( HQLLexer.IDENTIFIER, columnName ) );
+			}
+			return columnList;
+		}
+
+		protected Table createIndexAccessJoin(PersisterSpace lhs, String collectionPropertyName, HibernateTree selector) {
+			validateIndexedCollectionReference( lhs, collectionPropertyName );
+
+			QueryableCollection collectionPersister = resolveCollectionPersister( lhs, collectionPropertyName );
+			Table joinedTable = createJoin( lhs, collectionPersister, null, selector );
+
+			if ( log.isTraceEnabled() ) {
+				log.trace(
+						resolutionContext().getTreePrinter().renderAsString(
+								joinedTable.getParent(),
+								"implicit join : " + lhs.getSourceAlias() + "." + collectionPropertyName + "[]"
+						)
+				);
+			}
+
+			return joinedTable;
+		}
+
+		/**
+		 * {@inheritDoc}
+		 */
+		public String getOriginationPath() {
+			return originationPath;
+		}
+
+		/**
+		 * {@inheritDoc}
+		 */
+		public final String getDisplayText() {
+				return " ADPATER : SHOULD NEVER END UP IN TREE!";
+		}
+	}
+
+	protected Table createJoin(PersisterSpace lhs, String propertyName, String alias) {
+		validateJoinable( lhs, propertyName );
+		Type propertyType = lhs.getPropertyType( propertyName );
+		if ( propertyType.isEntityType() ) {
+			return createJoin( lhs, resolveEntityPersister( lhs, propertyName ), alias );
+		}
+		else {
+			// assume collection because of validation of being joinable...
+			return createJoin( lhs, resolveCollectionPersister( lhs, propertyName ), alias, null );
+		}
+	}
+
+	protected Table createJoin(PersisterSpace lhs, Queryable entityPersister, String alias) {
+		EntityType entityType = entityPersister.getEntityMetamodel().getEntityType();
+
+		TableAliasGenerator.TableAliasRoot tableAliasRoot = resolutionContext().getTableAliasGenerator()
+				.generateSqlAliasRoot( entityPersister, alias );
+		Table.EntityTableSpace tableSpace = new Table.EntityTableSpace( entityPersister, tableAliasRoot );
+		Table joinedTableExpression = tableSpace.getDrivingTable();
+
+		HibernateTree join = new HibernateTree( HQLLexer.JOIN );
+		join.addChild( buildJoinTypeNode() );
+		join.addChild( joinedTableExpression );
+
+		HibernateTree joinCondition;
+		final String lhsJoinProperty = entityType.getLHSPropertyName();
+		if ( lhsJoinProperty == null ) {
+			// join using the lhs PK
+			joinCondition = PersisterTableExpressionGenerator.generateJoinCorrelation(
+					lhs.getTableSpace().getJoinIntoTable().getAliasText(),
+					lhs.getTableSpace().getJoinIntoColumns(),
+					joinedTableExpression.getAliasText(),
+					entityPersister.getKeyColumnNames()
+			);
+		}
+		else {
+			// join using the columns to which the given lhs property is mapped
+			joinCondition = PersisterTableExpressionGenerator.generateJoinCorrelation(
+					lhs.getTableSpace().getContainingTable( lhsJoinProperty ).getAliasText(),
+					lhs.getTableSpace().getPropertyColumnNames( lhsJoinProperty ),
+					joinedTableExpression.getAliasText(),
+					entityPersister.getKeyColumnNames()
+			);
+		}
+
+		HibernateTree on = new HibernateTree( HQLLexer.ON );
+		join.addChild( on );
+		on.addChild( joinCondition );
+
+		return joinedTableExpression;
+	}
+
+	protected Table createJoin(PersisterSpace lhs, QueryableCollection collectionPersister, String sourceAlias, HibernateTree extraJoinConditions) {
+		CollectionType collectionType = collectionPersister.getCollectionType();
+
+		TableAliasGenerator.TableAliasRoot tableAliasRoot = resolutionContext().getTableAliasGenerator()
+				.generateSqlAliasRoot( collectionPersister, sourceAlias );
+		Table.CollectionTableSpace tableSpace = new Table.CollectionTableSpace( collectionPersister, tableAliasRoot );
+
+		Table collectionTableExpression = PersisterTableExpressionGenerator.generateTableExpression(
+				collectionPersister,
+				tableAliasRoot,
+				tableSpace
+		);
+
+		HibernateTree joinNode = new HibernateTree( HQLLexer.JOIN );
+		joinNode.addChild( buildJoinTypeNode() );
+		joinNode.addChild( collectionTableExpression );
+
+		HibernateTree joinCondition;
+		final String lhsJoinProperty = collectionType.getLHSPropertyName();
+		if ( lhsJoinProperty == null ) {
+			// join using the lhs PK
+			joinCondition = PersisterTableExpressionGenerator.generateJoinCorrelation(
+					lhs.getTableSpace().getJoinIntoTable().getAliasText(),
+					lhs.getTableSpace().getJoinIntoColumns(),
+					collectionTableExpression.getAliasText(),
+					collectionPersister.getKeyColumnNames()
+			);
+		}
+		else {
+			// join using the columns to which the given lhs property is mapped
+			joinCondition = PersisterTableExpressionGenerator.generateJoinCorrelation(
+					lhs.getTableSpace().getContainingTable( lhsJoinProperty ).getAliasText(),
+					lhs.getTableSpace().getPropertyColumnNames( lhsJoinProperty ),
+					collectionTableExpression.getAliasText(),
+					collectionPersister.getKeyColumnNames()
+			);
+		}
+
+		if ( extraJoinConditions != null ) {
+			HibernateTree mappedJoinCondition = joinCondition;
+			joinCondition = new HibernateTree( HQLLexer.AND );
+			joinCondition.addChild( mappedJoinCondition );
+			joinCondition.addChild( extraJoinConditions );
+		}
+
+		HibernateTree on = new HibernateTree( HQLLexer.ON );
+		joinNode.addChild( on );
+		on.addChild( joinCondition );
+
+		return collectionTableExpression;
+	}
+
+	protected void validateJoinable(PersisterSpace lhs, String propertyName) {
+		if ( ! isAssociation( lhs.getPropertyType( propertyName ) ) ) {
+			throw new InvalidPropertyJoinException( getPathThusFar(), lhs.getName(), propertyName );
+		}
+	}
+
+	protected boolean isAssociation(Type propertyType) {
+		return propertyType.isAssociationType();
+	}
+
+	protected void validateCollectionReference(PersisterSpace lhs, String propertyName) {
+		if ( ! isCollectionReference( lhs.getPropertyType( propertyName ) ) ) {
+			throw new CollectionExpectedException( getPathThusFar(), lhs.getName(), propertyName );
+		}
+	}
+
+	private boolean isCollectionReference(Type propertyType) {
+		return propertyType.isCollectionType();
+	}
+
+	protected void validateIndexedCollectionReference(PersisterSpace lhs, String propertyName) {
+		if ( ! isIndexedCollectionReference( lhs.getPropertyType( propertyName ) ) ) {
+			throw new IndexedCollectionExectedException( getPathThusFar(), lhs.getName(), propertyName );
+		}
+	}
+
+	private boolean isIndexedCollectionReference(Type propertyType) {
+		return isCollectionReference( propertyType )
+				&& resolveCollectionPersister( ( CollectionType ) propertyType ).hasIndex();
+	}
+
+	protected QueryableCollection resolveCollectionPersister(PersisterSpace lhs, String propertyName) {
+		return resolveCollectionPersister( ( CollectionType ) lhs.getPropertyType( propertyName ) );
+	}
+
+	protected QueryableCollection resolveCollectionPersister(CollectionType collectionType) {
+		return ( QueryableCollection ) getSessionFactoryImplementor().getCollectionPersister( collectionType.getRole() );
+	}
+
+	protected Queryable resolveEntityPersister(PersisterSpace lhs, String propertyName) {
+		return resolveEntityPersister( ( EntityType ) lhs.getPropertyType( propertyName ) );
+	}
+
+	protected Queryable resolveEntityPersister(EntityType entityType) {
+		return ( Queryable ) getSessionFactoryImplementor().getEntityPersister(
+				entityType.getAssociatedEntityName( getSessionFactoryImplementor() )
+		);
+	}
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/AbstractUnexpectedPropertyTypeException.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/AbstractUnexpectedPropertyTypeException.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/AbstractUnexpectedPropertyTypeException.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/AbstractUnexpectedPropertyTypeException.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,71 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+package org.hibernate.sql.ast.origin.hql.resolve.path.impl;
+
+import org.hibernate.QueryException;
+
+/**
+ * Basic exception type definition for indicating that the type of a referenced property did match the type
+ * expected given its position and semantic within the query.
+ *
+ * @author Steve Ebersole
+ */
+public class AbstractUnexpectedPropertyTypeException extends QueryException {
+	private final String path;
+	private final String persisterName;
+	private final String propertyName;
+
+	public AbstractUnexpectedPropertyTypeException(String path, String persisterName, String propertyName) {
+		super();
+		this.path = path;
+		this.persisterName = persisterName;
+		this.propertyName = propertyName;
+	}
+
+	@Override
+	protected String internalGetMessage() {
+		return "Referenced property [" + buildPropertyReferenceFragment() + "] was not of expected type";
+	}
+
+	protected String buildPropertyReferenceFragment() {
+		return path + " (" + persisterName + ")." + propertyName;
+	}
+
+	public String getPath() {
+		return path;
+	}
+
+	public String getPersisterName() {
+		return persisterName;
+	}
+
+	public String getPropertyName() {
+		return propertyName;
+	}
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/BasicPathResolutionStrategySupport.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/BasicPathResolutionStrategySupport.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/BasicPathResolutionStrategySupport.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/BasicPathResolutionStrategySupport.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,334 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+
+package org.hibernate.sql.ast.origin.hql.resolve.path.impl;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.HibernateException;
+import org.hibernate.hql.CollectionProperties;
+import org.hibernate.persister.collection.QueryableCollection;
+import org.hibernate.persister.entity.EntityPersister;
+import org.hibernate.sql.ast.common.HibernateTree;
+import org.hibernate.sql.ast.origin.hql.resolve.PersisterSpace;
+import org.hibernate.sql.ast.origin.hql.resolve.PropertyPathTerminus;
+import org.hibernate.sql.ast.origin.hql.resolve.ResolutionContext;
+import org.hibernate.sql.ast.origin.hql.resolve.path.PathedPropertyReferenceSource;
+import org.hibernate.sql.ast.tree.Table;
+import org.hibernate.type.ComponentType;
+import org.hibernate.type.EntityType;
+import org.hibernate.type.Type;
+
+/**
+ * todo : javadocs
+ *
+ * @author Steve Ebersole
+ */
+public class BasicPathResolutionStrategySupport extends AbstractPathResolutionStrategy {
+	private static final Logger log = LoggerFactory.getLogger( BasicPathResolutionStrategySupport.class );
+
+
+	public BasicPathResolutionStrategySupport(ResolutionContext resolutionContext) {
+		super( resolutionContext );
+	}
+
+	protected PathedPropertyReferenceSource internalHandleRoot(PersisterSpace persisterSpace) {
+		return new RootSourceImpl( persisterSpace );
+	}
+
+	private PathedPropertyReferenceSource determineAppropriateIntermediateSourceType(PersisterSpace origin, String propertyName) {
+		final Type propertyType = origin.getPropertyType( propertyName );
+		if ( propertyType.isComponentType() ) {
+			return new ComponentIntermediatePathSource( origin, propertyName, ( ComponentType ) propertyType );
+		}
+		else if ( propertyType.isEntityType() ) {
+			return new EntityIntermediatePathSource( origin, propertyName );
+		}
+		else if ( propertyType.isCollectionType() ) {
+			return new CollectionIntermediatePathSource( origin, propertyName );
+		}
+		else {
+			return new SimpleIntermediatePathSource();
+		}
+	}
+
+	/**
+	 * Is the given property name a reference to the primary key of the associated
+	 * entity construed by the given entity type?
+	 * <p/>
+	 * For example, consider a fragment like order.customer.id
+	 * (where order is a from-element alias).  Here, we'd have:
+	 * propertyName = "id" AND
+	 * owningType = ManyToOneType(Customer)
+	 * and are being asked to determine whether "customer.id" is a reference
+	 * to customer's PK...
+	 *
+	 * @param propertyName The name of the property to check.
+	 * @param owningType The type represeting the entity "owning" the property
+	 * @return True if propertyName references the enti ty's (owningType->associatedEntity)
+	 * primary key; false otherwise.
+	 */
+	private boolean isReferenceToPrimaryKey(EntityType owningType, String propertyName) {
+		EntityPersister persister = getSessionFactoryImplementor().getEntityPersister(
+				owningType.getAssociatedEntityName( getSessionFactoryImplementor() )
+		);
+		if ( persister.getEntityMetamodel().hasNonIdentifierPropertyNamedId() ) {
+			// only the identifier property field name can be a reference to the associated entity's PK...
+			return propertyName.equals( persister.getIdentifierPropertyName() ) && owningType.isReferenceToPrimaryKey();
+		}
+		else {
+			// here, we have two possibilities:
+			// 		1) the property-name matches the explicitly identifier property name
+			//		2) the property-name matches the implicit 'id' property name
+			if ( EntityPersister.ENTITY_ID.equals( propertyName ) ) {
+				// the referenced node text is the special 'id'
+				return owningType.isReferenceToPrimaryKey();
+			}
+			else {
+				String keyPropertyName = owningType.getIdentifierOrUniqueKeyPropertyName( getSessionFactoryImplementor() );
+				return keyPropertyName != null && keyPropertyName.equals( propertyName ) && owningType.isReferenceToPrimaryKey();
+			}
+		}
+	}
+
+
+
+	// source impls ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+	private class RootSourceImpl extends AbstractPathedPropertyReferenceSource {
+		private final PersisterSpace lhs;
+
+		public RootSourceImpl(PersisterSpace lhs) {
+			this.lhs = lhs;
+		}
+
+		public PathedPropertyReferenceSource handleIntermediatePathPart(String name) {
+			return determineAppropriateIntermediateSourceType( lhs, name );
+		}
+
+		public HibernateTree handleTerminalPathPart(String name) {
+			if ( lhs.getPropertyType( name ).isEntityType() ) {
+				if ( shouldTerminalEntityPropertyForceJoin() ) {
+					locateOrBuildPropertyJoinedTable( lhs, name, null, false, false );
+				}
+			}
+			return generatePropertyColumnList( lhs, name );
+		}
+
+		public PathedPropertyReferenceSource handleIntermediateIndexAccess(String collectionPropertyName, HibernateTree selector) {
+			validateIndexedCollectionReference( lhs, collectionPropertyName );
+			QueryableCollection collectionPersister = resolveCollectionPersister( lhs, collectionPropertyName );
+
+			Table joinedCollectionTable = createJoin( lhs, collectionPersister, null, selector );
+			return new IndexAccessIntermediatePathSource(joinedCollectionTable.getTableSpace().getPersisterSpace() );
+		}
+
+		public HibernateTree handleTerminalIndexAccess(String collectionPropertyName, HibernateTree selector) {
+			return handleTerminalIndexAccess( lhs, collectionPropertyName, selector );
+		}
+
+		public String getText() {
+			return "root-source {" + lhs.getSourceAlias() + "}";
+		}
+	}
+
+	protected class SimpleIntermediatePathSource extends AbstractPathedPropertyReferenceSource {
+		public PathedPropertyReferenceSource handleIntermediatePathPart(String name) {
+			throw new HibernateException( "cannot dereference simple value as part of path expression" );
+		}
+
+		public HibernateTree handleTerminalPathPart(String name) {
+			throw new HibernateException( "cannot dereference simple value as part of path expression" );
+		}
+
+		public PathedPropertyReferenceSource handleIntermediateIndexAccess(String name, HibernateTree selector) {
+			throw new HibernateException( "cannot apply index operation to simple value" );
+		}
+
+		public HibernateTree handleTerminalIndexAccess(String name, HibernateTree selector) {
+			throw new HibernateException( "cannot apply index operation to simple value" );
+		}
+	}
+
+	private class ComponentIntermediatePathSource extends AbstractPathedPropertyReferenceSource {
+		private final PersisterSpace lhs;
+		private final String propertyPath;
+		private final ComponentType componentType;
+
+		public ComponentIntermediatePathSource(PersisterSpace lhs, String propertyPath) {
+			this( lhs, propertyPath, ( ComponentType ) lhs.getPropertyType( propertyPath ) );
+		}
+
+		private ComponentIntermediatePathSource(PersisterSpace lhs, String propertyPath, ComponentType componentType) {
+			this.lhs = lhs;
+			this.propertyPath = propertyPath;
+			this.componentType = componentType;
+		}
+
+		public PathedPropertyReferenceSource handleIntermediatePathPart(String propertyName) {
+			final int index = locateComponentPropertyIndex( componentType, propertyName );
+			final String path = buildComponentDereferencePath( propertyName );
+			final Type propertyType = componentType.getSubtypes()[index];
+			if ( propertyType.isComponentType() ) {
+				return new ComponentIntermediatePathSource( lhs, path, ( ComponentType ) propertyType );
+			}
+			else if ( propertyType.isEntityType() ) {
+				return new EntityIntermediatePathSource( lhs, path );
+			}
+			else {
+				return new SimpleIntermediatePathSource();
+			}
+		}
+
+		public HibernateTree handleTerminalPathPart(String name) {
+			return generatePropertyColumnList( lhs, buildComponentDereferencePath( name ) );
+		}
+
+		public PathedPropertyReferenceSource handleIntermediateIndexAccess(String name, HibernateTree selector) {
+			throw new HibernateException( "cannot apply index operation to component value" );
+		}
+
+		public PropertyPathTerminus handleTerminalIndexAccess(String name, HibernateTree selector) {
+			throw new HibernateException( "cannot apply index operation to component value" );
+		}
+
+		private String buildComponentDereferencePath(String subPropertyName) {
+			return propertyPath + "." + subPropertyName;
+		}
+	}
+
+	protected class EntityIntermediatePathSource extends AbstractPathedPropertyReferenceSource {
+		private final PersisterSpace lhs;
+		private final String lhsPropertyName;
+
+		public EntityIntermediatePathSource(PersisterSpace lhs, String lhsPropertyName) {
+			this.lhs = lhs;
+			this.lhsPropertyName = lhsPropertyName;
+		}
+
+		public PathedPropertyReferenceSource handleIntermediatePathPart(String name) {
+			Table joinedTable = locateOrBuildPropertyJoinedTable( lhs, lhsPropertyName, null, false, false );
+			return determineAppropriateIntermediateSourceType( joinedTable.getTableSpace().getPersisterSpace(), name );
+		}
+
+		public HibernateTree handleTerminalPathPart(String name) {
+			final EntityType type = ( EntityType ) lhs.getPropertyType( lhsPropertyName );
+			if ( isReferenceToPrimaryKey( type, lhsPropertyName ) ) {
+				// todo : create a column-list based on the FKs...
+				return null;
+			}
+			else {
+				Table joinedTable = locateOrBuildPropertyJoinedTable( lhs, lhsPropertyName, null, false, false );
+				PersisterSpace rhs = joinedTable.getTableSpace().getPersisterSpace();
+				if ( type.isEntityType() ) {
+					if ( shouldTerminalEntityPropertyForceJoin() ) {
+						locateOrBuildPropertyJoinedTable( rhs, name, null, false, false );
+					}
+				}
+				return generatePropertyColumnList( rhs, name );
+			}
+
+		}
+
+		public PathedPropertyReferenceSource handleIntermediateIndexAccess(String name, HibernateTree selector) {
+			Table lhsJoinedTable = locateOrBuildPropertyJoinedTable( lhs, lhsPropertyName, null, false, false );
+			PersisterSpace lhsJoinedPersisterSpace = lhsJoinedTable.getTableSpace().getPersisterSpace();
+
+			validateIndexedCollectionReference( lhs, name );
+			QueryableCollection collectionPersister = resolveCollectionPersister( lhsJoinedPersisterSpace, name );
+			Table joinedTable = createJoin( lhsJoinedPersisterSpace, collectionPersister, null, selector );
+
+			return new IndexAccessIntermediatePathSource( joinedTable.getTableSpace().getPersisterSpace() );
+		}
+
+		public HibernateTree handleTerminalIndexAccess(String collectionPropertyName, HibernateTree selector) {
+			return handleTerminalIndexAccess( lhs, collectionPropertyName, selector );
+		}
+	}
+
+	protected boolean shouldTerminalEntityPropertyForceJoin() {
+		return false;
+	}
+
+	protected class CollectionIntermediatePathSource extends AbstractPathedPropertyReferenceSource {
+		private final PersisterSpace lhs;
+		private final String propertyName;
+
+		public CollectionIntermediatePathSource(PersisterSpace lhs, String propertyName) {
+			this.lhs = lhs;
+			this.propertyName = propertyName;
+		}
+
+		public PathedPropertyReferenceSource handleIntermediatePathPart(String name) {
+			throw new HibernateException( "cannot implicit join across a collection association" );
+		}
+
+		public HibernateTree handleTerminalPathPart(String name) {
+			// TODO : what are the circusmstances under which we need to *join* to the collection, as opposed to say munge it into a subquery???
+			if ( CollectionProperties.isAnyCollectionProperty( name ) ) {
+				Table joinedTable = locateOrBuildPropertyJoinedTable( lhs, propertyName, null, false, false );
+				return generatePropertyColumnList( joinedTable.getTableSpace().getPersisterSpace(), name );
+			}
+			throw new HibernateException( "cannot implicit join across a collection association" );
+		}
+
+		public PathedPropertyReferenceSource handleIntermediateIndexAccess(String name, HibernateTree selector) {
+			throw new HibernateException( "cannot implicit join across a collection association" );
+		}
+
+		public HibernateTree handleTerminalIndexAccess(String name, HibernateTree selector) {
+			throw new HibernateException( "cannot implicit join across a collection association" );
+		}
+	}
+
+	protected class IndexAccessIntermediatePathSource extends AbstractPathedPropertyReferenceSource {
+		private final PersisterSpace persisterSpace;
+
+		public IndexAccessIntermediatePathSource(PersisterSpace persisterSpace) {
+			this.persisterSpace = persisterSpace;
+		}
+
+		public PathedPropertyReferenceSource handleIntermediatePathPart(String name) {
+			return determineAppropriateIntermediateSourceType( persisterSpace, name );
+		}
+
+		public HibernateTree handleTerminalPathPart(String name) {
+			return generatePropertyColumnList( persisterSpace, name );
+		}
+
+		public PathedPropertyReferenceSource handleIntermediateIndexAccess(String name, HibernateTree selector) {
+			throw new IllegalStateException( "doubled up index operators" );
+		}
+
+		public HibernateTree handleTerminalIndexAccess(String name, HibernateTree selector) {
+			throw new IllegalStateException( "doubled up index operators" );
+		}
+	}
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/CollectionExpectedException.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/CollectionExpectedException.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/CollectionExpectedException.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/CollectionExpectedException.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,46 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+
+package org.hibernate.sql.ast.origin.hql.resolve.path.impl;
+
+/**
+ * Indicates that we were expecting a property reference to identify a collection, but it did not.
+ *
+ * @author Steve Ebersole
+ */
+public class CollectionExpectedException extends AbstractUnexpectedPropertyTypeException {
+	public CollectionExpectedException(String path, String persisterName, String propertyName) {
+		super( path, persisterName, propertyName );
+	}
+
+	@Override
+	protected String internalGetMessage() {
+		return "Expected property reference [" + buildPropertyReferenceFragment() + "] to identify a collection";
+	}
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/FromClausePathResolutionStrategy.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/FromClausePathResolutionStrategy.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/FromClausePathResolutionStrategy.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/FromClausePathResolutionStrategy.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,125 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+package org.hibernate.sql.ast.origin.hql.resolve.path.impl;
+
+import org.hibernate.QueryException;
+import org.hibernate.sql.ast.common.HibernateTree;
+import org.hibernate.sql.ast.common.JoinType;
+import org.hibernate.sql.ast.origin.hql.resolve.PersisterSpace;
+import org.hibernate.sql.ast.origin.hql.resolve.ResolutionContext;
+import org.hibernate.sql.ast.origin.hql.resolve.path.PathedPropertyReferenceSource;
+import org.hibernate.sql.ast.origin.hql.parse.HQLLexer;
+import org.hibernate.sql.ast.tree.Table;
+
+/**
+ *
+ * {@link org.hibernate.sql.ast.origin.hql.resolve.path.PathResolutionStrategy} for dealing with path expressions
+ * occuring in the <tt>FROM</tt> clause of a query.
+ *
+ * @author Steve Ebersole
+ */
+public class FromClausePathResolutionStrategy extends AbstractPathResolutionStrategy {
+	private final JoinType joinType;
+	private final boolean associationFetch;
+	private final boolean propertyFetch;
+	private final String alias;
+
+	/**
+	 * Instantiate a normalization strategy for handling path expressions in a <tt>FROM</tt> clause.
+	 *
+	 * @param resolutionContext The context for resolution.
+	 * @param joinType The type of explicit-join specified at the root of this path expression.
+	 * @param associationFetch Was association fetching indicated on this path expression?
+	 * @param propertyFetch Was property fetching indicated on this path expression?
+	 * @param alias The alias (if one) specified on this joined path expression.
+	 */
+	public FromClausePathResolutionStrategy(
+			ResolutionContext resolutionContext,
+			JoinType joinType,
+			boolean associationFetch,
+			boolean propertyFetch,
+			String alias) {
+		super( resolutionContext );
+		this.joinType = joinType;
+		this.associationFetch = associationFetch;
+		this.propertyFetch = propertyFetch;
+		this.alias = alias;
+	}
+
+	protected PathedPropertyReferenceSource internalHandleRoot(PersisterSpace persisterSpace) {
+		return new SourceImpl( persisterSpace );
+	}
+
+	private class SourceImpl extends AbstractPathedPropertyReferenceSource {
+		private final PersisterSpace lhs;
+
+		private SourceImpl(PersisterSpace lhs) {
+			this.lhs = lhs;
+		}
+
+		public PathedPropertyReferenceSource handleIntermediatePathPart(String name) {
+			// TODO : still need to account for paths including component dereferences...
+			Table joinedTable = buildPropertyJoinedTable( lhs, name, null, false, associationFetch );
+			return new SourceImpl( joinedTable.getTableSpace().getPersisterSpace() );
+		}
+
+		public HibernateTree handleTerminalPathPart(String propertyName) {
+			validateJoinable( lhs, propertyName );
+
+			Table joinedTable = buildPropertyJoinedTable( lhs, propertyName, alias, propertyFetch, associationFetch );
+			return joinedTable.getTableSpace().buildIdentifierColumnReferences();
+		}
+
+		public PathedPropertyReferenceSource handleIntermediateIndexAccess(String name, HibernateTree selector) {
+			throw new UnsupportedOperationException( "index operation not supported in from clause" );
+		}
+
+		public HibernateTree handleTerminalIndexAccess(String name, HibernateTree selector) {
+			throw new UnsupportedOperationException( "index operation not supported in from clause" );
+		}
+	}
+
+	protected HibernateTree buildJoinTypeNode() {
+		if ( joinType == JoinType.INNER ) {
+			return new HibernateTree( HQLLexer.INNER );
+		}
+		else if ( joinType == JoinType.LEFT ) {
+			return new HibernateTree( HQLLexer.LEFT );
+		}
+		else if ( joinType == JoinType.RIGHT ) {
+			return new HibernateTree( HQLLexer.RIGHT );
+		}
+		// if no match found, throw exception
+		throw new QueryException( "Unrecognized join type [" + joinType.toString() + "]" );
+	}
+
+	protected boolean areJoinsReusable() {
+		return false;
+	}
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/IndexedCollectionExectedException.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/IndexedCollectionExectedException.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/IndexedCollectionExectedException.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/IndexedCollectionExectedException.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,45 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+package org.hibernate.sql.ast.origin.hql.resolve.path.impl;
+
+/**
+ * Indicates that we were expecting a property reference to identify an indexed collection, but it did not.
+ *
+ * @author Steve Ebersole
+ */
+public class IndexedCollectionExectedException extends AbstractUnexpectedPropertyTypeException {
+	public IndexedCollectionExectedException(String path, String persisterName, String propertyName) {
+		super( path, persisterName, propertyName );
+	}
+
+	@Override
+	protected String internalGetMessage() {
+		return "Expected property reference [" + buildPropertyReferenceFragment() + "] to identify an indexed collection";
+	}
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/InvalidPropertyJoinException.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/InvalidPropertyJoinException.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/InvalidPropertyJoinException.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/InvalidPropertyJoinException.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,45 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+package org.hibernate.sql.ast.origin.hql.resolve.path.impl;
+
+/**
+ * Indicates an attempt to define an implicit or explicit property join based on a non-association property.
+ *
+ * @author Steve Ebersole
+ */
+public class InvalidPropertyJoinException extends AbstractUnexpectedPropertyTypeException {
+	public InvalidPropertyJoinException(String path, String persisterName, String propertyName) {
+		super( path, persisterName, propertyName );
+	}
+
+	@Override
+	protected String internalGetMessage() {
+		return "Referenced property [" + buildPropertyReferenceFragment() + "] not valid for join";
+	}
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/OnFragmentPathResolutionStrategy.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/OnFragmentPathResolutionStrategy.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/OnFragmentPathResolutionStrategy.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/OnFragmentPathResolutionStrategy.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,74 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+package org.hibernate.sql.ast.origin.hql.resolve.path.impl;
+
+import org.hibernate.HibernateException;
+import org.hibernate.sql.ast.origin.hql.resolve.PersisterSpace;
+import org.hibernate.sql.ast.origin.hql.resolve.ResolutionContext;
+import org.hibernate.sql.ast.origin.hql.resolve.path.PathedPropertyReferenceSource;
+
+/**
+ * {@link org.hibernate.sql.ast.origin.hql.resolve.path.PathResolutionStrategy} for dealing with path expressions
+ * occuring in the <tt>ON</tt> clause of a persister join.
+ *
+ * @author Steve Ebersole
+ */
+public class OnFragmentPathResolutionStrategy extends BasicPathResolutionStrategySupport {
+	private final PersisterSpace joinRhs;
+	private PersisterSpace joinLhs;
+
+	public OnFragmentPathResolutionStrategy(ResolutionContext resolutionContext, PersisterSpace joinRhs) {
+		super( resolutionContext );
+		this.joinRhs = joinRhs;
+	}
+
+	public PersisterSpace getDiscoveredLHS() {
+		return joinLhs;
+	}
+
+	protected PathedPropertyReferenceSource internalHandleRoot(PersisterSpace persisterSpace) {
+		// persisterSpace must either refer to our LHS or RHS...
+		if ( persisterSpace == joinRhs ) {
+			// nothing to do...
+		}
+		else if ( joinLhs != null ) {
+			if ( persisterSpace != joinLhs ) {
+				throw new HibernateException(
+						"path root not resolveable against either left-hand-side [" +
+						joinLhs.getSourceAlias() + "] nor right-hand-side [" +
+						joinRhs.getSourceAlias() + "] of the join"
+				);
+			}
+		}
+		else {
+			joinLhs = persisterSpace;
+		}
+		return super.internalHandleRoot( persisterSpace );
+	}
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/SelectClausePathResolutionStrategy.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/SelectClausePathResolutionStrategy.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/SelectClausePathResolutionStrategy.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/SelectClausePathResolutionStrategy.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,51 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+
+package org.hibernate.sql.ast.origin.hql.resolve.path.impl;
+
+import org.hibernate.sql.ast.origin.hql.resolve.ResolutionContext;
+
+/**
+ * Essentially the same stragety as {@link BasicPathResolutionStrategySupport} expcept that in the select clause
+ * an entity encountered as the terminal part must force a join...
+ * <p/>
+ * todo : the above is true as long as the path is not a function argument...
+ *
+ * @author Steve Ebersole
+ */
+public class SelectClausePathResolutionStrategy extends BasicPathResolutionStrategySupport {
+	public SelectClausePathResolutionStrategy(ResolutionContext resolutionContext) {
+		super( resolutionContext );
+	}
+
+	protected boolean shouldTerminalEntityPropertyForceJoin() {
+		// here we should *as long as* we are not part of a function processing
+		return ! resolutionContext().isCurrentlyProcessingFunction();
+	}
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/WithFragmentPathResolutionStrategy.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/WithFragmentPathResolutionStrategy.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/WithFragmentPathResolutionStrategy.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/hql/resolve/path/impl/WithFragmentPathResolutionStrategy.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,124 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party
+ * contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software
+ * Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+
+package org.hibernate.sql.ast.origin.hql.resolve.path.impl;
+
+import org.hibernate.HibernateException;
+import org.hibernate.sql.ast.origin.hql.resolve.PersisterSpace;
+import org.hibernate.sql.ast.origin.hql.resolve.ResolutionContext;
+import org.hibernate.sql.ast.origin.hql.resolve.path.PathedPropertyReferenceSource;
+import org.hibernate.sql.ast.common.HibernateTree;
+import org.hibernate.sql.ast.tree.Table;
+
+/**
+ * {@link org.hibernate.sql.ast.origin.hql.resolve.path.PathResolutionStrategy} for dealing with <tt>WITH</tt>
+ * fragments used to supply addition join conditions to property joins.
+ *
+ * @author Steve Ebersole
+ */
+public class WithFragmentPathResolutionStrategy extends BasicPathResolutionStrategySupport {
+	private final PersisterSpace lhs;
+
+	private String baseRhsPropertyName;
+	private PersisterSpace rhs;
+
+	public WithFragmentPathResolutionStrategy(ResolutionContext resolutionContext, PersisterSpace lhs) {
+		super( resolutionContext );
+		this.lhs = lhs;
+	}
+
+	@Override
+	protected PathedPropertyReferenceSource internalHandleRoot(PersisterSpace persisterSpace) {
+		rhs = persisterSpace;
+		return super.internalHandleRoot( persisterSpace );
+	}
+
+	@Override
+	protected PathedPropertyReferenceSource internalResolveIntermediatePathPart(PathedPropertyReferenceSource source, String pathPart) {
+		if ( baseRhsPropertyName == null ) {
+			baseRhsPropertyName = pathPart;
+		}
+		return super.internalResolveIntermediatePathPart( source, pathPart );
+	}
+
+	@Override
+	protected HibernateTree internalResolveTerminalPathPart(PathedPropertyReferenceSource source, String pathPart) {
+		if ( baseRhsPropertyName == null ) {
+			baseRhsPropertyName = pathPart;
+		}
+		return super.internalResolveTerminalPathPart( source, pathPart );
+	}
+
+	@Override
+	protected PathedPropertyReferenceSource internalHandleIntermediateIndexAccess(PathedPropertyReferenceSource source, String pathPart, HibernateTree selector) {
+		if ( baseRhsPropertyName == null ) {
+			baseRhsPropertyName = pathPart;
+		}
+		return super.internalHandleIntermediateIndexAccess( source, pathPart, selector );
+	}
+
+	@Override
+	protected HibernateTree internalHandleTerminalIndexAccess(PathedPropertyReferenceSource source, String pathPart, HibernateTree selector) {
+		if ( baseRhsPropertyName == null ) {
+			baseRhsPropertyName = pathPart;
+		}
+		return super.internalHandleTerminalIndexAccess( source, pathPart, selector );
+	}
+
+	public void applyWithFragment(HibernateTree withFragment) {
+		// first, locate the actual Join node which links the lhs and rhs...
+		Table lhsTable = lhs.getTableSpace().getContainingTable( baseRhsPropertyName );
+
+		// todo : implement...
+
+		// as simple as finding the table under lhsTable which contains a join to a table from the table-space associated with
+		// the rhs persister-space???
+
+//		Join join = null;
+//		AST nextPossible = lhs.getFirstChild();
+//		while ( nextPossible != null ) {
+//			if ( nextPossible instanceof Join ) {
+//				if ( ( ( Join ) nextPossible ).locateRhs() == rhs ) {
+//					join = ( Join ) nextPossible;
+//					break;
+//				}
+//			}
+//			nextPossible = nextPossible.getNextSibling();
+//		}
+//		if ( join == null ) {
+//			throw new QueryException( "could not locate specific join node to which to apply with fragment [" + withFragment + "]" );
+//		}
+//		join.addChild( withFragment );
+	}
+
+	protected void validateJoinCreation(PersisterSpace origin, String property) {
+		// todo : why not???
+		throw new HibernateException( "Path expressions [" + origin.getSourceAlias() + "." + property + "] within 'with clause' cannot result in physical join" );
+	}
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/ordering/ColumnMapper.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/ColumnMapper.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/ordering/ColumnMapper.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/ordering/ColumnMapper.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,46 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ *
+ */
+package org.hibernate.sql.ast.origin.ordering;
+
+import org.hibernate.HibernateException;
+
+/**
+ * Contract for mapping a (an assumed) property reference to its columns.
+ *
+ * @author Steve Ebersole
+ */
+public interface ColumnMapper {
+	/**
+	 * Resolve the property reference to its underlying columns.
+	 *
+	 * @param reference The property reference name.
+	 *
+	 * @return The underlying columns, or null if the property reference is unknown.
+	 *
+	 * @throws HibernateException Generally indicates that the property reference is unkown; interpretation is the
+	 * same as a null return.
+	 */
+	public String[] map(String reference) throws HibernateException;
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/ordering/OrderByFragmentParser.java (from rev 16437, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentParser.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/ordering/OrderByFragmentParser.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/ordering/OrderByFragmentParser.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,109 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ *
+ */
+package org.hibernate.sql.ast.origin.ordering;
+
+import org.antlr.runtime.TokenStream;
+import org.antlr.runtime.tree.CommonTree;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.sql.ast.common.HibernateTree;
+import org.hibernate.sql.Template;
+
+/**
+ * Extension of the Antlr-generated parser for the purpose of adding our custom parsing behavior.
+ *
+ * @author Steve Ebersole
+ */
+public class OrderByFragmentParser extends OrderByParser {
+	private static final Logger log = LoggerFactory.getLogger( OrderByFragmentParser.class );
+	private final TranslationContext context;
+
+	private final String openQuoteChar;
+	private final String closeQuoteChar;
+
+	public OrderByFragmentParser(TokenStream lexer, TranslationContext context) {
+		super( lexer );
+		this.context = context;
+
+		this.openQuoteChar = Character.toString( context.getDialect().openQuote() );
+		this.closeQuoteChar = Character.toString( context.getDialect().closeQuote() );
+	}
+
+	@Override
+	protected boolean isFunctionName(String text) {
+		log.trace( "Checking function name [" + text + "]" );
+		return context.getSqlFunctionRegistry().hasFunction( text );
+	}
+
+	@Override
+	protected boolean isPropertyName(String text) {
+		log.trace( "Checking property name [" + text + "]" );
+		try {
+			return context.getColumnMapper().map( text ) != null;
+		}
+		catch ( Throwable t ) {
+			return false;
+		}
+	}
+
+	@Override
+	protected CommonTree buildPropertyColumns(CommonTree propertyTree) {
+		final String text = extractPropertyName( propertyTree );
+		String[] columns = context.getColumnMapper().map( text );
+		if ( columns.length == 1 ) {
+			return buildColumn( columns[0] );
+		}
+		else {
+			HibernateTree vector = new HibernateTree( VECTOR_EXPR );
+			for ( String column : columns ) {
+				vector.addChild( buildColumn( column ) );
+			}
+			return vector;
+		}
+	}
+
+	private CommonTree buildColumn(String columnName) {
+		// ugh
+		HibernateTree columnNameNode;
+		if ( columnName.startsWith( openQuoteChar ) && columnName.endsWith( closeQuoteChar ) ) {
+			columnName = columnName.substring( 1, columnName.length() - 1 );
+			columnNameNode = new HibernateTree( QUOTED_IDENTIFIER, columnName );
+		}
+		else {
+			columnNameNode = new HibernateTree( IDENTIFIER, columnName );
+		}
+
+		HibernateTree tree = new HibernateTree( COLUMN );
+		tree.addChild( new HibernateTree( ALIAS_REF, Template.TEMPLATE ) );
+		tree.addChild( columnNameNode );
+
+		return tree;
+	}
+
+	private String extractPropertyName(CommonTree propertyTree) {
+		return propertyTree.getText();
+	}
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/ordering/OrderByFragmentTranslator.java (from rev 16437, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/OrderByFragmentTranslator.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/ordering/OrderByFragmentTranslator.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/ordering/OrderByFragmentTranslator.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,91 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ *
+ */
+package org.hibernate.sql.ast.origin.ordering;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.HibernateException;
+import org.hibernate.sql.ast.util.TreePrinter;
+import org.hibernate.sql.ast.origin.hql.parse.HQLLexer;
+
+import org.antlr.runtime.ANTLRStringStream;
+import org.antlr.runtime.CommonTokenStream;
+import org.antlr.runtime.tree.Tree;
+
+/**
+ * A translator which coordinates translation of an <tt>order-by</tt> mapping.
+ *
+ * @author Steve Ebersole
+ */
+public class OrderByFragmentTranslator {
+	private static final Logger log = LoggerFactory.getLogger( OrderByFragmentTranslator.class );
+
+	public final TranslationContext context;
+
+	public OrderByFragmentTranslator(TranslationContext context) {
+		this.context = context;
+	}
+
+	/**
+	 * The main contract, performing the translation.
+	 *
+	 * @param fragment The <tt>order-by</tt> mapping fragment to be translated.
+	 *
+	 * @return The translated fragment.
+	 */
+	public String render(String fragment) {
+		HQLLexer lexer = new HQLLexer( new ANTLRStringStream( fragment ) );
+		OrderByFragmentParser parser = new OrderByFragmentParser( new CommonTokenStream( lexer ), context );
+		try {
+            Tree tree = ( Tree ) parser.orderByFragment().getTree();
+
+            if ( log.isTraceEnabled() ) {
+                TreePrinter printer = new TreePrinter( OrderByParser.class );
+                log.trace( printer.renderAsString( tree, "--- {order-by fragment} ---" ) );
+            }
+		}
+		catch ( HibernateException e ) {
+			throw e;
+		}
+		catch ( Throwable t ) {
+			throw new HibernateException( "Unable to parse order-by fragment", t );
+		}
+
+//		OrderByFragmentRenderer renderer = new OrderByFragmentRenderer();
+//		try {
+//			renderer.orderByFragment( parser.getAST() );
+//		}
+//		catch ( HibernateException e ) {
+//			throw e;
+//		}
+//		catch ( Throwable t ) {
+//			throw new HibernateException( "Unable to render parsed order-by fragment", t );
+//		}
+//
+//		return renderer.getRenderedFragment();
+        return null;
+	}
+}

Copied: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/ordering/TranslationContext.java (from rev 16432, core/branches/antlr3/src/main/java/org/hibernate/sql/ast/ordering/TranslationContext.java)
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/ordering/TranslationContext.java	                        (rev 0)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/origin/ordering/TranslationContext.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,64 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ *
+ */
+package org.hibernate.sql.ast.origin.ordering;
+
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.function.SQLFunctionRegistry;
+
+/**
+ * Contract for contextual information required to perform translation.
+*
+* @author Steve Ebersole
+*/
+public interface TranslationContext {
+	/**
+	 * Retrieves the <tt>session factory</tt> for this context.
+	 *
+	 * @return The <tt>session factory</tt>
+	 */
+	public SessionFactoryImplementor getSessionFactory();
+
+	/**
+	 * Retrieves the <tt>dialect</tt> for this context.
+	 *
+	 * @return The <tt>dialect</tt>
+	 */
+	public Dialect getDialect();
+
+	/**
+	 * Retrieves the <tt>SQL function registry/tt> for this context.
+	 *
+	 * @return The SQL function registry.
+	 */
+	public SQLFunctionRegistry getSqlFunctionRegistry();
+
+	/**
+	 * Retrieves the <tt>column mapper</tt> for this context.
+	 *
+	 * @return The <tt>column mapper</tt>
+	 */
+	public ColumnMapper getColumnMapper();
+}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/parse/ParserContext.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/parse/ParserContext.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/parse/ParserContext.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,14 +0,0 @@
-package org.hibernate.sql.ast.phase.hql.parse;
-
-import java.util.List;
-
-public interface ParserContext {
-
-	public boolean isJavaConstant(String text);
-
-	public boolean isEntityName(String text);
-
-	public List getEntityImplementors(String text);
-	
-	public String buildUniqueImplicitAlias();
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/parse/ParserContextDefaultImpl.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/parse/ParserContextDefaultImpl.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/parse/ParserContextDefaultImpl.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,30 +0,0 @@
-package org.hibernate.sql.ast.phase.hql.parse;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.hibernate.sql.ast.alias.ImplicitAliasGenerator;
-
-public class ParserContextDefaultImpl implements ParserContext {
-
-	private final ImplicitAliasGenerator implicitAliasGenerator = new ImplicitAliasGenerator(); 
-	
-	public List getEntityImplementors(String text) {
-		List implementors = new ArrayList();
-		implementors.add(text);
-		return implementors;
-	}
-
-	public boolean isEntityName(String text) {
-		return true;
-	}
-
-	public boolean isJavaConstant(String text) {
-		return false;
-	}
-
-	public String buildUniqueImplicitAlias() {
-		return implicitAliasGenerator.buildUniqueImplicitAlias();
-	}
-
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HQLResolver.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HQLResolver.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HQLResolver.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,289 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-package org.hibernate.sql.ast.phase.hql.resolve;
-
-import org.antlr.runtime.RecognizerSharedState;
-import org.antlr.runtime.tree.CommonTree;
-import org.antlr.runtime.tree.Tree;
-import org.antlr.runtime.tree.TreeNodeStream;
-
-import org.hibernate.engine.SessionFactoryImplementor;
-import org.hibernate.persister.entity.Queryable;
-import org.hibernate.sql.ast.alias.DefaultTableAliasGenerator;
-import org.hibernate.sql.ast.alias.TableAliasGenerator;
-import org.hibernate.sql.ast.common.HibernateTree;
-import org.hibernate.sql.ast.common.JoinType;
-import org.hibernate.sql.ast.phase.hql.parse.HQLParser;
-import org.hibernate.sql.ast.phase.hql.resolve.path.PathResolutionStrategy;
-import org.hibernate.sql.ast.phase.hql.resolve.path.PathResolutionStrategyStack;
-import org.hibernate.sql.ast.phase.hql.resolve.path.PathedPropertyReferenceSource;
-import org.hibernate.sql.ast.phase.hql.resolve.path.impl.BasicPathResolutionStrategySupport;
-import org.hibernate.sql.ast.phase.hql.resolve.path.impl.FromClausePathResolutionStrategy;
-import org.hibernate.sql.ast.phase.hql.resolve.path.impl.SelectClausePathResolutionStrategy;
-import org.hibernate.sql.ast.tree.Table;
-import org.hibernate.sql.ast.tree.Table.EntityTableSpace;
-import org.hibernate.sql.ast.util.TreePrinter;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class HQLResolver extends GeneratedHQLResolver implements
-		ResolutionContext {
-	private static final Logger log = LoggerFactory
-			.getLogger( HQLResolver.class );
-
-	private final SessionFactoryImplementor sessionFactory;
-	private final PersisterSpaceContext persisterSpaceContext;
-	private final DefaultTableAliasGenerator defaultTableAliasGenerator;
-	private final PathResolutionStrategyStack pathResolutionStrategyStack;
-	private final TreePrinter printer;
-
-	private boolean isProcessingFunction = false;
-
-	public HQLResolver(TreeNodeStream input,
-					   SessionFactoryImplementor sessionFactory) {
-		this( input, new RecognizerSharedState(), sessionFactory );
-	}
-
-	public HQLResolver(TreeNodeStream input, RecognizerSharedState state,
-					   SessionFactoryImplementor sessionFactory) {
-		super( input, state );
-		this.sessionFactory = sessionFactory;
-		this.persisterSpaceContext = new RootPersisterSpaceContext();
-		this.defaultTableAliasGenerator = new DefaultTableAliasGenerator(
-				sessionFactory.getDialect()
-		);
-		this.printer = new TreePrinter( HQLParser.class );
-		this.pathResolutionStrategyStack = new PathResolutionStrategyStack();
-		this.pathResolutionStrategyStack
-				.push( new BasicPathResolutionStrategySupport( this ) );
-	}
-
-	protected void registerPersisterSpace(Tree entityName, Tree alias) {
-		String entityPersisterName = sessionFactory
-				.getImportedClassName( entityName.getText() );
-		Queryable entityPersister = ( Queryable ) sessionFactory
-				.getEntityPersister( entityPersisterName );
-
-		TableAliasGenerator.TableAliasRoot tableAliasRoot = getTableAliasGenerator()
-				.generateSqlAliasRoot( entityPersister, alias.getText() );
-		EntityTableSpace tableSpace = new Table.EntityTableSpace(
-				entityPersister, tableAliasRoot
-		);
-		registerPersisterSpace( tableSpace.getPersisterSpace() );
-	}
-
-	public PersisterSpaceContext getCurrentPersisterSpaceContext() {
-		return persisterSpaceContext;
-	}
-
-	public SessionFactoryImplementor getSessionFactoryImplementor() {
-		return sessionFactory;
-	}
-
-	public TableAliasGenerator getTableAliasGenerator() {
-		return defaultTableAliasGenerator;
-	}
-
-	public TreePrinter getTreePrinter() {
-		return printer;
-	}
-
-	public boolean isCurrentlyProcessingFunction() {
-		return isProcessingFunction;
-	}
-
-	public PathResolutionStrategyStack getPathResolutionStrategyStack() {
-		return pathResolutionStrategyStack;
-	}
-
-	public PathResolutionStrategy getCurrentPathResolutionStrategy() {
-		return pathResolutionStrategyStack.getCurrent();
-	}
-
-	public void registerAssociationFetch(PersisterSpace persisterSpace) {
-		throw new UnsupportedOperationException( "must be implemented!" );
-	}
-
-	public void registerPropertyFetch(PersisterSpace persisterSpace) {
-		throw new UnsupportedOperationException( "must be implemented!" );
-	}
-
-	protected void pushFromStrategy(JoinType joinType,
-									Tree assosiationFetchTree, Tree propertyFetchTree, Tree alias) {
-		boolean assosiationFetch = assosiationFetchTree != null ? true : false;
-		boolean propertyFetch = propertyFetchTree != null ? true : false;
-		pathResolutionStrategyStack.push(
-				new FromClausePathResolutionStrategy(
-						this, joinType, assosiationFetch, propertyFetch, alias
-								.getText()
-				)
-		);
-	}
-
-	protected void pushSelectStrategy() {
-		pathResolutionStrategyStack
-				.push( new SelectClausePathResolutionStrategy( this ) );
-	}
-
-	protected void popStrategy() {
-		pathResolutionStrategyStack.pop();
-	}
-
-	private void registerPersisterSpace(PersisterSpace persisterSpace) {
-		persisterSpaceContext.registerPersisterSpace( persisterSpace );
-	}
-
-	protected boolean isUnqualifiedPropertyReference() {
-		return locateOwningPersisterAlias( ( Tree ) input.LT( 1 ) ) != null;
-	}
-
-	protected String locateOwningPersisterAlias(Tree property) {
-		PersisterSpace persisterReference = getCurrentPersisterSpaceContext()
-				.locatePersisterSpaceExposingProperty( property.getText() );
-		return persisterReference == null ? null : persisterReference
-				.getSourceAlias();
-	}
-
-	protected boolean isPersisterReferenceAlias() {
-		Tree alias = ( Tree ) input.LT( 1 );
-		log.trace(
-				"Checking [" + textOrNull( alias )
-						+ "] as persister-ref alias"
-		);
-		return getCurrentPersisterSpaceContext().isContainedAlias(
-				alias.getText()
-		);
-	}
-
-	protected PathedPropertyReferenceSource normalizeUnqualifiedPropertyReference(
-			Tree property) {
-		return getCurrentPathResolutionStrategy().handleRoot(
-				getCurrentPersisterSpaceContext()
-						.locatePersisterSpaceExposingProperty(
-						property.getText()
-				)
-		);
-	}
-
-	protected PathedPropertyReferenceSource normalizeUnqualifiedRoot(
-			Tree propertyName) {
-		log.debug(
-				"normalizing path expression root as unqualified property ["
-						+ textOrNull( propertyName ) + "]"
-		);
-		PathedPropertyReferenceSource root = getCurrentPathResolutionStrategy()
-				.handleRoot(
-						getCurrentPersisterSpaceContext()
-								.locatePersisterSpaceExposingProperty(
-								propertyName.getText()
-						)
-				);
-		return root.handleIntermediatePathPart( propertyName.getText() );
-	}
-
-	protected PathedPropertyReferenceSource normalizeQualifiedRoot(Tree alias) {
-		log.debug(
-				"normalizing path expression root as alias ["
-						+ alias.getText() + "]"
-		);
-		return getCurrentPathResolutionStrategy().handleRoot(
-				getCurrentPersisterSpaceContext().locatePersisterSpaceByAlias(
-						alias.getText()
-				)
-		);
-	}
-
-	protected Tree normalizePropertyPathTerminus(
-			PathedPropertyReferenceSource source, Tree propertyNameNode) {
-		log.trace(
-				"normalizing terminal path expression ["
-						+ textOrNull( propertyNameNode ) + "]"
-		);
-		return getCurrentPathResolutionStrategy().handleTerminalPathPart(
-				source, propertyNameNode.getText()
-		);
-	}
-
-	protected PathedPropertyReferenceSource normalizePropertyPathIntermediary(
-			PathedPropertyReferenceSource source, Tree propertyName) {
-		log.trace(
-				"normalizing intermediate path expression ["
-						+ textOrNull( propertyName ) + "]"
-		);
-		return getCurrentPathResolutionStrategy().handleIntermediatePathPart(
-				( PathedPropertyReferenceSource ) source,
-				propertyName.getText()
-		);
-	}
-
-	protected PathedPropertyReferenceSource normalizeUnqualifiedPropertyReferenceSource(
-			Tree propertyName) {
-		return getCurrentPathResolutionStrategy().handleRoot(
-				getCurrentPersisterSpaceContext()
-						.locatePersisterSpaceExposingProperty(
-						propertyName.getText()
-				)
-		);
-	}
-
-	protected PathedPropertyReferenceSource normalizeIntermediateIndexOperation(
-			PathedPropertyReferenceSource collectionSource,
-			Tree collectionProperty, Tree selector) {
-		log.trace(
-				"normalizing intermediate index access ["
-						+ textOrNull( collectionProperty ) + "]"
-		);
-		return getCurrentPathResolutionStrategy()
-				.handleIntermediateIndexAccess(
-						collectionSource,
-						collectionProperty.getText(),
-						new HibernateTree( ( CommonTree ) selector )
-				);
-	}
-
-	protected void normalizeTerminalIndexOperation(
-			PathedPropertyReferenceSource propertyReferenceSource,
-			Tree collectionProperty, Tree selector) {
-		log.trace(
-				"normalizing terminal index access ["
-						+ textOrNull( collectionProperty ) + "]"
-		);
-		PathedPropertyReferenceSource collectionSource = propertyReferenceSource;
-		getCurrentPathResolutionStrategy().handleTerminalIndexAccess(
-				collectionSource, collectionProperty.getText(),
-				new HibernateTree( ( CommonTree ) selector )
-		);
-	}
-
-	private String textOrNull(Tree tree) {
-		return tree == null ? null : tree.getText();
-	}
-
-}
\ No newline at end of file

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HierarchicalPersisterSpaceContext.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HierarchicalPersisterSpaceContext.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HierarchicalPersisterSpaceContext.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,103 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-package org.hibernate.sql.ast.phase.hql.resolve;
-
-/**
- * Defines a hierarchical representation of a persister reference context.
- * <p/>
- * Generally speaking this notion should really only hold for SELECT statements.  Does not make sense for
- * INSERT or UPDATE or DELETE statements to have a parent, as that would mean they are being used as in a subqquery
- * (certainly, however, it makes sense for these to *be the parent* context...).
- *
- * @author Steve Ebersole
- */
-public class HierarchicalPersisterSpaceContext extends RootPersisterSpaceContext {
-	private final PersisterSpaceContext parent;
-
-	public HierarchicalPersisterSpaceContext(PersisterSpaceContext parent) {
-		super();
-		if ( parent == null ) {
-			throw new IllegalArgumentException( "Parent PersisterSpaceContext cannot be null!" );
-		}
-		this.parent = parent;
-	}
-
-	/**
-	 * Get the parent context of this context.
-	 *
-	 * @return Our parent context.
-	 */
-	public PersisterSpaceContext getParent() {
-		return parent;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 * <p/>
-	 * Overriden to project the lookup to our parent if not found locally.
-	 */
-	public boolean isContainedAlias(String alias) {
-		return super.isContainedAlias( alias ) || getParent().isContainedAlias( alias );
-	}
-
-	/**
-	 * {@inheritDoc}
-	 * <p/>
-	 * Overriden to project the lookup to our parent if not found locally.
-	 */
-	public boolean isContainedExposedProperty(String propertyName) {
-		return super.isContainedExposedProperty( propertyName ) || getParent().isContainedExposedProperty( propertyName );
-	}
-
-	/**
-	 * {@inheritDoc}
-	 * <p/>
-	 * Overriden to project the lookup to our parent if not found locally.
-	 */
-	public PersisterSpace locatePersisterSpaceByAlias(String alias) {
-		PersisterSpace persisterSpace = super.locatePersisterSpaceByAlias( alias );
-		if ( persisterSpace == null ) {
-			persisterSpace = getParent().locatePersisterSpaceByAlias( alias );
-		}
-		return persisterSpace;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 * <p/>
-	 * Overriden to project the lookup to our parent if not found locally.
-	 */
-	public PersisterSpace locatePersisterSpaceExposingProperty(String propertyName) {
-		PersisterSpace persisterSpace = super.locatePersisterSpaceExposingProperty( propertyName );
-		if ( persisterSpace == null ) {
-			persisterSpace = getParent().locatePersisterSpaceExposingProperty( propertyName );
-		}
-		return persisterSpace;
-	}
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpace.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpace.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpace.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,70 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-package org.hibernate.sql.ast.phase.hql.resolve;
-
-import org.hibernate.type.Type;
-import org.hibernate.sql.ast.tree.Table;
-
-/**
- *
- * @author Steve Ebersole
- */
-public interface PersisterSpace {
-	/**
-	 * Retrieve the corresponding alias from the input (HQL, etc).
-	 *
-	 * @return The source alias.
-	 */
-	public String getSourceAlias();
-
-	/**
-	 * Retrieve the name of the underlying persister.
-	 *
-	 * @return The persister name.
-	 */
-	public String getName();
-
-	/**
-	 * Retrieve the short (unqualified) version of the persister name.
-	 * <p/>
-	 * Useful for alias basing.
-	 *
-	 * @return The persister short name.
-	 */
-	public String getShortName();
-
-	public Table.TableSpace getTableSpace();
-
-	public boolean containsProperty(String propertyName);
-
-	public Type getPropertyType(String propertyName);
-
-	public Table locateReusablePropertyJoinedTable(String propertyName);
-	public void registerReusablePropertyJoinedTable(String propertyName, Table table);
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpaceContext.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpaceContext.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpaceContext.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,76 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-package org.hibernate.sql.ast.phase.hql.resolve;
-
-/**
- * The contract for defining a scoping for references to persisters.
- *
- * @author Steve Ebersole
- */
-public interface PersisterSpaceContext {
-	/**
-	 * Does the given text represent an alias for a persister within this context?
-	 *
-	 * @param text The potential persister alias.
-	 * @return True if given text is a persister alias; false otherwise.
-	 */
-	public boolean isContainedAlias(String text);
-
-	/**
-	 * Does the given text represent a property exposed from a persister in this context?
-	 *
-	 * @param text The potential property name.
-	 * @return True if a persister in this context exposes such a property; false otherwise.
-	 */
-	public boolean isContainedExposedProperty(String text);
-
-	/**
-	 * Locate a {@link PersisterSpace} by alias.
-	 *
-	 * @param alias The alias by which to locate the persister space.
-	 * @return The persister reference, or null.
-	 */
-	public PersisterSpace locatePersisterSpaceByAlias(String alias);
-
-	/**
-	 * Locate a {@link PersisterSpace} in this context defined by a persister which exposes the
-	 * specified property.
-	 *
-	 * @param propertyName The name of the property.
-	 * @return The persister space, or null.
-	 */
-	public PersisterSpace locatePersisterSpaceExposingProperty(String propertyName);
-
-	/**
-	 * Registers a persister space in this context.
-	 *
-	 * @param persisterSpace The persister reference to register.
-	 */
-	public void registerPersisterSpace(PersisterSpace persisterSpace);
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableExpressionGenerator.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableExpressionGenerator.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableExpressionGenerator.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,220 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-
-package org.hibernate.sql.ast.phase.hql.resolve;
-
-import org.hibernate.persister.MappedTableMetadata;
-import org.hibernate.persister.collection.QueryableCollection;
-import org.hibernate.persister.entity.Queryable;
-import org.hibernate.sql.ast.alias.TableAliasGenerator;
-import org.hibernate.sql.ast.common.HibernateTree;
-import org.hibernate.sql.ast.phase.hql.parse.HQLLexer;
-import org.hibernate.sql.ast.tree.Table;
-import org.hibernate.sql.ast.util.TreePrinter;
-
-/**
- * Generate table expressions for persisters.
- * <p/>
- * NOTE : temporary, until such time as we are able to have the persisters themselves return these structures.
- *
- * @author Steve Ebersole
- */
-public abstract class PersisterTableExpressionGenerator {
-	/**
-	 * Generate the table expression for the given entity persister.
-	 *
-	 * @param persister The entity persister.
-	 * @param aliasRoot The alias root for SQL alias generation.
-	 * @param tableSpace The table space to which any generated table references need to belong.
-	 *
-	 * @return The generated table expression (could be simply the root table in a joined table structure).
-	 */
-	public static Table generateTableExpression(
-			Queryable persister,
-			TableAliasGenerator.TableAliasRoot aliasRoot,
-			Table.EntityTableSpace tableSpace) {
-		MappedTableMetadata tableMetadata = persister.getMappedTableMetadata();
-
-		final String drivingTableName = tableMetadata.getDrivingTableName();
-		final String[] drivingTableJoinColumns = tableMetadata.getIdentifierColumnNames();
-		final String drivingTableAlias = aliasRoot.generate( 0 );
-		final Table drivingTable = generateTableReference( drivingTableName, drivingTableAlias, tableSpace );
-
-		int suffix = 0;
-
-		for ( MappedTableMetadata.JoinedTable joinedTable : tableMetadata.getJoinedTables() ) {
-			final String joinTableAlias = aliasRoot.generate( ++suffix );
-			final Table table = generateTableReference( joinedTable.getName(), joinTableAlias, tableSpace );
-
-			final HibernateTree join = new HibernateTree( HQLLexer.JOIN, "join" );
-			drivingTable.addChild( join );
-			if ( joinedTable.useInnerJoin() ) {
-				join.addChild( new HibernateTree( HQLLexer.INNER, "inner" ) );
-			}
-			else {
-				join.addChild( new HibernateTree( HQLLexer.LEFT, "left outer" ) );
-			}
-			join.addChild( table );
-
-			final HibernateTree on = new HibernateTree( HQLLexer.ON, "on" );
-			join.addChild( on );
-			final HibernateTree joinCondition = generateJoinCorrelation(
-					drivingTableAlias,
-					drivingTableJoinColumns,
-					joinTableAlias,
-					joinedTable.getKeyColumns()
-			);
-			on.addChild( joinCondition );
-		}
-
-		// todo : temporary...
-		System.out.println(
-				new TreePrinter( HQLLexer.class ).renderAsString( drivingTable, "Generated table space" )
-		);
-
-		return drivingTable;
-	}
-
-	/**
-	 * Generate the table expression for the given collection persister.
-	 *
-	 * @param collectionPersister The collection persister
-	 * @param aliasRoot The alias root for SQL alias generation.
-	 * @param tableSpace The table space to which any generated table references need to belong.
-	 *
-	 * @return The generated table expression (could be simply the root table in a joined table structure).
-	 */
-	public static Table generateTableExpression(
-			QueryableCollection collectionPersister,
-			TableAliasGenerator.TableAliasRoot aliasRoot,
-			Table.CollectionTableSpace tableSpace) {
-		if ( collectionPersister.isOneToMany() ) {
-			Table table = generateTableExpression(
-					( Queryable ) collectionPersister.getElementPersister(),
-					aliasRoot,
-					tableSpace.getEntityElementTableSpace()
-			);
-			tableSpace.setCollectionTable( table );
-			return table;
-		}
-		else {
-			Table associationTable = generateTableReference(
-					collectionPersister.getTableName(),
-					aliasRoot.generateCollectionTableAlias(),
-					tableSpace
-			);
-			tableSpace.setCollectionTable( associationTable );
-
-			if ( collectionPersister.isManyToMany() ) {
-				Queryable elementPersister = ( Queryable ) collectionPersister.getElementPersister();
-				Table drivingTable = generateTableExpression(
-						elementPersister,
-						aliasRoot,
-						tableSpace.getEntityElementTableSpace()
-				);
-
-				final HibernateTree join = new HibernateTree( HQLLexer.JOIN );
-				associationTable.addChild( join );
-				join.addChild( new HibernateTree( HQLLexer.LEFT, "left outer" ) );
-				join.addChild( drivingTable );
-
-				String[] entityFkColumnNames = collectionPersister.getElementColumnNames();
-				String[] entityPkColumnNames = elementPersister.getKeyColumnNames();
-
-				final HibernateTree on = new HibernateTree( HQLLexer.ON );
-				join.addChild( on );
-				final HibernateTree joinCondition = generateJoinCorrelation(
-						associationTable.getAliasText(),
-						entityFkColumnNames,
-						drivingTable.getAliasText(),
-						entityPkColumnNames
-				);
-				on.addChild( joinCondition );
-			}
-			return associationTable;
-		}
-	}
-
-	private static Table generateTableReference(String tableName, String tableAlias, Table.TableSpace tableSpace) {
-		return new Table( tableName, tableAlias, tableSpace );
-	}
-
-	/**
-	 * Creates a join correlation subtree (AST representing all the conditions on which the join occurs).
-	 *
-	 * @param lhsAlias The alias for the left-hand side (LHS) of the join
-	 * @param lhsColumns The LHS columns
-	 * @param rhsAlias The alias for the right-hand side (RHS) of the join
-	 * @param rhsColumns The RHS columns
-	 *
-	 * @return The join correlation AST.
-	 */
-	public static HibernateTree generateJoinCorrelation(
-			String lhsAlias,
-			String[] lhsColumns,
-			String rhsAlias,
-			String[] rhsColumns) {
-		HibernateTree correlation = generateJoinCorrelation( lhsAlias, lhsColumns[0], rhsAlias, rhsColumns[0] );
-		if ( lhsColumns.length > 1 ) {
-			for ( int i = 1; i < lhsColumns.length; i++ ) {
-				HibernateTree previous = correlation;
-				correlation = new HibernateTree( HQLLexer.AND, "and" );
-				correlation.addChild( previous );
-				correlation.addChild( generateJoinCorrelation( lhsAlias, lhsColumns[i], rhsAlias, rhsColumns[i] ) );
-			}
-		}
-		return correlation;
-	}
-
-	/**
-	 * Creates a join correlation subtree.  The difference here is that we have just a single column on each side.
-	 *
-	 * @param lhsAlias The alias for the left-hand side (LHS) of the join
-	 * @param lhsColumn The LHS column
-	 * @param rhsAlias The alias for the right-hand side (RHS) of the join
-	 * @param rhsColumn The RHS column
-	 *
-	 * @return The join correlation AST.
-	 */
-	public static HibernateTree generateJoinCorrelation(String lhsAlias, String lhsColumn, String rhsAlias, String rhsColumn) {
-		HibernateTree lhs = new HibernateTree( HQLLexer.COLUMN );
-		lhs.addChild( new HibernateTree( HQLLexer.ALIAS_REF, lhsAlias ) );
-		lhs.addChild( new HibernateTree( HQLLexer.IDENTIFIER, lhsColumn ) );
-
-		HibernateTree rhs = new HibernateTree( HQLLexer.COLUMN );
-		rhs.addChild( new HibernateTree( HQLLexer.ALIAS_REF, rhsAlias ) );
-		rhs.addChild( new HibernateTree( HQLLexer.IDENTIFIER, rhsColumn ) );
-
-		HibernateTree correlation = new HibernateTree( HQLLexer.EQUALS, "=" );
-		correlation.addChild( lhs );
-		correlation.addChild( rhs );
-
-		return correlation;
-	}
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PropertyPathTerminus.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PropertyPathTerminus.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PropertyPathTerminus.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,40 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-
-package org.hibernate.sql.ast.phase.hql.resolve;
-
-import org.hibernate.sql.ast.common.HibernateTree;
-
-/**
- * Represents the terminal part of a property path.
- *
- * @author Steve Ebersole
- */
-public abstract class PropertyPathTerminus extends HibernateTree {
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/ResolutionContext.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/ResolutionContext.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/ResolutionContext.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,94 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-
-package org.hibernate.sql.ast.phase.hql.resolve;
-
-import org.hibernate.engine.SessionFactoryImplementor;
-import org.hibernate.sql.ast.alias.TableAliasGenerator;
-import org.hibernate.sql.ast.phase.hql.resolve.path.PathResolutionStrategy;
-import org.hibernate.sql.ast.util.TreePrinter;
-
-/**
- * todo : javadocs
- *
- * @author Steve Ebersole
- */
-public interface ResolutionContext {
-
-	/**
-	 * The session factory available for this context.  Providing, for example, mapping information.
-	 *
-	 * @return The session factory.
-	 */
-	public SessionFactoryImplementor getSessionFactoryImplementor();
-
-	/**
-	 * The current {@link PersisterSpaceContext} for this context.  The {@link PersisterSpaceContext}
-	 * can change in relation to subqueries and such.  See {@link PersisterSpaceContext} docs for more info.
-	 *
-	 * @return The current {@link PersisterSpaceContext} for this resolution context.
-	 */
-	public PersisterSpaceContext getCurrentPersisterSpaceContext();
-
-//	/**
-//	 * The builder of {@link PersisterReference} instances for this context.
-//	 *
-//	 * @return The {@link PersisterReference} builder.
-//	 */
-//	public PersisterReferenceBuilder getPersisterReferenceBuilder();
-//
-//	/**
-//	 * The builder of {@link Join} instances pertaining to property joins for this context.
-//	 *
-//	 * @return The property {@link Join} builder.
-//	 */
-//	public PropertyJoinBuilder getPropertyJoinBuilder();
-
-	/**
-	 * The tree printer available for this context.
-	 *
-	 * @return The tree printer.
-	 */
-	public TreePrinter getTreePrinter();
-
-	public TableAliasGenerator getTableAliasGenerator();
-
-	/**
-	 * Is this context currently processing a function?
-	 *
-	 * @return True or false.
-	 */
-	public boolean isCurrentlyProcessingFunction();
-
-	public PathResolutionStrategy getCurrentPathResolutionStrategy();
-
-	public void registerAssociationFetch(PersisterSpace persisterSpace);
-
-	public void registerPropertyFetch(PersisterSpace persisterSpace);
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/RootPersisterSpaceContext.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/RootPersisterSpaceContext.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/RootPersisterSpaceContext.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,107 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-
-package org.hibernate.sql.ast.phase.hql.resolve;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.hibernate.QueryException;
-
-/**
- * Defines the contract for implementors of a "context" or a "scope" for references to persisters.  Generally speaking,
- * this maps to the notion of a FROM clause in a SELECT statement.  However, DML operations also have a notion of a
- * persister reference.  This, then, acts as the abstraction of these grouped references to persisters.
- *
- * @author Steve Ebersole
- */
-public class RootPersisterSpaceContext implements PersisterSpaceContext {
-	private static final Logger log = LoggerFactory.getLogger( RootPersisterSpaceContext.class );
-
-	private List<PersisterSpace> persisterSpaces = new ArrayList<PersisterSpace>();
-	private Map<String,PersisterSpace> aliasXref = new HashMap<String,PersisterSpace>();
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public void registerPersisterSpace(PersisterSpace persisterSpace) {
-		if ( persisterSpace.getSourceAlias() == null ) {
-			throw new IllegalArgumentException( "unexpected null persister-reference alias" );
-		}
-		persisterSpaces.add( persisterSpace );
-		aliasXref.put( persisterSpace.getSourceAlias(), persisterSpace );
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public boolean isContainedAlias(String alias) {
-		return aliasXref.containsKey( alias );
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public boolean isContainedExposedProperty(String propertyName) {
-		// a matching alias always takes precedence...
-		return ( ! isContainedAlias( propertyName ) ) && locatePersisterSpaceExposingProperty( propertyName ) != null;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public PersisterSpace locatePersisterSpaceByAlias(String alias) {
-		log.trace( "attempting to resolve [" + alias + "] as persister space alias" );
-		return aliasXref.get( alias );
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public PersisterSpace locatePersisterSpaceExposingProperty(String propertyName) {
-		log.trace( "attempting to resolve [" + propertyName + "] as unqualified property" );
-		PersisterSpace match = null;
-		for ( PersisterSpace persisterSpace : persisterSpaces ) {
-			if ( persisterSpace.containsProperty( propertyName ) ) {
-				if ( match != null ) {
-					// todo : better exception type
-					throw new QueryException( "multiple persisters contained property [" + propertyName + "]" );
-				}
-				match = persisterSpace;
-			}
-		}
-		return match;
-	}
-
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathResolutionStrategy.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathResolutionStrategy.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathResolutionStrategy.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,94 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-
-package org.hibernate.sql.ast.phase.hql.resolve.path;
-
-import org.hibernate.sql.ast.phase.hql.resolve.PersisterSpace;
-import org.hibernate.sql.ast.common.HibernateTree;
-
-/**
- * Applies a strategy pattern to the manner in which path expressions are normalized, allowing contextual pluggability
- * of the implicit-join and index-access handling rules...
- *
- * @author Steve Ebersole
- */
-public interface PathResolutionStrategy {
-	/**
-	 * Handle the root of the pathed property reference.
-	 *
-	 * @param persisterReference The root of the path.
-	 *
-	 * @return The source representation of the path root.
-	 */
-	public PathedPropertyReferenceSource handleRoot(PersisterSpace persisterReference);
-
-	/**
-	 * Handle an intermeidary path part.
-	 *
-	 * @param source The source of the property reference.
-	 * @param pathPart The current property path part.
-	 *
-	 * @return The new source for further property part handling.
-	 */
-	public PathedPropertyReferenceSource handleIntermediatePathPart(PathedPropertyReferenceSource source, String pathPart);
-
-	/**
-	 * Handle the terminal path part.
-	 *
-	 * @param source The source of the property reference.
-	 * @param pathPart The current (and terminal/last) path part.
-	 *
-	 * @return The terminal property reference indicated by the overall path.
-	 */
-	public HibernateTree handleTerminalPathPart(PathedPropertyReferenceSource source, String pathPart);
-
-	/**
-	 * Handle an index access operation (a.b[selector] for example).  In this particular case the index access
-	 * is further dereferenced (it is intermediate).
-	 *
-	 * @param source The source of the property reference.
-	 * @param pathPart The current property path part, here specifically naming the collection property
-	 * @param selector The index selection expression
-	 *
-	 * @return The new source for further property part handling.
-	 */
-	public PathedPropertyReferenceSource handleIntermediateIndexAccess(PathedPropertyReferenceSource source, String pathPart, HibernateTree selector);
-
-	/**
-	 * Handle an index access operation (a.b[selector] for example).  In this particular case the index access
-	 * is the terminus of the path expression.
-	 *
-	 * @param source The source of the property reference.
-	 * @param pathPart The current property path part, here specifically naming the collection property
-	 * @param selector The index selection expression
-	 *
-	 * @return The terminal property reference indicated by the overall path.
-	 */
-	public HibernateTree handleTerminalIndexAccess(PathedPropertyReferenceSource source, String pathPart, HibernateTree selector);
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathResolutionStrategyStack.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathResolutionStrategyStack.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathResolutionStrategyStack.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,53 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-
-package org.hibernate.sql.ast.phase.hql.resolve.path;
-
-import java.util.LinkedList;
-
-/**
- * Provides a stack of {@link PathResolutionStrategy} instances.
- *
- * @author Steve Ebersole
- */
-public class PathResolutionStrategyStack {
-	private LinkedList<PathResolutionStrategy> stack = new LinkedList<PathResolutionStrategy>();
-
-	public void push(PathResolutionStrategy handler) {
-		stack.addFirst( handler );
-	}
-
-	public PathResolutionStrategy pop() {
-		return stack.removeFirst();
-	}
-
-	public PathResolutionStrategy getCurrent() {
-		return stack.getFirst();
-	}
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathedPropertyReferenceSource.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathedPropertyReferenceSource.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/PathedPropertyReferenceSource.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,90 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-package org.hibernate.sql.ast.phase.hql.resolve.path;
-
-import org.antlr.runtime.tree.Tree;
-
-import org.hibernate.sql.ast.common.HibernateTree;
-
-/**
- * The contract for representing the non-terminal parts of a property path expression
- * <p/>
- * NOTE : extends AST so the grammar can more easily handle it, not because it will actually end up in the syntax
- * tree (it will not).
- *
- * @author Steve Ebersole
- */
-public interface PathedPropertyReferenceSource extends Tree {
-	/**
-	 * Return the path which led to this source.
-	 *
-	 * @return The origination path.
-	 */
-	public String getOriginationPath();
-
-	/**
-	 * Handle an intermediate path part reference.
-	 *
-	 * @param name The name for the path part to handle.
-	 *
-	 * @return An appropriate source representation of said intermeidate path part.
-	 */
-	public PathedPropertyReferenceSource handleIntermediatePathPart(String name);
-
-	/**
-	 * Handle the terminal path reference.
-	 *
-	 * @param name The name of the terminal path part.
-	 *
-	 * @return The property reference terminus.
-	 */
-	public HibernateTree handleTerminalPathPart(String name);
-
-	/**
-	 * Handle an index access operation (a.b[selector] for example).  In this particular case the index access
-	 * is further dereferenced (it is intermediate).
-	 *
-	 * @param collectionPropertyName The name of the collection property to which the index operator applies
-	 * @param selector The index selection expression
-	 *
-	 * @return An appropriate source representation of said intermeidate path part.
-	 */
-	public PathedPropertyReferenceSource handleIntermediateIndexAccess(String collectionPropertyName, HibernateTree selector);
-
-	/**
-	 * Handle an index access operation (a.b[selector] for example).  In this particular case the index access
-	 * is the terminus of the path expression.
-	 * 
-	 * @param collectionPropertyName The name of the collection property to which the index operator applies
-	 * @param selector The index selection expression
-	 *
-	 * @return The property reference terminus.
-	 */
-	public HibernateTree handleTerminalIndexAccess(String collectionPropertyName, HibernateTree selector);
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/AbstractPathResolutionStrategy.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/AbstractPathResolutionStrategy.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/AbstractPathResolutionStrategy.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,612 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-
-package org.hibernate.sql.ast.phase.hql.resolve.path.impl;
-
-import org.antlr.runtime.Token;
-import org.hibernate.QueryException;
-import org.hibernate.engine.SessionFactoryImplementor;
-import org.hibernate.persister.collection.QueryableCollection;
-import org.hibernate.persister.entity.Queryable;
-import org.hibernate.sql.ast.alias.TableAliasGenerator;
-import org.hibernate.sql.ast.common.HibernateToken;
-import org.hibernate.sql.ast.common.HibernateTree;
-import org.hibernate.sql.ast.phase.hql.parse.HQLParser;
-import org.hibernate.sql.ast.phase.hql.parse.HQLLexer;
-import org.hibernate.sql.ast.phase.hql.resolve.PersisterSpace;
-import org.hibernate.sql.ast.phase.hql.resolve.PersisterTableExpressionGenerator;
-import org.hibernate.sql.ast.phase.hql.resolve.ResolutionContext;
-import org.hibernate.sql.ast.phase.hql.resolve.path.PathResolutionStrategy;
-import org.hibernate.sql.ast.phase.hql.resolve.path.PathedPropertyReferenceSource;
-import org.hibernate.sql.ast.tree.Table;
-import org.hibernate.sql.ast.util.DisplayableNode;
-import org.hibernate.sql.ast.util.TreePrinter;
-import org.hibernate.type.CollectionType;
-import org.hibernate.type.ComponentType;
-import org.hibernate.type.EntityType;
-import org.hibernate.type.Type;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Abstract implementation of {@link PathResolutionStrategy} providing convenience methods to actual
- * {@link PathResolutionStrategy} implementors.
- *
- * @author Steve Ebersole
- */
-public abstract class AbstractPathResolutionStrategy implements PathResolutionStrategy {
-	private static final Logger log = LoggerFactory.getLogger( AbstractPathResolutionStrategy.class );
-
-	private final ResolutionContext resolutionContext;
-	private String pathThusFar = null;
-
-	protected AbstractPathResolutionStrategy(ResolutionContext resolutionContext) {
-		this.resolutionContext = resolutionContext;
-	}
-
-	// reolution context ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-	/**
-	 * Getter for property 'resolutionContext'.
-	 *
-	 * @return Value for property 'resolutionContext'.
-	 */
-	protected ResolutionContext resolutionContext() {
-		return resolutionContext;
-	}
-
-	protected final HibernateTree createNode(int type, String text) {
-		return new HibernateTree(type, text);
-	}
-
-	/**
-	 * Getter for property 'sessionFactoryImplementor'.
-	 *
-	 * @return Value for property 'sessionFactoryImplementor'.
-	 */
-	protected final SessionFactoryImplementor getSessionFactoryImplementor() {
-		return resolutionContext().getSessionFactoryImplementor();
-	}
-
-	/**
-	 * Getter for property 'ASTPrinter'.
-	 *
-	 * @return Value for property 'ASTPrinter'.
-	 */
-	protected final TreePrinter getTreePrinter() {
-		return resolutionContext().getTreePrinter();
-	}
-
-
-	// path ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-	protected void initializePathSoFar(String root) {
-		pathThusFar = root;
-	}
-
-	/**
-	 * Getter for property 'pathThusFar'.
-	 *
-	 * @return Value for property 'pathThusFar'.
-	 */
-	public String getPathThusFar() {
-		return pathThusFar;
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public final PathedPropertyReferenceSource handleRoot(PersisterSpace persisterSpace) {
-		initializePathSoFar( persisterSpace.getSourceAlias() );
-		log.trace( "handling root path source [" + pathThusFar + "]" );
-		return internalHandleRoot( persisterSpace );
-	}
-
-	/**
-	 * Hook for subclasses to process the path root.
-	 *
-	 * @param persisterSpace The persister defining the source root.
-	 * @return The appropriate property path source implementation.
-	 */
-	protected abstract PathedPropertyReferenceSource internalHandleRoot(PersisterSpace persisterSpace);
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public final PathedPropertyReferenceSource handleIntermediatePathPart(PathedPropertyReferenceSource source, String pathPart) {
-		pathThusFar = ( pathThusFar == null ) ? pathPart : pathThusFar + "." + pathPart;
-		log.trace( "handling intermediate path source [" + pathThusFar + "]" );
-		return internalResolveIntermediatePathPart( source, pathPart );
-	}
-
-	/**
-	 * Hook for subclasses to process an intermediate part of the path.
-	 *
-	 * @param source The source from which pathPart originates.
-	 * @param pathPart The name of the path part to be processed.
-	 * @return The appropriate property path source implementation.
-	 */
-	protected PathedPropertyReferenceSource internalResolveIntermediatePathPart(PathedPropertyReferenceSource source, String pathPart) {
-		return source.handleIntermediatePathPart( pathPart );
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public final HibernateTree handleTerminalPathPart(PathedPropertyReferenceSource source, String pathPart) {
-		pathThusFar = ( pathThusFar == null ) ? pathPart : pathThusFar + "." + pathPart;
-		log.trace( "handling terminal path part [" + pathThusFar + "]" );
-		try {
-			return internalResolveTerminalPathPart( source, pathPart );
-		}
-		finally {
-			pathThusFar = null;
-		}
-	}
-
-	/**
-	 * Hook for subclasses to process the terminal (or ending) part of a path.
-	 *
-	 * @param source The source from which pathPart originates.
-	 * @param pathPart The name of the path part to be processed.
-	 * @return a node representing the normalized property path.
-	 */
-	protected HibernateTree internalResolveTerminalPathPart(PathedPropertyReferenceSource source, String pathPart) {
-		return source.handleTerminalPathPart( pathPart );
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public final PathedPropertyReferenceSource handleIntermediateIndexAccess(PathedPropertyReferenceSource source, String pathPart, HibernateTree selector) {
-		pathThusFar = ( ( pathThusFar == null ) ? pathPart : pathThusFar + "." + pathPart ) + "[]";
-		log.trace( "handling intermediate index access [" + pathThusFar + "]" );
-		try {
-			return internalHandleIntermediateIndexAccess( source, pathPart, selector );
-		}
-		finally {
-			pathThusFar = null;
-		}
-	}
-
-	/**
-	 * Hook for subclasses to process an index access as an intermediate property path.
-	 *
-	 * @param source The source from which pathPart originates.
-	 * @param pathPart The name of the path part to be processed.
-	 * @param selector The index selector to be appliedto the indexed collection
-	 *
-	 * @return The appropriate property path source implementation.
-	 */
-	protected PathedPropertyReferenceSource internalHandleIntermediateIndexAccess(PathedPropertyReferenceSource source, String pathPart, HibernateTree selector) {
-		return source.handleIntermediateIndexAccess( pathPart, selector );
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public final HibernateTree handleTerminalIndexAccess(PathedPropertyReferenceSource source, String pathPart, HibernateTree selector) {
-		pathThusFar = ( ( pathThusFar == null ) ? pathPart : pathThusFar + "." + pathPart ) + "[]";
-		log.trace( "handling terminal index access [" + pathThusFar + "]" );
-		try {
-			return internalHandleTerminalIndexAccess( source, pathPart, selector );
-		}
-		finally {
-			pathThusFar = null;
-		}
-	}
-
-	/**
-	 * Hook for subclasses to process an index access as the terminus of a property path.
-	 *
-	 * @param source The source from which pathPart originates.
-	 * @param pathPart The name of the path part to be processed.
-	 * @param selector The index selector to be appliedto the indexed collection
-	 *
-	 * @return a node representing the normalized property path.
-	 */
-	protected HibernateTree internalHandleTerminalIndexAccess(PathedPropertyReferenceSource source, String pathPart, HibernateTree selector) {
-		return source.handleTerminalIndexAccess( pathPart, selector );
-	}
-
-	/**
-	 * Convenience method to locate the index of a component sub-property.  The returned index is relative to
-	 * {@link ComponentType#getPropertyNames}.
-	 *
-	 * @param componentType The component type mapping.
-	 * @param subPropertyName The sub-property name.
-	 * @return The index.
-	 */
-	protected static int locateComponentPropertyIndex(ComponentType componentType, String subPropertyName) {
-		String[] componentPropertyNames = componentType.getPropertyNames();
-		for ( int i = 0; i < componentPropertyNames.length; i++ ) {
-			if ( componentPropertyNames[i].equals( subPropertyName ) ) {
-				return i;
-			}
-		}
-		throw new QueryException( "could not locate component property [" + subPropertyName + "]" );
-	}
-
-	/**
-	 * Hook to allow subclasses to disallow implicit join.
-	 *
-	 * @param origin The persister-reference which is the origin of the property
-	 * @param property The property resulting in a join.
-	 */
-	protected void validateJoinCreation(PersisterSpace origin, String property) {
-		log.debug( "creating path expression implied join [" + origin.getSourceAlias() + "].[" + property + "]" );
-	}
-
-	/**
-	 * Hook to allow subclasses to define the type of join to use for an implciit join.
-	 * <p/>
-	 * The default is to use an {@link HQLParser#INNER} join.
-	 *
-	 * @return The join type node.
-	 */
-	protected HibernateTree buildJoinTypeNode() {
-		return createNode( HQLLexer.INNER, "inner" );
-	}
-
-	/**
-	 * Does this strategy allows property joins to be reused?
-	 *
-	 * @return True/false.
-	 */
-	protected boolean areJoinsReusable() {
-		return true;
-	}
-
-	/**
-	 * Locate (if property joins are reusable) or build an appropriate joined table.
-	 *
-	 * @param lhs The join lhs, which is the origin of the property.
-	 * @param propertyName The name of the property
-	 * @param alias The alias, if any, to apply to the generated RHS persister reference.
-	 * @param propertyFetching Should property fetching be applied to the generated RHS?
-	 * @param associationFetching Did this property join specify association fetching (join fetch)?
-	 * @return The appropriate join.
-	 */
-	protected final Table locateOrBuildPropertyJoinedTable(
-			PersisterSpace lhs,
-			String propertyName,
-			String alias,
-			boolean propertyFetching,
-			boolean associationFetching) {
-		Table joinedTable = null;
-		if ( areJoinsReusable() ) {
-			joinedTable = lhs.locateReusablePropertyJoinedTable( propertyName );
-		}
-
-		if ( joinedTable == null ) {
-			joinedTable = buildPropertyJoinedTable( lhs, propertyName, alias, propertyFetching, associationFetching );
-			if ( areJoinsReusable() ) {
-				lhs.registerReusablePropertyJoinedTable( propertyName, joinedTable );
-			}
-		}
-
-		return joinedTable;
-	}
-
-	/**
-	 * Build a property joined table
-	 *
-	 * @param lhs The join's left-hand-side persister-reference
-	 * @param propertyName The property name.
-	 * @param alias The alias to apply to the rhs of the join
-	 * @param propertyFetching should property fetching be applied to the joined persister?
-	 * @param associationFetching Should the association making up the property join also be fetched?
-	 *
-	 * @return The right-hand-side persister-reference.
-	 */
-	protected Table buildPropertyJoinedTable(
-			PersisterSpace lhs,
-			String propertyName,
-			String alias,
-			boolean propertyFetching,
-			boolean associationFetching) {
-		validateJoinCreation( lhs, propertyName );
-		Table joinedTable;
-		Type propertyType = lhs.getPropertyType( propertyName );
-		if ( propertyType.isEntityType() ) {
-			EntityType entityType = ( EntityType ) propertyType;
-			Queryable entityPersister = ( Queryable ) getSessionFactoryImplementor()
-					.getEntityPersister( entityType.getAssociatedEntityName( getSessionFactoryImplementor() ) );
-			joinedTable = createJoin( lhs, entityPersister, alias );
-		}
-		else if ( propertyType.isCollectionType() ) {
-			CollectionType collectionType = ( CollectionType ) propertyType;
-			QueryableCollection collectionPersister = ( QueryableCollection ) getSessionFactoryImplementor()
-					.getCollectionPersister( collectionType.getRole() );
-			joinedTable = createJoin( lhs, collectionPersister, alias, null );
-		}
-		else {
-			throw new InvalidPropertyJoinException( getPathThusFar(), lhs.getName(), propertyName );
-		}
-
-		if ( propertyFetching ) {
-			resolutionContext().registerPropertyFetch( joinedTable.getTableSpace().getPersisterSpace() );
-		}
-		if ( associationFetching ) {
-			resolutionContext.registerAssociationFetch( joinedTable.getTableSpace().getPersisterSpace() );
-		}
-
-		return joinedTable;
-	}
-
-	/**
-	 * Generate a column list (tree w/ token type {@link HQLParser#COLUMN_LIST} for the columns making up the given
-	 * property.
-	 *
-	 * @param origin The persister-space from which the property originates.
-	 * @param propertyName The name of the property being referenced.
-	 *
-	 * @return The column list.
-	 */
-	protected final HibernateTree generatePropertyColumnList(PersisterSpace origin, String propertyName) {
-		HibernateTree columnList = new HibernateTree( HQLLexer.COLUMN_LIST );
-		Table containingTable = origin.getTableSpace().getContainingTable( propertyName );
-		for ( String columnName : origin.getTableSpace().getPropertyColumnNames( propertyName ) ) {
-			final HibernateTree column = new HibernateTree( HQLLexer.COLUMN );
-			columnList.addChild( column );
-			column.addChild( new HibernateTree( HQLLexer.ALIAS_REF, containingTable.getAliasText() ) );
-			column.addChild( new HibernateTree( HQLLexer.IDENTIFIER, columnName ) );
-		}
-		return columnList;
-	}
-
-
-	// source impl support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-	public abstract class AbstractPathedPropertyReferenceSource
-			extends HibernateTree
-			implements PathedPropertyReferenceSource, DisplayableNode {
-		private final String originationPath;
-
-		/**
-		 * Constructs a new AbstractPathedPropertyReferenceSource.
-		 */
-		protected AbstractPathedPropertyReferenceSource() {
-			this( getPathThusFar() );
-		}
-
-		protected AbstractPathedPropertyReferenceSource(Token token) {
-			this( token, getPathThusFar() );
-		}
-
-		protected AbstractPathedPropertyReferenceSource(String originationPath) {
-			super( new HibernateToken( HQLLexer.IDENTIFIER, originationPath ) );
-			this.originationPath = originationPath;
-		}
-
-		protected AbstractPathedPropertyReferenceSource(Token token, String originationPath) {
-			super( token );
-			this.originationPath = originationPath;
-		}
-
-		public HibernateTree handleTerminalIndexAccess(PersisterSpace lhs, String collectionPropertyName, HibernateTree selector) {
-			Table joinedCollectionTable = createIndexAccessJoin( lhs, collectionPropertyName, selector );
-
-			// in general we need the collection element column list
-			QueryableCollection collectionPersister = resolveCollectionPersister( lhs, collectionPropertyName );
-			HibernateTree columnList = new HibernateTree( HQLLexer.COLUMN_LIST );
-			for ( String columnName : collectionPersister.getElementColumnNames() ) {
-				final HibernateTree column = new HibernateTree( HQLLexer.COLUMN );
-				column.addChild( new HibernateTree( HQLLexer.ALIAS_REF, joinedCollectionTable.getAliasText() ) );
-				column.addChild( new HibernateTree( HQLLexer.IDENTIFIER, columnName ) );
-			}
-			return columnList;
-		}
-
-		protected Table createIndexAccessJoin(PersisterSpace lhs, String collectionPropertyName, HibernateTree selector) {
-			validateIndexedCollectionReference( lhs, collectionPropertyName );
-
-			QueryableCollection collectionPersister = resolveCollectionPersister( lhs, collectionPropertyName );
-			Table joinedTable = createJoin( lhs, collectionPersister, null, selector );
-
-			if ( log.isTraceEnabled() ) {
-				log.trace(
-						resolutionContext().getTreePrinter().renderAsString(
-								joinedTable.getParent(),
-								"implicit join : " + lhs.getSourceAlias() + "." + collectionPropertyName + "[]"
-						)
-				);
-			}
-
-			return joinedTable;
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		public String getOriginationPath() {
-			return originationPath;
-		}
-
-		/**
-		 * {@inheritDoc}
-		 */
-		public final String getDisplayText() {
-				return " ADPATER : SHOULD NEVER END UP IN TREE!";
-		}
-	}
-
-	protected Table createJoin(PersisterSpace lhs, String propertyName, String alias) {
-		validateJoinable( lhs, propertyName );
-		Type propertyType = lhs.getPropertyType( propertyName );
-		if ( propertyType.isEntityType() ) {
-			return createJoin( lhs, resolveEntityPersister( lhs, propertyName ), alias );
-		}
-		else {
-			// assume collection because of validation of being joinable...
-			return createJoin( lhs, resolveCollectionPersister( lhs, propertyName ), alias, null );
-		}
-	}
-
-	protected Table createJoin(PersisterSpace lhs, Queryable entityPersister, String alias) {
-		EntityType entityType = entityPersister.getEntityMetamodel().getEntityType();
-
-		TableAliasGenerator.TableAliasRoot tableAliasRoot = resolutionContext().getTableAliasGenerator()
-				.generateSqlAliasRoot( entityPersister, alias );
-		Table.EntityTableSpace tableSpace = new Table.EntityTableSpace( entityPersister, tableAliasRoot );
-		Table joinedTableExpression = tableSpace.getDrivingTable();
-
-		HibernateTree join = new HibernateTree( HQLLexer.JOIN );
-		join.addChild( buildJoinTypeNode() );
-		join.addChild( joinedTableExpression );
-
-		HibernateTree joinCondition;
-		final String lhsJoinProperty = entityType.getLHSPropertyName();
-		if ( lhsJoinProperty == null ) {
-			// join using the lhs PK
-			joinCondition = PersisterTableExpressionGenerator.generateJoinCorrelation(
-					lhs.getTableSpace().getJoinIntoTable().getAliasText(),
-					lhs.getTableSpace().getJoinIntoColumns(),
-					joinedTableExpression.getAliasText(),
-					entityPersister.getKeyColumnNames()
-			);
-		}
-		else {
-			// join using the columns to which the given lhs property is mapped
-			joinCondition = PersisterTableExpressionGenerator.generateJoinCorrelation(
-					lhs.getTableSpace().getContainingTable( lhsJoinProperty ).getAliasText(),
-					lhs.getTableSpace().getPropertyColumnNames( lhsJoinProperty ),
-					joinedTableExpression.getAliasText(),
-					entityPersister.getKeyColumnNames()
-			);
-		}
-
-		HibernateTree on = new HibernateTree( HQLLexer.ON );
-		join.addChild( on );
-		on.addChild( joinCondition );
-
-		return joinedTableExpression;
-	}
-
-	protected Table createJoin(PersisterSpace lhs, QueryableCollection collectionPersister, String sourceAlias, HibernateTree extraJoinConditions) {
-		CollectionType collectionType = collectionPersister.getCollectionType();
-
-		TableAliasGenerator.TableAliasRoot tableAliasRoot = resolutionContext().getTableAliasGenerator()
-				.generateSqlAliasRoot( collectionPersister, sourceAlias );
-		Table.CollectionTableSpace tableSpace = new Table.CollectionTableSpace( collectionPersister, tableAliasRoot );
-
-		Table collectionTableExpression = PersisterTableExpressionGenerator.generateTableExpression(
-				collectionPersister,
-				tableAliasRoot,
-				tableSpace
-		);
-
-		HibernateTree joinNode = new HibernateTree( HQLLexer.JOIN );
-		joinNode.addChild( buildJoinTypeNode() );
-		joinNode.addChild( collectionTableExpression );
-
-		HibernateTree joinCondition;
-		final String lhsJoinProperty = collectionType.getLHSPropertyName();
-		if ( lhsJoinProperty == null ) {
-			// join using the lhs PK
-			joinCondition = PersisterTableExpressionGenerator.generateJoinCorrelation(
-					lhs.getTableSpace().getJoinIntoTable().getAliasText(),
-					lhs.getTableSpace().getJoinIntoColumns(),
-					collectionTableExpression.getAliasText(),
-					collectionPersister.getKeyColumnNames()
-			);
-		}
-		else {
-			// join using the columns to which the given lhs property is mapped
-			joinCondition = PersisterTableExpressionGenerator.generateJoinCorrelation(
-					lhs.getTableSpace().getContainingTable( lhsJoinProperty ).getAliasText(),
-					lhs.getTableSpace().getPropertyColumnNames( lhsJoinProperty ),
-					collectionTableExpression.getAliasText(),
-					collectionPersister.getKeyColumnNames()
-			);
-		}
-
-		if ( extraJoinConditions != null ) {
-			HibernateTree mappedJoinCondition = joinCondition;
-			joinCondition = new HibernateTree( HQLLexer.AND );
-			joinCondition.addChild( mappedJoinCondition );
-			joinCondition.addChild( extraJoinConditions );
-		}
-
-		HibernateTree on = new HibernateTree( HQLLexer.ON );
-		joinNode.addChild( on );
-		on.addChild( joinCondition );
-
-		return collectionTableExpression;
-	}
-
-	protected void validateJoinable(PersisterSpace lhs, String propertyName) {
-		if ( ! isAssociation( lhs.getPropertyType( propertyName ) ) ) {
-			throw new InvalidPropertyJoinException( getPathThusFar(), lhs.getName(), propertyName );
-		}
-	}
-
-	protected boolean isAssociation(Type propertyType) {
-		return propertyType.isAssociationType();
-	}
-
-	protected void validateCollectionReference(PersisterSpace lhs, String propertyName) {
-		if ( ! isCollectionReference( lhs.getPropertyType( propertyName ) ) ) {
-			throw new CollectionExpectedException( getPathThusFar(), lhs.getName(), propertyName );
-		}
-	}
-
-	private boolean isCollectionReference(Type propertyType) {
-		return propertyType.isCollectionType();
-	}
-
-	protected void validateIndexedCollectionReference(PersisterSpace lhs, String propertyName) {
-		if ( ! isIndexedCollectionReference( lhs.getPropertyType( propertyName ) ) ) {
-			throw new IndexedCollectionExectedException( getPathThusFar(), lhs.getName(), propertyName );
-		}
-	}
-
-	private boolean isIndexedCollectionReference(Type propertyType) {
-		return isCollectionReference( propertyType )
-				&& resolveCollectionPersister( ( CollectionType ) propertyType ).hasIndex();
-	}
-
-	protected QueryableCollection resolveCollectionPersister(PersisterSpace lhs, String propertyName) {
-		return resolveCollectionPersister( ( CollectionType ) lhs.getPropertyType( propertyName ) );
-	}
-
-	protected QueryableCollection resolveCollectionPersister(CollectionType collectionType) {
-		return ( QueryableCollection ) getSessionFactoryImplementor().getCollectionPersister( collectionType.getRole() );
-	}
-
-	protected Queryable resolveEntityPersister(PersisterSpace lhs, String propertyName) {
-		return resolveEntityPersister( ( EntityType ) lhs.getPropertyType( propertyName ) );
-	}
-
-	protected Queryable resolveEntityPersister(EntityType entityType) {
-		return ( Queryable ) getSessionFactoryImplementor().getEntityPersister(
-				entityType.getAssociatedEntityName( getSessionFactoryImplementor() )
-		);
-	}
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/AbstractUnexpectedPropertyTypeException.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/AbstractUnexpectedPropertyTypeException.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/AbstractUnexpectedPropertyTypeException.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,71 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-
-package org.hibernate.sql.ast.phase.hql.resolve.path.impl;
-
-import org.hibernate.QueryException;
-
-/**
- * todo : javadocs
- *
- * @author Steve Ebersole
- */
-public class AbstractUnexpectedPropertyTypeException extends QueryException {
-	private final String path;
-	private final String persisterName;
-	private final String propertyName;
-
-	public AbstractUnexpectedPropertyTypeException(String path, String persisterName, String propertyName) {
-		super();
-		this.path = path;
-		this.persisterName = persisterName;
-		this.propertyName = propertyName;
-	}
-
-	@Override
-	protected String internalGetMessage() {
-		return "Referenced property [" + buildPropertyReferenceFragment() + "] was not of expected type";
-	}
-
-	protected String buildPropertyReferenceFragment() {
-		return path + " (" + persisterName + ")." + propertyName;
-	}
-
-	public String getPath() {
-		return path;
-	}
-
-	public String getPersisterName() {
-		return persisterName;
-	}
-
-	public String getPropertyName() {
-		return propertyName;
-	}
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/BasicPathResolutionStrategySupport.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/BasicPathResolutionStrategySupport.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/BasicPathResolutionStrategySupport.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,334 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-
-package org.hibernate.sql.ast.phase.hql.resolve.path.impl;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.hibernate.HibernateException;
-import org.hibernate.hql.CollectionProperties;
-import org.hibernate.persister.collection.QueryableCollection;
-import org.hibernate.persister.entity.EntityPersister;
-import org.hibernate.sql.ast.common.HibernateTree;
-import org.hibernate.sql.ast.phase.hql.resolve.PersisterSpace;
-import org.hibernate.sql.ast.phase.hql.resolve.PropertyPathTerminus;
-import org.hibernate.sql.ast.phase.hql.resolve.ResolutionContext;
-import org.hibernate.sql.ast.phase.hql.resolve.path.PathedPropertyReferenceSource;
-import org.hibernate.sql.ast.tree.Table;
-import org.hibernate.type.ComponentType;
-import org.hibernate.type.EntityType;
-import org.hibernate.type.Type;
-
-/**
- * todo : javadocs
- *
- * @author Steve Ebersole
- */
-public class BasicPathResolutionStrategySupport extends AbstractPathResolutionStrategy {
-	private static final Logger log = LoggerFactory.getLogger( BasicPathResolutionStrategySupport.class );
-
-
-	public BasicPathResolutionStrategySupport(ResolutionContext resolutionContext) {
-		super( resolutionContext );
-	}
-
-	protected PathedPropertyReferenceSource internalHandleRoot(PersisterSpace persisterSpace) {
-		return new RootSourceImpl( persisterSpace );
-	}
-
-	private PathedPropertyReferenceSource determineAppropriateIntermediateSourceType(PersisterSpace origin, String propertyName) {
-		final Type propertyType = origin.getPropertyType( propertyName );
-		if ( propertyType.isComponentType() ) {
-			return new ComponentIntermediatePathSource( origin, propertyName, ( ComponentType ) propertyType );
-		}
-		else if ( propertyType.isEntityType() ) {
-			return new EntityIntermediatePathSource( origin, propertyName );
-		}
-		else if ( propertyType.isCollectionType() ) {
-			return new CollectionIntermediatePathSource( origin, propertyName );
-		}
-		else {
-			return new SimpleIntermediatePathSource();
-		}
-	}
-
-	/**
-	 * Is the given property name a reference to the primary key of the associated
-	 * entity construed by the given entity type?
-	 * <p/>
-	 * For example, consider a fragment like order.customer.id
-	 * (where order is a from-element alias).  Here, we'd have:
-	 * propertyName = "id" AND
-	 * owningType = ManyToOneType(Customer)
-	 * and are being asked to determine whether "customer.id" is a reference
-	 * to customer's PK...
-	 *
-	 * @param propertyName The name of the property to check.
-	 * @param owningType The type represeting the entity "owning" the property
-	 * @return True if propertyName references the enti ty's (owningType->associatedEntity)
-	 * primary key; false otherwise.
-	 */
-	private boolean isReferenceToPrimaryKey(EntityType owningType, String propertyName) {
-		EntityPersister persister = getSessionFactoryImplementor().getEntityPersister(
-				owningType.getAssociatedEntityName( getSessionFactoryImplementor() )
-		);
-		if ( persister.getEntityMetamodel().hasNonIdentifierPropertyNamedId() ) {
-			// only the identifier property field name can be a reference to the associated entity's PK...
-			return propertyName.equals( persister.getIdentifierPropertyName() ) && owningType.isReferenceToPrimaryKey();
-		}
-		else {
-			// here, we have two possibilities:
-			// 		1) the property-name matches the explicitly identifier property name
-			//		2) the property-name matches the implicit 'id' property name
-			if ( EntityPersister.ENTITY_ID.equals( propertyName ) ) {
-				// the referenced node text is the special 'id'
-				return owningType.isReferenceToPrimaryKey();
-			}
-			else {
-				String keyPropertyName = owningType.getIdentifierOrUniqueKeyPropertyName( getSessionFactoryImplementor() );
-				return keyPropertyName != null && keyPropertyName.equals( propertyName ) && owningType.isReferenceToPrimaryKey();
-			}
-		}
-	}
-
-
-
-	// source impls ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-	private class RootSourceImpl extends AbstractPathedPropertyReferenceSource {
-		private final PersisterSpace lhs;
-
-		public RootSourceImpl(PersisterSpace lhs) {
-			this.lhs = lhs;
-		}
-
-		public PathedPropertyReferenceSource handleIntermediatePathPart(String name) {
-			return determineAppropriateIntermediateSourceType( lhs, name );
-		}
-
-		public HibernateTree handleTerminalPathPart(String name) {
-			if ( lhs.getPropertyType( name ).isEntityType() ) {
-				if ( shouldTerminalEntityPropertyForceJoin() ) {
-					locateOrBuildPropertyJoinedTable( lhs, name, null, false, false );
-				}
-			}
-			return generatePropertyColumnList( lhs, name );
-		}
-
-		public PathedPropertyReferenceSource handleIntermediateIndexAccess(String collectionPropertyName, HibernateTree selector) {
-			validateIndexedCollectionReference( lhs, collectionPropertyName );
-			QueryableCollection collectionPersister = resolveCollectionPersister( lhs, collectionPropertyName );
-
-			Table joinedCollectionTable = createJoin( lhs, collectionPersister, null, selector );
-			return new IndexAccessIntermediatePathSource(joinedCollectionTable.getTableSpace().getPersisterSpace() );
-		}
-
-		public HibernateTree handleTerminalIndexAccess(String collectionPropertyName, HibernateTree selector) {
-			return handleTerminalIndexAccess( lhs, collectionPropertyName, selector );
-		}
-
-		public String getText() {
-			return "root-source {" + lhs.getSourceAlias() + "}";
-		}
-	}
-
-	protected class SimpleIntermediatePathSource extends AbstractPathedPropertyReferenceSource {
-		public PathedPropertyReferenceSource handleIntermediatePathPart(String name) {
-			throw new HibernateException( "cannot dereference simple value as part of path expression" );
-		}
-
-		public HibernateTree handleTerminalPathPart(String name) {
-			throw new HibernateException( "cannot dereference simple value as part of path expression" );
-		}
-
-		public PathedPropertyReferenceSource handleIntermediateIndexAccess(String name, HibernateTree selector) {
-			throw new HibernateException( "cannot apply index operation to simple value" );
-		}
-
-		public HibernateTree handleTerminalIndexAccess(String name, HibernateTree selector) {
-			throw new HibernateException( "cannot apply index operation to simple value" );
-		}
-	}
-
-	private class ComponentIntermediatePathSource extends AbstractPathedPropertyReferenceSource {
-		private final PersisterSpace lhs;
-		private final String propertyPath;
-		private final ComponentType componentType;
-
-		public ComponentIntermediatePathSource(PersisterSpace lhs, String propertyPath) {
-			this( lhs, propertyPath, ( ComponentType ) lhs.getPropertyType( propertyPath ) );
-		}
-
-		private ComponentIntermediatePathSource(PersisterSpace lhs, String propertyPath, ComponentType componentType) {
-			this.lhs = lhs;
-			this.propertyPath = propertyPath;
-			this.componentType = componentType;
-		}
-
-		public PathedPropertyReferenceSource handleIntermediatePathPart(String propertyName) {
-			final int index = locateComponentPropertyIndex( componentType, propertyName );
-			final String path = buildComponentDereferencePath( propertyName );
-			final Type propertyType = componentType.getSubtypes()[index];
-			if ( propertyType.isComponentType() ) {
-				return new ComponentIntermediatePathSource( lhs, path, ( ComponentType ) propertyType );
-			}
-			else if ( propertyType.isEntityType() ) {
-				return new EntityIntermediatePathSource( lhs, path );
-			}
-			else {
-				return new SimpleIntermediatePathSource();
-			}
-		}
-
-		public HibernateTree handleTerminalPathPart(String name) {
-			return generatePropertyColumnList( lhs, buildComponentDereferencePath( name ) );
-		}
-
-		public PathedPropertyReferenceSource handleIntermediateIndexAccess(String name, HibernateTree selector) {
-			throw new HibernateException( "cannot apply index operation to component value" );
-		}
-
-		public PropertyPathTerminus handleTerminalIndexAccess(String name, HibernateTree selector) {
-			throw new HibernateException( "cannot apply index operation to component value" );
-		}
-
-		private String buildComponentDereferencePath(String subPropertyName) {
-			return propertyPath + "." + subPropertyName;
-		}
-	}
-
-	protected class EntityIntermediatePathSource extends AbstractPathedPropertyReferenceSource {
-		private final PersisterSpace lhs;
-		private final String lhsPropertyName;
-
-		public EntityIntermediatePathSource(PersisterSpace lhs, String lhsPropertyName) {
-			this.lhs = lhs;
-			this.lhsPropertyName = lhsPropertyName;
-		}
-
-		public PathedPropertyReferenceSource handleIntermediatePathPart(String name) {
-			Table joinedTable = locateOrBuildPropertyJoinedTable( lhs, lhsPropertyName, null, false, false );
-			return determineAppropriateIntermediateSourceType( joinedTable.getTableSpace().getPersisterSpace(), name );
-		}
-
-		public HibernateTree handleTerminalPathPart(String name) {
-			final EntityType type = ( EntityType ) lhs.getPropertyType( lhsPropertyName );
-			if ( isReferenceToPrimaryKey( type, lhsPropertyName ) ) {
-				// todo : create a column-list based on the FKs...
-				return null;
-			}
-			else {
-				Table joinedTable = locateOrBuildPropertyJoinedTable( lhs, lhsPropertyName, null, false, false );
-				PersisterSpace rhs = joinedTable.getTableSpace().getPersisterSpace();
-				if ( type.isEntityType() ) {
-					if ( shouldTerminalEntityPropertyForceJoin() ) {
-						locateOrBuildPropertyJoinedTable( rhs, name, null, false, false );
-					}
-				}
-				return generatePropertyColumnList( rhs, name );
-			}
-
-		}
-
-		public PathedPropertyReferenceSource handleIntermediateIndexAccess(String name, HibernateTree selector) {
-			Table lhsJoinedTable = locateOrBuildPropertyJoinedTable( lhs, lhsPropertyName, null, false, false );
-			PersisterSpace lhsJoinedPersisterSpace = lhsJoinedTable.getTableSpace().getPersisterSpace();
-
-			validateIndexedCollectionReference( lhs, name );
-			QueryableCollection collectionPersister = resolveCollectionPersister( lhsJoinedPersisterSpace, name );
-			Table joinedTable = createJoin( lhsJoinedPersisterSpace, collectionPersister, null, selector );
-
-			return new IndexAccessIntermediatePathSource( joinedTable.getTableSpace().getPersisterSpace() );
-		}
-
-		public HibernateTree handleTerminalIndexAccess(String collectionPropertyName, HibernateTree selector) {
-			return handleTerminalIndexAccess( lhs, collectionPropertyName, selector );
-		}
-	}
-
-	protected boolean shouldTerminalEntityPropertyForceJoin() {
-		return false;
-	}
-
-	protected class CollectionIntermediatePathSource extends AbstractPathedPropertyReferenceSource {
-		private final PersisterSpace lhs;
-		private final String propertyName;
-
-		public CollectionIntermediatePathSource(PersisterSpace lhs, String propertyName) {
-			this.lhs = lhs;
-			this.propertyName = propertyName;
-		}
-
-		public PathedPropertyReferenceSource handleIntermediatePathPart(String name) {
-			throw new HibernateException( "cannot implicit join across a collection association" );
-		}
-
-		public HibernateTree handleTerminalPathPart(String name) {
-			// TODO : what are the circusmstances under which we need to *join* to the collection, as opposed to say munge it into a subquery???
-			if ( CollectionProperties.isAnyCollectionProperty( name ) ) {
-				Table joinedTable = locateOrBuildPropertyJoinedTable( lhs, propertyName, null, false, false );
-				return generatePropertyColumnList( joinedTable.getTableSpace().getPersisterSpace(), name );
-			}
-			throw new HibernateException( "cannot implicit join across a collection association" );
-		}
-
-		public PathedPropertyReferenceSource handleIntermediateIndexAccess(String name, HibernateTree selector) {
-			throw new HibernateException( "cannot implicit join across a collection association" );
-		}
-
-		public HibernateTree handleTerminalIndexAccess(String name, HibernateTree selector) {
-			throw new HibernateException( "cannot implicit join across a collection association" );
-		}
-	}
-
-	protected class IndexAccessIntermediatePathSource extends AbstractPathedPropertyReferenceSource {
-		private final PersisterSpace persisterSpace;
-
-		public IndexAccessIntermediatePathSource(PersisterSpace persisterSpace) {
-			this.persisterSpace = persisterSpace;
-		}
-
-		public PathedPropertyReferenceSource handleIntermediatePathPart(String name) {
-			return determineAppropriateIntermediateSourceType( persisterSpace, name );
-		}
-
-		public HibernateTree handleTerminalPathPart(String name) {
-			return generatePropertyColumnList( persisterSpace, name );
-		}
-
-		public PathedPropertyReferenceSource handleIntermediateIndexAccess(String name, HibernateTree selector) {
-			throw new IllegalStateException( "doubled up index operators" );
-		}
-
-		public HibernateTree handleTerminalIndexAccess(String name, HibernateTree selector) {
-			throw new IllegalStateException( "doubled up index operators" );
-		}
-	}
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/CollectionExpectedException.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/CollectionExpectedException.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/CollectionExpectedException.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,46 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-
-package org.hibernate.sql.ast.phase.hql.resolve.path.impl;
-
-/**
- * Indicates that we were expecting a property reference to identify a collection, but it did not.
- *
- * @author Steve Ebersole
- */
-public class CollectionExpectedException extends AbstractUnexpectedPropertyTypeException {
-	public CollectionExpectedException(String path, String persisterName, String propertyName) {
-		super( path, persisterName, propertyName );
-	}
-
-	@Override
-	protected String internalGetMessage() {
-		return "Expected property reference [" + buildPropertyReferenceFragment() + "] to identify collection";
-	}
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/FromClausePathResolutionStrategy.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/FromClausePathResolutionStrategy.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/FromClausePathResolutionStrategy.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,125 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-package org.hibernate.sql.ast.phase.hql.resolve.path.impl;
-
-import org.hibernate.QueryException;
-import org.hibernate.sql.ast.common.HibernateTree;
-import org.hibernate.sql.ast.common.JoinType;
-import org.hibernate.sql.ast.phase.hql.parse.HQLLexer;
-import org.hibernate.sql.ast.phase.hql.resolve.PersisterSpace;
-import org.hibernate.sql.ast.phase.hql.resolve.ResolutionContext;
-import org.hibernate.sql.ast.phase.hql.resolve.path.PathedPropertyReferenceSource;
-import org.hibernate.sql.ast.tree.Table;
-
-/**
- *
- * {@link org.hibernate.sql.ast.phase.hql.resolve.path.PathResolutionStrategy} for dealing with path expressions
- * occuring in the <tt>FROM</tt> clause of a query.
- *
- * @author Steve Ebersole
- */
-public class FromClausePathResolutionStrategy extends AbstractPathResolutionStrategy {
-	private final JoinType joinType;
-	private final boolean associationFetch;
-	private final boolean propertyFetch;
-	private final String alias;
-
-	/**
-	 * Instantiate a normalization strategy for handling path expressions in a <tt>FROM</tt> clause.
-	 *
-	 * @param resolutionContext The context for resolution.
-	 * @param joinType The type of explicit-join specified at the root of this path expression.
-	 * @param associationFetch Was association fetching indicated on this path expression?
-	 * @param propertyFetch Was property fetching indicated on this path expression?
-	 * @param alias The alias (if one) specified on this joined path expression.
-	 */
-	public FromClausePathResolutionStrategy(
-			ResolutionContext resolutionContext,
-			JoinType joinType,
-			boolean associationFetch,
-			boolean propertyFetch,
-			String alias) {
-		super( resolutionContext );
-		this.joinType = joinType;
-		this.associationFetch = associationFetch;
-		this.propertyFetch = propertyFetch;
-		this.alias = alias;
-	}
-
-	protected PathedPropertyReferenceSource internalHandleRoot(PersisterSpace persisterSpace) {
-		return new SourceImpl( persisterSpace );
-	}
-
-	private class SourceImpl extends AbstractPathedPropertyReferenceSource {
-		private final PersisterSpace lhs;
-
-		private SourceImpl(PersisterSpace lhs) {
-			this.lhs = lhs;
-		}
-
-		public PathedPropertyReferenceSource handleIntermediatePathPart(String name) {
-			// TODO : still need to account for paths including component dereferences...
-			Table joinedTable = buildPropertyJoinedTable( lhs, name, null, false, associationFetch );
-			return new SourceImpl( joinedTable.getTableSpace().getPersisterSpace() );
-		}
-
-		public HibernateTree handleTerminalPathPart(String propertyName) {
-			validateJoinable( lhs, propertyName );
-
-			Table joinedTable = buildPropertyJoinedTable( lhs, propertyName, alias, propertyFetch, associationFetch );
-			return joinedTable.getTableSpace().buildIdentifierColumnReferences();
-		}
-
-		public PathedPropertyReferenceSource handleIntermediateIndexAccess(String name, HibernateTree selector) {
-			throw new UnsupportedOperationException( "index operation not supported in from clause" );
-		}
-
-		public HibernateTree handleTerminalIndexAccess(String name, HibernateTree selector) {
-			throw new UnsupportedOperationException( "index operation not supported in from clause" );
-		}
-	}
-
-	protected HibernateTree buildJoinTypeNode() {
-		if ( joinType == JoinType.INNER ) {
-			return new HibernateTree( HQLLexer.INNER );
-		}
-		else if ( joinType == JoinType.LEFT ) {
-			return new HibernateTree( HQLLexer.LEFT );
-		}
-		else if ( joinType == JoinType.RIGHT ) {
-			return new HibernateTree( HQLLexer.RIGHT );
-		}
-		// if no match found, throw exception
-		throw new QueryException( "Unrecognized join type [" + joinType.toString() + "]" );
-	}
-
-	protected boolean areJoinsReusable() {
-		return false;
-	}
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/IndexedCollectionExectedException.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/IndexedCollectionExectedException.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/IndexedCollectionExectedException.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,46 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-
-package org.hibernate.sql.ast.phase.hql.resolve.path.impl;
-
-/**
- * Indicates that we were expecting a property reference to identify an indexed collection, but it did not.
- *
- * @author Steve Ebersole
- */
-public class IndexedCollectionExectedException extends AbstractUnexpectedPropertyTypeException {
-	public IndexedCollectionExectedException(String path, String persisterName, String propertyName) {
-		super( path, persisterName, propertyName );
-	}
-
-	@Override
-	protected String internalGetMessage() {
-		return "Expected property reference [" + buildPropertyReferenceFragment() + "] to identify indexed collection";
-	}
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/InvalidPropertyJoinException.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/InvalidPropertyJoinException.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/InvalidPropertyJoinException.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,46 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-
-package org.hibernate.sql.ast.phase.hql.resolve.path.impl;
-
-/**
- * Indicates an attempt to define an implicit or explicit property join based on a non-association property.
- *
- * @author Steve Ebersole
- */
-public class InvalidPropertyJoinException extends AbstractUnexpectedPropertyTypeException {
-	public InvalidPropertyJoinException(String path, String persisterName, String propertyName) {
-		super( path, persisterName, propertyName );
-	}
-
-	@Override
-	protected String internalGetMessage() {
-		return "Referenced property [" + buildPropertyReferenceFragment() + "] not valid for join";
-	}
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/OnFragmentPathResolutionStrategy.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/OnFragmentPathResolutionStrategy.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/OnFragmentPathResolutionStrategy.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,74 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-package org.hibernate.sql.ast.phase.hql.resolve.path.impl;
-
-import org.hibernate.HibernateException;
-import org.hibernate.sql.ast.phase.hql.resolve.PersisterSpace;
-import org.hibernate.sql.ast.phase.hql.resolve.ResolutionContext;
-import org.hibernate.sql.ast.phase.hql.resolve.path.PathedPropertyReferenceSource;
-
-/**
- * {@link org.hibernate.sql.ast.phase.hql.resolve.path.PathResolutionStrategy} for dealing with path expressions
- * occuring in the <tt>ON</tt> clause of a persister join.
- *
- * @author Steve Ebersole
- */
-public class OnFragmentPathResolutionStrategy extends BasicPathResolutionStrategySupport {
-	private final PersisterSpace joinRhs;
-	private PersisterSpace joinLhs;
-
-	public OnFragmentPathResolutionStrategy(ResolutionContext resolutionContext, PersisterSpace joinRhs) {
-		super( resolutionContext );
-		this.joinRhs = joinRhs;
-	}
-
-	public PersisterSpace getDiscoveredLHS() {
-		return joinLhs;
-	}
-
-	protected PathedPropertyReferenceSource internalHandleRoot(PersisterSpace persisterSpace) {
-		// persisterSpace must either refer to our LHS or RHS...
-		if ( persisterSpace == joinRhs ) {
-			// nothing to do...
-		}
-		else if ( joinLhs != null ) {
-			if ( persisterSpace != joinLhs ) {
-				throw new HibernateException(
-						"path root not resolveable against either left-hand-side [" +
-						joinLhs.getSourceAlias() + "] nor right-hand-side [" +
-						joinRhs.getSourceAlias() + "] of the join"
-				);
-			}
-		}
-		else {
-			joinLhs = persisterSpace;
-		}
-		return super.internalHandleRoot( persisterSpace );
-	}
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/SelectClausePathResolutionStrategy.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/SelectClausePathResolutionStrategy.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/SelectClausePathResolutionStrategy.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,51 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-
-package org.hibernate.sql.ast.phase.hql.resolve.path.impl;
-
-import org.hibernate.sql.ast.phase.hql.resolve.ResolutionContext;
-
-/**
- * Essentially the same stragety as {@link BasicPathResolutionStrategySupport} expcept that in the select clause
- * an entity encountered as the terminal part must force a join...
- * <p/>
- * todo : the above is true as long as the path is not a function argument...
- *
- * @author Steve Ebersole
- */
-public class SelectClausePathResolutionStrategy extends BasicPathResolutionStrategySupport {
-	public SelectClausePathResolutionStrategy(ResolutionContext resolutionContext) {
-		super( resolutionContext );
-	}
-
-	protected boolean shouldTerminalEntityPropertyForceJoin() {
-		// here we should *as long as* we are not part of a function processing
-		return ! resolutionContext().isCurrentlyProcessingFunction();
-	}
-}

Deleted: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/WithFragmentPathResolutionStrategy.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/WithFragmentPathResolutionStrategy.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/WithFragmentPathResolutionStrategy.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,125 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party
- * contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software
- * Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-
-package org.hibernate.sql.ast.phase.hql.resolve.path.impl;
-
-import org.hibernate.QueryException;
-import org.hibernate.HibernateException;
-import org.hibernate.sql.ast.phase.hql.resolve.PersisterSpace;
-import org.hibernate.sql.ast.phase.hql.resolve.ResolutionContext;
-import org.hibernate.sql.ast.phase.hql.resolve.path.PathedPropertyReferenceSource;
-import org.hibernate.sql.ast.common.HibernateTree;
-import org.hibernate.sql.ast.tree.Table;
-
-/**
- * {@link org.hibernate.sql.ast.phase.hql.resolve.path.PathResolutionStrategy} for dealing with <tt>WITH</tt>
- * fragments used to supply addition join conditions to property joins.
- *
- * @author Steve Ebersole
- */
-public class WithFragmentPathResolutionStrategy extends BasicPathResolutionStrategySupport {
-	private final PersisterSpace lhs;
-
-	private String baseRhsPropertyName;
-	private PersisterSpace rhs;
-
-	public WithFragmentPathResolutionStrategy(ResolutionContext resolutionContext, PersisterSpace lhs) {
-		super( resolutionContext );
-		this.lhs = lhs;
-	}
-
-	@Override
-	protected PathedPropertyReferenceSource internalHandleRoot(PersisterSpace persisterSpace) {
-		rhs = persisterSpace;
-		return super.internalHandleRoot( persisterSpace );
-	}
-
-	@Override
-	protected PathedPropertyReferenceSource internalResolveIntermediatePathPart(PathedPropertyReferenceSource source, String pathPart) {
-		if ( baseRhsPropertyName == null ) {
-			baseRhsPropertyName = pathPart;
-		}
-		return super.internalResolveIntermediatePathPart( source, pathPart );
-	}
-
-	@Override
-	protected HibernateTree internalResolveTerminalPathPart(PathedPropertyReferenceSource source, String pathPart) {
-		if ( baseRhsPropertyName == null ) {
-			baseRhsPropertyName = pathPart;
-		}
-		return super.internalResolveTerminalPathPart( source, pathPart );
-	}
-
-	@Override
-	protected PathedPropertyReferenceSource internalHandleIntermediateIndexAccess(PathedPropertyReferenceSource source, String pathPart, HibernateTree selector) {
-		if ( baseRhsPropertyName == null ) {
-			baseRhsPropertyName = pathPart;
-		}
-		return super.internalHandleIntermediateIndexAccess( source, pathPart, selector );
-	}
-
-	@Override
-	protected HibernateTree internalHandleTerminalIndexAccess(PathedPropertyReferenceSource source, String pathPart, HibernateTree selector) {
-		if ( baseRhsPropertyName == null ) {
-			baseRhsPropertyName = pathPart;
-		}
-		return super.internalHandleTerminalIndexAccess( source, pathPart, selector );
-	}
-
-	public void applyWithFragment(HibernateTree withFragment) {
-		// first, locate the actual Join node which links the lhs and rhs...
-		Table lhsTable = lhs.getTableSpace().getContainingTable( baseRhsPropertyName );
-
-		// todo : implement...
-
-		// as simple as finding the table under lhsTable which contains a join to a table from the table-space associated with
-		// the rhs persister-space???
-
-//		Join join = null;
-//		AST nextPossible = lhs.getFirstChild();
-//		while ( nextPossible != null ) {
-//			if ( nextPossible instanceof Join ) {
-//				if ( ( ( Join ) nextPossible ).locateRhs() == rhs ) {
-//					join = ( Join ) nextPossible;
-//					break;
-//				}
-//			}
-//			nextPossible = nextPossible.getNextSibling();
-//		}
-//		if ( join == null ) {
-//			throw new QueryException( "could not locate specific join node to which to apply with fragment [" + withFragment + "]" );
-//		}
-//		join.addChild( withFragment );
-	}
-
-	protected void validateJoinCreation(PersisterSpace origin, String property) {
-		// todo : why not???
-		throw new HibernateException( "Path expressions [" + origin.getSourceAlias() + "." + property + "] within 'with clause' cannot result in physical join" );
-	}
-}

Modified: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/Table.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/Table.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/Table.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -36,9 +36,9 @@
 import org.hibernate.sql.ast.common.HibernateTree;
 import org.hibernate.sql.ast.common.HibernateToken;
 import org.hibernate.sql.ast.util.DisplayableNode;
-import org.hibernate.sql.ast.phase.hql.parse.HQLLexer;
-import org.hibernate.sql.ast.phase.hql.resolve.PersisterSpace;
-import org.hibernate.sql.ast.phase.hql.resolve.PersisterTableExpressionGenerator;
+import org.hibernate.sql.ast.origin.hql.resolve.PersisterSpace;
+import org.hibernate.sql.ast.origin.hql.resolve.PersisterTableExpressionGenerator;
+import org.hibernate.sql.ast.origin.hql.parse.HQLLexer;
 import org.hibernate.persister.entity.Queryable;
 import org.hibernate.persister.collection.QueryableCollection;
 import org.hibernate.util.StringHelper;

Modified: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/TreePrinter.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/TreePrinter.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/util/TreePrinter.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -191,23 +191,22 @@
 		}
 
 		StringBuffer buf = new StringBuffer();
-		buf.append( "[" ).append( getTokenTypeName( tree.getType() ) ).append( "] " );
+		buf.append( "[" ).append( getTokenTypeName( tree.getType() ) );
 		if ( showClassNames ) {
-			buf.append( StringHelper.unqualify( tree.getClass().getName() ) ).append( ": " );
+			buf.append( " (" ).append( StringHelper.unqualify( tree.getClass().getName() ) ).append( ')' );
 		}
+		buf.append( "] " );
 
-        buf.append( "'" );
         String text = tree.getText();
-		if ( text == null ) {
-			text = "{text:null}";
+		if ( text != null ) {
+        	buf.append( "'" );
+			appendEscapedMultibyteChars( text, buf );
+        	buf.append( "'" );
 		}
-		appendEscapedMultibyteChars(text, buf);
-        buf.append( "'" );
 
         if ( tree instanceof DisplayableNode ) {
             DisplayableNode displayableNode = ( DisplayableNode ) tree;
-            // Add a space before the display text.
-            buf.append( " " ).append( displayableNode.getDisplayText() );
+            buf.append( " => " ).append( displayableNode.getDisplayText() );
         }
         return buf.toString();
     }

Added: core/branches/antlr3/src/main/resources/org/hibernate/sql/ast/template/GenericSQL.stg
===================================================================
--- core/branches/antlr3/src/main/resources/org/hibernate/sql/ast/template/GenericSQL.stg	                        (rev 0)
+++ core/branches/antlr3/src/main/resources/org/hibernate/sql/ast/template/GenericSQL.stg	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,49 @@
+group GenericSQL;
+
+
+orderByClause(sortSpecifications) ::= <<
+order by <orderByFragment(sortSpecifications)>
+>>
+
+orderByFragment(sortSpecifications) ::= <<
+<sortSpecifications; separator=", ">
+>>
+
+sortSpecification(sortKey,collationSpecification,orderingSpecification) ::= <<
+<sortKey> <collationSpecification> <orderingSpecification>
+>>
+
+
+<! ------------------------------------------------------------------------- !>
+<! UPDATE statement related templates !>
+<! ------------------------------------------------------------------------- !>
+updateStatement(table,assignments,whereClause) ::= <<
+update <table> set <assignments; separator=", "> <whereClause>
+>>
+
+assignment(target,value) ::= <<
+<target> = <value>
+>>
+
+<! ------------------------------------------------------------------------- !>
+<! DELETE statement related templates !>
+<! ------------------------------------------------------------------------- !>
+deleteStatement(table,whereClause) ::= <<
+delete <table> <whereClause>
+>>
+
+<! ------------------------------------------------------------------------- !>
+<! table/table-expression related templates
+<! ------------------------------------------------------------------------- !>
+tableExpression(name,alias) ::= <<
+<name><alias>
+>>
+
+tableName(name) ::= <<
+<name>
+>>
+
+tableAliasDeclaration(alias) ::= <<
+</ >as <alias>
+<<
+

Added: core/branches/antlr3/src/main/resources/org/hibernate/sql/ast/template/OrderBy.stg
===================================================================
--- core/branches/antlr3/src/main/resources/org/hibernate/sql/ast/template/OrderBy.stg	                        (rev 0)
+++ core/branches/antlr3/src/main/resources/org/hibernate/sql/ast/template/OrderBy.stg	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,26 @@
+group OrderBy;
+
+
+orderByClause(sortSpecifications) ::= <<
+order by <orderByFragment(sortSpecifications)>
+>>
+
+orderByFragment(sortSpecifications) ::= <<
+<sortSpecifications; separator=", ">
+>>
+
+sortSpecification(sortKey,collationSpecification,orderingSpecification) ::= <<
+<sortKey> <collationSpecification> <orderingSpecification>
+>>
+
+column(qualifier,name) ::= <<
+<qualifier>.<name>
+>>
+
+function(name,arguments) ::= <<
+<name>(<arguments; separator=", ">)
+>>
+
+noArgumentFunction(name) ::= <<
+<name>
+>>
\ No newline at end of file

Modified: core/branches/antlr3/src/test/java/org/hibernate/sql/TemplateTest.java
===================================================================
--- core/branches/antlr3/src/test/java/org/hibernate/sql/TemplateTest.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/test/java/org/hibernate/sql/TemplateTest.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -31,7 +31,7 @@
 import org.hibernate.persister.entity.PropertyMapping;
 import org.hibernate.type.Type;
 import org.hibernate.QueryException;
-import org.hibernate.sql.ast.ordering.ColumnMapper;
+import org.hibernate.sql.ast.origin.ordering.ColumnMapper;
 import org.hibernate.dialect.Dialect;
 import org.hibernate.dialect.HSQLDialect;
 import org.hibernate.dialect.function.SQLFunctionRegistry;

Deleted: core/branches/antlr3/src/test/java/org/hibernate/sql/ast/ordering/OrderByParserTest.java
===================================================================
--- core/branches/antlr3/src/test/java/org/hibernate/sql/ast/ordering/OrderByParserTest.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/test/java/org/hibernate/sql/ast/ordering/OrderByParserTest.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -1,244 +0,0 @@
-/*
- * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-package org.hibernate.sql.ast.ordering;
-
-import java.util.Collections;
-import java.util.Map;
-
-import junit.framework.TestCase;
-import junit.framework.AssertionFailedError;
-
-import org.hibernate.persister.entity.PropertyMapping;
-import org.hibernate.QueryException;
-import org.hibernate.Hibernate;
-import org.hibernate.HibernateException;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.HSQLDialect;
-import org.hibernate.dialect.function.SQLFunctionRegistry;
-import org.hibernate.dialect.function.SQLFunction;
-import org.hibernate.dialect.function.SQLFunctionTemplate;
-import org.hibernate.engine.SessionFactoryImplementor;
-import org.hibernate.sql.ast.phase.hql.parse.HQLLexer;
-import org.hibernate.sql.ast.util.ASTUtil;
-import org.hibernate.sql.ast.util.TreePrinter;
-import org.hibernate.sql.Template;
-import org.hibernate.type.Type;
-
-import org.antlr.runtime.ANTLRStringStream;
-import org.antlr.runtime.CommonTokenStream;
-import org.antlr.runtime.tree.Tree;
-import org.antlr.runtime.tree.CommonTree;
-
-/**
- * Assertions against the structures generated by various paths of the "order-by" mapping fragment parser.
- *
- * @author Steve Ebersole
- */
-public class OrderByParserTest extends TestCase {
-	public static final PropertyMapping STANDARD_PROPERTY_MAPPING = new PropertyMapping() {
-		public String[] toColumns(String propertyName) throws QueryException, UnsupportedOperationException {
-			if ( "component".equals( propertyName ) ) {
-				return new String[] { "comp_1", "comp_2" };
-			}
-			else if ( "component.prop1".equals( propertyName ) ) {
-				return new String[] { "comp_1" };
-			}
-			else if ( "component.prop2".equals( propertyName ) ) {
-				return new String[] { "comp_2" };
-			}
-			else if ( "property".equals( propertyName ) ) {
-				return new String[] { "prop" };
-			}
-			throw new QueryException( "could not resolve property: " + propertyName );
-		}
-
-		public Type toType(String propertyName) throws QueryException {
-			throw new UnsupportedOperationException( "toType(propertyName) not supported here" );
-		}
-
-		public String[] toColumns(String alias, String propertyName) throws QueryException {
-			throw new UnsupportedOperationException( "toColumns(alias,propertyName) not supported here" );
-		}
-
-		public Type getType() {
-			throw new UnsupportedOperationException( "getType() not supported here" );
-		}
-	};
-
-	public static final ColumnMapper STANDARD_MAPPER = new ColumnMapper() {
-		public String[] map(String reference) {
-			return STANDARD_PROPERTY_MAPPING.toColumns( reference );
-		}
-	};
-
-	public OrderByParserTest() {
-	}
-
-	public OrderByParserTest(String name) {
-		super( name );
-	}
-
-    public void testSQLReferences() {
-        String fragment = "sql asc, sql desc";
-        CommonTree tree = parse( fragment );
-
-		assertTokenType( HQLLexer.ORDER_BY, tree );
-		assertEquals( 2, tree.getChildCount() );
-
-		Tree firstSortSpec = tree.getChild( 0 );
-		assertTokenType( HQLLexer.SORT_SPEC, firstSortSpec );
-		assertEquals( 2, firstSortSpec.getChildCount() );
-		assertTokenType( HQLLexer.COLUMN, firstSortSpec.getChild( 0 ) );
-		assertTokenType( HQLLexer.ALIAS_REF, firstSortSpec.getChild( 0 ).getChild( 0 ) );
-		assertEquals( Template.TEMPLATE, firstSortSpec.getChild( 0 ).getChild( 0 ).getText() );
-		assertTokenType( HQLLexer.IDENTIFIER, firstSortSpec.getChild( 0 ).getChild( 1 ) );
-		assertEquals( "sql", firstSortSpec.getChild( 0 ).getChild( 1 ).getText() );
-		assertTokenType( HQLLexer.ORDER_SPEC, firstSortSpec.getChild( 1 ) );
-		assertEquals( "asc", firstSortSpec.getChild( 1 ).getText() );
-
-		Tree secondSortSpec = tree.getChild( 1 );
-		assertTokenType( HQLLexer.SORT_SPEC, secondSortSpec.getType() );
-		assertEquals( 2, secondSortSpec.getChildCount() );
-		assertTokenType( HQLLexer.COLUMN, secondSortSpec.getChild( 0 ) );
-		assertTokenType( HQLLexer.ALIAS_REF, secondSortSpec.getChild( 0 ).getChild( 0 ) );
-		assertEquals( Template.TEMPLATE, secondSortSpec.getChild( 0 ).getChild( 0 ).getText() );
-		assertTokenType( HQLLexer.IDENTIFIER, secondSortSpec.getChild( 0 ).getChild( 1 ) );
-		assertEquals( "sql", secondSortSpec.getChild( 0 ).getChild( 1 ).getText() );
-		assertTokenType( HQLLexer.ORDER_SPEC, secondSortSpec.getChild( 1 ) );
-		assertEquals( "desc", secondSortSpec.getChild( 1 ).getText() );
-    }
-
-    public void testQuotedSQLReferences() {
-        String fragment = "`sql` asc, `sql` desc";
-        CommonTree tree = parse( fragment );
-
-		assertTokenType( HQLLexer.ORDER_BY, tree.getType() );
-		assertEquals( 2, tree.getChildCount() );
-
-		Tree firstSortSpec = tree.getChild( 0 );
-		assertTokenType( HQLLexer.SORT_SPEC, firstSortSpec.getType() );
-		assertEquals( 2, firstSortSpec.getChildCount() );
-		assertTokenType( HQLLexer.COLUMN, firstSortSpec.getChild( 0 ) );
-		assertTokenType( HQLLexer.ALIAS_REF, firstSortSpec.getChild( 0 ).getChild( 0 ) );
-		assertEquals( Template.TEMPLATE, firstSortSpec.getChild( 0 ).getChild( 0 ).getText() );
-		assertTokenType( HQLLexer.QUOTED_IDENTIFIER, firstSortSpec.getChild( 0 ).getChild( 1 ) );
-		assertEquals( "`sql`", firstSortSpec.getChild( 0 ).getChild( 1 ).getText() );
-		assertTokenType( HQLLexer.ORDER_SPEC, firstSortSpec.getChild( 1 ) );
-		assertEquals( "asc", firstSortSpec.getChild( 1 ).getText() );
-
-		Tree secondSortSpec = tree.getChild( 1 );
-		assertTokenType( HQLLexer.SORT_SPEC, secondSortSpec.getType() );
-		assertEquals( 2, secondSortSpec.getChildCount() );
-		assertTokenType( HQLLexer.COLUMN, secondSortSpec.getChild( 0 ) );
-		assertTokenType( HQLLexer.ALIAS_REF, secondSortSpec.getChild( 0 ).getChild( 0 ) );
-		assertEquals( Template.TEMPLATE, secondSortSpec.getChild( 0 ).getChild( 0 ).getText() );
-		assertTokenType( HQLLexer.QUOTED_IDENTIFIER, secondSortSpec.getChild( 0 ).getChild( 1 ) );
-		assertEquals( "`sql`", secondSortSpec.getChild( 0 ).getChild( 1 ).getText() );
-		assertTokenType( HQLLexer.ORDER_SPEC, secondSortSpec.getChild( 1 ) );
-		assertEquals( "desc", secondSortSpec.getChild( 1 ).getText() );
-    }
-
-    public void testPropertyReference() {
-		String fragment = "property asc, property desc";
-        CommonTree tree = parse( fragment );
-
-		assertTokenType( HQLLexer.ORDER_BY, tree.getType() );
-		assertEquals( 2, tree.getChildCount() );
-
-		Tree firstSortSpec = tree.getChild( 0 );
-		assertTokenType( HQLLexer.SORT_SPEC, firstSortSpec.getType() );
-		assertEquals( 2, firstSortSpec.getChildCount() );
-		assertTokenType( HQLLexer.COLUMN, firstSortSpec.getChild( 0 ) );
-		assertTokenType( HQLLexer.ALIAS_REF, firstSortSpec.getChild( 0 ).getChild( 0 ) );
-		assertEquals( Template.TEMPLATE, firstSortSpec.getChild( 0 ).getChild( 0 ).getText() );
-		assertTokenType( HQLLexer.IDENTIFIER, firstSortSpec.getChild( 0 ).getChild( 1 ) );
-		assertEquals( "prop", firstSortSpec.getChild( 0 ).getChild( 1 ).getText() );
-		assertTokenType( HQLLexer.ORDER_SPEC, firstSortSpec.getChild( 1 ) );
-		assertEquals( "asc", firstSortSpec.getChild( 1 ).getText() );
-	}
-
-	protected CommonTree parse(String orderByFragment) {
-		final Dialect dialect = new HSQLDialect();
-		final SQLFunction myFunction = new SQLFunctionTemplate( Hibernate.STRING, "myFunction($1)" );
-		final SQLFunctionRegistry functionRegistry = new SQLFunctionRegistry( dialect, Collections.singletonMap( "myFunction", myFunction ) );
-		return parse(
-				orderByFragment,
-				new TranslationContext() {
-					public SessionFactoryImplementor getSessionFactory() {
-						return null;
-					}
-
-					public Dialect getDialect() {
-						return dialect;
-					}
-
-					public SQLFunctionRegistry getSqlFunctionRegistry() {
-						return functionRegistry;
-					}
-
-					public ColumnMapper getColumnMapper() {
-						return STANDARD_MAPPER;
-					}
-				}
-		);
-	}
-
-	private static final TreePrinter TREE_PRINTER = new TreePrinter( HQLLexer.class );
-
-	protected CommonTree parse(String orderByFragment, TranslationContext context) {
-		try {
-			HQLLexer lexer = new HQLLexer( new ANTLRStringStream( orderByFragment ) );
-			OrderByFragmentParser parser = new OrderByFragmentParser( new CommonTokenStream( lexer ), context );
-			CommonTree rtn = parser.orderByFragment().tree;
-			// temp
-			System.out.println(
-					TREE_PRINTER.renderAsString( rtn, "fragment" )
-			);
-			return rtn;
-		}
-		catch ( HibernateException e ) {
-			throw e;
-		}
-		catch ( Throwable t ) {
-			throw new HibernateException( "Unable to parse order-by fragment", t );
-		}
-	}
-
-	private static final Map<Integer,String> tokenNameMap = ( Map<Integer,String> ) ASTUtil.generateTokenNameCache( HQLLexer.class );
-
-	public void assertTokenType(int expected, int actual) {
-		if ( expected != actual ) {
-			throw new AssertionFailedError(
-					"expected:<"+ tokenNameMap.get( expected ) +"> but was:<"+ tokenNameMap.get( actual ) +">"
-			);
-		}
-	}
-
-	public void assertTokenType(int expected, Tree tree) {
-		if ( tree == null ) {
-			throw new AssertionFailedError(
-					"expected:<"+ tokenNameMap.get( expected ) +"> but was:<null>"
-			);
-		}
-		assertTokenType( expected, tree.getType() );
-	}
-}

Copied: core/branches/antlr3/src/test/java/org/hibernate/sql/ast/origin/ordering/OrderByParserTest.java (from rev 16437, core/branches/antlr3/src/test/java/org/hibernate/sql/ast/ordering/OrderByParserTest.java)
===================================================================
--- core/branches/antlr3/src/test/java/org/hibernate/sql/ast/origin/ordering/OrderByParserTest.java	                        (rev 0)
+++ core/branches/antlr3/src/test/java/org/hibernate/sql/ast/origin/ordering/OrderByParserTest.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -0,0 +1,284 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+package org.hibernate.sql.ast.origin.ordering;
+
+import java.util.Collections;
+import java.util.Map;
+
+import junit.framework.TestCase;
+import junit.framework.AssertionFailedError;
+
+import org.hibernate.persister.entity.PropertyMapping;
+import org.hibernate.QueryException;
+import org.hibernate.Hibernate;
+import org.hibernate.HibernateException;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.HSQLDialect;
+import org.hibernate.dialect.function.SQLFunctionRegistry;
+import org.hibernate.dialect.function.SQLFunction;
+import org.hibernate.dialect.function.SQLFunctionTemplate;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.sql.ast.util.ASTUtil;
+import org.hibernate.sql.ast.util.TreePrinter;
+import org.hibernate.sql.ast.origin.hql.parse.HQLLexer;
+import org.hibernate.sql.Template;
+import org.hibernate.type.Type;
+
+import org.antlr.runtime.ANTLRStringStream;
+import org.antlr.runtime.CommonTokenStream;
+import org.antlr.runtime.tree.Tree;
+import org.antlr.runtime.tree.CommonTree;
+
+/**
+ * Assertions against the structures generated by various paths of the "order-by" mapping fragment parser.
+ *
+ * @author Steve Ebersole
+ */
+public class OrderByParserTest extends TestCase {
+	public static final PropertyMapping STANDARD_PROPERTY_MAPPING = new PropertyMapping() {
+		public String[] toColumns(String propertyName) throws QueryException, UnsupportedOperationException {
+			if ( "component".equals( propertyName ) ) {
+				return new String[] { "comp_1", "comp_2" };
+			}
+			else if ( "component.prop1".equals( propertyName ) ) {
+				return new String[] { "comp_1" };
+			}
+			else if ( "component.prop2".equals( propertyName ) ) {
+				return new String[] { "comp_2" };
+			}
+			else if ( "property".equals( propertyName ) ) {
+				return new String[] { "prop" };
+			}
+			throw new QueryException( "could not resolve property: " + propertyName );
+		}
+
+		public Type toType(String propertyName) throws QueryException {
+			throw new UnsupportedOperationException( "toType(propertyName) not supported here" );
+		}
+
+		public String[] toColumns(String alias, String propertyName) throws QueryException {
+			throw new UnsupportedOperationException( "toColumns(alias,propertyName) not supported here" );
+		}
+
+		public Type getType() {
+			throw new UnsupportedOperationException( "getType() not supported here" );
+		}
+	};
+
+	public static final ColumnMapper STANDARD_MAPPER = new ColumnMapper() {
+		public String[] map(String reference) {
+			return STANDARD_PROPERTY_MAPPING.toColumns( reference );
+		}
+	};
+
+	public OrderByParserTest() {
+	}
+
+	public OrderByParserTest(String name) {
+		super( name );
+	}
+
+    public void testSQLReferences() {
+        String fragment = "sql asc, sql desc";
+        CommonTree tree = parse( fragment );
+
+		assertRootStructure( tree, 2 );
+
+		Tree firstSortSpec = tree.getChild( 0 );
+		assertTokenType( HQLLexer.SORT_SPEC, firstSortSpec );
+		assertEquals( 2, firstSortSpec.getChildCount() );
+		assertTokenType( HQLLexer.COLUMN, firstSortSpec.getChild( 0 ) );
+		assertTokenType( HQLLexer.ALIAS_REF, firstSortSpec.getChild( 0 ).getChild( 0 ) );
+		assertEquals( Template.TEMPLATE, firstSortSpec.getChild( 0 ).getChild( 0 ).getText() );
+		assertTokenType( HQLLexer.IDENTIFIER, firstSortSpec.getChild( 0 ).getChild( 1 ) );
+		assertEquals( "sql", firstSortSpec.getChild( 0 ).getChild( 1 ).getText() );
+		assertTokenType( HQLLexer.ORDER_SPEC, firstSortSpec.getChild( 1 ) );
+		assertEquals( "asc", firstSortSpec.getChild( 1 ).getText() );
+
+		Tree secondSortSpec = tree.getChild( 1 );
+		assertTokenType( HQLLexer.SORT_SPEC, secondSortSpec.getType() );
+		assertEquals( 2, secondSortSpec.getChildCount() );
+		assertTokenType( HQLLexer.COLUMN, secondSortSpec.getChild( 0 ) );
+		assertTokenType( HQLLexer.ALIAS_REF, secondSortSpec.getChild( 0 ).getChild( 0 ) );
+		assertEquals( Template.TEMPLATE, secondSortSpec.getChild( 0 ).getChild( 0 ).getText() );
+		assertTokenType( HQLLexer.IDENTIFIER, secondSortSpec.getChild( 0 ).getChild( 1 ) );
+		assertEquals( "sql", secondSortSpec.getChild( 0 ).getChild( 1 ).getText() );
+		assertTokenType( HQLLexer.ORDER_SPEC, secondSortSpec.getChild( 1 ) );
+		assertEquals( "desc", secondSortSpec.getChild( 1 ).getText() );
+    }
+
+    public void testQuotedSQLReferences() {
+        String fragment = "`sql` asc, `sql` desc";
+        CommonTree tree = parse( fragment );
+
+		assertRootStructure( tree, 2 );
+
+		Tree firstSortSpec = tree.getChild( 0 );
+		assertTokenType( HQLLexer.SORT_SPEC, firstSortSpec.getType() );
+		assertEquals( 2, firstSortSpec.getChildCount() );
+		assertTokenType( HQLLexer.COLUMN, firstSortSpec.getChild( 0 ) );
+		assertTokenType( HQLLexer.ALIAS_REF, firstSortSpec.getChild( 0 ).getChild( 0 ) );
+		assertEquals( Template.TEMPLATE, firstSortSpec.getChild( 0 ).getChild( 0 ).getText() );
+		assertTokenType( HQLLexer.QUOTED_IDENTIFIER, firstSortSpec.getChild( 0 ).getChild( 1 ) );
+		assertEquals( "`sql`", firstSortSpec.getChild( 0 ).getChild( 1 ).getText() );
+		assertTokenType( HQLLexer.ORDER_SPEC, firstSortSpec.getChild( 1 ) );
+		assertEquals( "asc", firstSortSpec.getChild( 1 ).getText() );
+
+		Tree secondSortSpec = tree.getChild( 1 );
+		assertTokenType( HQLLexer.SORT_SPEC, secondSortSpec.getType() );
+		assertEquals( 2, secondSortSpec.getChildCount() );
+		assertTokenType( HQLLexer.COLUMN, secondSortSpec.getChild( 0 ) );
+		assertTokenType( HQLLexer.ALIAS_REF, secondSortSpec.getChild( 0 ).getChild( 0 ) );
+		assertEquals( Template.TEMPLATE, secondSortSpec.getChild( 0 ).getChild( 0 ).getText() );
+		assertTokenType( HQLLexer.QUOTED_IDENTIFIER, secondSortSpec.getChild( 0 ).getChild( 1 ) );
+		assertEquals( "`sql`", secondSortSpec.getChild( 0 ).getChild( 1 ).getText() );
+		assertTokenType( HQLLexer.ORDER_SPEC, secondSortSpec.getChild( 1 ) );
+		assertEquals( "desc", secondSortSpec.getChild( 1 ).getText() );
+    }
+
+    public void testPropertyReference() {
+		String fragment = "property asc, property desc";
+        CommonTree tree = parse( fragment );
+
+		assertRootStructure( tree, 2 );
+
+		Tree firstSortSpec = tree.getChild( 0 );
+		assertTokenType( HQLLexer.SORT_SPEC, firstSortSpec.getType() );
+		assertEquals( 2, firstSortSpec.getChildCount() );
+		assertTokenType( HQLLexer.COLUMN, firstSortSpec.getChild( 0 ) );
+		assertTokenType( HQLLexer.ALIAS_REF, firstSortSpec.getChild( 0 ).getChild( 0 ) );
+		assertEquals( Template.TEMPLATE, firstSortSpec.getChild( 0 ).getChild( 0 ).getText() );
+		assertTokenType( HQLLexer.IDENTIFIER, firstSortSpec.getChild( 0 ).getChild( 1 ) );
+		assertEquals( "prop", firstSortSpec.getChild( 0 ).getChild( 1 ).getText() );
+		assertTokenType( HQLLexer.ORDER_SPEC, firstSortSpec.getChild( 1 ) );
+		assertEquals( "asc", firstSortSpec.getChild( 1 ).getText() );
+
+		Tree secondSortSpec = tree.getChild( 1 );
+		assertTokenType( HQLLexer.SORT_SPEC, secondSortSpec.getType() );
+		assertEquals( 2, secondSortSpec.getChildCount() );
+		assertTokenType( HQLLexer.COLUMN, secondSortSpec.getChild( 0 ) );
+		assertTokenType( HQLLexer.ALIAS_REF, secondSortSpec.getChild( 0 ).getChild( 0 ) );
+		assertEquals( Template.TEMPLATE, secondSortSpec.getChild( 0 ).getChild( 0 ).getText() );
+		assertTokenType( HQLLexer.IDENTIFIER, secondSortSpec.getChild( 0 ).getChild( 1 ) );
+		assertEquals( "prop", secondSortSpec.getChild( 0 ).getChild( 1 ).getText() );
+		assertTokenType( HQLLexer.ORDER_SPEC, secondSortSpec.getChild( 1 ) );
+		assertEquals( "desc", secondSortSpec.getChild( 1 ).getText() );
+	}
+
+    public void testFunctionReference() {
+		String fragment = "upper(sql) asc, lower(sql) desc";
+		CommonTree tree = parse( fragment );
+
+		assertRootStructure( tree, 2 );
+
+		Tree firstSortSpec = tree.getChild( 0 );
+		assertTokenType( HQLLexer.SORT_SPEC, firstSortSpec.getType() );
+		assertEquals( 2, firstSortSpec.getChildCount() );
+		assertTokenType( HQLLexer.UPPER, firstSortSpec.getChild( 0 ) );
+		assertEquals( 1, firstSortSpec.getChild( 0 ).getChildCount() );
+		assertTokenType( HQLLexer.COLUMN, firstSortSpec.getChild( 0 ).getChild( 0 ) );
+		assertTokenType( HQLLexer.IDENTIFIER, firstSortSpec.getChild( 0 ).getChild( 0 ).getChild( 1 ) );
+		assertEquals( "sql", firstSortSpec.getChild( 0 ).getChild( 0 ).getChild( 1 ).getText() );
+		assertEquals( "asc", firstSortSpec.getChild( 1 ).getText() );
+
+		Tree secondSortSpec = tree.getChild( 1 );
+		assertTokenType( HQLLexer.SORT_SPEC, secondSortSpec.getType() );
+		assertEquals( 2, secondSortSpec.getChildCount() );
+		assertTokenType( HQLLexer.LOWER, secondSortSpec.getChild( 0 ) );
+		assertEquals( 1, secondSortSpec.getChild( 0 ).getChildCount() );
+		assertTokenType( HQLLexer.COLUMN, secondSortSpec.getChild( 0 ).getChild( 0 ) );
+		assertTokenType( HQLLexer.IDENTIFIER, secondSortSpec.getChild( 0 ).getChild( 0 ).getChild( 1 ) );
+		assertEquals( "sql", secondSortSpec.getChild( 0 ).getChild( 0 ).getChild( 1 ).getText() );
+		assertEquals( "desc", secondSortSpec.getChild( 1 ).getText() );
+	}
+
+	protected CommonTree parse(String orderByFragment) {
+		final Dialect dialect = new HSQLDialect();
+		final SQLFunction myFunction = new SQLFunctionTemplate( Hibernate.STRING, "myFunction($1)" );
+		final SQLFunctionRegistry functionRegistry = new SQLFunctionRegistry( dialect, Collections.singletonMap( "myFunction", myFunction ) );
+		return parse(
+				orderByFragment,
+				new TranslationContext() {
+					public SessionFactoryImplementor getSessionFactory() {
+						return null;
+					}
+
+					public Dialect getDialect() {
+						return dialect;
+					}
+
+					public SQLFunctionRegistry getSqlFunctionRegistry() {
+						return functionRegistry;
+					}
+
+					public ColumnMapper getColumnMapper() {
+						return STANDARD_MAPPER;
+					}
+				}
+		);
+	}
+
+	private static final TreePrinter TREE_PRINTER = new TreePrinter( HQLLexer.class );
+
+	protected CommonTree parse(String orderByFragment, TranslationContext context) {
+		try {
+			HQLLexer lexer = new HQLLexer( new ANTLRStringStream( orderByFragment ) );
+			OrderByFragmentParser parser = new OrderByFragmentParser( new CommonTokenStream( lexer ), context );
+			CommonTree rtn = parser.orderByFragment().tree;
+			// temp
+			System.out.println(
+					TREE_PRINTER.renderAsString( rtn, "fragment" )
+			);
+			return rtn;
+		}
+		catch ( HibernateException e ) {
+			throw e;
+		}
+		catch ( Throwable t ) {
+			throw new HibernateException( "Unable to parse order-by fragment", t );
+		}
+	}
+
+	private static final Map<Integer,String> tokenNameMap = ( Map<Integer,String> ) ASTUtil.generateTokenNameCache( HQLLexer.class );
+
+	public void assertTokenType(int expected, int actual) {
+		if ( expected != actual ) {
+			throw new AssertionFailedError(
+					"expected:<"+ tokenNameMap.get( expected ) +"> but was:<"+ tokenNameMap.get( actual ) +">"
+			);
+		}
+	}
+
+	public void assertTokenType(int expected, Tree tree) {
+		if ( tree == null ) {
+			throw new AssertionFailedError(
+					"expected:<"+ tokenNameMap.get( expected ) +"> but was:<null>"
+			);
+		}
+		assertTokenType( expected, tree.getType() );
+	}
+
+	public void assertRootStructure(Tree tree, int expectedSortSpecCount) {
+		assertTokenType( HQLLexer.ORDER_BY, tree.getType() );
+		assertEquals( expectedSortSpecCount, tree.getChildCount() );
+	}
+}

Modified: core/branches/antlr3/src/test/java/org/hibernate/sql/ast/phase/hql/resolve/TestHQLResolver.java
===================================================================
--- core/branches/antlr3/src/test/java/org/hibernate/sql/ast/phase/hql/resolve/TestHQLResolver.java	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/test/java/org/hibernate/sql/ast/phase/hql/resolve/TestHQLResolver.java	2009-04-28 16:13:04 UTC (rev 16467)
@@ -12,8 +12,9 @@
 import org.hibernate.dialect.HSQLDialect;
 import org.hibernate.engine.SessionFactoryImplementor;
 import org.hibernate.hql.classic.ClassicQueryTranslatorFactory;
-import org.hibernate.sql.ast.phase.hql.parse.HQLLexer;
-import org.hibernate.sql.ast.phase.hql.parse.HQLParser;
+import org.hibernate.sql.ast.origin.hql.resolve.HQLResolver;
+import org.hibernate.sql.ast.origin.hql.parse.HQLParser;
+import org.hibernate.sql.ast.origin.hql.parse.HQLLexer;
 
 public class TestHQLResolver extends TestCase {
 

Modified: core/branches/antlr3/src/test/resources/log4j.properties
===================================================================
--- core/branches/antlr3/src/test/resources/log4j.properties	2009-04-27 15:26:25 UTC (rev 16466)
+++ core/branches/antlr3/src/test/resources/log4j.properties	2009-04-28 16:13:04 UTC (rev 16467)
@@ -30,5 +30,5 @@
 
 log4j.logger.org.hibernate.test=info
 log4j.logger.org.hibernate.tool.hbm2ddl=debug
-log4j.logger.org.hibernate.sql.ast.ordering.OrderByFragmentTranslator=trace
+log4j.logger.org.hibernate.sql.ast.origin.ordering.OrderByFragmentTranslator=trace
 log4j.logger.org.hibernate.hql.ast=trace
\ No newline at end of file




More information about the hibernate-commits mailing list