Java Code Examples for org.hibernate.persister.entity.Joinable#consumesEntityAlias()

The following examples show how to use org.hibernate.persister.entity.Joinable#consumesEntityAlias() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CriteriaJoinWalker.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected String generateTableAlias(int n, String path, 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 );
}
 
Example 2
Source File: JoinWalker.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
	 * Add on association (one-to-one, many-to-one, or a collection) to a list
	 * of associations to be fetched by outerjoin
	 */
	private void addAssociationToJoinTree(
			final AssociationType type,
			final String[] aliasedLhsColumns,
			final String alias,
			final PropertyPath path,
			final int currentDepth,
			final JoinType joinType) throws MappingException {

		Joinable joinable = type.getAssociatedJoinable( getFactory() );

		// important to generate alias based on size of association collection
		// *before* adding this join to that collection
		String subalias = generateTableAlias( associations.size() + 1, path, joinable );

		// NOTE : it should be fine to continue to pass only filters below
		// (instead of LoadQueryInfluencers) since "from that point on" we
		// only need to worry about restrictions (and not say adding more
		// joins)
		OuterJoinableAssociation assoc = new OuterJoinableAssociation(
				path,
				type,
				alias,
				aliasedLhsColumns,
				subalias,
				joinType,
				joinable.consumesEntityAlias() ? getWithClause( path ) : "",
				hasRestriction( path ),
				getFactory(),
				loadQueryInfluencers.getEnabledFilters()
		);
		assoc.validateJoin( path.getFullPath() );
		associations.add( assoc );

		int nextDepth = currentDepth + 1;
//		path = "";
		if ( !joinable.isCollection() ) {
			if ( joinable instanceof OuterJoinLoadable ) {
				walkEntityTree(
						(OuterJoinLoadable) joinable,
						subalias,
						path,
						nextDepth
				);
			}
		}
		else {
			if ( joinable instanceof QueryableCollection ) {
				walkCollectionTree(
						(QueryableCollection) joinable,
						subalias,
						path,
						nextDepth
				);
			}
		}

	}
 
Example 3
Source File: JoinWalker.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Generate a select list of columns containing all properties of the entity classes
 */
protected final String selectString(List associations) throws MappingException {

	if ( associations.size() == 0 ) {
		return "";
	}
	else {
		StringBuilder buf = new StringBuilder( associations.size() * 100 );
		int entityAliasCount = 0;
		int collectionAliasCount = 0;
		for ( int i = 0; i < associations.size(); i++ ) {
			OuterJoinableAssociation join = (OuterJoinableAssociation) associations.get( i );
			OuterJoinableAssociation next = ( i == associations.size() - 1 )
					? null
					: (OuterJoinableAssociation) associations.get( i + 1 );
			final Joinable joinable = join.getJoinable();
			final String entitySuffix = ( suffixes == null || entityAliasCount >= suffixes.length )
					? null
					: suffixes[entityAliasCount];
			final String collectionSuffix = ( collectionSuffixes == null || collectionAliasCount >= collectionSuffixes.length )
					? null
					: collectionSuffixes[collectionAliasCount];
			final String selectFragment = joinable.selectFragment(
					next == null ? null : next.getJoinable(),
					next == null ? null : next.getRHSAlias(),
					join.getRHSAlias(),
					entitySuffix,
					collectionSuffix,
					join.getJoinType() == JoinType.LEFT_OUTER_JOIN
			);
			if ( selectFragment.trim().length() > 0 ) {
				buf.append( ", " ).append( selectFragment );
			}
			if ( joinable.consumesEntityAlias() ) {
				entityAliasCount++;
			}
			if ( joinable.consumesCollectionAlias() &&
					join.getJoinType() == JoinType.LEFT_OUTER_JOIN &&
					!join.hasRestriction() ) {
				collectionAliasCount++;
			}
		}
		return buf.toString();
	}
}
 
Example 4
Source File: CriteriaJoinWalker.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected String generateTableAlias(int n, PropertyPath path, Joinable joinable) {
	// TODO: deal with side-effects (changes to includeInResultRowList, userAliasList, resultTypeList)!!!

	// for collection-of-entity, we are called twice for given "path"
	// once for the collection Joinable, once for the entity Joinable.
	// the second call will/must "consume" the alias + perform side effects according to consumesEntityAlias()
	// for collection-of-other, however, there is only one call 
	// it must "consume" the alias + perform side effects, despite what consumeEntityAlias() return says
	// 
	// note: the logic for adding to the userAliasList is still strictly based on consumesEntityAlias return value
	boolean checkForSqlAlias = joinable.consumesEntityAlias();

	if ( !checkForSqlAlias && joinable.isCollection() ) {
		// is it a collection-of-other (component or value) ?
		CollectionPersister collectionPersister = (CollectionPersister) joinable;
		Type elementType = collectionPersister.getElementType();
		if ( elementType.isComponentType() || !elementType.isEntityType() ) {
			checkForSqlAlias = true;
		}
	}

	String sqlAlias = null;

	if ( checkForSqlAlias ) {
		final Criteria subcriteria = translator.getCriteria( path.getFullPath() );
		sqlAlias = subcriteria == null ? null : translator.getSQLAlias( subcriteria );

		if ( joinable.consumesEntityAlias() && !translator.hasProjection() ) {
			includeInResultRowList.add( subcriteria != null && subcriteria.getAlias() != null );
			if ( sqlAlias != null ) {
				if ( subcriteria.getAlias() != null ) {
					userAliasList.add( subcriteria.getAlias() );
					resultTypeList.add( translator.getResultType( subcriteria ) );
				}
			}
		}
	}

	if ( sqlAlias == null ) {
		sqlAlias = super.generateTableAlias( n + translator.getSQLAliasCount(), path, joinable );
	}

	return sqlAlias;
}
 
Example 5
Source File: JoinWalker.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Generate a select list of columns containing all properties of the entity classes
 */
protected final String selectString(List associations)
throws MappingException {

	if ( associations.size()==0 ) {
		return "";
	}
	else {
		StringBuffer buf = new StringBuffer( associations.size() * 100 )
			.append(", ");
		int entityAliasCount=0;
		int collectionAliasCount=0;
		for ( int i=0; i<associations.size(); i++ ) {
			OuterJoinableAssociation join = (OuterJoinableAssociation) associations.get(i);
			OuterJoinableAssociation next = (i == associations.size() - 1)
			        ? null
			        : ( OuterJoinableAssociation ) associations.get( i + 1 );
			final Joinable joinable = join.getJoinable();
			final String entitySuffix = ( suffixes == null || entityAliasCount >= suffixes.length )
			        ? null
			        : suffixes[entityAliasCount];
			final String collectionSuffix = ( collectionSuffixes == null || collectionAliasCount >= collectionSuffixes.length )
			        ? null
			        : collectionSuffixes[collectionAliasCount];
			final String selectFragment = joinable.selectFragment(
					next == null ? null : next.getJoinable(),
					next == null ? null : next.getRHSAlias(),
					join.getRHSAlias(),
					entitySuffix,
			        collectionSuffix,
					join.getJoinType()==JoinFragment.LEFT_OUTER_JOIN
			);
			buf.append(selectFragment);
			if ( joinable.consumesEntityAlias() ) entityAliasCount++;
			if ( joinable.consumesCollectionAlias() && join.getJoinType()==JoinFragment.LEFT_OUTER_JOIN ) collectionAliasCount++;
			if (
				i<associations.size()-1 &&
				selectFragment.trim().length()>0
			) {
				buf.append(", ");
			}
		}
		return buf.toString();
	}
}