FileDocCategorySizeDatePackage
OneToManyJoinWalker.javaAPI DocHibernate 3.2.54017Sun Jul 24 01:53:06 BST 2005org.hibernate.loader.collection

OneToManyJoinWalker

public class OneToManyJoinWalker extends CollectionJoinWalker
Walker for one-to-many associations
see
OneToManyLoader
author
Gavin King

Fields Summary
private final org.hibernate.persister.collection.QueryableCollection
oneToManyPersister
Constructors Summary
public OneToManyJoinWalker(org.hibernate.persister.collection.QueryableCollection oneToManyPersister, int batchSize, String subquery, org.hibernate.engine.SessionFactoryImplementor factory, Map enabledFilters)


		super(factory, enabledFilters);

		this.oneToManyPersister = oneToManyPersister;

		final OuterJoinLoadable elementPersister = (OuterJoinLoadable) oneToManyPersister.getElementPersister();
		final String alias = generateRootAlias( oneToManyPersister.getRole() );

		walkEntityTree(elementPersister, alias);

		List allAssociations = new ArrayList();
		allAssociations.addAll(associations);
		allAssociations.add( new OuterJoinableAssociation( 
				oneToManyPersister.getCollectionType(),
				null, 
				null, 
				alias, 
				JoinFragment.LEFT_OUTER_JOIN, 
				getFactory(), 
				CollectionHelper.EMPTY_MAP 
			) );
		
		initPersisters(allAssociations, LockMode.NONE);
		initStatementString(elementPersister, alias, batchSize, subquery);

	
Methods Summary
private voidinitStatementString(org.hibernate.persister.entity.OuterJoinLoadable elementPersister, java.lang.String alias, int batchSize, java.lang.String subquery)


		final int joins = countEntityPersisters( associations );
		suffixes = BasicLoader.generateSuffixes( joins + 1 );

		final int collectionJoins = countCollectionPersisters( associations ) + 1;
		collectionSuffixes = BasicLoader.generateSuffixes( joins + 1, collectionJoins );

		StringBuffer whereString = whereString(
				alias, 
				oneToManyPersister.getKeyColumnNames(), 
				subquery,
				batchSize
			);
		String filter = oneToManyPersister.filterFragment( alias, getEnabledFilters() );
		whereString.insert( 0, StringHelper.moveAndToBeginning(filter) );

		JoinFragment ojf = mergeOuterJoins(associations);
		Select select = new Select( getDialect() )
			.setSelectClause(
				oneToManyPersister.selectFragment(null, null, alias, suffixes[joins], collectionSuffixes[0], true) +
				selectString(associations)
			)
			.setFromClause(
				elementPersister.fromTableFragment(alias) +
				elementPersister.fromJoinFragment(alias, true, true)
			)
			.setWhereClause( whereString.toString() )
			.setOuterJoins(
				ojf.toFromFragmentString(),
				ojf.toWhereFragmentString() +
				elementPersister.whereJoinFragment(alias, true, true)
			);

		select.setOrderByClause( orderBy( associations, oneToManyPersister.getSQLOrderByString(alias) ) );

		if ( getFactory().getSettings().isCommentsEnabled() ) {
			select.setComment( "load one-to-many " + oneToManyPersister.getRole() );
		}

		sql = select.toStatementString();
	
protected booleanisDuplicateAssociation(java.lang.String foreignKeyTable, java.lang.String[] foreignKeyColumns)

		//disable a join back to this same association
		final boolean isSameJoin = oneToManyPersister.getTableName().equals(foreignKeyTable) &&
			Arrays.equals( foreignKeyColumns, oneToManyPersister.getKeyColumnNames() );
		return isSameJoin || 
			super.isDuplicateAssociation(foreignKeyTable, foreignKeyColumns);
	
public java.lang.StringtoString()

		return getClass().getName() + '(" + oneToManyPersister.getRole() + ')";