Java Code Examples for org.hibernate.type.AssociationType#getAssociatedJoinable()

The following examples show how to use org.hibernate.type.AssociationType#getAssociatedJoinable() . 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 OuterJoinableAssociation(
		PropertyPath propertyPath,
		AssociationType joinableType,
		String lhsAlias,
		String[] lhsColumns,
		String rhsAlias,
		JoinType joinType,
		String withClause,
		boolean hasRestriction,
		SessionFactoryImplementor factory,
		Map enabledFilters) throws MappingException {
	this.propertyPath = propertyPath;
	this.joinableType = joinableType;
	this.lhsAlias = lhsAlias;
	this.lhsColumns = lhsColumns;
	this.rhsAlias = rhsAlias;
	this.joinType = joinType;
	this.joinable = joinableType.getAssociatedJoinable( factory );
	this.rhsColumns = JoinHelper.getRHSColumnNames( joinableType, factory );
	this.on = joinableType.getOnCondition( rhsAlias, factory, enabledFilters )
			+ ( withClause == null || withClause.trim().length() == 0 ? "" : " and ( " + withClause + " )" );
	this.hasRestriction = hasRestriction;
	this.enabledFilters = enabledFilters; // needed later for many-to-many/filter application
}
 
Example 2
Source File: OuterJoinableAssociation.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public OuterJoinableAssociation(
	AssociationType joinableType,
	String lhsAlias,
	String[] lhsColumns,
	String rhsAlias,
	int joinType,
	SessionFactoryImplementor factory,
	Map enabledFilters)
throws MappingException {
	this.joinableType = joinableType;
	this.lhsAlias = lhsAlias;
	this.lhsColumns = lhsColumns;
	this.rhsAlias = rhsAlias;
	this.joinType = joinType;
	this.joinable = joinableType.getAssociatedJoinable(factory);
	this.rhsColumns = JoinHelper.getRHSColumnNames(joinableType, factory);
	this.on = joinableType.getOnCondition(rhsAlias, factory, enabledFilters);
	this.enabledFilters = enabledFilters; // needed later for many-to-many/filter application
}
 
Example 3
Source File: EntityBasedAssociationAttribute.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public AssociationKey getAssociationKey() {
	final AssociationType type = getType();

	if ( type.isAnyType() ) {
		return new AssociationKey(
				JoinHelper.getLHSTableName( type, attributeNumber(), (OuterJoinLoadable) getSource() ),
				JoinHelper.getLHSColumnNames(
						type,
						attributeNumber(),
						0,
						(OuterJoinLoadable) getSource(),
						sessionFactory()
				)
		);
	}

	final Joinable joinable = type.getAssociatedJoinable( sessionFactory() );

	if ( type.getForeignKeyDirection() == ForeignKeyDirection.FROM_PARENT ) {
		final String lhsTableName;
		final String[] lhsColumnNames;

		if ( joinable.isCollection() ) {
			final QueryableCollection collectionPersister = (QueryableCollection) joinable;
			lhsTableName = collectionPersister.getTableName();
			lhsColumnNames = collectionPersister.getElementColumnNames();
		}
		else {
			final OuterJoinLoadable entityPersister = (OuterJoinLoadable) source();
			lhsTableName = getLHSTableName( type, attributeNumber(), entityPersister );
			lhsColumnNames = getLHSColumnNames( type, attributeNumber(), entityPersister, sessionFactory() );
		}
		return new AssociationKey( lhsTableName, lhsColumnNames );
	}
	else {
		return new AssociationKey( joinable.getTableName(), getRHSColumnNames( type, sessionFactory() ) );
	}
}
 
Example 4
Source File: JoinHelper.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Get the columns of the associated table which are to 
 * be used in the join
 */
public static String[] getRHSColumnNames(AssociationType type, SessionFactoryImplementor factory) {
	String uniqueKeyPropertyName = type.getRHSUniqueKeyPropertyName();
	Joinable joinable = type.getAssociatedJoinable(factory);
	if (uniqueKeyPropertyName==null) {
		return joinable.getKeyColumnNames();
	}
	else {
		return ( (OuterJoinLoadable) joinable ).getPropertyColumnNames(uniqueKeyPropertyName);
	}
}
 
Example 5
Source File: JoinSequence.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
Join(AssociationType associationType, String alias, int joinType, String[] lhsColumns)
		throws MappingException {
	this.associationType = associationType;
	this.joinable = associationType.getAssociatedJoinable( factory );
	this.alias = alias;
	this.joinType = joinType;
	this.lhsColumns = lhsColumns;
}
 
Example 6
Source File: JoinSequence.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
Join(AssociationType associationType, String alias, int joinType, String[] lhsColumns)
		throws MappingException {
	this.associationType = associationType;
	this.joinable = associationType.getAssociatedJoinable( factory );
	this.alias = alias;
	this.joinType = joinType;
	this.lhsColumns = lhsColumns;
}
 
Example 7
Source File: JoinSequence.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
Join(AssociationType associationType, String alias, int joinType, String[] lhsColumns)
		throws MappingException {
	this.associationType = associationType;
	this.joinable = associationType.getAssociatedJoinable( factory );
	this.alias = alias;
	this.joinType = joinType;
	this.lhsColumns = lhsColumns;
}
 
Example 8
Source File: JoinSequence.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
Join(AssociationType associationType, String alias, int joinType, String[] lhsColumns)
		throws MappingException {
	this.associationType = associationType;
	this.joinable = associationType.getAssociatedJoinable( factory );
	this.alias = alias;
	this.joinType = joinType;
	this.lhsColumns = lhsColumns;
}
 
Example 9
Source File: JoinSequence.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
Join(AssociationType associationType, String alias, int joinType, String[] lhsColumns)
		throws MappingException {
	this.associationType = associationType;
	this.joinable = associationType.getAssociatedJoinable( factory );
	this.alias = alias;
	this.joinType = joinType;
	this.lhsColumns = lhsColumns;
}
 
Example 10
Source File: JoinSequence.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
Join(AssociationType associationType, String alias, int joinType, String[] lhsColumns)
		throws MappingException {
	this.associationType = associationType;
	this.joinable = associationType.getAssociatedJoinable( factory );
	this.alias = alias;
	this.joinType = joinType;
	this.lhsColumns = lhsColumns;
}
 
Example 11
Source File: JoinSequence.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
Join(AssociationType associationType, String alias, int joinType, String[] lhsColumns)
		throws MappingException {
	this.associationType = associationType;
	this.joinable = associationType.getAssociatedJoinable( factory );
	this.alias = alias;
	this.joinType = joinType;
	this.lhsColumns = lhsColumns;
}
 
Example 12
Source File: JoinSequence.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
Join(AssociationType associationType, String alias, int joinType, String[] lhsColumns)
		throws MappingException {
	this.associationType = associationType;
	this.joinable = associationType.getAssociatedJoinable( factory );
	this.alias = alias;
	this.joinType = joinType;
	this.lhsColumns = lhsColumns;
}
 
Example 13
Source File: JoinSequence.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
Join(AssociationType associationType, String alias, int joinType, String[] lhsColumns)
		throws MappingException {
	this.associationType = associationType;
	this.joinable = associationType.getAssociatedJoinable( factory );
	this.alias = alias;
	this.joinType = joinType;
	this.lhsColumns = lhsColumns;
}
 
Example 14
Source File: JoinSequence.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
Join(AssociationType associationType, String alias, int joinType, String[] lhsColumns)
		throws MappingException {
	this.associationType = associationType;
	this.joinable = associationType.getAssociatedJoinable( factory );
	this.alias = alias;
	this.joinType = joinType;
	this.lhsColumns = lhsColumns;
}
 
Example 15
Source File: JoinSequence.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
Join(AssociationType associationType, String alias, int joinType, String[] lhsColumns)
		throws MappingException {
	this.associationType = associationType;
	this.joinable = associationType.getAssociatedJoinable( factory );
	this.alias = alias;
	this.joinType = joinType;
	this.lhsColumns = lhsColumns;
}
 
Example 16
Source File: JoinSequence.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
Join(
		SessionFactoryImplementor factory,
		AssociationType associationType,
		String alias,
		JoinType joinType,
		String[][] lhsColumns) throws MappingException {
	this.associationType = associationType;
	this.joinable = associationType.getAssociatedJoinable( factory );
	this.alias = alias;
	this.joinType = joinType;
	this.lhsColumns = lhsColumns;
}
 
Example 17
Source File: JoinHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the columns of the associated table which are to be used in the join
 *
 * @param type The type
 * @param factory The SessionFactory
 *
 * @return The columns for the right-hand-side of the join
 */
public static String[] getRHSColumnNames(AssociationType type, SessionFactoryImplementor factory) {
	final String uniqueKeyPropertyName = type.getRHSUniqueKeyPropertyName();
	final Joinable joinable = type.getAssociatedJoinable( factory );
	if ( uniqueKeyPropertyName == null ) {
		return joinable.getKeyColumnNames();
	}
	else {
		return ( (OuterJoinLoadable) joinable ).getPropertyColumnNames( uniqueKeyPropertyName );
	}
}
 
Example 18
Source File: JoinSequence.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
Join(AssociationType associationType, String alias, int joinType, String[] lhsColumns)
		throws MappingException {
	this.associationType = associationType;
	this.joinable = associationType.getAssociatedJoinable( factory );
	this.alias = alias;
	this.joinType = joinType;
	this.lhsColumns = lhsColumns;
}
 
Example 19
Source File: AttributeNodeImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private <X> SubgraphImpl<X> internalMakeKeySubgraph(Class<X> type) {
	if ( ! attribute.isCollection() ) {
		throw new IllegalArgumentException(
				String.format( "Non-collection attribute [%s] cannot be target of key subgraph", getAttributeName() )
		);
	}

	final PluralAttributeImpl pluralAttribute = (PluralAttributeImpl) attribute;
	if ( pluralAttribute.getCollectionType() != PluralAttribute.CollectionType.MAP ) {
		throw new IllegalArgumentException(
				String.format( "Non-Map attribute [%s] cannot be target of key subgraph", getAttributeName() )
		);
	}

	final AssociationType attributeType = (AssociationType) Helper.resolveType( sessionFactory(), attribute );
	final QueryableCollection collectionPersister = (QueryableCollection) attributeType.getAssociatedJoinable( sessionFactory() );
	final Type indexType = collectionPersister.getIndexType();

	if ( ! indexType.isAssociationType() ) {
		throw new IllegalArgumentException(
				String.format( "Map index [%s] is not an entity; cannot be target of key subgraph", getAttributeName() )
		);
	}

	if ( keySubgraphMap == null ) {
		keySubgraphMap = new HashMap<>();
	}

	final AssociationType indexAssociationType = (AssociationType) indexType;
	final EntityPersister indexEntityPersister = (EntityPersister) indexAssociationType.getAssociatedJoinable( sessionFactory() );

	if ( type == null ) {
		type = indexEntityPersister.getMappedClass();
	}
	else {
		if ( !isTreatableAs( indexEntityPersister, type ) ) {
			throw new IllegalArgumentException(
					String.format(
							"Map key [%s] cannot be treated as requested type [%s] : %s",
							getAttributeName(),
							type.getName(),
							indexEntityPersister.getMappedClass().getName()
					)
			);
		}
	}

	final SubgraphImpl<X> subgraph = new SubgraphImpl<>( this.sessionFactory, attribute.getDeclaringType(), type );
	keySubgraphMap.put( type, subgraph );
	return subgraph;
}
 
Example 20
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
				);
			}
		}

	}