use of org.hibernate.loader.plan.spi.EntityFetch in project hibernate-orm by hibernate.
the class LoadQueryJoinAndFetchProcessor method processFetch.
private void processFetch(SelectStatementBuilder selectStatementBuilder, FetchSource fetchSource, Fetch fetch, ReaderCollector readerCollector, FetchStatsImpl fetchStats) {
// process fetch even if it is not join fetched
if (EntityFetch.class.isInstance(fetch)) {
final EntityFetch entityFetch = (EntityFetch) fetch;
processEntityFetch(selectStatementBuilder, fetchSource, entityFetch, readerCollector, fetchStats);
} else if (CollectionAttributeFetch.class.isInstance(fetch)) {
final CollectionAttributeFetch collectionFetch = (CollectionAttributeFetch) fetch;
processCollectionFetch(selectStatementBuilder, fetchSource, collectionFetch, readerCollector, fetchStats);
} else {
// but do still need to visit their fetches...
if (FetchSource.class.isInstance(fetch)) {
processFetches((FetchSource) fetch, selectStatementBuilder, readerCollector, fetchStats);
}
}
}
use of org.hibernate.loader.plan.spi.EntityFetch in project hibernate-orm by hibernate.
the class EntityReferenceInitializerImpl method handleMissingIdentifier.
private void handleMissingIdentifier(ResultSetProcessingContext context) {
if (EntityFetch.class.isInstance(entityReference)) {
final EntityFetch fetch = (EntityFetch) entityReference;
final EntityType fetchedType = fetch.getFetchedType();
if (!fetchedType.isOneToOne()) {
return;
}
final EntityReferenceProcessingState fetchOwnerState = context.getOwnerProcessingState(fetch);
if (fetchOwnerState == null) {
throw new IllegalStateException("Could not locate fetch owner state");
}
final EntityKey ownerEntityKey = fetchOwnerState.getEntityKey();
if (ownerEntityKey != null) {
context.getSession().getPersistenceContext().addNullProperty(ownerEntityKey, fetchedType.getPropertyName());
}
}
}
use of org.hibernate.loader.plan.spi.EntityFetch in project hibernate-orm by hibernate.
the class ResultSetProcessingContextImpl method getProcessingState.
@Override
public EntityReferenceProcessingState getProcessingState(final EntityReference entityReference) {
if (identifierResolutionContextMap == null) {
identifierResolutionContextMap = new IdentityHashMap<>();
}
EntityReferenceProcessingState context = identifierResolutionContextMap.get(entityReference);
if (context == null) {
context = new EntityReferenceProcessingState() {
private boolean wasMissingIdentifier;
private Object identifierHydratedForm;
private EntityKey entityKey;
private Object[] hydratedState;
private Object entityInstance;
@Override
public EntityReference getEntityReference() {
return entityReference;
}
@Override
public void registerMissingIdentifier() {
if (!EntityFetch.class.isInstance(entityReference)) {
throw new IllegalStateException("Missing return row identifier");
}
ResultSetProcessingContextImpl.this.registerNonExists((EntityFetch) entityReference);
wasMissingIdentifier = true;
}
@Override
public boolean isMissingIdentifier() {
return wasMissingIdentifier;
}
@Override
public void registerIdentifierHydratedForm(Object identifierHydratedForm) {
this.identifierHydratedForm = identifierHydratedForm;
}
@Override
public Object getIdentifierHydratedForm() {
return identifierHydratedForm;
}
@Override
public void registerEntityKey(EntityKey entityKey) {
this.entityKey = entityKey;
}
@Override
public EntityKey getEntityKey() {
return entityKey;
}
@Override
public void registerHydratedState(Object[] hydratedState) {
this.hydratedState = hydratedState;
}
@Override
public Object[] getHydratedState() {
return hydratedState;
}
@Override
public void registerEntityInstance(Object entityInstance) {
this.entityInstance = entityInstance;
}
@Override
public Object getEntityInstance() {
return entityInstance;
}
};
identifierResolutionContextMap.put(entityReference, context);
}
return context;
}
use of org.hibernate.loader.plan.spi.EntityFetch in project hibernate-orm by hibernate.
the class LoadQueryJoinAndFetchProcessor method processEntityFetch.
private void processEntityFetch(SelectStatementBuilder selectStatementBuilder, FetchSource fetchSource, EntityFetch fetch, ReaderCollector readerCollector, FetchStatsImpl fetchStats) {
// todo : still need to think through expressing bi-directionality in the new model...
// if ( BidirectionalEntityFetch.class.isInstance( fetch ) ) {
// log.tracef( "Skipping bi-directional entity fetch [%s]", fetch );
// return;
// }
fetchStats.processingFetch(fetch);
if (!FetchStrategyHelper.isJoinFetched(fetch.getFetchStrategy())) {
// not join fetched, so nothing else to do
return;
}
// First write out the SQL SELECT fragments
final Joinable joinable = (Joinable) fetch.getEntityPersister();
EntityReferenceAliases aliases = aliasResolutionContext.resolveEntityReferenceAliases(fetch.getQuerySpaceUid());
// the null arguments here relate to many-to-many fetches
selectStatementBuilder.appendSelectClauseFragment(joinable.selectFragment(null, null, aliases.getTableAlias(), aliases.getColumnAliases().getSuffix(), null, true));
// process its identifier fetches first (building EntityReferenceInitializers for them if needed)
if (fetch.getIdentifierDescription().hasFetches()) {
final FetchSource entityIdentifierAsFetchSource = (FetchSource) fetch.getIdentifierDescription();
for (Fetch identifierFetch : entityIdentifierAsFetchSource.getFetches()) {
processFetch(selectStatementBuilder, fetch, identifierFetch, readerCollector, fetchStats);
}
}
// build an EntityReferenceInitializers for the incoming fetch itself
readerCollector.add(new EntityReferenceInitializerImpl(fetch, aliases));
// then visit each of our (non-identifier) fetches
processFetches(fetch, selectStatementBuilder, readerCollector, fetchStats);
}
use of org.hibernate.loader.plan.spi.EntityFetch in project hibernate-orm by hibernate.
the class AbstractRowReader method resolveEntityKey.
private void resolveEntityKey(ResultSet resultSet, ResultSetProcessingContextImpl context, FetchSource fetchSource) throws SQLException {
// Resolve any bidirectional entity references first.
for (BidirectionalEntityReference bidirectionalEntityReference : fetchSource.getBidirectionalEntityReferences()) {
final EntityReferenceInitializer targetEntityReferenceInitializer = entityInitializerByEntityReference.get(bidirectionalEntityReference.getTargetEntityReference());
resolveEntityKey(resultSet, context, targetEntityReferenceInitializer);
targetEntityReferenceInitializer.hydrateEntityState(resultSet, context);
}
for (Fetch fetch : fetchSource.getFetches()) {
if (EntityFetch.class.isInstance(fetch)) {
final EntityFetch entityFetch = (EntityFetch) fetch;
final EntityReferenceInitializer entityReferenceInitializer = entityInitializerByEntityReference.get(entityFetch);
if (entityReferenceInitializer != null) {
resolveEntityKey(resultSet, context, entityReferenceInitializer);
entityReferenceInitializer.hydrateEntityState(resultSet, context);
}
} else if (CompositeFetch.class.isInstance(fetch)) {
resolveEntityKey(resultSet, context, (CompositeFetch) fetch);
}
}
}
Aggregations