use of org.hibernate.loader.plan.spi.JoinDefinedByMetadata in project hibernate-orm by hibernate.
the class EntityQuerySpaceImpl method makeCompositeIdentifierQuerySpace.
@Override
public ExpandingCompositeQuerySpace makeCompositeIdentifierQuerySpace() {
final String compositeQuerySpaceUid = getUid() + "-id";
final ExpandingCompositeQuerySpace rhs = getExpandingQuerySpaces().makeCompositeQuerySpace(compositeQuerySpaceUid, new CompositePropertyMapping((CompositeType) getEntityPersister().getIdentifierType(), (PropertyMapping) getEntityPersister(), getEntityPersister().getIdentifierPropertyName()), canJoinsBeRequired());
final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createCompositeJoin(this, EntityPersister.ENTITY_ID, rhs, canJoinsBeRequired(), (CompositeType) persister.getIdentifierType());
internalGetJoins().add(join);
return rhs;
}
use of org.hibernate.loader.plan.spi.JoinDefinedByMetadata in project hibernate-orm by hibernate.
the class QuerySpaceHelper method makeCollectionQuerySpace.
public ExpandingCollectionQuerySpace makeCollectionQuerySpace(ExpandingQuerySpace lhsQuerySpace, AssociationAttributeDefinition attributeDefinition, String querySpaceUid, FetchStrategy fetchStrategy) {
final CollectionType fetchedType = (CollectionType) attributeDefinition.getType();
final CollectionPersister fetchedPersister = attributeDefinition.toCollectionDefinition().getCollectionPersister();
if (fetchedPersister == null) {
throw new WalkingException(String.format("Unable to locate CollectionPersister [%s] for fetch [%s]", fetchedType.getRole(), attributeDefinition.getName()));
}
final boolean required = lhsQuerySpace.canJoinsBeRequired() && !attributeDefinition.isNullable();
final ExpandingCollectionQuerySpace rhs = lhsQuerySpace.getExpandingQuerySpaces().makeCollectionQuerySpace(querySpaceUid, fetchedPersister, required);
if (shouldIncludeJoin(fetchStrategy)) {
final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createCollectionJoin(lhsQuerySpace, attributeDefinition.getName(), rhs, required, (CollectionType) attributeDefinition.getType(), fetchedPersister.getFactory());
lhsQuerySpace.addJoin(join);
}
return rhs;
}
use of org.hibernate.loader.plan.spi.JoinDefinedByMetadata in project hibernate-orm by hibernate.
the class LoadQueryJoinAndFetchProcessor method renderManyToManyJoin.
private void renderManyToManyJoin(Join join, JoinFragment joinFragment) {
// for many-to-many we have 3 table aliases. By way of example, consider a normal m-n: User<->Role
// where User is the FetchOwner and Role (User.roles) is the Fetch. We'd have:
// 1) the owner's table : user - in terms of rendering the joins (not the fetch select fragments), the
// lhs table alias is only needed to qualify the lhs join columns, but we already have the qualified
// columns here (aliasedLhsColumnNames)
//final String ownerTableAlias = ...;
// 2) the m-n table : user_role
// 3) the element table : role
final EntityPersister entityPersister = ((EntityQuerySpace) join.getRightHandSide()).getEntityPersister();
final String entityTableAlias = aliasResolutionContext.resolveSqlTableAliasFromQuerySpaceUid(join.getRightHandSide().getUid());
if (StringHelper.isEmpty(entityTableAlias)) {
throw new IllegalStateException("Collection element (many-to-many) table alias cannot be empty");
}
final String manyToManyFilter;
if (JoinDefinedByMetadata.class.isInstance(join) && CollectionPropertyNames.COLLECTION_ELEMENTS.equals(((JoinDefinedByMetadata) join).getJoinedPropertyName())) {
final CollectionQuerySpace leftHandSide = (CollectionQuerySpace) join.getLeftHandSide();
final CollectionPersister persister = leftHandSide.getCollectionPersister();
manyToManyFilter = persister.getManyToManyFilterFragment(entityTableAlias, buildingParameters.getQueryInfluencers().getEnabledFilters());
} else {
manyToManyFilter = null;
}
addJoins(join, joinFragment, (Joinable) entityPersister, manyToManyFilter);
}
use of org.hibernate.loader.plan.spi.JoinDefinedByMetadata in project hibernate-orm by hibernate.
the class QuerySpaceHelper method makeEntityQuerySpace.
public ExpandingEntityQuerySpace makeEntityQuerySpace(ExpandingQuerySpace lhsQuerySpace, EntityPersister fetchedPersister, String attributeName, EntityType attributeType, String querySpaceUid, boolean required, boolean shouldIncludeJoin) {
final ExpandingEntityQuerySpace rhs = lhsQuerySpace.getExpandingQuerySpaces().makeEntityQuerySpace(querySpaceUid, fetchedPersister, required);
if (shouldIncludeJoin) {
final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createEntityJoin(lhsQuerySpace, attributeName, rhs, required, attributeType, fetchedPersister.getFactory());
lhsQuerySpace.addJoin(join);
}
return rhs;
}
use of org.hibernate.loader.plan.spi.JoinDefinedByMetadata in project hibernate-orm by hibernate.
the class QuerySpaceHelper method makeCompositeQuerySpace.
public ExpandingCompositeQuerySpace makeCompositeQuerySpace(ExpandingQuerySpace lhsQuerySpace, CompositePropertyMapping compositePropertyMapping, String attributeName, CompositeType attributeType, String querySpaceUid, boolean required, boolean shouldIncludeJoin) {
final ExpandingCompositeQuerySpace rhs = lhsQuerySpace.getExpandingQuerySpaces().makeCompositeQuerySpace(querySpaceUid, compositePropertyMapping, required);
if (shouldIncludeJoin) {
final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createCompositeJoin(lhsQuerySpace, attributeName, rhs, required, attributeType);
lhsQuerySpace.addJoin(join);
}
return rhs;
}
Aggregations