Search in sources :

Example 1 with LoadQueryInfluencers

use of org.hibernate.engine.spi.LoadQueryInfluencers in project hibernate-orm by hibernate.

the class EncapsulatedCompositeAttributeResultSetProcessorTest method doCompare.

private void doCompare(SessionFactoryImplementor sf, OuterJoinLoadable persister) {
    final LoadQueryInfluencers influencers = LoadQueryInfluencers.NONE;
    final LockMode lockMode = LockMode.NONE;
    final int batchSize = 1;
    final EntityJoinWalker walker = new EntityJoinWalker(persister, persister.getKeyColumnNames(), batchSize, lockMode, sf, influencers);
    final LoadQueryDetails details = Helper.INSTANCE.buildLoadQueryDetails(persister, sf);
    compare(walker, details);
}
Also used : LoadQueryInfluencers(org.hibernate.engine.spi.LoadQueryInfluencers) LoadQueryDetails(org.hibernate.loader.plan.exec.spi.LoadQueryDetails) EntityJoinWalker(org.hibernate.loader.entity.EntityJoinWalker) LockMode(org.hibernate.LockMode)

Example 2 with LoadQueryInfluencers

use of org.hibernate.engine.spi.LoadQueryInfluencers in project hibernate-orm by hibernate.

the class LoadPlanStructureAssertionHelper method performBasicComparison.

/**
 * Performs a basic comparison.  Builds a LoadPlan for the given persister and compares it against the
 * expectations according to the Loader/Walker corollary.
 *
 * @param sf The SessionFactory
 * @param persister The entity persister for which to build a LoadPlan and compare against the Loader/Walker
 * expectations.
 */
public void performBasicComparison(SessionFactoryImplementor sf, OuterJoinLoadable persister) {
    // todo : allow these to be passed in by tests?
    final LoadQueryInfluencers influencers = LoadQueryInfluencers.NONE;
    final LockMode lockMode = LockMode.NONE;
    final int batchSize = 1;
    // legacy Loader-based contracts...
    final EntityJoinWalker walker = new EntityJoinWalker(persister, persister.getKeyColumnNames(), batchSize, lockMode, sf, influencers);
    // final EntityLoader loader = new EntityLoader( persister, lockMode, sf, influencers );
    LoadPlan plan = buildLoadPlan(sf, persister, influencers, lockMode);
    LoadQueryDetails details = BatchingLoadQueryDetailsFactory.INSTANCE.makeEntityLoadQueryDetails(plan, persister.getKeyColumnNames(), new QueryBuildingParametersImpl(influencers, batchSize, lockMode, null), sf);
    compare(walker, details);
}
Also used : LoadQueryInfluencers(org.hibernate.engine.spi.LoadQueryInfluencers) QueryBuildingParametersImpl(org.hibernate.loader.plan.exec.query.internal.QueryBuildingParametersImpl) LoadPlan(org.hibernate.loader.plan.spi.LoadPlan) LoadQueryDetails(org.hibernate.loader.plan.exec.spi.LoadQueryDetails) EntityJoinWalker(org.hibernate.loader.entity.EntityJoinWalker) LockMode(org.hibernate.LockMode)

Example 3 with LoadQueryInfluencers

use of org.hibernate.engine.spi.LoadQueryInfluencers in project hibernate-orm by hibernate.

the class CompositionSingularSubAttributesHelper method getSingularSubAttributes.

private static Iterable<AttributeDefinition> getSingularSubAttributes(final AttributeSource source, final OuterJoinLoadable ownerEntityPersister, final CompositeType compositeType, final String lhsTableName, final String[] lhsColumns) {
    return new Iterable<AttributeDefinition>() {

        @Override
        public Iterator<AttributeDefinition> iterator() {
            return new Iterator<AttributeDefinition>() {

                private final int numberOfAttributes = compositeType.getSubtypes().length;

                private int currentSubAttributeNumber;

                private int currentColumnPosition;

                @Override
                public boolean hasNext() {
                    return currentSubAttributeNumber < numberOfAttributes;
                }

                @Override
                public AttributeDefinition next() {
                    final int subAttributeNumber = currentSubAttributeNumber;
                    currentSubAttributeNumber++;
                    final String name = compositeType.getPropertyNames()[subAttributeNumber];
                    final Type type = compositeType.getSubtypes()[subAttributeNumber];
                    final int columnPosition = currentColumnPosition;
                    final int columnSpan = type.getColumnSpan(ownerEntityPersister.getFactory());
                    final String[] subAttributeLhsColumns = ArrayHelper.slice(lhsColumns, columnPosition, columnSpan);
                    final boolean[] propertyNullability = compositeType.getPropertyNullability();
                    final boolean nullable = propertyNullability == null || propertyNullability[subAttributeNumber];
                    currentColumnPosition += columnSpan;
                    if (type.isAssociationType()) {
                        final AssociationType aType = (AssociationType) type;
                        return new AssociationAttributeDefinition() {

                            @Override
                            public AssociationKey getAssociationKey() {
                                return new AssociationKey(lhsTableName, subAttributeLhsColumns);
                            }

                            @Override
                            public AssociationNature getAssociationNature() {
                                if (type.isAnyType()) {
                                    return AssociationNature.ANY;
                                } else {
                                    // cannot be a collection
                                    return AssociationNature.ENTITY;
                                }
                            }

                            @Override
                            public EntityDefinition toEntityDefinition() {
                                if (getAssociationNature() != AssociationNature.ENTITY) {
                                    throw new WalkingException("Cannot build EntityDefinition from non-entity-typed attribute");
                                }
                                return (EntityPersister) aType.getAssociatedJoinable(ownerEntityPersister.getFactory());
                            }

                            @Override
                            public AnyMappingDefinition toAnyDefinition() {
                                if (getAssociationNature() != AssociationNature.ANY) {
                                    throw new WalkingException("Cannot build AnyMappingDefinition from non-any-typed attribute");
                                }
                                // todo : not sure how lazy is propogated into the component for a subattribute of type any
                                return new StandardAnyTypeDefinition((AnyType) aType, false);
                            }

                            @Override
                            public CollectionDefinition toCollectionDefinition() {
                                throw new WalkingException("A collection cannot be mapped to a composite ID sub-attribute.");
                            }

                            @Override
                            public FetchStrategy determineFetchPlan(LoadQueryInfluencers loadQueryInfluencers, PropertyPath propertyPath) {
                                return new FetchStrategy(FetchTiming.IMMEDIATE, FetchStyle.JOIN);
                            }

                            @Override
                            public CascadeStyle determineCascadeStyle() {
                                return CascadeStyles.NONE;
                            }

                            @Override
                            public HydratedCompoundValueHandler getHydratedCompoundValueExtractor() {
                                return null;
                            }

                            @Override
                            public String getName() {
                                return name;
                            }

                            @Override
                            public AssociationType getType() {
                                return aType;
                            }

                            @Override
                            public boolean isNullable() {
                                return nullable;
                            }

                            @Override
                            public AttributeSource getSource() {
                                return source;
                            }
                        };
                    } else if (type.isComponentType()) {
                        return new CompositionDefinition() {

                            @Override
                            public String getName() {
                                return name;
                            }

                            @Override
                            public CompositeType getType() {
                                return (CompositeType) type;
                            }

                            @Override
                            public boolean isNullable() {
                                return nullable;
                            }

                            @Override
                            public AttributeSource getSource() {
                                return source;
                            }

                            @Override
                            public Iterable<AttributeDefinition> getAttributes() {
                                return CompositionSingularSubAttributesHelper.getSingularSubAttributes(this, ownerEntityPersister, (CompositeType) type, lhsTableName, subAttributeLhsColumns);
                            }
                        };
                    } else {
                        return new AttributeDefinition() {

                            @Override
                            public String getName() {
                                return name;
                            }

                            @Override
                            public Type getType() {
                                return type;
                            }

                            @Override
                            public boolean isNullable() {
                                return nullable;
                            }

                            @Override
                            public AttributeSource getSource() {
                                return source;
                            }
                        };
                    }
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException("Remove operation not supported here");
                }
            };
        }
    };
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) AbstractEntityPersister(org.hibernate.persister.entity.AbstractEntityPersister) AssociationKey(org.hibernate.persister.walking.spi.AssociationKey) AttributeSource(org.hibernate.persister.walking.spi.AttributeSource) FetchStrategy(org.hibernate.engine.FetchStrategy) AssociationAttributeDefinition(org.hibernate.persister.walking.spi.AssociationAttributeDefinition) AttributeDefinition(org.hibernate.persister.walking.spi.AttributeDefinition) WalkingException(org.hibernate.persister.walking.spi.WalkingException) LoadQueryInfluencers(org.hibernate.engine.spi.LoadQueryInfluencers) AnyType(org.hibernate.type.AnyType) CompositeType(org.hibernate.type.CompositeType) AssociationType(org.hibernate.type.AssociationType) Type(org.hibernate.type.Type) AssociationType(org.hibernate.type.AssociationType) Iterator(java.util.Iterator) PropertyPath(org.hibernate.loader.PropertyPath) AssociationAttributeDefinition(org.hibernate.persister.walking.spi.AssociationAttributeDefinition) CompositionDefinition(org.hibernate.persister.walking.spi.CompositionDefinition) CompositeType(org.hibernate.type.CompositeType)

Example 4 with LoadQueryInfluencers

use of org.hibernate.engine.spi.LoadQueryInfluencers in project hibernate-orm by hibernate.

the class EntityGraphLoadPlanBuilderTest method buildLoadPlan.

private LoadPlan buildLoadPlan(EntityGraph entityGraph, Mode mode, Class clazz) {
    LoadQueryInfluencers loadQueryInfluencers = new LoadQueryInfluencers(sfi());
    if (Mode.FETCH == mode) {
        loadQueryInfluencers.setFetchGraph(entityGraph);
    } else {
        loadQueryInfluencers.setLoadGraph(entityGraph);
    }
    EntityPersister ep = (EntityPersister) sfi().getClassMetadata(clazz);
    AbstractLoadPlanBuildingAssociationVisitationStrategy strategy = Mode.FETCH == mode ? new FetchGraphLoadPlanBuildingStrategy(sfi(), loadQueryInfluencers, LockMode.NONE) : new LoadGraphLoadPlanBuildingStrategy(sfi(), loadQueryInfluencers, LockMode.NONE);
    return MetamodelDrivenLoadPlanBuilder.buildRootEntityLoadPlan(strategy, ep);
}
Also used : LoadQueryInfluencers(org.hibernate.engine.spi.LoadQueryInfluencers) EntityPersister(org.hibernate.persister.entity.EntityPersister) AbstractLoadPlanBuildingAssociationVisitationStrategy(org.hibernate.loader.plan.build.internal.AbstractLoadPlanBuildingAssociationVisitationStrategy) FetchGraphLoadPlanBuildingStrategy(org.hibernate.loader.plan.build.internal.FetchGraphLoadPlanBuildingStrategy) LoadGraphLoadPlanBuildingStrategy(org.hibernate.loader.plan.build.internal.LoadGraphLoadPlanBuildingStrategy)

Example 5 with LoadQueryInfluencers

use of org.hibernate.engine.spi.LoadQueryInfluencers in project hibernate-orm by hibernate.

the class TwoPhaseLoad method isEagerFetchProfile.

private static Boolean isEagerFetchProfile(SharedSessionContractImplementor session, String role) {
    LoadQueryInfluencers loadQueryInfluencers = session.getLoadQueryInfluencers();
    for (String fetchProfileName : loadQueryInfluencers.getEnabledFetchProfileNames()) {
        FetchProfile fp = session.getFactory().getFetchProfile(fetchProfileName);
        Fetch fetch = fp.getFetchByRole(role);
        if (fetch != null && Fetch.Style.JOIN == fetch.getStyle()) {
            return true;
        }
    }
    return null;
}
Also used : LoadQueryInfluencers(org.hibernate.engine.spi.LoadQueryInfluencers) Fetch(org.hibernate.engine.profile.Fetch) FetchProfile(org.hibernate.engine.profile.FetchProfile)

Aggregations

LoadQueryInfluencers (org.hibernate.engine.spi.LoadQueryInfluencers)5 LockMode (org.hibernate.LockMode)2 EntityJoinWalker (org.hibernate.loader.entity.EntityJoinWalker)2 LoadQueryDetails (org.hibernate.loader.plan.exec.spi.LoadQueryDetails)2 EntityPersister (org.hibernate.persister.entity.EntityPersister)2 Iterator (java.util.Iterator)1 FetchStrategy (org.hibernate.engine.FetchStrategy)1 Fetch (org.hibernate.engine.profile.Fetch)1 FetchProfile (org.hibernate.engine.profile.FetchProfile)1 PropertyPath (org.hibernate.loader.PropertyPath)1 AbstractLoadPlanBuildingAssociationVisitationStrategy (org.hibernate.loader.plan.build.internal.AbstractLoadPlanBuildingAssociationVisitationStrategy)1 FetchGraphLoadPlanBuildingStrategy (org.hibernate.loader.plan.build.internal.FetchGraphLoadPlanBuildingStrategy)1 LoadGraphLoadPlanBuildingStrategy (org.hibernate.loader.plan.build.internal.LoadGraphLoadPlanBuildingStrategy)1 QueryBuildingParametersImpl (org.hibernate.loader.plan.exec.query.internal.QueryBuildingParametersImpl)1 LoadPlan (org.hibernate.loader.plan.spi.LoadPlan)1 AbstractEntityPersister (org.hibernate.persister.entity.AbstractEntityPersister)1 AssociationAttributeDefinition (org.hibernate.persister.walking.spi.AssociationAttributeDefinition)1 AssociationKey (org.hibernate.persister.walking.spi.AssociationKey)1 AttributeDefinition (org.hibernate.persister.walking.spi.AttributeDefinition)1 AttributeSource (org.hibernate.persister.walking.spi.AttributeSource)1