Search in sources :

Example 1 with JoinDefinedByMetadata

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;
}
Also used : ExpandingCompositeQuerySpace(org.hibernate.loader.plan.build.spi.ExpandingCompositeQuerySpace) PropertyMapping(org.hibernate.persister.entity.PropertyMapping) JoinDefinedByMetadata(org.hibernate.loader.plan.spi.JoinDefinedByMetadata) CompositeType(org.hibernate.type.CompositeType)

Example 2 with JoinDefinedByMetadata

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;
}
Also used : CollectionPersister(org.hibernate.persister.collection.CollectionPersister) CollectionType(org.hibernate.type.CollectionType) JoinDefinedByMetadata(org.hibernate.loader.plan.spi.JoinDefinedByMetadata) WalkingException(org.hibernate.persister.walking.spi.WalkingException) ExpandingCollectionQuerySpace(org.hibernate.loader.plan.build.spi.ExpandingCollectionQuerySpace)

Example 3 with JoinDefinedByMetadata

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);
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) CollectionPersister(org.hibernate.persister.collection.CollectionPersister) JoinDefinedByMetadata(org.hibernate.loader.plan.spi.JoinDefinedByMetadata) EntityQuerySpace(org.hibernate.loader.plan.spi.EntityQuerySpace) CollectionQuerySpace(org.hibernate.loader.plan.spi.CollectionQuerySpace)

Example 4 with JoinDefinedByMetadata

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;
}
Also used : JoinDefinedByMetadata(org.hibernate.loader.plan.spi.JoinDefinedByMetadata) ExpandingEntityQuerySpace(org.hibernate.loader.plan.build.spi.ExpandingEntityQuerySpace)

Example 5 with JoinDefinedByMetadata

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;
}
Also used : ExpandingCompositeQuerySpace(org.hibernate.loader.plan.build.spi.ExpandingCompositeQuerySpace) JoinDefinedByMetadata(org.hibernate.loader.plan.spi.JoinDefinedByMetadata)

Aggregations

JoinDefinedByMetadata (org.hibernate.loader.plan.spi.JoinDefinedByMetadata)6 ExpandingCompositeQuerySpace (org.hibernate.loader.plan.build.spi.ExpandingCompositeQuerySpace)2 CollectionQuerySpace (org.hibernate.loader.plan.spi.CollectionQuerySpace)2 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)2 AssertionFailure (org.hibernate.AssertionFailure)1 ExpandingCollectionQuerySpace (org.hibernate.loader.plan.build.spi.ExpandingCollectionQuerySpace)1 ExpandingEntityQuerySpace (org.hibernate.loader.plan.build.spi.ExpandingEntityQuerySpace)1 EntityQuerySpace (org.hibernate.loader.plan.spi.EntityQuerySpace)1 Join (org.hibernate.loader.plan.spi.Join)1 EntityPersister (org.hibernate.persister.entity.EntityPersister)1 PropertyMapping (org.hibernate.persister.entity.PropertyMapping)1 WalkingException (org.hibernate.persister.walking.spi.WalkingException)1 CollectionType (org.hibernate.type.CollectionType)1 CompositeType (org.hibernate.type.CompositeType)1