FileDocCategorySizeDatePackage
CriteriaJoinWalker.javaAPI DocHibernate 3.2.54836Mon Jan 23 14:21:02 GMT 2006org.hibernate.loader.criteria

CriteriaJoinWalker

public class CriteriaJoinWalker extends org.hibernate.loader.AbstractEntityJoinWalker
A JoinWalker for Criteria queries.
see
CriteriaLoader
author
Gavin King

Fields Summary
private final CriteriaQueryTranslator
translator
private final Set
querySpaces
private final org.hibernate.type.Type[]
resultTypes
private final String[]
userAliases
private final List
userAliasList
Constructors Summary
public CriteriaJoinWalker(org.hibernate.persister.entity.OuterJoinLoadable persister, CriteriaQueryTranslator translator, org.hibernate.engine.SessionFactoryImplementor factory, org.hibernate.impl.CriteriaImpl criteria, String rootEntityName, Map enabledFilters)

		super(persister, factory, enabledFilters);

		this.translator = translator;

		querySpaces = translator.getQuerySpaces();

		if ( translator.hasProjection() ) {
			resultTypes = translator.getProjectedTypes();
			
			initProjection( 
					translator.getSelect(), 
					translator.getWhereCondition(), 
					translator.getOrderBy(),
					translator.getGroupBy(),
					LockMode.NONE 
				);
		}
		else {
			resultTypes = new Type[] { TypeFactory.manyToOne( persister.getEntityName() ) };

			initAll( translator.getWhereCondition(), translator.getOrderBy(), LockMode.NONE );
		}
		
		userAliasList.add( criteria.getAlias() ); //root entity comes *last*
		userAliases = ArrayHelper.toStringArray(userAliasList);

	
Methods Summary
protected java.lang.StringgenerateRootAlias(java.lang.String tableName)

		return CriteriaQueryTranslator.ROOT_SQL_ALIAS;
	
protected java.lang.StringgenerateTableAlias(int n, java.lang.String path, org.hibernate.persister.entity.Joinable joinable)

		if ( joinable.consumesEntityAlias() ) {
			final Criteria subcriteria = translator.getCriteria(path);
			String sqlAlias = subcriteria==null ? null : translator.getSQLAlias(subcriteria);
			if (sqlAlias!=null) {
				userAliasList.add( subcriteria.getAlias() ); //alias may be null
				return sqlAlias; //EARLY EXIT
			}
			else {
				userAliasList.add(null);
			}
		}
		return super.generateTableAlias( n + translator.getSQLAliasCount(), path, joinable );
	
public java.lang.StringgetComment()

		return "criteria query";
	
protected intgetJoinType(org.hibernate.type.AssociationType type, org.hibernate.FetchMode config, java.lang.String path, java.lang.String lhsTable, java.lang.String[] lhsColumns, boolean nullable, int currentDepth, org.hibernate.engine.CascadeStyle cascadeStyle)


		if ( translator.isJoin(path) ) {
			return translator.getJoinType( path );
		}
		else {
			if ( translator.hasProjection() ) {
				return -1;
			}
			else {
				FetchMode fetchMode = translator.getRootCriteria()
					.getFetchMode(path);
				if ( isDefaultFetchMode(fetchMode) ) {
					return super.getJoinType(
							type, 
							config, 
							path, 
							lhsTable, 
							lhsColumns, 
							nullable,
							currentDepth, cascadeStyle
						);
				}
				else {
					if ( fetchMode==FetchMode.JOIN ) {
						isDuplicateAssociation(lhsTable, lhsColumns, type); //deliberately ignore return value!
						return getJoinType(nullable, currentDepth);
					}
					else {
						return -1;
					}
				}
			}
		}
	
public java.util.SetgetQuerySpaces()

		return querySpaces;
	
public org.hibernate.type.Type[]getResultTypes()


	   
		return resultTypes;
	
public java.lang.String[]getUserAliases()

		return userAliases;
	
protected java.lang.StringgetWhereFragment()
Use the discriminator, to narrow the select to instances of the queried subclass, also applying any filters.

		return super.getWhereFragment() +
			( (Queryable) getPersister() ).filterFragment( getAlias(), getEnabledFilters() );
	
private static booleanisDefaultFetchMode(org.hibernate.FetchMode fetchMode)

		return fetchMode==null || fetchMode==FetchMode.DEFAULT;