mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-17 00:24:57 +00:00
HHH-8276 - Integrate LoadPlans into UniqueEntityLoader (PoC)
This commit is contained in:
parent
f32c736160
commit
e1105fb6d3
@ -44,8 +44,9 @@ public CollectionQuerySpaceImpl(
|
||||
CollectionPersister persister,
|
||||
String uid,
|
||||
QuerySpacesImpl querySpaces,
|
||||
boolean canJoinsBeRequired,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
super( uid, Disposition.COLLECTION, querySpaces, sessionFactory );
|
||||
super( uid, Disposition.COLLECTION, querySpaces, canJoinsBeRequired, sessionFactory );
|
||||
this.persister = persister;
|
||||
}
|
||||
|
||||
@ -62,11 +63,13 @@ public PropertyMapping getPropertyMapping() {
|
||||
public JoinImpl addIndexEntityJoin(
|
||||
final EntityPersister indexPersister,
|
||||
LoadPlanBuildingContext context) {
|
||||
final boolean required = canJoinsBeRequired();
|
||||
final String entityQuerySpaceUid = getQuerySpaces().generateImplicitUid();
|
||||
final EntityQuerySpaceImpl entityQuerySpace = new EntityQuerySpaceImpl(
|
||||
indexPersister,
|
||||
entityQuerySpaceUid,
|
||||
getQuerySpaces(),
|
||||
required,
|
||||
sessionFactory()
|
||||
);
|
||||
getQuerySpaces().registerQuerySpace( entityQuerySpace );
|
||||
@ -77,7 +80,7 @@ public JoinImpl addIndexEntityJoin(
|
||||
entityQuerySpace,
|
||||
// not sure this 'rhsColumnNames' bit is correct...
|
||||
( (Queryable) indexPersister ).getKeyColumnNames(),
|
||||
false
|
||||
required
|
||||
);
|
||||
internalGetJoins().add( join );
|
||||
|
||||
@ -96,6 +99,7 @@ public JoinImpl addIndexCompositeJoin(
|
||||
),
|
||||
compositeQuerySpaceUid,
|
||||
getQuerySpaces(),
|
||||
canJoinsBeRequired(),
|
||||
sessionFactory()
|
||||
);
|
||||
getQuerySpaces().registerQuerySpace( compositeQuerySpace );
|
||||
@ -105,7 +109,7 @@ public JoinImpl addIndexCompositeJoin(
|
||||
"index",
|
||||
compositeQuerySpace,
|
||||
null,
|
||||
false
|
||||
canJoinsBeRequired()
|
||||
);
|
||||
internalGetJoins().add( join );
|
||||
|
||||
@ -120,6 +124,7 @@ public JoinImpl addElementEntityJoin(
|
||||
elementPersister,
|
||||
entityQuerySpaceUid,
|
||||
getQuerySpaces(),
|
||||
canJoinsBeRequired(),
|
||||
sessionFactory()
|
||||
);
|
||||
( (QuerySpacesImpl) context.getQuerySpaces() ).registerQuerySpace( entityQuerySpace );
|
||||
@ -130,7 +135,7 @@ public JoinImpl addElementEntityJoin(
|
||||
"id",
|
||||
entityQuerySpace,
|
||||
( (Queryable) elementPersister ).getKeyColumnNames(),
|
||||
false
|
||||
canJoinsBeRequired()
|
||||
);
|
||||
internalGetJoins().add( join );
|
||||
|
||||
@ -150,6 +155,7 @@ public Join addElementCompositeJoin(
|
||||
),
|
||||
compositeQuerySpaceUid,
|
||||
getQuerySpaces(),
|
||||
canJoinsBeRequired(),
|
||||
sessionFactory()
|
||||
);
|
||||
( (QuerySpacesImpl) context.getQuerySpaces() ).registerQuerySpace( compositeQuerySpace );
|
||||
@ -160,7 +166,7 @@ public Join addElementCompositeJoin(
|
||||
"elements",
|
||||
compositeQuerySpace,
|
||||
null,
|
||||
false
|
||||
canJoinsBeRequired()
|
||||
);
|
||||
internalGetJoins().add( join );
|
||||
|
||||
|
@ -45,20 +45,23 @@ public CompositeQuerySpaceImpl(
|
||||
CompositePropertyMapping compositeSubPropertyMapping,
|
||||
String uid,
|
||||
QuerySpacesImpl querySpaces,
|
||||
boolean canJoinsBeRequired,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
super( uid, Disposition.COMPOSITE, querySpaces, sessionFactory );
|
||||
super( uid, Disposition.COMPOSITE, querySpaces, canJoinsBeRequired, sessionFactory );
|
||||
this.compositeSubPropertyMapping = compositeSubPropertyMapping;
|
||||
}
|
||||
|
||||
public CompositeQuerySpaceImpl(
|
||||
EntityQuerySpaceImpl entityQuerySpace,
|
||||
CompositePropertyMapping compositePropertyMapping,
|
||||
String uid) {
|
||||
String uid,
|
||||
boolean canJoinsBeRequired) {
|
||||
// todo : we may need to keep around the owning entity query space to be able to properly handle circularity...
|
||||
this(
|
||||
compositePropertyMapping,
|
||||
uid,
|
||||
entityQuerySpace.getQuerySpaces(),
|
||||
canJoinsBeRequired,
|
||||
entityQuerySpace.sessionFactory()
|
||||
);
|
||||
}
|
||||
@ -71,11 +74,13 @@ public PropertyMapping getPropertyMapping() {
|
||||
@Override
|
||||
public JoinImpl addCompositeJoin(CompositionDefinition compositionDefinition, String querySpaceUid) {
|
||||
final String propertyPath = compositionDefinition.getName();
|
||||
final boolean required = canJoinsBeRequired() && !compositionDefinition.isNullable();
|
||||
|
||||
final CompositeQuerySpaceImpl rhs = new CompositeQuerySpaceImpl(
|
||||
compositeSubPropertyMapping,
|
||||
querySpaceUid,
|
||||
getQuerySpaces(),
|
||||
required,
|
||||
sessionFactory()
|
||||
);
|
||||
getQuerySpaces().registerQuerySpace( rhs );
|
||||
@ -85,7 +90,7 @@ public JoinImpl addCompositeJoin(CompositionDefinition compositionDefinition, St
|
||||
propertyPath,
|
||||
rhs,
|
||||
null,
|
||||
compositionDefinition.isNullable()
|
||||
required
|
||||
);
|
||||
internalGetJoins().add( join );
|
||||
|
||||
@ -98,10 +103,13 @@ public JoinImpl addEntityJoin(
|
||||
EntityPersister persister,
|
||||
String querySpaceUid,
|
||||
boolean optional) {
|
||||
final boolean required = canJoinsBeRequired() && !optional;
|
||||
|
||||
final EntityQuerySpaceImpl rhs = new EntityQuerySpaceImpl(
|
||||
persister,
|
||||
querySpaceUid,
|
||||
getQuerySpaces(),
|
||||
required,
|
||||
sessionFactory()
|
||||
);
|
||||
getQuerySpaces().registerQuerySpace( rhs );
|
||||
@ -115,7 +123,7 @@ public JoinImpl addEntityJoin(
|
||||
(EntityType) attributeDefinition.getType(),
|
||||
sessionFactory()
|
||||
),
|
||||
optional
|
||||
required
|
||||
);
|
||||
internalGetJoins().add( join );
|
||||
|
||||
@ -127,10 +135,13 @@ public JoinImpl addCollectionJoin(
|
||||
AttributeDefinition attributeDefinition,
|
||||
CollectionPersister collectionPersister,
|
||||
String querySpaceUid) {
|
||||
final boolean required = canJoinsBeRequired() && ! attributeDefinition.isNullable();
|
||||
|
||||
final CollectionQuerySpaceImpl rhs = new CollectionQuerySpaceImpl(
|
||||
collectionPersister,
|
||||
querySpaceUid,
|
||||
getQuerySpaces(),
|
||||
required,
|
||||
sessionFactory()
|
||||
);
|
||||
getQuerySpaces().registerQuerySpace( rhs );
|
||||
@ -140,7 +151,7 @@ public JoinImpl addCollectionJoin(
|
||||
attributeDefinition.getName(),
|
||||
rhs,
|
||||
( (CollectionType) attributeDefinition.getType() ).getAssociatedJoinable( sessionFactory() ).getKeyColumnNames(),
|
||||
attributeDefinition.isNullable()
|
||||
required
|
||||
);
|
||||
internalGetJoins().add( join );
|
||||
|
||||
|
@ -47,8 +47,9 @@ public EntityQuerySpaceImpl(
|
||||
EntityPersister persister,
|
||||
String uid,
|
||||
QuerySpacesImpl querySpaces,
|
||||
boolean canJoinsBeRequired,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
super( uid, Disposition.ENTITY, querySpaces, sessionFactory );
|
||||
super( uid, Disposition.ENTITY, querySpaces, canJoinsBeRequired, sessionFactory );
|
||||
this.persister = persister;
|
||||
}
|
||||
|
||||
@ -71,6 +72,8 @@ public EntityPersister getEntityPersister() {
|
||||
|
||||
@Override
|
||||
public JoinImpl addCompositeJoin(CompositionDefinition compositionDefinition, String querySpaceUid) {
|
||||
final boolean required = canJoinsBeRequired() && !compositionDefinition.isNullable();
|
||||
|
||||
final CompositeQuerySpaceImpl rhs = new CompositeQuerySpaceImpl(
|
||||
new CompositePropertyMapping(
|
||||
compositionDefinition.getType(),
|
||||
@ -79,6 +82,7 @@ public JoinImpl addCompositeJoin(CompositionDefinition compositionDefinition, St
|
||||
),
|
||||
querySpaceUid,
|
||||
getQuerySpaces(),
|
||||
required,
|
||||
sessionFactory()
|
||||
);
|
||||
getQuerySpaces().registerQuerySpace( rhs );
|
||||
@ -88,7 +92,7 @@ public JoinImpl addCompositeJoin(CompositionDefinition compositionDefinition, St
|
||||
compositionDefinition.getName(),
|
||||
rhs,
|
||||
null,
|
||||
compositionDefinition.isNullable()
|
||||
required
|
||||
);
|
||||
internalGetJoins().add( join );
|
||||
|
||||
@ -100,10 +104,13 @@ public JoinImpl addEntityJoin(
|
||||
EntityPersister persister,
|
||||
String querySpaceUid,
|
||||
boolean optional) {
|
||||
final boolean required = canJoinsBeRequired() && !optional;
|
||||
|
||||
final EntityQuerySpaceImpl rhs = new EntityQuerySpaceImpl(
|
||||
persister,
|
||||
querySpaceUid,
|
||||
getQuerySpaces(),
|
||||
required,
|
||||
sessionFactory()
|
||||
);
|
||||
getQuerySpaces().registerQuerySpace( rhs );
|
||||
@ -116,7 +123,7 @@ public JoinImpl addEntityJoin(
|
||||
(EntityType) attribute.getType(),
|
||||
sessionFactory()
|
||||
),
|
||||
optional
|
||||
required
|
||||
);
|
||||
internalGetJoins().add( join );
|
||||
|
||||
@ -128,10 +135,13 @@ public JoinImpl addCollectionJoin(
|
||||
AttributeDefinition attributeDefinition,
|
||||
CollectionPersister collectionPersister,
|
||||
String querySpaceUid) {
|
||||
final boolean required = canJoinsBeRequired() && !attributeDefinition.isNullable();
|
||||
|
||||
final CollectionQuerySpaceImpl rhs = new CollectionQuerySpaceImpl(
|
||||
collectionPersister,
|
||||
querySpaceUid,
|
||||
getQuerySpaces(),
|
||||
required,
|
||||
sessionFactory()
|
||||
);
|
||||
getQuerySpaces().registerQuerySpace( rhs );
|
||||
@ -141,7 +151,7 @@ public JoinImpl addCollectionJoin(
|
||||
attributeDefinition.getName(),
|
||||
rhs,
|
||||
( (CollectionType) attributeDefinition.getType() ).getAssociatedJoinable( sessionFactory() ).getKeyColumnNames(),
|
||||
attributeDefinition.isNullable()
|
||||
required
|
||||
);
|
||||
internalGetJoins().add( join );
|
||||
|
||||
@ -158,7 +168,8 @@ public Join makeCompositeIdentifierJoin() {
|
||||
(PropertyMapping) getEntityPersister(),
|
||||
getEntityPersister().getIdentifierPropertyName()
|
||||
),
|
||||
compositeQuerySpaceUid
|
||||
compositeQuerySpaceUid,
|
||||
canJoinsBeRequired()
|
||||
);
|
||||
getQuerySpaces().registerQuerySpace( rhs );
|
||||
|
||||
@ -167,7 +178,7 @@ public Join makeCompositeIdentifierJoin() {
|
||||
"id",
|
||||
rhs,
|
||||
null,
|
||||
false
|
||||
canJoinsBeRequired()
|
||||
);
|
||||
internalGetJoins().add( join );
|
||||
|
||||
|
@ -69,7 +69,7 @@ public QuerySpace getRightHandSide() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRightHandSideOptional() {
|
||||
public boolean isRightHandSideRequired() {
|
||||
return rightHandSideOptional;
|
||||
}
|
||||
|
||||
|
@ -95,6 +95,7 @@ public EntityQuerySpace makeEntityQuerySpace(String uid, EntityPersister entityP
|
||||
entityPersister,
|
||||
uid,
|
||||
this,
|
||||
true,
|
||||
sessionFactory
|
||||
);
|
||||
registerQuerySpace( space );
|
||||
@ -113,6 +114,7 @@ public CollectionQuerySpaceImpl makeCollectionQuerySpace(String uid, CollectionP
|
||||
collectionPersister,
|
||||
uid,
|
||||
this,
|
||||
true,
|
||||
sessionFactory
|
||||
);
|
||||
registerQuerySpace( space );
|
||||
|
@ -42,6 +42,7 @@ public abstract class AbstractQuerySpace extends AbstractPlanNode implements Que
|
||||
private final String uid;
|
||||
private final Disposition disposition;
|
||||
private final QuerySpacesImpl querySpaces;
|
||||
private final boolean canJoinsBeRequired;
|
||||
|
||||
private List<Join> joins;
|
||||
|
||||
@ -49,11 +50,13 @@ public AbstractQuerySpace(
|
||||
String uid,
|
||||
Disposition disposition,
|
||||
QuerySpacesImpl querySpaces,
|
||||
boolean canJoinsBeRequired,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
super( sessionFactory );
|
||||
this.uid = uid;
|
||||
this.disposition = disposition;
|
||||
this.querySpaces = querySpaces;
|
||||
this.canJoinsBeRequired = canJoinsBeRequired;
|
||||
}
|
||||
|
||||
protected SessionFactoryImplementor sessionFactory() {
|
||||
@ -63,6 +66,15 @@ protected SessionFactoryImplementor sessionFactory() {
|
||||
// todo : copy ctor - that depends how graph copying works here...
|
||||
|
||||
|
||||
/**
|
||||
* Can any joins created from here (with this as the left-hand side) be required joins?
|
||||
*
|
||||
* @return {@code true} indicates joins can be required; {@code false} indicates they cannot.
|
||||
*/
|
||||
public boolean canJoinsBeRequired() {
|
||||
return canJoinsBeRequired;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides subclasses access to the spaces to which this space belongs.
|
||||
*
|
||||
|
@ -179,7 +179,7 @@ private void renderEntityJoin(Join join, JoinFragment joinFragment) {
|
||||
addJoins(
|
||||
joinFragment,
|
||||
joinable,
|
||||
join.isRightHandSideOptional() ? JoinType.LEFT_OUTER_JOIN : JoinType.INNER_JOIN,
|
||||
join.isRightHandSideRequired() ? JoinType.INNER_JOIN : JoinType.LEFT_OUTER_JOIN,
|
||||
aliases.getTableAlias(),
|
||||
rhsColumnNames,
|
||||
aliasedLhsColumnNames,
|
||||
|
@ -40,7 +40,7 @@ public interface Join {
|
||||
|
||||
public QuerySpace getRightHandSide();
|
||||
|
||||
public boolean isRightHandSideOptional();
|
||||
public boolean isRightHandSideRequired();
|
||||
|
||||
// Ugh! This part will unfortunately be SQL specific :( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
@ -25,6 +25,11 @@
|
||||
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
||||
import org.hibernate.test.annotations.Country;
|
||||
import org.hibernate.test.annotations.collectionelement.Boy;
|
||||
import org.hibernate.test.annotations.collectionelement.Matrix;
|
||||
import org.hibernate.test.annotations.collectionelement.TestCourse;
|
||||
import org.hibernate.test.loadplans.process.EncapsulatedCompositeIdResultSetProcessorTest;
|
||||
|
||||
//import org.hibernate.loader.plan2.spi.BidirectionalEntityFetch;
|
||||
@ -255,6 +260,23 @@ public void testManyToMany() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnotherBasicCollection() {
|
||||
Configuration cfg = new Configuration();
|
||||
cfg.addAnnotatedClass( Boy.class );
|
||||
cfg.addAnnotatedClass( Country.class );
|
||||
cfg.addAnnotatedClass( TestCourse.class );
|
||||
cfg.addAnnotatedClass( Matrix.class );
|
||||
SessionFactoryImplementor sf = (SessionFactoryImplementor) cfg.buildSessionFactory();
|
||||
|
||||
try {
|
||||
doCompare( sf, (OuterJoinLoadable) sf.getClassMetadata( Boy.class ) );
|
||||
}
|
||||
finally {
|
||||
sf.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void doCompare(SessionFactoryImplementor sf, OuterJoinLoadable persister) {
|
||||
LoadPlanStructureAssertionHelper.INSTANCE.performBasicComparison( sf, persister );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user