use of org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping in project hibernate-orm by hibernate.
the class AbstractCompositeIdentifierMapping method forEachJdbcValue.
@Override
public int forEachJdbcValue(Object value, Clause clause, int offset, JdbcValuesConsumer valuesConsumer, SharedSessionContractImplementor session) {
int span = 0;
final List<AttributeMapping> attributeMappings = getEmbeddableTypeDescriptor().getAttributeMappings();
for (int i = 0; i < attributeMappings.size(); i++) {
final AttributeMapping attributeMapping = attributeMappings.get(i);
final Object o = attributeMapping.getPropertyAccess().getGetter().get(value);
if (attributeMapping instanceof ToOneAttributeMapping) {
final ToOneAttributeMapping toOneAttributeMapping = (ToOneAttributeMapping) attributeMapping;
final ForeignKeyDescriptor fkDescriptor = toOneAttributeMapping.getForeignKeyDescriptor();
final Object identifier = fkDescriptor.getAssociationKeyFromSide(o, toOneAttributeMapping.getSideNature().inverse(), session);
span += fkDescriptor.forEachJdbcValue(identifier, clause, span + offset, valuesConsumer, session);
} else {
span += attributeMapping.forEachJdbcValue(o, clause, span + offset, valuesConsumer, session);
}
}
return span;
}
use of org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping 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);
}
}
use of org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping in project hibernate-orm by hibernate.
the class CircularFetchImpl method createAssembler.
@Override
public DomainResultAssembler createAssembler(FetchParentAccess parentAccess, AssemblerCreationState creationState) {
final DomainResultAssembler resultAssembler = keyResult.createResultAssembler(parentAccess, creationState);
final EntityInitializer initializer = (EntityInitializer) creationState.resolveInitializer(getNavigablePath(), referencedModelPart, () -> {
if (timing == FetchTiming.IMMEDIATE) {
if (selectByUniqueKey) {
return new EntitySelectFetchByUniqueKeyInitializer(parentAccess, fetchable, getNavigablePath(), entityMappingType.getEntityPersister(), resultAssembler);
}
final EntityPersister entityPersister = entityMappingType.getEntityPersister();
if (entityPersister.isBatchLoadable()) {
return new BatchEntitySelectFetchInitializer(parentAccess, (ToOneAttributeMapping) referencedModelPart, getReferencedPath(), entityPersister, resultAssembler);
} else {
return new EntitySelectFetchInitializer(parentAccess, (ToOneAttributeMapping) referencedModelPart, getReferencedPath(), entityPersister, resultAssembler);
}
} else {
return new EntityDelayedFetchInitializer(parentAccess, getReferencedPath(), fetchable, selectByUniqueKey, resultAssembler);
}
});
return new BiDirectionalFetchAssembler(initializer, fetchable.getJavaType());
}
use of org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping in project hibernate-orm by hibernate.
the class FetchMementoHbmStandard method resolve.
@Override
public FetchBuilder resolve(Parent parent, Consumer<String> querySpaceConsumer, ResultSetMappingResolutionContext context) {
final Map<String, FetchBuilder> fetchBuilderMap = new HashMap<>();
fetchMementoMap.forEach((attrName, fetchMemento) -> fetchBuilderMap.put(attrName, fetchMemento.resolve(this, querySpaceConsumer, context)));
final DynamicResultBuilderEntityStandard resultBuilder;
if (fetchable instanceof PluralAttributeMapping) {
resultBuilder = new DynamicResultBuilderEntityStandard((EntityMappingType) ((PluralAttributeMapping) fetchable).getElementDescriptor().getPartMappingType(), tableAlias, navigablePath);
FetchBuilder element = fetchBuilderMap.get("element");
if (element != null) {
if (element instanceof DynamicFetchBuilder) {
resultBuilder.addIdColumnAliases(((DynamicFetchBuilder) element).getColumnAliases().toArray(new String[0]));
} else {
resultBuilder.addIdColumnAliases(((CompleteFetchBuilderEntityValuedModelPart) element).getColumnAliases().toArray(new String[0]));
}
}
FetchBuilder index = fetchBuilderMap.get("index");
if (index != null) {
resultBuilder.addFetchBuilder(CollectionPart.Nature.INDEX.getName(), index);
}
for (Map.Entry<String, FetchBuilder> entry : fetchBuilderMap.entrySet()) {
if (entry.getKey().startsWith(ELEMENT_PREFIX)) {
resultBuilder.addFetchBuilder(entry.getKey().substring(ELEMENT_PREFIX.length()), entry.getValue());
}
}
} else {
resultBuilder = new DynamicResultBuilderEntityStandard(((ToOneAttributeMapping) fetchable).getEntityMappingType(), tableAlias, navigablePath);
fetchBuilderMap.forEach(resultBuilder::addFetchBuilder);
}
return new DynamicFetchBuilderLegacy(tableAlias, ownerTableAlias, fetchable.getFetchableName(), keyColumnNames, fetchBuilderMap, resultBuilder);
}
use of org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping in project hibernate-orm by hibernate.
the class PluralAttributePath method resolvePathPart.
@Override
public DomainPath resolvePathPart(String name, String identifier, boolean isTerminal, TranslationContext translationContext) {
final ModelPart subPart = pluralAttributeMapping.findSubPart(name, null);
if (subPart != null) {
if (subPart instanceof CollectionPart) {
return new CollectionPartPath(this, (CollectionPart) subPart);
}
if (subPart instanceof EmbeddableValuedModelPart) {
return new DomainPathContinuation(navigablePath.append(name), this, subPart);
}
if (subPart instanceof ToOneAttributeMapping) {
return new FkDomainPathContinuation(navigablePath.append(name), this, (ToOneAttributeMapping) subPart);
}
// leaf case:
final CollectionPartPath elementPath = new CollectionPartPath(this, pluralAttributeMapping.getElementDescriptor());
return (DomainPath) elementPath.resolvePathPart(name, identifier, isTerminal, translationContext);
}
if (pluralAttributeMapping.getElementDescriptor() instanceof EmbeddableValuedModelPart) {
final EmbeddableValuedModelPart elementDescriptor = (EmbeddableValuedModelPart) pluralAttributeMapping.getElementDescriptor();
final ModelPart elementSubPart = elementDescriptor.findSubPart(name, null);
if (elementSubPart != null) {
// create the CollectionSubPath to use as the `lhs` for the element sub-path
final CollectionPartPath elementPath = new CollectionPartPath(this, (CollectionPart) elementDescriptor);
return new DomainPathContinuation(elementPath.getNavigablePath().append(name), this, elementSubPart);
}
}
if (pluralAttributeMapping.getIndexDescriptor() instanceof EmbeddableValuedModelPart) {
final EmbeddableValuedModelPart indexDescriptor = (EmbeddableValuedModelPart) pluralAttributeMapping.getIndexDescriptor();
final ModelPart indexSubPart = indexDescriptor.findSubPart(name, null);
if (indexSubPart != null) {
// create the CollectionSubPath to use as the `lhs` for the element sub-path
final CollectionPartPath indexPath = new CollectionPartPath(this, (CollectionPart) indexDescriptor);
return new DomainPathContinuation(indexPath.getNavigablePath().append(name), this, indexSubPart);
}
}
return null;
}
Aggregations