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

The following examples show how to use org.hibernate.sql.JoinFragment#INNER_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: JoinWalker.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Should we join this association?
 */
protected boolean isJoinable(
	final int joinType,
	final Set visitedAssociationKeys, 
	final String lhsTable,
	final String[] lhsColumnNames,
	final AssociationType type,
	final int depth
) {
	if (joinType<0) return false;
	
	if (joinType==JoinFragment.INNER_JOIN) return true;
	
	Integer maxFetchDepth = getFactory().getSettings().getMaximumFetchDepth();
	final boolean tooDeep = maxFetchDepth!=null && 
		depth >= maxFetchDepth.intValue();
	
	return !tooDeep && !isDuplicateAssociation(lhsTable, lhsColumnNames, type);
}
 
Example 2
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 3
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 4
Source File: IdentNode.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void resolveIndex(AST parent) throws SemanticException {
	// An ident node can represent an index expression if the ident
	// represents a naked property ref
	//      *Note: this makes the assumption (which is currently the case
	//      in the hql-sql grammar) that the ident is first resolved
	//      itself (addrExpr -> resolve()).  The other option, if that
	//      changes, is to call resolve from here; but it is
	//      currently un-needed overhead.
	if (!(isResolved() && nakedPropertyRef)) {
		throw new UnsupportedOperationException();
	}

	String propertyName = getOriginalText();
	if (!getDataType().isCollectionType()) {
		throw new SemanticException("Collection expected; [" + propertyName + "] does not refer to a collection property");
	}

	// TODO : most of below was taken verbatim from DotNode; should either delegate this logic or super-type it
	CollectionType type = (CollectionType) getDataType();
	String role = type.getRole();
	QueryableCollection queryableCollection = getSessionFactoryHelper().requireQueryableCollection(role);

	String alias = null;  // DotNode uses null here...
	String columnTableAlias = getFromElement().getTableAlias();
	int joinType = JoinFragment.INNER_JOIN;
	boolean fetch = false;

	FromElementFactory factory = new FromElementFactory(
			getWalker().getCurrentFromClause(),
			getFromElement(),
			propertyName,
			alias,
			getFromElement().toColumns(columnTableAlias, propertyName, false),
			true
	);
	FromElement elem = factory.createCollection(queryableCollection, role, joinType, fetch, true);
	setFromElement(elem);
	getWalker().addQuerySpaces(queryableCollection.getCollectionSpaces());	// Always add the collection's query spaces.
}
 
Example 5
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 6
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 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: 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 17
Source File: FromElementFactory.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
FromElement createElementJoin(QueryableCollection queryableCollection) throws SemanticException {
		FromElement elem;

		implied = true; //TODO: always true for now, but not if we later decide to support elements() in the from clause
		inElementsFunction = true;
		Type elementType = queryableCollection.getElementType();
		if ( !elementType.isEntityType() ) {
			throw new IllegalArgumentException( "Cannot create element join for a collection of non-entities!" );
		}
		this.queryableCollection = queryableCollection;
		SessionFactoryHelper sfh = fromClause.getSessionFactoryHelper();
		FromElement destination = null;
		String tableAlias = null;
		EntityPersister entityPersister = queryableCollection.getElementPersister();
		tableAlias = fromClause.getAliasGenerator().createName( entityPersister.getEntityName() );
		String associatedEntityName = entityPersister.getEntityName();
		EntityPersister targetEntityPersister = sfh.requireClassPersister( associatedEntityName );
		// Create the FROM element for the target (the elements of the collection).
		destination = createAndAddFromElement( 
				associatedEntityName,
				classAlias,
				targetEntityPersister,
				( EntityType ) queryableCollection.getElementType(),
				tableAlias
			);
		// If the join is implied, then don't include sub-classes on the element.
		if ( implied ) {
			destination.setIncludeSubclasses( false );
		}
		fromClause.addCollectionJoinFromElementByPath( path, destination );
//		origin.addDestination(destination);
		// Add the query spaces.
		fromClause.getWalker().addQuerySpaces( entityPersister.getQuerySpaces() );

		CollectionType type = queryableCollection.getCollectionType();
		String role = type.getRole();
		String roleAlias = origin.getTableAlias();

		String[] targetColumns = sfh.getCollectionElementColumns( role, roleAlias );
		AssociationType elementAssociationType = sfh.getElementAssociationType( type );

		// Create the join element under the from element.
		int joinType = JoinFragment.INNER_JOIN;
		JoinSequence joinSequence = sfh.createJoinSequence( implied, elementAssociationType, tableAlias, joinType, targetColumns );
		elem = initializeJoin( path, destination, joinSequence, targetColumns, origin, false );
		elem.setUseFromFragment( true );	// The associated entity is implied, but it must be included in the FROM.
		elem.setCollectionTableAlias( roleAlias );	// The collection alias is the role.
		return elem;
	}