use of org.hibernate.metamodel.mapping.PluralAttributeMapping in project hibernate-orm by hibernate.
the class LoadPlanBuilderTest method testCollectionInitializerCase.
@Test
public void testCollectionInitializerCase(SessionFactoryScope scope) {
final SessionFactoryImplementor sessionFactory = scope.getSessionFactory();
final EntityPersister posterEntityDescriptor = sessionFactory.getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(Poster.class);
final PluralAttributeMapping messages = (PluralAttributeMapping) posterEntityDescriptor.findAttributeMapping("messages");
final CollectionLoaderSingleKey loader = new CollectionLoaderSingleKey(messages, LoadQueryInfluencers.NONE, sessionFactory);
assertThat(loader.getSqlAst().getDomainResultDescriptors()).hasSize(1);
assertThat(loader.getSqlAst().getDomainResultDescriptors().get(0)).isInstanceOf(CollectionDomainResult.class);
final CollectionDomainResult domainResult = (CollectionDomainResult) loader.getSqlAst().getDomainResultDescriptors().get(0);
DomainResultGraphPrinter.logDomainResultGraph(loader.getSqlAst().getDomainResultDescriptors());
assertThat(domainResult.getFetches()).isEmpty();
}
use of org.hibernate.metamodel.mapping.PluralAttributeMapping in project hibernate-orm by hibernate.
the class PluralAttributeMappingTests method testMaps.
@Test
public void testMaps(SessionFactoryScope scope) {
final MappingMetamodel domainModel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
final EntityMappingType containerEntityDescriptor = domainModel.getEntityDescriptor(EntityOfMaps.class);
assertThat(containerEntityDescriptor.getNumberOfAttributeMappings(), is(17));
final PluralAttributeMapping basicByBasic = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("basicByBasic");
assertThat(basicByBasic, notNullValue());
assertThat(basicByBasic.getKeyDescriptor(), notNullValue());
assertThat(basicByBasic.getElementDescriptor(), notNullValue());
final PluralAttributeMapping sortedBasicByBasic = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("sortedBasicByBasic");
assertThat(sortedBasicByBasic, notNullValue());
assertThat(sortedBasicByBasic.getKeyDescriptor(), notNullValue());
assertThat(sortedBasicByBasic.getElementDescriptor(), notNullValue());
final PluralAttributeMapping sortedBasicByBasicWithSortNaturalByDefault = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("sortedBasicByBasicWithSortNaturalByDefault");
assertThat(sortedBasicByBasicWithSortNaturalByDefault, notNullValue());
assertThat(sortedBasicByBasicWithSortNaturalByDefault.getKeyDescriptor(), notNullValue());
assertThat(sortedBasicByBasicWithSortNaturalByDefault.getElementDescriptor(), notNullValue());
final PluralAttributeMapping basicByEnum = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("basicByEnum");
assertThat(basicByEnum, notNullValue());
assertThat(basicByEnum.getKeyDescriptor(), notNullValue());
assertThat(basicByEnum.getElementDescriptor(), notNullValue());
final PluralAttributeMapping basicByConvertedEnum = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("basicByConvertedEnum");
assertThat(basicByConvertedEnum, notNullValue());
assertThat(basicByConvertedEnum.getKeyDescriptor(), notNullValue());
assertThat(basicByConvertedEnum.getElementDescriptor(), notNullValue());
final PluralAttributeMapping someStuffByBasic = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("componentByBasic");
assertThat(someStuffByBasic, notNullValue());
assertThat(someStuffByBasic.getKeyDescriptor(), notNullValue());
assertThat(someStuffByBasic.getElementDescriptor(), notNullValue());
final PluralAttributeMapping basicBySomeStuff = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("basicByComponent");
assertThat(basicBySomeStuff, notNullValue());
assertThat(basicBySomeStuff.getKeyDescriptor(), notNullValue());
assertThat(basicBySomeStuff.getElementDescriptor(), notNullValue());
final PluralAttributeMapping oneToManyByBasic = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("oneToManyByBasic");
assertThat(oneToManyByBasic, notNullValue());
assertThat(oneToManyByBasic.getKeyDescriptor(), notNullValue());
assertThat(oneToManyByBasic.getElementDescriptor(), notNullValue());
final PluralAttributeMapping basicByOneToMany = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("basicByOneToMany");
assertThat(basicByOneToMany, notNullValue());
assertThat(basicByOneToMany.getKeyDescriptor(), notNullValue());
assertThat(basicByOneToMany.getElementDescriptor(), notNullValue());
final PluralAttributeMapping manyToManyByBasic = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("manyToManyByBasic");
assertThat(manyToManyByBasic, notNullValue());
assertThat(manyToManyByBasic.getKeyDescriptor(), notNullValue());
assertThat(manyToManyByBasic.getElementDescriptor(), notNullValue());
final PluralAttributeMapping sortedManyToManyByBasic = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("sortedManyToManyByBasic");
assertThat(sortedManyToManyByBasic, notNullValue());
assertThat(sortedManyToManyByBasic.getKeyDescriptor(), notNullValue());
assertThat(sortedManyToManyByBasic.getElementDescriptor(), notNullValue());
final PluralAttributeMapping sortedManyToManyByBasicWithSortNaturalByDefault = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("sortedManyToManyByBasicWithSortNaturalByDefault");
assertThat(sortedManyToManyByBasicWithSortNaturalByDefault, notNullValue());
assertThat(sortedManyToManyByBasicWithSortNaturalByDefault.getKeyDescriptor(), notNullValue());
assertThat(sortedManyToManyByBasicWithSortNaturalByDefault.getElementDescriptor(), notNullValue());
final PluralAttributeMapping componentByBasicOrdered = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("componentByBasicOrdered");
assertThat(componentByBasicOrdered, notNullValue());
assertThat(componentByBasicOrdered.getKeyDescriptor(), notNullValue());
assertThat(componentByBasicOrdered.getElementDescriptor(), notNullValue());
assertThat(componentByBasicOrdered.getOrderByFragment(), notNullValue());
}
use of org.hibernate.metamodel.mapping.PluralAttributeMapping in project hibernate-orm by hibernate.
the class VirtualIdEmbeddable method forEachJdbcValue.
@Override
public int forEachJdbcValue(Object value, Clause clause, int offset, JdbcValuesConsumer valuesConsumer, SharedSessionContractImplementor session) {
int span = 0;
for (int i = 0; i < attributeMappings.size(); i++) {
final AttributeMapping attributeMapping = attributeMappings.get(i);
if (attributeMapping instanceof PluralAttributeMapping) {
continue;
}
final Object o = attributeMapping.getPropertyAccess().getGetter().get(value);
span += attributeMapping.forEachJdbcValue(o, clause, span + offset, valuesConsumer, session);
}
return span;
}
use of org.hibernate.metamodel.mapping.PluralAttributeMapping in project hibernate-orm by hibernate.
the class IdClassEmbeddable method forEachJdbcValue.
@Override
public int forEachJdbcValue(Object value, Clause clause, int offset, JdbcValuesConsumer valuesConsumer, SharedSessionContractImplementor session) {
int span = 0;
for (int i = 0; i < attributeMappings.size(); i++) {
final AttributeMapping attributeMapping = attributeMappings.get(i);
if (attributeMapping instanceof PluralAttributeMapping) {
continue;
}
final Object o = attributeMapping.getPropertyAccess().getGetter().get(value);
span += attributeMapping.forEachJdbcValue(o, clause, span + offset, valuesConsumer, session);
}
return span;
}
use of org.hibernate.metamodel.mapping.PluralAttributeMapping in project hibernate-orm by hibernate.
the class DynamicFetchBuilderStandard method buildFetch.
@Override
public Fetch buildFetch(FetchParent parent, NavigablePath fetchPath, JdbcValuesMetadata jdbcResultsMetadata, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
final DomainResultCreationStateImpl creationStateImpl = ResultsHelper.impl(domainResultCreationState);
final TableGroup ownerTableGroup = creationStateImpl.getFromClauseAccess().getTableGroup(parent.getNavigablePath());
final Fetchable attributeMapping = (Fetchable) parent.getReferencedMappingContainer().findSubPart(fetchableName, null);
final SqlExpressionResolver sqlExpressionResolver = domainResultCreationState.getSqlAstCreationState().getSqlExpressionResolver();
final SelectableConsumer selectableConsumer = (selectionIndex, selectableMapping) -> {
final TableReference tableReference = ownerTableGroup.resolveTableReference(fetchPath, selectableMapping.getContainingTableExpression());
final String columnAlias = columnNames.get(selectionIndex);
sqlExpressionResolver.resolveSqlSelection(sqlExpressionResolver.resolveSqlExpression(createColumnReferenceKey(tableReference, selectableMapping.getSelectionExpression()), state -> {
final int resultSetPosition = jdbcResultsMetadata.resolveColumnPosition(columnAlias);
final int valuesArrayPosition = resultSetPosition - 1;
return new ResultSetMappingSqlSelection(valuesArrayPosition, selectableMapping.getJdbcMapping());
}), selectableMapping.getJdbcMapping().getMappedJavaType(), domainResultCreationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration());
};
if (attributeMapping instanceof BasicValuedMapping) {
attributeMapping.forEachSelectable(selectableConsumer);
return parent.generateFetchableFetch(attributeMapping, fetchPath, FetchTiming.IMMEDIATE, true, null, creationStateImpl);
} else if (attributeMapping instanceof EmbeddedAttributeMapping) {
attributeMapping.forEachSelectable(selectableConsumer);
return parent.generateFetchableFetch(attributeMapping, fetchPath, FetchTiming.IMMEDIATE, false, null, creationStateImpl);
} else if (attributeMapping instanceof ToOneAttributeMapping) {
final ToOneAttributeMapping toOneAttributeMapping = (ToOneAttributeMapping) attributeMapping;
toOneAttributeMapping.getForeignKeyDescriptor().getPart(toOneAttributeMapping.getSideNature()).forEachSelectable(selectableConsumer);
return parent.generateFetchableFetch(attributeMapping, fetchPath, FetchTiming.DELAYED, false, null, creationStateImpl);
} else {
assert attributeMapping instanceof PluralAttributeMapping;
final PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) attributeMapping;
pluralAttributeMapping.getKeyDescriptor().visitTargetSelectables(selectableConsumer);
return parent.generateFetchableFetch(attributeMapping, fetchPath, FetchTiming.DELAYED, false, null, creationStateImpl);
}
}
Aggregations