use of org.hibernate.engine.spi.EffectiveEntityGraph in project hibernate-orm by hibernate.
the class SessionImpl method internalLoad.
@Override
public Object internalLoad(String entityName, Object id, boolean eager, boolean nullable) {
final EffectiveEntityGraph effectiveEntityGraph = getLoadQueryInfluencers().getEffectiveEntityGraph();
final GraphSemantic semantic = effectiveEntityGraph.getSemantic();
final RootGraphImplementor<?> graph = effectiveEntityGraph.getGraph();
boolean clearedEffectiveGraph = false;
if (semantic != null) {
if (!graph.appliesTo(entityName)) {
log.debug("Clearing effective entity graph for subsequent-select");
clearedEffectiveGraph = true;
effectiveEntityGraph.clear();
}
}
try {
final LoadType type;
if (nullable) {
type = LoadEventListener.INTERNAL_LOAD_NULLABLE;
} else {
type = eager ? LoadEventListener.INTERNAL_LOAD_EAGER : LoadEventListener.INTERNAL_LOAD_LAZY;
}
LoadEvent event = loadEvent;
loadEvent = null;
event = recycleEventInstance(event, id, entityName);
fireLoadNoChecks(event, type);
Object result = event.getResult();
if (!nullable) {
UnresolvableObjectException.throwIfNull(result, id, entityName);
}
if (loadEvent == null) {
event.setEntityClassName(null);
event.setEntityId(null);
event.setInstanceToLoad(null);
event.setResult(null);
loadEvent = event;
}
return result;
} finally {
if (clearedEffectiveGraph) {
effectiveEntityGraph.applyGraph(graph, semantic);
}
}
}
use of org.hibernate.engine.spi.EffectiveEntityGraph 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.engine.spi.EffectiveEntityGraph in project hibernate-orm by hibernate.
the class NaturalIdMultiLoadAccessStandard method multiLoad.
@Override
@SuppressWarnings("unchecked")
public List<T> multiLoad(Object... ids) {
final CacheMode sessionCacheMode = session.getCacheMode();
boolean cacheModeChanged = false;
if (cacheMode != null) {
// todo : account for "conceptually equal"
if (cacheMode != sessionCacheMode) {
session.setCacheMode(cacheMode);
cacheModeChanged = true;
}
}
session.autoFlushIfRequired((Set) CollectionHelper.setOf(entityDescriptor.getQuerySpaces()));
final LoadQueryInfluencers loadQueryInfluencers = session.getLoadQueryInfluencers();
try {
final EffectiveEntityGraph effectiveEntityGraph = loadQueryInfluencers.getEffectiveEntityGraph();
final GraphSemantic initialGraphSemantic = effectiveEntityGraph.getSemantic();
final RootGraphImplementor<?> initialGraph = effectiveEntityGraph.getGraph();
final boolean hadInitialGraph = initialGraphSemantic != null;
if (graphSemantic != null) {
if (rootGraph == null) {
throw new IllegalArgumentException("Graph semantic specified, but no RootGraph was supplied");
}
effectiveEntityGraph.applyGraph(rootGraph, graphSemantic);
}
try {
return (List<T>) entityDescriptor.getMultiNaturalIdLoader().multiLoad(ids, this, session);
} finally {
if (graphSemantic != null) {
if (hadInitialGraph) {
effectiveEntityGraph.applyGraph(initialGraph, initialGraphSemantic);
} else {
effectiveEntityGraph.clear();
}
}
}
} finally {
if (cacheModeChanged) {
// change it back
session.setCacheMode(sessionCacheMode);
}
}
}
use of org.hibernate.engine.spi.EffectiveEntityGraph in project hibernate-orm by hibernate.
the class EntityGraphLoadPlanBuilderTest method buildSqlSelectAst.
private <T> SelectStatement buildSqlSelectAst(Class<T> entityType, RootGraphImplementor<T> entityGraph, GraphSemantic mode, SessionFactoryScope scope) {
final EntityPersister entityDescriptor = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(entityType);
final LoadQueryInfluencers loadQueryInfluencers = new LoadQueryInfluencers(scope.getSessionFactory());
final EffectiveEntityGraph effectiveEntityGraph = loadQueryInfluencers.getEffectiveEntityGraph();
effectiveEntityGraph.applyGraph(entityGraph, mode);
return LoaderSelectBuilder.createSelect(entityDescriptor, null, entityDescriptor.getIdentifierMapping(), null, 1, loadQueryInfluencers, LockOptions.READ, jdbcParameter -> {
}, scope.getSessionFactory());
}
use of org.hibernate.engine.spi.EffectiveEntityGraph 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