use of org.hibernate.graph.spi.RootGraphImplementor in project hibernate-orm by hibernate.
the class LoaderSelectBuilder method determineGraphTraversalState.
private static EntityGraphTraversalState determineGraphTraversalState(LoadQueryInfluencers loadQueryInfluencers) {
if (loadQueryInfluencers != null) {
final EffectiveEntityGraph effectiveEntityGraph = loadQueryInfluencers.getEffectiveEntityGraph();
if (effectiveEntityGraph != null) {
final GraphSemantic graphSemantic = effectiveEntityGraph.getSemantic();
final RootGraphImplementor rootGraphImplementor = effectiveEntityGraph.getGraph();
if (graphSemantic != null && rootGraphImplementor != null) {
return new StandardEntityGraphTraversalStateImpl(graphSemantic, rootGraphImplementor);
}
}
}
return null;
}
use of org.hibernate.graph.spi.RootGraphImplementor in project hibernate-orm by hibernate.
the class CriteriaEntityGraphTest method testSemanticsWithSubgraph.
@ParameterizedTest
@EnumSource(GraphSemantic.class)
void testSemanticsWithSubgraph(GraphSemantic graphSemantic) {
scope.inTransaction(session -> {
final RootGraphImplementor<Cat> eg = session.createEntityGraph(Cat.class);
eg.addSubgraph("owner", Person.class);
final SelectStatement sqlAst = buildSqlSelectAst(Cat.class, eg, graphSemantic, session);
// Check the from-clause
assertEntityValuedJoinedGroup(sqlAst, "owner", Person.class, this::assertPersonHomeAddressJoinedGroup);
// Check the domain-result graph
assertDomainResult(sqlAst, Cat.class, "owner", Person.class, entityFetch -> {
if (graphSemantic == GraphSemantic.LOAD) {
assertThat(entityFetch, instanceOf(EntityFetchJoinedImpl.class));
final EntityResult entityResult = ((EntityFetchJoinedImpl) entityFetch).getEntityResult();
final Map<String, Class<? extends Fetch>> fetchClassByAttributeName = entityResult.getFetches().stream().collect(Collectors.toMap(fetch -> fetch.getFetchedMapping().getPartName(), Fetch::getClass));
final Map<String, Class<? extends Fetch>> expectedFetchClassByAttributeName = new HashMap<>();
expectedFetchClassByAttributeName.put("pets", DelayedCollectionFetch.class);
expectedFetchClassByAttributeName.put("homeAddress", EmbeddableFetchImpl.class);
expectedFetchClassByAttributeName.put("company", EntityDelayedFetchImpl.class);
assertThat(fetchClassByAttributeName, is(expectedFetchClassByAttributeName));
}
});
});
}
use of org.hibernate.graph.spi.RootGraphImplementor in project hibernate-reactive by hibernate.
the class ReactiveStatelessSessionImpl method reactiveGet.
@Override
public <T> CompletionStage<T> reactiveGet(Class<? extends T> entityClass, Object id, LockMode lockMode, EntityGraph<T> fetchGraph) {
checkOpen();
if (fetchGraph != null) {
getLoadQueryInfluencers().getEffectiveEntityGraph().applyGraph((RootGraphImplementor<T>) fetchGraph, GraphSemantic.FETCH);
}
ReactiveEntityPersister persister = (ReactiveEntityPersister) getFactory().getMetamodel().entityPersister(entityClass);
LockOptions lockOptions = getNullSafeLockOptions(lockMode);
return persister.reactiveLoad((Serializable) id, null, lockOptions, this).whenComplete((v, e) -> {
if (getPersistenceContext().isLoadFinished()) {
getPersistenceContext().clear();
}
getLoadQueryInfluencers().getEffectiveEntityGraph().clear();
}).thenApply(entity -> (T) entity);
}
use of org.hibernate.graph.spi.RootGraphImplementor in project hibernate-reactive by hibernate.
the class ReactiveSessionImpl method reactiveInternalLoad.
@Override
public CompletionStage<Object> reactiveInternalLoad(String entityName, Serializable id, boolean eager, boolean nullable) {
final EffectiveEntityGraph effectiveEntityGraph = getLoadQueryInfluencers().getEffectiveEntityGraph();
final GraphSemantic semantic = effectiveEntityGraph.getSemantic();
final RootGraphImplementor<?> graph = effectiveEntityGraph.getGraph();
boolean clearedEffectiveGraph;
if (semantic == null || graph.appliesTo(entityName)) {
clearedEffectiveGraph = false;
} else {
// log.debug( "Clearing effective entity graph for subsequent-select" );
clearedEffectiveGraph = true;
effectiveEntityGraph.clear();
}
final LoadEventListener.LoadType type;
if (nullable) {
type = LoadEventListener.INTERNAL_LOAD_NULLABLE;
} else {
type = eager ? LoadEventListener.INTERNAL_LOAD_EAGER : LoadEventListener.INTERNAL_LOAD_LAZY;
}
threadCheck();
LoadEvent event = new LoadEvent(id, entityName, true, this, getReadOnlyFromLoadQueryInfluencers());
return fireLoadNoChecks(event, type).thenApply(v -> {
Object result = event.getResult();
if (!nullable) {
UnresolvableObjectException.throwIfNull(result, id, entityName);
}
return result;
}).whenComplete((v, x) -> {
if (clearedEffectiveGraph) {
effectiveEntityGraph.applyGraph(graph, semantic);
}
});
}
Aggregations