Search in sources :

Example 1 with Return

use of org.hibernate.loader.plan.spi.Return in project hibernate-orm by hibernate.

the class LoadPlanTreePrinter method logTree.

private void logTree(LoadPlan loadPlan, AliasResolutionContext aliasResolutionContext, PrintWriter printWriter) {
    printWriter.println("LoadPlan(" + extractDetails(loadPlan) + ")");
    printWriter.println(TreePrinterHelper.INSTANCE.generateNodePrefix(1) + "Returns");
    for (Return rtn : loadPlan.getReturns()) {
        ReturnGraphTreePrinter.INSTANCE.write(rtn, 2, printWriter);
        printWriter.flush();
    }
    QuerySpaceTreePrinter.INSTANCE.write(loadPlan.getQuerySpaces(), 1, aliasResolutionContext, printWriter);
    printWriter.flush();
}
Also used : EntityReturn(org.hibernate.loader.plan.spi.EntityReturn) CollectionReturn(org.hibernate.loader.plan.spi.CollectionReturn) Return(org.hibernate.loader.plan.spi.Return)

Example 2 with Return

use of org.hibernate.loader.plan.spi.Return in project hibernate-orm by hibernate.

the class LoadPlanBuilderTest method testSimpleBuild.

@Test
public void testSimpleBuild() {
    EntityPersister ep = (EntityPersister) sessionFactory().getClassMetadata(Message.class);
    FetchStyleLoadPlanBuildingAssociationVisitationStrategy strategy = new FetchStyleLoadPlanBuildingAssociationVisitationStrategy(sessionFactory(), LoadQueryInfluencers.NONE, LockMode.NONE);
    LoadPlan plan = MetamodelDrivenLoadPlanBuilder.buildRootEntityLoadPlan(strategy, ep);
    assertFalse(plan.hasAnyScalarReturns());
    assertEquals(1, plan.getReturns().size());
    Return rtn = plan.getReturns().get(0);
    EntityReturn entityReturn = ExtraAssertions.assertTyping(EntityReturn.class, rtn);
    assertNotNull(entityReturn.getFetches());
    assertEquals(1, entityReturn.getFetches().length);
    Fetch fetch = entityReturn.getFetches()[0];
    EntityFetch entityFetch = ExtraAssertions.assertTyping(EntityFetch.class, fetch);
    assertNotNull(entityFetch.getFetches());
    assertEquals(0, entityFetch.getFetches().length);
    LoadPlanTreePrinter.INSTANCE.logTree(plan, new AliasResolutionContextImpl(sessionFactory()));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) Fetch(org.hibernate.loader.plan.spi.Fetch) EntityFetch(org.hibernate.loader.plan.spi.EntityFetch) EntityFetch(org.hibernate.loader.plan.spi.EntityFetch) AliasResolutionContextImpl(org.hibernate.loader.plan.exec.internal.AliasResolutionContextImpl) CollectionReturn(org.hibernate.loader.plan.spi.CollectionReturn) Return(org.hibernate.loader.plan.spi.Return) EntityReturn(org.hibernate.loader.plan.spi.EntityReturn) LoadPlan(org.hibernate.loader.plan.spi.LoadPlan) FetchStyleLoadPlanBuildingAssociationVisitationStrategy(org.hibernate.loader.plan.build.internal.FetchStyleLoadPlanBuildingAssociationVisitationStrategy) EntityReturn(org.hibernate.loader.plan.spi.EntityReturn) Test(org.junit.Test)

Example 3 with Return

use of org.hibernate.loader.plan.spi.Return in project hibernate-orm by hibernate.

the class LoadPlanBuilderTest method testCascadeBasedBuild.

@Test
public void testCascadeBasedBuild() {
    EntityPersister ep = (EntityPersister) sessionFactory().getClassMetadata(Message.class);
    CascadeStyleLoadPlanBuildingAssociationVisitationStrategy strategy = new CascadeStyleLoadPlanBuildingAssociationVisitationStrategy(CascadingActions.MERGE, sessionFactory(), LoadQueryInfluencers.NONE, LockMode.NONE);
    LoadPlan plan = MetamodelDrivenLoadPlanBuilder.buildRootEntityLoadPlan(strategy, ep);
    assertFalse(plan.hasAnyScalarReturns());
    assertEquals(1, plan.getReturns().size());
    Return rtn = plan.getReturns().get(0);
    EntityReturn entityReturn = ExtraAssertions.assertTyping(EntityReturn.class, rtn);
    assertNotNull(entityReturn.getFetches());
    assertEquals(1, entityReturn.getFetches().length);
    Fetch fetch = entityReturn.getFetches()[0];
    EntityFetch entityFetch = ExtraAssertions.assertTyping(EntityFetch.class, fetch);
    assertNotNull(entityFetch.getFetches());
    assertEquals(0, entityFetch.getFetches().length);
    LoadPlanTreePrinter.INSTANCE.logTree(plan, new AliasResolutionContextImpl(sessionFactory()));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) Fetch(org.hibernate.loader.plan.spi.Fetch) EntityFetch(org.hibernate.loader.plan.spi.EntityFetch) EntityFetch(org.hibernate.loader.plan.spi.EntityFetch) AliasResolutionContextImpl(org.hibernate.loader.plan.exec.internal.AliasResolutionContextImpl) CascadeStyleLoadPlanBuildingAssociationVisitationStrategy(org.hibernate.loader.plan.build.internal.CascadeStyleLoadPlanBuildingAssociationVisitationStrategy) CollectionReturn(org.hibernate.loader.plan.spi.CollectionReturn) Return(org.hibernate.loader.plan.spi.Return) EntityReturn(org.hibernate.loader.plan.spi.EntityReturn) LoadPlan(org.hibernate.loader.plan.spi.LoadPlan) EntityReturn(org.hibernate.loader.plan.spi.EntityReturn) Test(org.junit.Test)

Example 4 with Return

use of org.hibernate.loader.plan.spi.Return in project hibernate-orm by hibernate.

the class LoadPlanBuilderTest method testCollectionInitializerCase.

@Test
public void testCollectionInitializerCase() {
    CollectionPersister cp = sessionFactory().getCollectionPersister(Poster.class.getName() + ".messages");
    FetchStyleLoadPlanBuildingAssociationVisitationStrategy strategy = new FetchStyleLoadPlanBuildingAssociationVisitationStrategy(sessionFactory(), LoadQueryInfluencers.NONE, LockMode.NONE);
    LoadPlan plan = MetamodelDrivenLoadPlanBuilder.buildRootCollectionLoadPlan(strategy, cp);
    assertFalse(plan.hasAnyScalarReturns());
    assertEquals(1, plan.getReturns().size());
    Return rtn = plan.getReturns().get(0);
    CollectionReturn collectionReturn = ExtraAssertions.assertTyping(CollectionReturn.class, rtn);
    assertNotNull(collectionReturn.getElementGraph());
    assertNotNull(collectionReturn.getElementGraph().getFetches());
    // the collection Message elements are fetched, but Message.poster is not fetched
    // (because that collection is owned by that Poster)
    assertEquals(0, collectionReturn.getElementGraph().getFetches().length);
    EntityReference entityReference = ExtraAssertions.assertTyping(EntityReference.class, collectionReturn.getElementGraph());
    assertNotNull(entityReference.getFetches());
    assertEquals(0, entityReference.getFetches().length);
    LoadPlanTreePrinter.INSTANCE.logTree(plan, new AliasResolutionContextImpl(sessionFactory()));
}
Also used : AliasResolutionContextImpl(org.hibernate.loader.plan.exec.internal.AliasResolutionContextImpl) CollectionPersister(org.hibernate.persister.collection.CollectionPersister) CollectionReturn(org.hibernate.loader.plan.spi.CollectionReturn) Return(org.hibernate.loader.plan.spi.Return) EntityReturn(org.hibernate.loader.plan.spi.EntityReturn) LoadPlan(org.hibernate.loader.plan.spi.LoadPlan) CollectionReturn(org.hibernate.loader.plan.spi.CollectionReturn) FetchStyleLoadPlanBuildingAssociationVisitationStrategy(org.hibernate.loader.plan.build.internal.FetchStyleLoadPlanBuildingAssociationVisitationStrategy) EntityReference(org.hibernate.loader.plan.spi.EntityReference) Test(org.junit.Test)

Aggregations

CollectionReturn (org.hibernate.loader.plan.spi.CollectionReturn)4 EntityReturn (org.hibernate.loader.plan.spi.EntityReturn)4 Return (org.hibernate.loader.plan.spi.Return)4 AliasResolutionContextImpl (org.hibernate.loader.plan.exec.internal.AliasResolutionContextImpl)3 LoadPlan (org.hibernate.loader.plan.spi.LoadPlan)3 Test (org.junit.Test)3 FetchStyleLoadPlanBuildingAssociationVisitationStrategy (org.hibernate.loader.plan.build.internal.FetchStyleLoadPlanBuildingAssociationVisitationStrategy)2 EntityFetch (org.hibernate.loader.plan.spi.EntityFetch)2 Fetch (org.hibernate.loader.plan.spi.Fetch)2 EntityPersister (org.hibernate.persister.entity.EntityPersister)2 CascadeStyleLoadPlanBuildingAssociationVisitationStrategy (org.hibernate.loader.plan.build.internal.CascadeStyleLoadPlanBuildingAssociationVisitationStrategy)1 EntityReference (org.hibernate.loader.plan.spi.EntityReference)1 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)1