⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fromelement.java

📁 一个Java持久层类库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// $Id: FromElement.java 10852 2006-11-21 17:39:14Z steve.ebersole@jboss.com $package org.hibernate.hql.ast.tree;import java.util.LinkedList;import java.util.List;import org.hibernate.QueryException;import org.hibernate.engine.JoinSequence;import org.hibernate.hql.QueryTranslator;import org.hibernate.hql.CollectionProperties;import org.hibernate.hql.antlr.SqlTokenTypes;import org.hibernate.hql.ast.util.ASTUtil;import org.hibernate.hql.ast.HqlSqlWalker;import org.hibernate.persister.collection.QueryableCollection;import org.hibernate.persister.entity.EntityPersister;import org.hibernate.persister.entity.PropertyMapping;import org.hibernate.persister.entity.Queryable;import org.hibernate.type.EntityType;import org.hibernate.type.Type;import org.hibernate.util.StringHelper;import org.slf4j.Logger;import org.slf4j.LoggerFactory;/** * Represents a single mapped class mentioned in an HQL FROM clause.  Each * class reference will have the following symbols: * <ul> * <li>A class name - This is the name of the Java class that is mapped by Hibernate.</li> * <li>[optional] an HQL alias for the mapped class.</li> * <li>A table name - The name of the table that is mapped to the Java class.</li> * <li>A table alias - The alias for the table that will be used in the resulting SQL.</li> * </ul> * <br> * User: josh<br> * Date: Dec 6, 2003<br> * Time: 10:28:17 AM<br> */public class FromElement extends HqlSqlWalkerNode implements DisplayableNode {	private static final Logger log = LoggerFactory.getLogger( FromElement.class );	private String className;	private String classAlias;	private String tableAlias;	private String collectionTableAlias;	private FromClause fromClause;	private boolean includeSubclasses = true;	private boolean collectionJoin = false;	private FromElement origin;	private String[] columns;	private String role;	private boolean fetch;	private boolean isAllPropertyFetch;	private boolean filter = false;	private int sequence = -1;	private boolean useFromFragment = false;	private boolean initialized = false;	private FromElementType elementType;	private boolean useWhereFragment = true;	private List destinations = new LinkedList();	private boolean manyToMany = false;	private String withClauseFragment = null;	private String withClauseJoinAlias;	private boolean dereferencedBySuperclassProperty;	private boolean dereferencedBySubclassProperty;	public FromElement() {	}	public String getCollectionSuffix() {		return elementType.getCollectionSuffix();	}	public void setCollectionSuffix(String suffix) {		elementType.setCollectionSuffix(suffix);	}	public void initializeCollection(FromClause fromClause, String classAlias, String tableAlias) {		doInitialize( fromClause, tableAlias, null, classAlias, null, null );		initialized = true;	}	public void initializeEntity(	        FromClause fromClause,	        String className,	        EntityPersister persister,	        EntityType type,	        String classAlias,	        String tableAlias) {		doInitialize( fromClause, tableAlias, className, classAlias, persister, type );		this.sequence = fromClause.nextFromElementCounter();		initialized = true;	}	private void doInitialize(FromClause fromClause, String tableAlias, String className, String classAlias,							  EntityPersister persister, 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 EntityPersister getEntityPersister() {		return elementType.getEntityPersister();	}	public Type getDataType() {		return elementType.getDataType();	}	public Type getSelectType() {		return elementType.getSelectType();	}	public Queryable getQueryable() {		return elementType.getQueryable();	}	public String getClassName() {		return className;	}	public String getClassAlias() {		return classAlias;		//return classAlias == null ? className : classAlias;	}	private String getTableName() {		Queryable queryable = getQueryable();		return ( queryable != null ) ? queryable.getTableName() : "{none}";	}	public String getTableAlias() {		return tableAlias;	}	/**	 * 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.	 */	String renderScalarIdentifierSelect(int i) {		return elementType.renderScalarIdentifierSelect( i );	}	void checkInitialized() {		if ( !initialized ) {			throw new IllegalStateException( "FromElement has not been initialized!" );		}	}	/**	 * 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.	 */	String renderIdentifierSelect(int size, int k) {		return elementType.renderIdentifierSelect( size, 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.	 */	String renderPropertySelect(int size, int k) {		return elementType.renderPropertySelect( size, k, isAllPropertyFetch );	}	String renderCollectionSelectFragment(int size, int k) {		return elementType.renderCollectionSelectFragment( size, k );	}	String renderValueCollectionSelectFragment(int size, int k) {		return elementType.renderValueCollectionSelectFragment( size, k );	}	public FromClause getFromClause() {		return fromClause;	}	/**	 * 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	 */	public boolean isImplied() {		return false;	// This is an explicit FROM element.	}	/**	 * Returns additional display text for the AST node.	 *	 * @return String - The additional display text.	 */	public String getDisplayText() {		StringBuffer buf = new StringBuffer();		buf.append( "FromElement{" );		appendDisplayText( buf );		buf.append( "}" );		return buf.toString();	}	protected void appendDisplayText(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( "}" );	}	public int hashCode() {		return super.hashCode();	}	public boolean equals(Object obj) {		return super.equals( obj );	}	public void setJoinSequence(JoinSequence joinSequence) {		elementType.setJoinSequence( joinSequence );	}	public JoinSequence getJoinSequence() {		return elementType.getJoinSequence();	}	public void setIncludeSubclasses(boolean includeSubclasses) {		if ( isDereferencedBySuperclassOrSubclassProperty() ) {			if ( !includeSubclasses && log.isTraceEnabled() ) {				log.trace( "attempt to disable subclass-inclusions", new Exception( "stack-trace source" ) );			}		}		this.includeSubclasses = includeSubclasses;	}	public boolean isIncludeSubclasses() {		return includeSubclasses;	}	public boolean isDereferencedBySuperclassOrSubclassProperty() {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -