Java Code Examples for org.hibernate.sql.JoinFragment#LEFT_OUTER_JOIN

The following examples show how to use org.hibernate.sql.JoinFragment#LEFT_OUTER_JOIN . 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: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Translates an AST join type (i.e., the token type) into a JoinFragment.XXX join type.
 *
 * @param astJoinType The AST join type (from HqlSqlTokenTypes or SqlTokenTypes)
 * @return a JoinFragment.XXX join type.
 * @see JoinFragment
 * @see SqlTokenTypes
 */
public static int toHibernateJoinType(int astJoinType) {
	switch ( astJoinType ) {
		case LEFT_OUTER:
			return JoinFragment.LEFT_OUTER_JOIN;
		case INNER:
			return JoinFragment.INNER_JOIN;
		case RIGHT_OUTER:
			return JoinFragment.RIGHT_OUTER_JOIN;
		default:
			throw new AssertionFailure( "undefined join type " + astJoinType );
	}
}
 
Example 2
Source File: JoinProcessor.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Translates an AST join type (i.e., the token type) into a JoinFragment.XXX join type.
 *
 * @param astJoinType The AST join type (from HqlSqlTokenTypes or SqlTokenTypes)
 * @return a JoinFragment.XXX join type.
 * @see JoinFragment
 * @see SqlTokenTypes
 */
public static int toHibernateJoinType(int astJoinType) {
	switch ( astJoinType ) {
		case LEFT_OUTER:
			return JoinFragment.LEFT_OUTER_JOIN;
		case INNER:
			return JoinFragment.INNER_JOIN;
		case RIGHT_OUTER:
			return JoinFragment.RIGHT_OUTER_JOIN;
		default:
			throw new AssertionFailure( "undefined join type " + astJoinType );
	}
}
 
Example 3
Source File: BasicCollectionJoinWalker.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * We can use an inner join for first many-to-many association
 */
protected int getJoinType(
		AssociationType type, 
		FetchMode config, 
		String path, 
		Set visitedAssociations,
		String lhsTable,
		String[] lhsColumns,
		boolean nullable,
		int currentDepth)
throws MappingException {

	int joinType = super.getJoinType(
			type, 
			config, 
			path, 
			lhsTable, 
			lhsColumns, 
			nullable, 
			currentDepth,
			null
		);
	//we can use an inner join for the many-to-many
	if ( joinType==JoinFragment.LEFT_OUTER_JOIN && "".equals(path) ) {
		joinType=JoinFragment.INNER_JOIN;
	}
	return joinType;
}
 
Example 4
Source File: JoinWalker.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Count the number of instances of Joinable which are actually
 * also instances of PersistentCollection which are being fetched
 * by outer join
 */
protected static final int countCollectionPersisters(List associations)
throws MappingException {
	int result = 0;
	Iterator iter = associations.iterator();
	while ( iter.hasNext() ) {
		OuterJoinableAssociation oj = (OuterJoinableAssociation) iter.next();
		if ( oj.getJoinType()==JoinFragment.LEFT_OUTER_JOIN && oj.getJoinable().isCollection() ) {
			result++;
		}
	}
	return result;
}
 
Example 5
Source File: JoinWalker.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Use an inner join if it is a non-null association and this
 * is the "first" join in a series
 */
protected int getJoinType(boolean nullable, int currentDepth) {
	//TODO: this is too conservative; if all preceding joins were 
	//      also inner joins, we could use an inner join here
	return !nullable && currentDepth==0 ? 
				JoinFragment.INNER_JOIN : 
				JoinFragment.LEFT_OUTER_JOIN;
}
 
Example 6
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Translates an AST join type (i.e., the token type) into a JoinFragment.XXX join type.
 *
 * @param astJoinType The AST join type (from HqlSqlTokenTypes or SqlTokenTypes)
 * @return a JoinFragment.XXX join type.
 * @see JoinFragment
 * @see SqlTokenTypes
 */
public static int toHibernateJoinType(int astJoinType) {
	switch ( astJoinType ) {
		case LEFT_OUTER:
			return JoinFragment.LEFT_OUTER_JOIN;
		case INNER:
			return JoinFragment.INNER_JOIN;
		case RIGHT_OUTER:
			return JoinFragment.RIGHT_OUTER_JOIN;
		default:
			throw new AssertionFailure( "undefined join type " + astJoinType );
	}
}
 
Example 7
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Translates an AST join type (i.e., the token type) into a JoinFragment.XXX join type.
 *
 * @param astJoinType The AST join type (from HqlSqlTokenTypes or SqlTokenTypes)
 * @return a JoinFragment.XXX join type.
 * @see JoinFragment
 * @see SqlTokenTypes
 */
public static int toHibernateJoinType(int astJoinType) {
	switch ( astJoinType ) {
		case LEFT_OUTER:
			return JoinFragment.LEFT_OUTER_JOIN;
		case INNER:
			return JoinFragment.INNER_JOIN;
		case RIGHT_OUTER:
			return JoinFragment.RIGHT_OUTER_JOIN;
		default:
			throw new AssertionFailure( "undefined join type " + astJoinType );
	}
}
 
Example 8
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Translates an AST join type (i.e., the token type) into a JoinFragment.XXX join type.
 *
 * @param astJoinType The AST join type (from HqlSqlTokenTypes or SqlTokenTypes)
 * @return a JoinFragment.XXX join type.
 * @see JoinFragment
 * @see SqlTokenTypes
 */
public static int toHibernateJoinType(int astJoinType) {
	switch ( astJoinType ) {
		case LEFT_OUTER:
			return JoinFragment.LEFT_OUTER_JOIN;
		case INNER:
			return JoinFragment.INNER_JOIN;
		case RIGHT_OUTER:
			return JoinFragment.RIGHT_OUTER_JOIN;
		default:
			throw new AssertionFailure( "undefined join type " + astJoinType );
	}
}
 
Example 9
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Translates an AST join type (i.e., the token type) into a JoinFragment.XXX join type.
 *
 * @param astJoinType The AST join type (from HqlSqlTokenTypes or SqlTokenTypes)
 * @return a JoinFragment.XXX join type.
 * @see JoinFragment
 * @see SqlTokenTypes
 */
public static int toHibernateJoinType(int astJoinType) {
	switch ( astJoinType ) {
		case LEFT_OUTER:
			return JoinFragment.LEFT_OUTER_JOIN;
		case INNER:
			return JoinFragment.INNER_JOIN;
		case RIGHT_OUTER:
			return JoinFragment.RIGHT_OUTER_JOIN;
		default:
			throw new AssertionFailure( "undefined join type " + astJoinType );
	}
}
 
Example 10
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Translates an AST join type (i.e., the token type) into a JoinFragment.XXX join type.
 *
 * @param astJoinType The AST join type (from HqlSqlTokenTypes or SqlTokenTypes)
 * @return a JoinFragment.XXX join type.
 * @see JoinFragment
 * @see SqlTokenTypes
 */
public static int toHibernateJoinType(int astJoinType) {
	switch ( astJoinType ) {
		case LEFT_OUTER:
			return JoinFragment.LEFT_OUTER_JOIN;
		case INNER:
			return JoinFragment.INNER_JOIN;
		case RIGHT_OUTER:
			return JoinFragment.RIGHT_OUTER_JOIN;
		default:
			throw new AssertionFailure( "undefined join type " + astJoinType );
	}
}
 
Example 11
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Translates an AST join type (i.e., the token type) into a JoinFragment.XXX join type.
 *
 * @param astJoinType The AST join type (from HqlSqlTokenTypes or SqlTokenTypes)
 * @return a JoinFragment.XXX join type.
 * @see JoinFragment
 * @see SqlTokenTypes
 */
public static int toHibernateJoinType(int astJoinType) {
	switch ( astJoinType ) {
		case LEFT_OUTER:
			return JoinFragment.LEFT_OUTER_JOIN;
		case INNER:
			return JoinFragment.INNER_JOIN;
		case RIGHT_OUTER:
			return JoinFragment.RIGHT_OUTER_JOIN;
		default:
			throw new AssertionFailure( "undefined join type " + astJoinType );
	}
}
 
Example 12
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Translates an AST join type (i.e., the token type) into a JoinFragment.XXX join type.
 *
 * @param astJoinType The AST join type (from HqlSqlTokenTypes or SqlTokenTypes)
 * @return a JoinFragment.XXX join type.
 * @see JoinFragment
 * @see SqlTokenTypes
 */
public static int toHibernateJoinType(int astJoinType) {
	switch ( astJoinType ) {
		case LEFT_OUTER:
			return JoinFragment.LEFT_OUTER_JOIN;
		case INNER:
			return JoinFragment.INNER_JOIN;
		case RIGHT_OUTER:
			return JoinFragment.RIGHT_OUTER_JOIN;
		default:
			throw new AssertionFailure( "undefined join type " + astJoinType );
	}
}
 
Example 13
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Translates an AST join type (i.e., the token type) into a JoinFragment.XXX join type.
 *
 * @param astJoinType The AST join type (from HqlSqlTokenTypes or SqlTokenTypes)
 * @return a JoinFragment.XXX join type.
 * @see JoinFragment
 * @see SqlTokenTypes
 */
public static int toHibernateJoinType(int astJoinType) {
	switch ( astJoinType ) {
		case LEFT_OUTER:
			return JoinFragment.LEFT_OUTER_JOIN;
		case INNER:
			return JoinFragment.INNER_JOIN;
		case RIGHT_OUTER:
			return JoinFragment.RIGHT_OUTER_JOIN;
		default:
			throw new AssertionFailure( "undefined join type " + astJoinType );
	}
}
 
Example 14
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Translates an AST join type (i.e., the token type) into a JoinFragment.XXX join type.
 *
 * @param astJoinType The AST join type (from HqlSqlTokenTypes or SqlTokenTypes)
 * @return a JoinFragment.XXX join type.
 * @see JoinFragment
 * @see SqlTokenTypes
 */
public static int toHibernateJoinType(int astJoinType) {
	switch ( astJoinType ) {
		case LEFT_OUTER:
			return JoinFragment.LEFT_OUTER_JOIN;
		case INNER:
			return JoinFragment.INNER_JOIN;
		case RIGHT_OUTER:
			return JoinFragment.RIGHT_OUTER_JOIN;
		default:
			throw new AssertionFailure( "undefined join type " + astJoinType );
	}
}
 
Example 15
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Translates an AST join type (i.e., the token type) into a JoinFragment.XXX join type.
 *
 * @param astJoinType The AST join type (from HqlSqlTokenTypes or SqlTokenTypes)
 * @return a JoinFragment.XXX join type.
 * @see JoinFragment
 * @see SqlTokenTypes
 */
public static int toHibernateJoinType(int astJoinType) {
	switch ( astJoinType ) {
		case LEFT_OUTER:
			return JoinFragment.LEFT_OUTER_JOIN;
		case INNER:
			return JoinFragment.INNER_JOIN;
		case RIGHT_OUTER:
			return JoinFragment.RIGHT_OUTER_JOIN;
		default:
			throw new AssertionFailure( "undefined join type " + astJoinType );
	}
}
 
Example 16
Source File: JoinWalker.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void initPersisters(final List associations, final LockMode lockMode) throws MappingException {
	
	final int joins = countEntityPersisters(associations);
	final int collections = countCollectionPersisters(associations);

	collectionOwners = collections==0 ? null : new int[collections];
	collectionPersisters = collections==0 ? null : new CollectionPersister[collections];
	collectionSuffixes = BasicLoader.generateSuffixes( joins + 1, collections );

	persisters = new Loadable[joins];
	aliases = new String[joins];
	owners = new int[joins];
	ownerAssociationTypes = new EntityType[joins];
	lockModeArray = ArrayHelper.fillArray(lockMode, joins);
	
	int i=0;
	int j=0;
	Iterator iter = associations.iterator();
	while ( iter.hasNext() ) {
		final OuterJoinableAssociation oj = (OuterJoinableAssociation) iter.next();
		if ( !oj.isCollection() ) {
			
			persisters[i] = (Loadable) oj.getJoinable();
			aliases[i] = oj.getRHSAlias();
			owners[i] = oj.getOwner(associations);
			ownerAssociationTypes[i] = (EntityType) oj.getJoinableType();
			i++;
			
		}
		else {
			
			QueryableCollection collPersister = (QueryableCollection) oj.getJoinable();
			if ( oj.getJoinType()==JoinFragment.LEFT_OUTER_JOIN ) {
				//it must be a collection fetch
				collectionPersisters[j] = collPersister;
				collectionOwners[j] = oj.getOwner(associations);
				j++;
			}

			if ( collPersister.isOneToMany() ) {
				persisters[i] = (Loadable) collPersister.getElementPersister();
				aliases[i] = oj.getRHSAlias();
				i++;
			}
		}
	}

	if ( ArrayHelper.isAllNegative(owners) ) owners = null;
	if ( collectionOwners!=null && ArrayHelper.isAllNegative(collectionOwners) ) {
		collectionOwners = null;
	}
}
 
Example 17
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();
	}
}