FileDocCategorySizeDatePackage
FromElement.javaAPI DocHibernate 3.2.516450Tue Nov 21 10:38:44 GMT 2006org.hibernate.hql.ast.tree

FromElement

public class FromElement extends HqlSqlWalkerNode implements DisplayableNode
Represents a single mapped class mentioned in an HQL FROM clause. Each class reference will have the following symbols:
  • A class name - This is the name of the Java class that is mapped by Hibernate.
  • [optional] an HQL alias for the mapped class.
  • A table name - The name of the table that is mapped to the Java class.
  • A table alias - The alias for the table that will be used in the resulting SQL.

User: josh
Date: Dec 6, 2003
Time: 10:28:17 AM

Fields Summary
private static final Log
log
private String
className
private String
classAlias
private String
tableAlias
private String
collectionTableAlias
private FromClause
fromClause
private boolean
includeSubclasses
private boolean
collectionJoin
private FromElement
origin
private String[]
columns
private String
role
private boolean
fetch
private boolean
isAllPropertyFetch
private boolean
filter
private int
sequence
private boolean
useFromFragment
private boolean
initialized
private FromElementType
elementType
private boolean
useWhereFragment
private List
destinations
private boolean
manyToMany
private String
withClauseFragment
private String
withClauseJoinAlias
private boolean
dereferencedBySuperclassProperty
private boolean
dereferencedBySubclassProperty
Constructors Summary
public FromElement()


	  
	
Methods Summary
private voidaddDestination(org.hibernate.hql.ast.tree.FromElement fromElement)

		destinations.add( fromElement );
	
protected voidappendDisplayText(java.lang.StringBuffer buf)

		buf.append( isImplied() ? (
				isImpliedInFromClause() ? "implied in FROM clause" : "implied" )
				: "explicit" );
		buf.append( "," ).append( isCollectionJoin() ? "collection join" : "not a collection join" );
		buf.append( "," ).append( fetch ? "fetch join" : "not a fetch join" );
		buf.append( "," ).append( isAllPropertyFetch ? "fetch all properties" : "fetch non-lazy properties" );
		buf.append( ",classAlias=" ).append( getClassAlias() );
		buf.append( ",role=" ).append( role );
		buf.append( ",tableName=" ).append( getTableName() );
		buf.append( ",tableAlias=" ).append( getTableAlias() );
		FromElement origin = getRealOrigin();
		buf.append( ",origin=" ).append( origin == null ? "null" : origin.getText() );
		buf.append( ",colums={" );
		if ( columns != null ) {
			for ( int i = 0; i < columns.length; i++ ) {
				buf.append( columns[i] );
				if ( i < columns.length ) {
					buf.append( " " );
				}
			}
		}
		buf.append( ",className=" ).append( className );
		buf.append( "}" );
	
voidcheckInitialized()

		if ( !initialized ) {
			throw new IllegalStateException( "FromElement has not been initialized!" );
		}
	
private voiddoInitialize(FromClause fromClause, java.lang.String tableAlias, java.lang.String className, java.lang.String classAlias, org.hibernate.persister.entity.EntityPersister persister, org.hibernate.type.EntityType type)

		if ( initialized ) {
			throw new IllegalStateException( "Already initialized!!" );
		}
		this.fromClause = fromClause;
		this.tableAlias = tableAlias;
		this.className = className;
		this.classAlias = classAlias;
		this.elementType = new FromElementType( this, persister, type );
		// Register the FromElement with the FROM clause, now that we have the names and aliases.
		fromClause.registerFromElement( this );
		if ( log.isDebugEnabled() ) {
			log.debug( fromClause + " :  " + className + " ("
					+ ( classAlias == null ? "no alias" : classAlias ) + ") -> " + tableAlias );
		}
	
public booleanequals(java.lang.Object obj)

		return super.equals( obj );
	
public java.lang.StringgetClassAlias()

		return classAlias;
		//return classAlias == null ? className : classAlias;
	
public java.lang.StringgetClassName()

		return className;
	
public java.lang.StringgetCollectionSuffix()

		return elementType.getCollectionSuffix();
	
public java.lang.StringgetCollectionTableAlias()

		return collectionTableAlias;
	
public org.hibernate.type.TypegetDataType()

		return elementType.getDataType();
	
public java.util.ListgetDestinations()

		return destinations;
	
public java.lang.StringgetDisplayText()
Returns additional display text for the AST node.

return
String - The additional display text.

		StringBuffer buf = new StringBuffer();
		buf.append( "FromElement{" );
		appendDisplayText( buf );
		buf.append( "}" );
		return buf.toString();
	
public org.hibernate.persister.entity.EntityPersistergetEntityPersister()

		return elementType.getEntityPersister();
	
public FromClausegetFromClause()

		return fromClause;
	
public java.lang.StringgetIdentityColumn()

		checkInitialized();
		String table = getTableAlias();
		if ( table == null ) {
			throw new IllegalStateException( "No table alias for node " + this );
		}
		String[] cols;
		String propertyName;
		if ( getEntityPersister() != null && getEntityPersister().getEntityMetamodel() != null
				&& getEntityPersister().getEntityMetamodel().hasNonIdentifierPropertyNamedId() ) {
			propertyName = getEntityPersister().getIdentifierPropertyName();
		}
		else {
			propertyName = EntityPersister.ENTITY_ID;
		}
		if ( getWalker().getStatementType() == HqlSqlWalker.SELECT ) {
			cols = getPropertyMapping( propertyName ).toColumns( table, propertyName );
		}
		else {
			cols = getPropertyMapping( propertyName ).toColumns( propertyName );
		}
		String result = StringHelper.join( ", ", cols );
		return  cols.length == 1 ? result : "(" + result + ")";
	
public org.hibernate.engine.JoinSequencegetJoinSequence()

		return elementType.getJoinSequence();
	
public org.hibernate.hql.ast.tree.FromElementgetOrigin()

		return origin;
	
public org.hibernate.persister.entity.PropertyMappinggetPropertyMapping(java.lang.String propertyName)

		return elementType.getPropertyMapping( propertyName );
	
public org.hibernate.type.TypegetPropertyType(java.lang.String propertyName, java.lang.String propertyPath)

		return elementType.getPropertyType( propertyName, propertyPath );
	
public org.hibernate.persister.entity.QueryablegetQueryable()

		return elementType.getQueryable();
	
public org.hibernate.persister.collection.QueryableCollectiongetQueryableCollection()

		return elementType.getQueryableCollection();
	
public org.hibernate.hql.ast.tree.FromElementgetRealOrigin()

		if ( origin == null ) {
			return null;
		}
		if ( origin.getText() == null || "".equals( origin.getText() ) ) {
			return origin.getRealOrigin();
		}
		return origin;
	
public org.hibernate.type.TypegetSelectType()

		return elementType.getSelectType();
	
public intgetSequence()

		return sequence;
	
public java.lang.StringgetTableAlias()

		return tableAlias;
	
private java.lang.StringgetTableName()

		Queryable queryable = getQueryable();
		return ( queryable != null ) ? queryable.getTableName() : "{none}";
	
public java.lang.StringgetWithClauseFragment()

		return withClauseFragment;
	
public java.lang.StringgetWithClauseJoinAlias()

		return withClauseJoinAlias;
	
public voidhandlePropertyBeingDereferenced(org.hibernate.type.Type propertySource, java.lang.String propertyName)

		if ( getQueryableCollection() != null && CollectionProperties.isCollectionProperty( propertyName ) ) {
			// propertyName refers to something like collection.size...
			return;
		}
		if ( propertySource.isComponentType() ) {
			// property name is a sub-path of a component...
			return;
		}

		Queryable persister = getQueryable();
		if ( persister != null ) {
			try {
				Queryable.Declarer propertyDeclarer = persister.getSubclassPropertyDeclarer( propertyName );
				if ( log.isTraceEnabled() ) {
					log.trace( "handling property dereference [" + persister.getEntityName() + " (" + getClassAlias() + ") -> " + propertyName + " (" + propertyDeclarer + ")]" );
				}
				if ( propertyDeclarer == Queryable.Declarer.SUBCLASS ) {
					dereferencedBySubclassProperty = true;
					includeSubclasses = true;
				}
				else if ( propertyDeclarer == Queryable.Declarer.SUPERCLASS ) {
					dereferencedBySuperclassProperty = true;
				}
			}
			catch( QueryException ignore ) {
				// ignore it; the incoming property could not be found so we
				// cannot be sure what to do here.  At the very least, the
				// safest is to simply not apply any dereference toggling...

			}
		}
	
public booleanhasCacheablePersister()

		if ( getQueryableCollection() != null ) {
			return getQueryableCollection().hasCache();
		}
		else {
			return getQueryable().hasCache();
		}
	
public inthashCode()

		return super.hashCode();
	
public booleaninProjectionList()

		return !isImplied() && isFromOrJoinFragment();
	
public voidinitializeCollection(FromClause fromClause, java.lang.String classAlias, java.lang.String tableAlias)

		doInitialize( fromClause, tableAlias, null, classAlias, null, null );
		initialized = true;
	
public voidinitializeEntity(FromClause fromClause, java.lang.String className, org.hibernate.persister.entity.EntityPersister persister, org.hibernate.type.EntityType type, java.lang.String classAlias, java.lang.String tableAlias)

		doInitialize( fromClause, tableAlias, className, classAlias, persister, type );
		this.sequence = fromClause.nextFromElementCounter();
		initialized = true;
	
public booleanisAllPropertyFetch()

		return isAllPropertyFetch;
	
public booleanisCollectionJoin()

		return collectionJoin;
	
public booleanisCollectionOfValuesOrComponents()

		return elementType.isCollectionOfValuesOrComponents();
	
public booleanisDereferencedBySubclassProperty()

		return dereferencedBySubclassProperty;
	
public booleanisDereferencedBySuperclassOrSubclassProperty()

		return dereferencedBySubclassProperty || dereferencedBySuperclassProperty;
	
public booleanisDereferencedBySuperclassProperty()

		return dereferencedBySuperclassProperty;
	
public booleanisEntity()

		return elementType.isEntity();
	
public booleanisFetch()

		return fetch;
	
public booleanisFilter()

		return filter;
	
public booleanisFromOrJoinFragment()

		return getType() == SqlTokenTypes.FROM_FRAGMENT || getType() == SqlTokenTypes.JOIN_FRAGMENT;
	
public booleanisImplied()
Returns true if this FromElement was implied by a path, or false if this FROM element is explicitly declared in the FROM clause.

return
true if this FromElement was implied by a path, or false if this FROM element is explicitly declared

		return false;	// This is an explicit FROM element.
	
public booleanisImpliedInFromClause()

		return false;	// Since this is an explicit FROM element, it can't be implied in the FROM clause.
	
public booleanisIncludeSubclasses()

		return includeSubclasses;
	
public booleanisManyToMany()

		return manyToMany;
	
java.lang.StringrenderCollectionSelectFragment(int size, int k)

		return elementType.renderCollectionSelectFragment( size, k );
	
java.lang.StringrenderIdentifierSelect(int size, int k)
Returns the identifier select SQL fragment.

param
size The total number of returned types.
param
k The sequence of the current returned type.
return
the identifier select SQL fragment.

		return elementType.renderIdentifierSelect( size, k );
	
java.lang.StringrenderPropertySelect(int size, int k)
Returns the property select SQL fragment.

param
size The total number of returned types.
param
k The sequence of the current returned type.
return
the property select SQL fragment.

		return elementType.renderPropertySelect( size, k, isAllPropertyFetch );
	
java.lang.StringrenderScalarIdentifierSelect(int i)
Render the identifier select, but in a 'scalar' context (i.e. generate the column alias).

param
i the sequence of the returned type
return
the identifier select with the column alias.

		return elementType.renderScalarIdentifierSelect( i );
	
java.lang.StringrenderValueCollectionSelectFragment(int size, int k)

		return elementType.renderValueCollectionSelectFragment( size, k );
	
public voidsetAllPropertyFetch(boolean fetch)

		isAllPropertyFetch = fetch;
	
public voidsetCollectionJoin(boolean collectionJoin)

		this.collectionJoin = collectionJoin;
	
public voidsetCollectionSuffix(java.lang.String suffix)

		elementType.setCollectionSuffix(suffix);
	
public voidsetCollectionTableAlias(java.lang.String collectionTableAlias)

		this.collectionTableAlias = collectionTableAlias;
	
public voidsetColumns(java.lang.String[] columns)

		this.columns = columns;
	
public voidsetFetch(boolean fetch)

		this.fetch = fetch;
		// Fetch can't be used with scroll() or iterate().
		if ( fetch && getWalker().isShallowQuery() ) {
			throw new QueryException( QueryTranslator.ERROR_CANNOT_FETCH_WITH_ITERATE );
		}
	
public voidsetFilter(boolean b)

		filter = b;
	
public voidsetImpliedInFromClause(boolean flag)

		throw new UnsupportedOperationException( "Explicit FROM elements can't be implied in the FROM clause!" );
	
public voidsetInProjectionList(boolean inProjectionList)

		// Do nothing, eplicit from elements are *always* in the projection list.
	
public voidsetIncludeSubclasses(boolean includeSubclasses)

		if ( isDereferencedBySuperclassOrSubclassProperty() ) {
			if ( !includeSubclasses && log.isTraceEnabled() ) {
				log.trace( "attempt to disable subclass-inclusions", new Exception( "stack-trace source" ) );
			}
		}
		this.includeSubclasses = includeSubclasses;
	
public voidsetJoinSequence(org.hibernate.engine.JoinSequence joinSequence)

		elementType.setJoinSequence( joinSequence );
	
public voidsetOrigin(org.hibernate.hql.ast.tree.FromElement origin, boolean manyToMany)

		this.origin = origin;
		this.manyToMany = manyToMany;
		origin.addDestination( this );
		if ( origin.getFromClause() == this.getFromClause() ) {
			// TODO: Figure out a better way to get the FROM elements in a proper tree structure.
			// If this is not the destination of a many-to-many, add it as a child of the origin.
			if ( manyToMany ) {
				ASTUtil.appendSibling( origin, this );
			}
			else {
				if ( !getWalker().isInFrom() && !getWalker().isInSelect() ) {
					getFromClause().addChild( this );
				}
				else {
					origin.addChild( this );
				}
			}
		}
		else if ( !getWalker().isInFrom() ) {
			// HHH-276 : implied joins in a subselect where clause - The destination needs to be added
			// to the destination's from clause.
			getFromClause().addChild( this );	// Not sure if this is will fix everything, but it works.
		}
		else {
			// Otherwise, the destination node was implied by the FROM clause and the FROM clause processor
			// will automatically add it in the right place.
		}
	
public voidsetQueryableCollection(org.hibernate.persister.collection.QueryableCollection queryableCollection)

		elementType.setQueryableCollection( queryableCollection );
	
public voidsetRole(java.lang.String role)

		this.role = role;
	
public voidsetUseFromFragment(boolean useFromFragment)

		this.useFromFragment = useFromFragment;
	
public voidsetUseWhereFragment(boolean b)

		useWhereFragment = b;
	
public voidsetWithClauseFragment(java.lang.String withClauseJoinAlias, java.lang.String withClauseFragment)

		this.withClauseJoinAlias = withClauseJoinAlias;
		this.withClauseFragment = withClauseFragment;
	
public java.lang.String[]toColumns(java.lang.String tableAlias, java.lang.String path, boolean inSelect)

		return elementType.toColumns( tableAlias, path, inSelect );
	
public java.lang.String[]toColumns(java.lang.String tableAlias, java.lang.String path, boolean inSelect, boolean forceAlias)

		return elementType.toColumns( tableAlias, path, inSelect, forceAlias );
	
public booleanuseFromFragment()

		checkInitialized();
		// If it's not implied or it is implied and it's a many to many join where the target wasn't found.
		return !isImplied() || this.useFromFragment;
	
public booleanuseWhereFragment()

		return useWhereFragment;