use of org.hibernate.sql.ast.tree.from.TableGroup in project hibernate-orm by hibernate.
the class EntityGraphLoadPlanBuilderTest method assertEntityValuedJoinedGroup.
private void assertEntityValuedJoinedGroup(SelectStatement sqlAst, String expectedAttributeName, Class<?> expectedEntityJpaClass, Consumer<TableGroup> tableGroupConsumer) {
final FromClause fromClause = sqlAst.getQuerySpec().getFromClause();
assertThat(fromClause.getRoots(), hasSize(1));
final TableGroup rootTableGroup = fromClause.getRoots().get(0);
assertThat(rootTableGroup.getTableGroupJoins(), hasSize(1));
final TableGroup joinedGroup = CollectionUtils.getOnlyElement(rootTableGroup.getTableGroupJoins()).getJoinedGroup();
assertThat(joinedGroup.getModelPart().getPartName(), is(expectedAttributeName));
assertThat(joinedGroup.getModelPart().getJavaType().getJavaTypeClass(), assignableTo(expectedEntityJpaClass));
assertThat(joinedGroup.getModelPart(), instanceOf(EntityValuedModelPart.class));
tableGroupConsumer.accept(joinedGroup);
}
use of org.hibernate.sql.ast.tree.from.TableGroup 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.ast.tree.from.TableGroup in project hibernate-orm by hibernate.
the class HqlEntityGraphTest method assertEntityValuedJoinedGroup.
private void assertEntityValuedJoinedGroup(SelectStatement sqlAst, String expectedAttributeName, Class<?> expectedEntityJpaClass, Consumer<TableGroup> tableGroupConsumer) {
final FromClause fromClause = sqlAst.getQuerySpec().getFromClause();
assertThat(fromClause.getRoots(), hasSize(1));
final TableGroup rootTableGroup = fromClause.getRoots().get(0);
assertThat(rootTableGroup.getTableGroupJoins(), hasSize(1));
final TableGroup joinedGroup = rootTableGroup.getTableGroupJoins().iterator().next().getJoinedGroup();
assertThat(joinedGroup.getModelPart().getPartName(), is(expectedAttributeName));
assertThat(joinedGroup.getModelPart().getJavaType().getJavaTypeClass(), assignableTo(expectedEntityJpaClass));
assertThat(joinedGroup.getModelPart(), instanceOf(EntityValuedModelPart.class));
tableGroupConsumer.accept(joinedGroup);
}
use of org.hibernate.sql.ast.tree.from.TableGroup in project hibernate-orm by hibernate.
the class HqlEntityGraphTest method assertPluralAttributeJoinedGroup.
private void assertPluralAttributeJoinedGroup(SelectStatement sqlAst, String expectedPluralAttributeName, Consumer<TableGroup> tableGroupConsumer) {
final FromClause fromClause = sqlAst.getQuerySpec().getFromClause();
assertThat(fromClause.getRoots(), hasSize(1));
final TableGroup root = fromClause.getRoots().get(0);
assertThat(root.getTableGroupJoins(), hasSize(1));
final TableGroup joinedGroup = root.getTableGroupJoins().iterator().next().getJoinedGroup();
assertThat(joinedGroup.getModelPart().getPartName(), is(expectedPluralAttributeName));
assertThat(joinedGroup.getModelPart(), instanceOf(PluralAttributeMapping.class));
tableGroupConsumer.accept(joinedGroup);
}
use of org.hibernate.sql.ast.tree.from.TableGroup in project hibernate-orm by hibernate.
the class EntityGraphLoadPlanBuilderTest method assertPersonHomeAddressJoinedGroup.
private void assertPersonHomeAddressJoinedGroup(TableGroup tableGroup) {
assertThat(tableGroup.getTableGroupJoins(), hasSize(1));
final TableGroup joinedGroup = CollectionUtils.getOnlyElement(tableGroup.getTableGroupJoins()).getJoinedGroup();
assertThat(joinedGroup.getModelPart().getPartName(), is("homeAddress"));
assertThat(joinedGroup.getModelPart(), instanceOf(EmbeddedAttributeMapping.class));
assertThat(joinedGroup, instanceOf(StandardVirtualTableGroup.class));
}
Aggregations