Skip to content

Commit

Permalink
HHH-8276 - Integrate LoadPlans into UniqueEntityLoader (PoC)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbadner authored and sebersole committed Oct 9, 2013
1 parent 9e1acba commit 1e79efd
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 18 deletions.
Expand Up @@ -158,18 +158,18 @@ private EntityFetch buildEntityFetch(
final ExpandingQuerySpace leftHandSide = (ExpandingQuerySpace) resolveCompositeQuerySpace(
loadPlanBuildingContext
);
final Join join = leftHandSide.addEntityJoin(
attributeDefinition,
fetchedPersister,
loadPlanBuildingContext.getQuerySpaces().generateImplicitUid(),
attributeDefinition.isNullable()
);
final EntityFetch fetch;
if ( targetEntityReference == null ) {
final Join join = leftHandSide.addEntityJoin(
attributeDefinition,
fetchedPersister,
loadPlanBuildingContext.getQuerySpaces().generateImplicitUid(),
attributeDefinition.isNullable()
);
fetch = new EntityFetchImpl( this, attributeDefinition, fetchStrategy, join );
}
else {
fetch = new BidirectionalEntityFetchImpl( this, attributeDefinition, fetchStrategy, join, targetEntityReference );
fetch = new BidirectionalEntityFetchImpl( this, attributeDefinition, fetchStrategy, targetEntityReference );
}
addFetch( fetch );
return fetch;
Expand Down
Expand Up @@ -192,18 +192,18 @@ private EntityFetch buildEntityFetch(
}

final ExpandingQuerySpace leftHandSide = (ExpandingQuerySpace) entityQuerySpace;
final Join join = leftHandSide.addEntityJoin(
attributeDefinition,
fetchedPersister,
loadPlanBuildingContext.getQuerySpaces().generateImplicitUid(),
attributeDefinition.isNullable()
);
final EntityFetch fetch;
if ( targetEntityReference == null ) {
final Join join = leftHandSide.addEntityJoin(
attributeDefinition,
fetchedPersister,
loadPlanBuildingContext.getQuerySpaces().generateImplicitUid(),
attributeDefinition.isNullable()
);
fetch = new EntityFetchImpl( this, attributeDefinition, fetchStrategy, join );
}
else {
fetch = new BidirectionalEntityFetchImpl( this, attributeDefinition, fetchStrategy, join, targetEntityReference );
fetch = new BidirectionalEntityFetchImpl( this, attributeDefinition, fetchStrategy, targetEntityReference );
}
addFetch( fetch );
return fetch;
Expand Down
Expand Up @@ -24,11 +24,17 @@
package org.hibernate.loader.plan2.build.internal.returns;

import org.hibernate.engine.FetchStrategy;
import org.hibernate.loader.PropertyPath;
import org.hibernate.loader.plan2.build.spi.ExpandingFetchSource;
import org.hibernate.loader.plan2.spi.BidirectionalEntityFetch;
import org.hibernate.loader.plan2.spi.EntityFetch;
import org.hibernate.loader.plan2.spi.EntityIdentifierDescription;
import org.hibernate.loader.plan2.spi.EntityReference;
import org.hibernate.loader.plan2.spi.Join;
import org.hibernate.loader.plan2.spi.Fetch;
import org.hibernate.loader.plan2.spi.FetchSource;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.walking.spi.AssociationAttributeDefinition;
import org.hibernate.type.EntityType;

/**
* Represents an entity fetch that is bi-directionally join fetched.
Expand All @@ -39,20 +45,86 @@
*
* @author Steve Ebersole
*/
public class BidirectionalEntityFetchImpl extends EntityFetchImpl implements BidirectionalEntityFetch {
public class BidirectionalEntityFetchImpl implements BidirectionalEntityFetch, EntityFetch {
private final ExpandingFetchSource fetchSource;
private final AssociationAttributeDefinition fetchedAttribute;
private final FetchStrategy fetchStrategy;
private final EntityReference targetEntityReference;
private final PropertyPath propertyPath;

public BidirectionalEntityFetchImpl(
ExpandingFetchSource fetchSource,
AssociationAttributeDefinition fetchedAttribute,
FetchStrategy fetchStrategy,
Join fetchedJoin,
EntityReference targetEntityReference) {
super( fetchSource, fetchedAttribute, fetchStrategy, fetchedJoin );
this.fetchSource = fetchSource;
this.fetchedAttribute = fetchedAttribute;
this.fetchStrategy = fetchStrategy;
this.targetEntityReference = targetEntityReference;
this.propertyPath = fetchSource.getPropertyPath().append( fetchedAttribute.getName() );
}

public EntityReference getTargetEntityReference() {
return targetEntityReference;
}

@Override
public FetchSource getSource() {
return fetchSource;
}

@Override
public PropertyPath getPropertyPath() {
return propertyPath;
}

@Override
public FetchStrategy getFetchStrategy() {
return fetchStrategy;
}

@Override
public EntityType getFetchedType() {
return (EntityType) fetchedAttribute.getType();
}

@Override
public boolean isNullable() {
return fetchedAttribute.isNullable();
}

@Override
public String getAdditionalJoinConditions() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}

@Override
public String[] toSqlSelectFragments(String alias) {
return new String[0]; //To change body of implemented methods use File | Settings | File Templates.
}

@Override
public String getQuerySpaceUid() {
return targetEntityReference.getQuerySpaceUid();
}

@Override
public Fetch[] getFetches() {
return FetchSource.NO_FETCHES;
}

@Override
public EntityReference resolveEntityReference() {
return this;
}

@Override
public EntityPersister getEntityPersister() {
return targetEntityReference.getEntityPersister();
}

@Override
public EntityIdentifierDescription getIdentifierDescription() {
return targetEntityReference.getIdentifierDescription();
}
}
Expand Up @@ -27,6 +27,7 @@
import java.io.PrintStream;
import java.io.PrintWriter;

import org.hibernate.loader.plan2.spi.BidirectionalEntityFetch;
import org.hibernate.loader.plan2.spi.CollectionFetch;
import org.hibernate.loader.plan2.spi.CollectionFetchableElement;
import org.hibernate.loader.plan2.spi.CollectionFetchableIndex;
Expand Down Expand Up @@ -152,6 +153,9 @@ private String extractDetails(CompositeFetch compositeFetch) {
}

private void writeEntityReferenceFetches(EntityReference entityReference, int depth, PrintWriter printWriter) {
if ( BidirectionalEntityFetch.class.isInstance( entityReference ) ) {
return;
}
if ( entityReference.getIdentifierDescription().hasFetches() ) {
printWriter.println( TreePrinterHelper.INSTANCE.generateNodePrefix( depth ) + "(entity id) " );
writeFetches( ( (FetchSource) entityReference.getIdentifierDescription() ).getFetches(), depth+1, printWriter );
Expand Down

0 comments on commit 1e79efd

Please sign in to comment.