use of org.hibernate.sql.results.graph.entity.internal.EntityFetchJoinedImpl in project hibernate-orm by hibernate.
the class CriteriaEntityGraphTest method testFetchSemanticsWithDeepSubgraph.
@Test
void testFetchSemanticsWithDeepSubgraph() {
scope.inTransaction(session -> {
final RootGraphImplementor<Cat> eg = session.createEntityGraph(Cat.class);
eg.addSubgraph("owner", Person.class).addSubgraph("company", ExpressCompany.class);
final SelectStatement sqlAst = buildSqlSelectAst(Cat.class, eg, GraphSemantic.FETCH, session);
// Check the from-clause
assertEntityValuedJoinedGroup(sqlAst, "owner", Person.class, tableGroup -> {
List<TableGroupJoin> tableGroupJoins = tableGroup.getTableGroupJoins();
Map<String, Class<? extends TableGroup>> tableGroupByName = tableGroupJoins.stream().map(TableGroupJoin::getJoinedGroup).collect(Collectors.toMap(tg -> tg.getModelPart().getPartName(), TableGroup::getClass));
Map<String, Class<? extends TableGroup>> expectedTableGroupByName = new HashMap<>();
expectedTableGroupByName.put("homeAddress", StandardVirtualTableGroup.class);
expectedTableGroupByName.put("company", LazyTableGroup.class);
assertThat(tableGroupByName, is(expectedTableGroupByName));
});
// Check the domain-result graph
assertDomainResult(sqlAst, Cat.class, "owner", Person.class, entityFetch -> {
assertThat(entityFetch, instanceOf(EntityFetchJoinedImpl.class));
final EntityResult ownerEntityResult = ((EntityFetchJoinedImpl) entityFetch).getEntityResult();
final Map<String, Class<? extends Fetch>> fetchClassByAttributeName = ownerEntityResult.getFetches().stream().collect(Collectors.toMap(fetch -> fetch.getFetchedMapping().getPartName(), Fetch::getClass));
final Map<String, Class<? extends Fetch>> expectedFetchClassByAttributeName = new HashMap<>();
expectedFetchClassByAttributeName.put("homeAddress", EmbeddableFetchImpl.class);
expectedFetchClassByAttributeName.put("pets", DelayedCollectionFetch.class);
expectedFetchClassByAttributeName.put("company", EntityFetchJoinedImpl.class);
assertThat(fetchClassByAttributeName, is(expectedFetchClassByAttributeName));
Fetchable fetchable = getFetchable("company", Person.class);
final Fetch companyFetch = ownerEntityResult.findFetch(fetchable);
List<Fetch> fetches = ownerEntityResult.getFetches();
assertThat(companyFetch, notNullValue());
final EntityResult companyEntityResult = ((EntityFetchJoinedImpl) companyFetch).getEntityResult();
assertThat(companyEntityResult.getFetches(), hasSize(1));
final Fetch shipAddressesFetch = companyEntityResult.getFetches().get(0);
assertThat(shipAddressesFetch.getFetchedMapping().getPartName(), is("shipAddresses"));
assertThat(shipAddressesFetch, instanceOf(DelayedCollectionFetch.class));
});
});
}
use of org.hibernate.sql.results.graph.entity.internal.EntityFetchJoinedImpl in project hibernate-orm by hibernate.
the class EntityGraphLoadPlanBuilderTest method testFetchLoadPlanBuildingWithDeepSubgraph.
@Test
void testFetchLoadPlanBuildingWithDeepSubgraph() {
scope.inTransaction(em -> {
final RootGraphImplementor<Cat> eg = em.createEntityGraph(Cat.class);
eg.addSubgraph("owner", Person.class).addSubgraph("company", ExpressCompany.class);
final SelectStatement sqlAst = buildSqlSelectAst(Cat.class, eg, GraphSemantic.FETCH, scope);
// Check the from-clause
assertEntityValuedJoinedGroup(sqlAst, "owner", Person.class, tableGroup -> {
List<TableGroupJoin> tableGroupJoins = tableGroup.getTableGroupJoins();
Map<String, Class<? extends TableGroup>> tableGroupByName = tableGroupJoins.stream().map(TableGroupJoin::getJoinedGroup).collect(Collectors.toMap(tg -> tg.getModelPart().getPartName(), TableGroup::getClass));
Map<String, Class<? extends TableGroup>> expectedTableGroupByName = new HashMap<>();
expectedTableGroupByName.put("homeAddress", StandardVirtualTableGroup.class);
expectedTableGroupByName.put("company", LazyTableGroup.class);
assertThat(tableGroupByName, is(expectedTableGroupByName));
});
// Check the domain-result graph
assertDomainResult(sqlAst, Cat.class, "owner", Person.class, entityFetch -> {
assertThat(entityFetch, instanceOf(EntityFetchJoinedImpl.class));
final EntityResult ownerEntityResult = ((EntityFetchJoinedImpl) entityFetch).getEntityResult();
final Map<String, Class<? extends Fetch>> fetchClassByAttributeName = ownerEntityResult.getFetches().stream().collect(Collectors.toMap(fetch -> fetch.getFetchedMapping().getPartName(), Fetch::getClass));
final Map<String, Class<? extends Fetch>> expectedFetchClassByAttributeName = new HashMap<>();
expectedFetchClassByAttributeName.put("homeAddress", EmbeddableFetchImpl.class);
expectedFetchClassByAttributeName.put("pets", DelayedCollectionFetch.class);
expectedFetchClassByAttributeName.put("company", EntityFetchJoinedImpl.class);
assertThat(fetchClassByAttributeName, is(expectedFetchClassByAttributeName));
Fetchable fetchable = getFetchable("company", Person.class);
final Fetch companyFetch = ownerEntityResult.findFetch(fetchable);
assertThat(companyFetch, notNullValue());
final EntityResult companyEntityResult = ((EntityFetchJoinedImpl) companyFetch).getEntityResult();
assertThat(companyEntityResult.getFetches(), hasSize(1));
final Fetch shipAddressesFetch = companyEntityResult.getFetches().get(0);
assertThat(shipAddressesFetch.getFetchedMapping().getPartName(), is("shipAddresses"));
assertThat(shipAddressesFetch, instanceOf(DelayedCollectionFetch.class));
});
});
}
use of org.hibernate.sql.results.graph.entity.internal.EntityFetchJoinedImpl in project hibernate-orm by hibernate.
the class EntityGraphLoadPlanBuilderTest method testLoadPlanBuildingWithSubgraph.
@ParameterizedTest
@EnumSource(GraphSemantic.class)
void testLoadPlanBuildingWithSubgraph(GraphSemantic graphSemantic) {
scope.inTransaction(em -> {
final RootGraphImplementor<Cat> eg = em.createEntityGraph(Cat.class);
eg.addSubgraph("owner", Person.class);
final SelectStatement sqlAst = buildSqlSelectAst(Cat.class, eg, graphSemantic, scope);
// Check the from-clause
assertEntityValuedJoinedGroup(sqlAst, "owner", Person.class, this::assertPersonHomeAddressJoinedGroup);
// Check the domain-result graph
assertDomainResult(sqlAst, Cat.class, "owner", Person.class, entityFetch -> {
if (graphSemantic == GraphSemantic.LOAD) {
assertThat(entityFetch, instanceOf(EntityFetchJoinedImpl.class));
final EntityResult entityResult = ((EntityFetchJoinedImpl) entityFetch).getEntityResult();
final Map<String, Class<? extends Fetch>> fetchClassByAttributeName = entityResult.getFetches().stream().collect(Collectors.toMap(fetch -> fetch.getFetchedMapping().getPartName(), Fetch::getClass));
final Map<String, Class<? extends Fetch>> expectedFetchClassByAttributeName = new HashMap<>();
expectedFetchClassByAttributeName.put("pets", DelayedCollectionFetch.class);
expectedFetchClassByAttributeName.put("homeAddress", EmbeddableFetchImpl.class);
expectedFetchClassByAttributeName.put("company", EntityDelayedFetchImpl.class);
assertThat(fetchClassByAttributeName, is(expectedFetchClassByAttributeName));
}
});
});
}
use of org.hibernate.sql.results.graph.entity.internal.EntityFetchJoinedImpl in project hibernate-orm by hibernate.
the class HqlEntityGraphTest method testFetchSemanticsWithDeepSubgraph.
@Test
void testFetchSemanticsWithDeepSubgraph() {
scope.inTransaction(session -> {
final RootGraphImplementor<Cat> eg = session.createEntityGraph(Cat.class);
eg.addSubgraph("owner", Person.class).addSubgraph("company", ExpressCompany.class);
final SelectStatement sqlAst = buildSqlSelectAst(Cat.class, "select c from Cat as c", eg, GraphSemantic.FETCH, session);
// Check the from-clause
assertEntityValuedJoinedGroup(sqlAst, "owner", Person.class, tableGroup -> {
List<TableGroupJoin> tableGroupJoins = tableGroup.getTableGroupJoins();
Map<String, Class<? extends TableGroup>> tableGroupByName = tableGroupJoins.stream().map(TableGroupJoin::getJoinedGroup).collect(Collectors.toMap(tg -> tg.getModelPart().getPartName(), TableGroup::getClass));
Map<String, Class<? extends TableGroup>> expectedTableGroupByName = new HashMap<>();
expectedTableGroupByName.put("homeAddress", StandardVirtualTableGroup.class);
expectedTableGroupByName.put("company", LazyTableGroup.class);
assertThat(tableGroupByName, is(expectedTableGroupByName));
});
// Check the domain-result graph
assertDomainResult(sqlAst, Cat.class, "owner", Person.class, entityFetch -> {
assertThat(entityFetch, instanceOf(EntityFetchJoinedImpl.class));
final EntityResult ownerEntityResult = ((EntityFetchJoinedImpl) entityFetch).getEntityResult();
final Map<String, Class<? extends Fetch>> fetchClassByAttributeName = ownerEntityResult.getFetches().stream().collect(Collectors.toMap(fetch -> fetch.getFetchedMapping().getPartName(), Fetch::getClass));
final Map<String, Class<? extends Fetch>> expectedFetchClassByAttributeName = new HashMap<>();
expectedFetchClassByAttributeName.put("homeAddress", EmbeddableFetchImpl.class);
expectedFetchClassByAttributeName.put("pets", DelayedCollectionFetch.class);
expectedFetchClassByAttributeName.put("company", EntityFetchJoinedImpl.class);
assertThat(fetchClassByAttributeName, is(expectedFetchClassByAttributeName));
Fetchable fetchable = getFetchable("company", Person.class);
final Fetch companyFetch = ownerEntityResult.findFetch(fetchable);
assertThat(companyFetch, notNullValue());
final EntityResult companyEntityResult = ((EntityFetchJoinedImpl) companyFetch).getEntityResult();
assertThat(companyEntityResult.getFetches(), hasSize(1));
final Fetch shipAddressesFetch = companyEntityResult.getFetches().get(0);
assertThat(shipAddressesFetch.getFetchedMapping().getPartName(), is("shipAddresses"));
assertThat(shipAddressesFetch, instanceOf(DelayedCollectionFetch.class));
});
});
}
use of org.hibernate.sql.results.graph.entity.internal.EntityFetchJoinedImpl in project hibernate-orm by hibernate.
the class HqlEntityGraphTest method testSemanticsWithSubgraph.
@ParameterizedTest
@EnumSource(GraphSemantic.class)
void testSemanticsWithSubgraph(GraphSemantic graphSemantic) {
scope.inTransaction(session -> {
final RootGraphImplementor<Cat> eg = session.createEntityGraph(Cat.class);
eg.addSubgraph("owner", Person.class);
final SelectStatement sqlAst = buildSqlSelectAst(Cat.class, "select c from Cat as c", eg, graphSemantic, session);
// Check the from-clause
assertEntityValuedJoinedGroup(sqlAst, "owner", Person.class, this::assertPersonHomeAddressJoinedGroup);
// Check the domain-result graph
assertDomainResult(sqlAst, Cat.class, "owner", Person.class, entityFetch -> {
if (graphSemantic == GraphSemantic.LOAD) {
assertThat(entityFetch, instanceOf(EntityFetchJoinedImpl.class));
final EntityResult entityResult = ((EntityFetchJoinedImpl) entityFetch).getEntityResult();
final Map<String, Class<? extends Fetch>> fetchClassByAttributeName = entityResult.getFetches().stream().collect(Collectors.toMap(fetch -> fetch.getFetchedMapping().getPartName(), Fetch::getClass));
final Map<String, Class<? extends Fetch>> expectedFetchClassByAttributeName = new HashMap<>();
expectedFetchClassByAttributeName.put("pets", DelayedCollectionFetch.class);
expectedFetchClassByAttributeName.put("homeAddress", EmbeddableFetchImpl.class);
expectedFetchClassByAttributeName.put("company", EntityDelayedFetchImpl.class);
assertThat(fetchClassByAttributeName, is(expectedFetchClassByAttributeName));
}
});
});
}
Aggregations