Java Code Examples for org.hibernate.sql.JoinFragment#addJoin()

The following examples show how to use org.hibernate.sql.JoinFragment#addJoin() . 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: OuterJoinableAssociation.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void addManyToManyJoin(JoinFragment outerjoin, QueryableCollection collection) throws MappingException {
	String manyToManyFilter = collection.getManyToManyFilterFragment( rhsAlias, enabledFilters );
	String condition = "".equals( manyToManyFilter )
			? on
			: "".equals( on )
			? manyToManyFilter
			: on + " and " + manyToManyFilter;
	outerjoin.addJoin(
			joinable.getTableName(),
			rhsAlias,
			lhsColumns,
			rhsColumns,
			joinType,
			condition
	);
	outerjoin.addJoins(
			joinable.fromJoinFragment( rhsAlias, false, true ),
			joinable.whereJoinFragment( rhsAlias, false, true )
	);
}
 
Example 2
Source File: AbstractEntityPersister.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected JoinFragment createJoin(int[] tableNumbers, String drivingAlias) {
	final String[] keyCols = StringHelper.qualify( drivingAlias, getSubclassTableKeyColumns( tableNumbers[0] ) );
	final JoinFragment jf = getFactory().getDialect().createOuterJoinFragment();
	// IMPL NOTE : notice that we skip the first table; it is the driving table!
	for ( int i = 1; i < tableNumbers.length; i++ ) {
		final int j = tableNumbers[i];
		jf.addJoin(
				getSubclassTableName( j ),
				generateTableAlias( getRootAlias(), j ),
				keyCols,
				getSubclassTableKeyColumns( j ),
				isInverseSubclassTable( j ) || isNullableSubclassTable( j )
						? JoinType.LEFT_OUTER_JOIN
						: JoinType.INNER_JOIN
		);
	}
	return jf;
}
 
Example 3
Source File: OuterJoinableAssociation.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void addManyToManyJoin(JoinFragment outerjoin, QueryableCollection collection) throws MappingException {
	String manyToManyFilter = collection.getManyToManyFilterFragment( rhsAlias, enabledFilters );
	String condition = "".equals( manyToManyFilter )
			? on
			: "".equals( on )
					? manyToManyFilter
					: on + " and " + manyToManyFilter;
	outerjoin.addJoin(
	        joinable.getTableName(),
	        rhsAlias,
	        lhsColumns,
	        rhsColumns,
	        joinType,
	        condition
	);
	outerjoin.addJoins(
		joinable.fromJoinFragment(rhsAlias, false, true),
		joinable.whereJoinFragment(rhsAlias, false, true)
	);
}
 
Example 4
Source File: AbstractEntityPersister.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected JoinFragment createJoin(String name, boolean innerJoin, boolean includeSubclasses) {
	final String[] idCols = StringHelper.qualify( name, getIdentifierColumnNames() ); //all joins join to the pk of the driving table
	final JoinFragment join = getFactory().getDialect().createOuterJoinFragment();
	final int tableSpan = getSubclassTableSpan();
	for ( int j = 1; j < tableSpan; j++ ) { //notice that we skip the first table; it is the driving table!
		final boolean joinIsIncluded = isClassOrSuperclassTable( j ) ||
				( includeSubclasses && !isSubclassTableSequentialSelect( j ) && !isSubclassTableLazy( j ) );
		if ( joinIsIncluded ) {
			join.addJoin( getSubclassTableName( j ),
					generateTableAlias( name, j ),
					idCols,
					getSubclassTableKeyColumns( j ),
					innerJoin && isClassOrSuperclassTable( j ) && !isInverseTable( j ) && !isNullableTable( j ) ?
					JoinFragment.INNER_JOIN : //we can inner join to superclass tables (the row MUST be there)
					JoinFragment.LEFT_OUTER_JOIN //we can never inner join to subclass tables
				);
		}
	}
	return join;
}
 
Example 5
Source File: OuterJoinableAssociation.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void addJoins(JoinFragment outerjoin) throws MappingException {
	outerjoin.addJoin(
			joinable.getTableName(),
			rhsAlias,
			lhsColumns,
			rhsColumns,
			joinType,
			on
	);
	outerjoin.addJoins(
			joinable.fromJoinFragment( rhsAlias, false, true ),
			joinable.whereJoinFragment( rhsAlias, false, true )
	);
}
 
Example 6
Source File: AbstractEntityPersister.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected JoinFragment createJoin(
		String name,
		boolean innerJoin,
		boolean includeSubclasses,
		Set<String> treatAsDeclarations) {
	// IMPL NOTE : all joins join to the pk of the driving table
	final String[] idCols = StringHelper.qualify( name, getIdentifierColumnNames() );
	final JoinFragment join = getFactory().getDialect().createOuterJoinFragment();
	final int tableSpan = getSubclassTableSpan();
	// IMPL NOTE : notice that we skip the first table; it is the driving table!
	for ( int j = 1; j < tableSpan; j++ ) {
		final JoinType joinType = determineSubclassTableJoinType(
				j,
				innerJoin,
				includeSubclasses,
				treatAsDeclarations
		);

		if ( joinType != null && joinType != JoinType.NONE ) {
			join.addJoin(
					getSubclassTableName( j ),
					generateTableAlias( name, j ),
					idCols,
					getSubclassTableKeyColumns( j ),
					joinType
			);
		}
	}
	return join;
}
 
Example 7
Source File: OuterJoinableAssociation.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void addJoins(JoinFragment outerjoin) throws MappingException {
	outerjoin.addJoin(
		joinable.getTableName(),
		rhsAlias,
		lhsColumns,
		rhsColumns,
		joinType,
		on
	);
	outerjoin.addJoins(
		joinable.fromJoinFragment(rhsAlias, false, true),
		joinable.whereJoinFragment(rhsAlias, false, true)
	);
}
 
Example 8
Source File: AbstractEntityPersister.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected JoinFragment createJoin(int[] tableNumbers, String drivingAlias) {
	final String[] keyCols = StringHelper.qualify( drivingAlias, getSubclassTableKeyColumns( tableNumbers[0] ) );
	final JoinFragment jf = getFactory().getDialect().createOuterJoinFragment();
	for ( int i = 1; i < tableNumbers.length; i++ ) { //skip the driving table
		final int j = tableNumbers[i];
		jf.addJoin( getSubclassTableName( j ),
				generateTableAlias( getRootAlias(), j ),
				keyCols,
				getSubclassTableKeyColumns( j ),
				isInverseSubclassTable( j ) || isNullableSubclassTable( j ) ?
				JoinFragment.LEFT_OUTER_JOIN :
				JoinFragment.INNER_JOIN );
	}
	return jf;
}
 
Example 9
Source File: LoadQueryJoinAndFetchProcessor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void addJoins(
		Join join,
		JoinFragment joinFragment,
		Joinable joinable,
		String joinConditions) {
	final String rhsTableAlias = aliasResolutionContext.resolveSqlTableAliasFromQuerySpaceUid(
			join.getRightHandSide().getUid()
	);
	if ( StringHelper.isEmpty( rhsTableAlias ) ) {
		throw new IllegalStateException( "Join's RHS table alias cannot be empty" );
	}

	final String lhsTableAlias = aliasResolutionContext.resolveSqlTableAliasFromQuerySpaceUid(
			join.getLeftHandSide().getUid()
	);
	if ( lhsTableAlias == null ) {
		throw new IllegalStateException( "QuerySpace with that UID was not yet registered in the AliasResolutionContext" );
	}

	String otherConditions = join.getAnyAdditionalJoinConditions( rhsTableAlias );
	if ( !StringHelper.isEmpty( otherConditions ) && !StringHelper.isEmpty( joinConditions ) ) {
		otherConditions += " and " + joinConditions;
	}
	else if ( !StringHelper.isEmpty( joinConditions ) ) {
		otherConditions = joinConditions;
	}

	// add join fragments from the collection table -> element entity table ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	final String additionalJoinConditions = resolveAdditionalJoinCondition(
			rhsTableAlias,
			otherConditions,
			joinable,
			getJoinedAssociationTypeOrNull( join )
	);

	String[] joinColumns = join.resolveAliasedLeftHandSideJoinConditionColumns( lhsTableAlias );
	if ( joinColumns.length == 0 ) {
		// When no columns are available, this is a special join that involves multiple subtypes
		AbstractEntityPersister persister = (AbstractEntityPersister) ( (EntityQuerySpace) join.getLeftHandSide() ).getEntityPersister();

		String[][] polyJoinColumns = persister.getPolymorphicJoinColumns(
				lhsTableAlias,
				( (JoinDefinedByMetadata) join ).getJoinedPropertyName()
		);

		joinFragment.addJoin(
				joinable.getTableName(),
				rhsTableAlias,
				polyJoinColumns,
				join.resolveNonAliasedRightHandSideJoinConditionColumns(),
				join.isRightHandSideRequired() ? JoinType.INNER_JOIN : JoinType.LEFT_OUTER_JOIN,
				additionalJoinConditions
		);
	}
	else {
		joinFragment.addJoin(
				joinable.getTableName(),
				rhsTableAlias,
				joinColumns,
				join.resolveNonAliasedRightHandSideJoinConditionColumns(),
				join.isRightHandSideRequired() ? JoinType.INNER_JOIN : JoinType.LEFT_OUTER_JOIN,
				additionalJoinConditions
		);
	}
	joinFragment.addJoins(
			joinable.fromJoinFragment( rhsTableAlias, false, true ),
			joinable.whereJoinFragment( rhsTableAlias, false, true )
	);
}