FileDocCategorySizeDatePackage
MethodNode.javaAPI DocHibernate 3.2.56370Tue Jul 12 15:27:30 BST 2005org.hibernate.hql.ast.tree

MethodNode

public class MethodNode extends AbstractSelectExpression implements SelectExpression
Represents a method call.
author
josh Aug 16, 2004 7:59:42 AM

Fields Summary
private static final Log
log
private String
methodName
private FromElement
fromElement
private String[]
selectColumns
private org.hibernate.dialect.function.SQLFunction
function
private boolean
inSelect
Constructors Summary
Methods Summary
private voidcollectionProperty(antlr.collections.AST path, antlr.collections.AST name)

		if ( path == null ) {
			throw new SemanticException( "Collection function " + name.getText() + " has no path!" );
		}

		SqlNode expr = ( SqlNode ) path;
		Type type = expr.getDataType();
		if ( log.isDebugEnabled() ) {
			log.debug( "collectionProperty() :  name=" + name + " type=" + type );
		}

		resolveCollectionProperty( expr );
	
private voiddialectFunction(antlr.collections.AST exprList)

		function = getSessionFactoryHelper().findSQLFunction( methodName );
		if ( function != null ) {
			AST firstChild = exprList != null ? exprList.getFirstChild() : null;
			Type functionReturnType = getSessionFactoryHelper()
					.findFunctionReturnType( methodName, firstChild );
			setDataType( functionReturnType );
		}
		//TODO:
		/*else {
			methodName = (String) getWalker().getTokenReplacements().get( methodName );
		}*/
	
public java.lang.StringgetDisplayText()

		return "{" +
				"method=" + getMethodName() +
				",selectColumns=" + ( selectColumns == null ? 
						null : Arrays.asList( selectColumns ) ) +
				",fromElement=" + fromElement.getTableAlias() +
				"}";
	
public FromElementgetFromElement()

		return fromElement;
	
private java.lang.StringgetMethodName()

		return methodName;
	
public org.hibernate.dialect.function.SQLFunctiongetSQLFunction()

		return function;
	
private voidhandleElements(FromReferenceNode collectionNode, java.lang.String propertyName)

		FromElement collectionFromElement = collectionNode.getFromElement();
		QueryableCollection queryableCollection = collectionFromElement.getQueryableCollection();

		String path = collectionNode.getPath() + "[]." + propertyName;
		log.debug( "Creating elements for " + path );

		fromElement = collectionFromElement;
		if ( !collectionFromElement.isCollectionOfValuesOrComponents() ) {
			getWalker().addQuerySpaces( queryableCollection.getElementPersister().getQuerySpaces() );
		}

		setDataType( queryableCollection.getElementType() );
		selectColumns = collectionFromElement.toColumns( fromElement.getTableAlias(), propertyName, inSelect );
	
public voidinitializeMethodNode(antlr.collections.AST name, boolean inSelect)

		name.setType( SqlTokenTypes.METHOD_NAME );
		String text = name.getText();
		methodName = text.toLowerCase();	// Use the lower case function name.
		this.inSelect = inSelect;			// Remember whether we're in a SELECT clause or not.
	
public booleanisCollectionPropertyMethod()

		return CollectionProperties.isAnyCollectionProperty( methodName );
	
public booleanisScalar()

		// Method expressions in a SELECT should always be considered scalar.
		return true;
	
private voidprepareAnyImplicitJoins(DotNode dotNode)

		if ( dotNode.getLhs() instanceof DotNode ) {
			DotNode lhs = ( DotNode ) dotNode.getLhs();
			FromElement lhsOrigin = lhs.getFromElement();
			if ( lhsOrigin != null && "".equals( lhsOrigin.getText() ) ) {
				String lhsOriginText = lhsOrigin.getQueryable().getTableName() +
				        " " + lhsOrigin.getTableAlias();
				lhsOrigin.setText( lhsOriginText );
			}
			prepareAnyImplicitJoins( lhs );
		}
	
protected voidprepareSelectColumns(java.lang.String[] columns)

		return;
	
public voidresolve(boolean inSelect)


	      
		// Get the function name node.
		AST name = getFirstChild();
		initializeMethodNode( name, inSelect );
		AST exprList = name.getNextSibling();
		// If the expression list has exactly one expression, and the type of the expression is a collection
		// then this might be a collection function, such as index(c) or size(c).
		if ( ASTUtil.hasExactlyOneChild( exprList ) && isCollectionPropertyMethod() ) {
			collectionProperty( exprList.getFirstChild(), name );
		}
		else {
			dialectFunction( exprList );
		}
	
public voidresolveCollectionProperty(antlr.collections.AST expr)

		String propertyName = CollectionProperties.getNormalizedPropertyName( getMethodName() );
		if ( expr instanceof FromReferenceNode ) {
			FromReferenceNode collectionNode = ( FromReferenceNode ) expr;
			// If this is 'elements' then create a new FROM element.
			if ( CollectionPropertyNames.COLLECTION_ELEMENTS.equals( propertyName ) ) {
				handleElements( collectionNode, propertyName );
			}
			else {
				// Not elements(x)
				fromElement = collectionNode.getFromElement();
				setDataType( fromElement.getPropertyType( propertyName, propertyName ) );
				selectColumns = fromElement.toColumns( fromElement.getTableAlias(), propertyName, inSelect );
			}
			if ( collectionNode instanceof DotNode ) {
				prepareAnyImplicitJoins( ( DotNode ) collectionNode );
			}
			if ( !inSelect ) {
				fromElement.setText( "" );
				fromElement.setUseWhereFragment( false );
			}
			prepareSelectColumns( selectColumns );
			setText( selectColumns[0] );
			setType( SqlTokenTypes.SQL_TOKEN );
		}
		else {
			throw new SemanticException( 
					"Unexpected expression " + expr + 
					" found for collection function " + propertyName 
				);
		}
	
public voidsetScalarColumnText(int i)

		if ( selectColumns == null ) { 	// Dialect function
			ColumnHelper.generateSingleScalarColumn( this, i );
		}
		else {	// Collection 'property function'
			ColumnHelper.generateScalarColumns( this, selectColumns, i );
		}