HHH-8276 - Integrate LoadPlans into UniqueEntityLoader (PoC)

This commit is contained in:
Gail Badner 2013-09-17 14:26:37 -07:00 committed by Steve Ebersole
parent 9e1acbac41
commit 1e79efd10a
4 changed files with 94 additions and 18 deletions

View File

@ -158,18 +158,18 @@ public abstract class AbstractCompositeFetch implements CompositeFetch, Expandin
final ExpandingQuerySpace leftHandSide = (ExpandingQuerySpace) resolveCompositeQuerySpace(
loadPlanBuildingContext
);
final EntityFetch fetch;
if ( targetEntityReference == null ) {
final Join join = leftHandSide.addEntityJoin(
attributeDefinition,
fetchedPersister,
loadPlanBuildingContext.getQuerySpaces().generateImplicitUid(),
attributeDefinition.isNullable()
);
final EntityFetch fetch;
if ( targetEntityReference == null ) {
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;

View File

@ -192,18 +192,18 @@ public abstract class AbstractEntityReference implements EntityReference, Expand
}
final ExpandingQuerySpace leftHandSide = (ExpandingQuerySpace) entityQuerySpace;
final EntityFetch fetch;
if ( targetEntityReference == null ) {
final Join join = leftHandSide.addEntityJoin(
attributeDefinition,
fetchedPersister,
loadPlanBuildingContext.getQuerySpaces().generateImplicitUid(),
attributeDefinition.isNullable()
);
final EntityFetch fetch;
if ( targetEntityReference == null ) {
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;

View File

@ -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.
@ -39,20 +45,86 @@ import org.hibernate.persister.walking.spi.AssociationAttributeDefinition;
*
* @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();
}
}

View File

@ -27,6 +27,7 @@ import java.io.ByteArrayOutputStream;
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;
@ -152,6 +153,9 @@ public class ReturnGraphTreePrinter {
}
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 );