Skip to content

Commit

Permalink
Introduce VirtualIdEmbeddable and IdClassEmbeddable
Browse files Browse the repository at this point in the history
Clean-up

Still need to
  - integrate EmbeddableInstantiator work
  - integrate embedded forms.  `VirtualIdEmbeddable` does not really need it as it can use the id-mapping itself as the embedded form.  But `IdClassEmbedded` should really be integrated
  - integrate `VirtualKeyEmbeddable` and `VirtualKeyEmbedded` for use as inverse composite fks
  - share `#finishInit` handling for `EmbeddableMappingType`, `VirtualIdEmbeddable` and `IdClassEmbeddable`
  • Loading branch information
sebersole committed Dec 1, 2021
1 parent 0322d8f commit bb2b0a6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.List;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.function.BiConsumer;

import org.hibernate.FetchMode;
import org.hibernate.MappingException;
Expand Down Expand Up @@ -68,7 +67,6 @@
import org.hibernate.metamodel.mapping.PropertyBasedMapping;
import org.hibernate.metamodel.mapping.SelectableMapping;
import org.hibernate.metamodel.mapping.SelectableMappings;
import org.hibernate.metamodel.mapping.SingularAttributeMapping;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadata;
import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess;
import org.hibernate.metamodel.model.convert.spi.BasicValueConverter;
Expand Down Expand Up @@ -149,9 +147,7 @@ public static CompositeIdentifierMapping buildNonEncapsulatedCompositeIdentifier
EntityPersister entityPersister,
String rootTableName,
String[] rootTableKeyColumnNames,
CompositeType cidType,
PersistentClass bootEntityDescriptor,
BiConsumer<String,SingularAttributeMapping> idSubAttributeConsumer,
MappingModelCreationProcess creationProcess) {
return new NonAggregatedIdentifierMappingImpl(
entityPersister,
Expand All @@ -160,81 +156,6 @@ public static CompositeIdentifierMapping buildNonEncapsulatedCompositeIdentifier
rootTableKeyColumnNames,
creationProcess
);

// final Component bootIdClassComponent = (Component) bootEntityDescriptor.getIdentifier();
// final Component bootVirtualComponent;
// if ( bootEntityDescriptor.getIdentifierMapper() == null ) {
// // If there is no id-class, there apparently also is no id mapper
// bootVirtualComponent = bootIdClassComponent;
// }
// else {
// bootVirtualComponent = bootEntityDescriptor.getIdentifierMapper();
// }
//
// final EmbeddableMappingType embeddableMappingType = EmbeddableMappingType.from(
// bootVirtualComponent,
// (CompositeType) bootVirtualComponent.getType(),
// rootTableName,
// rootTableKeyColumnNames,
// attributeMappingType -> {
// final PropertyAccess propertyAccess = PropertyAccessStrategyMapImpl.INSTANCE.buildPropertyAccess(
// null,
// EntityIdentifierMapping.ROLE_LOCAL_NAME
// );
// final StateArrayContributorMetadataAccess attributeMetadataAccess = getStateArrayContributorMetadataAccess(
// propertyAccess
// );
//
// final EmbeddableMappingType idClassType;
// if ( bootIdClassComponent != bootVirtualComponent ) {
// idClassType = EmbeddableMappingType.from(
// bootIdClassComponent,
// (CompositeType) bootIdClassComponent.getType(),
// rootTableName,
// rootTableKeyColumnNames,
// idClassEmbeddableType -> new EmbeddedAttributeMapping(
// "{id-class}",
// entityPersister.getNavigableRole()
// .append( EntityIdentifierMapping.ROLE_LOCAL_NAME )
// .append( "{id-class}" ),
// -1,
// null,
// attributeMetadataAccess,
// (String) null,
// FetchTiming.IMMEDIATE,
// FetchStyle.JOIN,
// idClassEmbeddableType,
// entityPersister,
// propertyAccess,
// null
// ),
// creationProcess
// );
// }
// else {
// idClassType = attributeMappingType;
// }
// return new NonAggregatedIdentifierMappingImpl(
// attributeMappingType,
// entityPersister,
// idClassType,
// attributeMetadataAccess,
// rootTableName,
// creationProcess
// );
// },
// creationProcess
// );
//
// // Inject the model part also in the composite type of the id-class, because that is what we actually "instantiate"
// // which needs the model part for instantiation
//// final CompositeIdentifierMapping compositeIdentifierMapping = (CompositeIdentifierMapping) virtualIdEmbeddable.getEmbeddedValueMapping();
//// ( (CompositeTypeImplementor) virtualIdSource.getType() ).injectMappingModelPart(
//// (EmbeddableValuedModelPart) compositeIdentifierMapping,
//// creationProcess
//// );
//
// return compositeIdentifierMapping;
}


Expand Down Expand Up @@ -319,6 +240,7 @@ public CascadeStyle getCascadeStyle() {
// we want to "decompose" the "type" into its various pieces as expected by the mapping
assert valueConverter.getRelationalJavaDescriptor() == resolution.getRelationalJavaDescriptor();

//noinspection unchecked
final BasicType<?> mappingBasicType = creationProcess.getCreationContext()
.getDomainModel()
.getTypeConfiguration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5878,7 +5878,7 @@ protected EntityIdentifierMapping generateIdentifierMapping(
}

// otherwise we have a non-encapsulated composite-identifier
return generateNonEncapsulatedCompositeIdentifierMapping( creationProcess, bootEntityDescriptor, cidType );
return generateNonEncapsulatedCompositeIdentifierMapping( creationProcess, bootEntityDescriptor );
}

return new BasicEntityIdentifierMappingImpl(
Expand All @@ -5894,17 +5894,14 @@ protected EntityIdentifierMapping generateIdentifierMapping(

protected EntityIdentifierMapping generateNonEncapsulatedCompositeIdentifierMapping(
MappingModelCreationProcess creationProcess,
PersistentClass bootEntityDescriptor,
CompositeType cidType) {
PersistentClass bootEntityDescriptor) {
assert declaredAttributeMappings != null;

return MappingModelCreationHelper.buildNonEncapsulatedCompositeIdentifierMapping(
this,
getTableName(),
getRootTableKeyColumnNames(),
cidType,
bootEntityDescriptor,
declaredAttributeMappings::put,
creationProcess
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -1215,7 +1214,7 @@ protected EntityIdentifierMapping generateIdentifierMapping(
}

// otherwise we have a non-encapsulated composite-identifier
return generateNonEncapsulatedCompositeIdentifierMapping( creationProcess, bootEntityDescriptor, cidType );
return generateNonEncapsulatedCompositeIdentifierMapping( creationProcess, bootEntityDescriptor );
}

return new BasicEntityIdentifierMappingImpl(
Expand Down Expand Up @@ -1265,17 +1264,14 @@ protected EntityDiscriminatorMapping generateDiscriminatorMapping(MappingModelCr

protected EntityIdentifierMapping generateNonEncapsulatedCompositeIdentifierMapping(
MappingModelCreationProcess creationProcess,
PersistentClass bootEntityDescriptor,
CompositeType cidType) {
PersistentClass bootEntityDescriptor) {
assert declaredAttributeMappings != null;

return MappingModelCreationHelper.buildNonEncapsulatedCompositeIdentifierMapping(
this,
getTableName(),
tableKeyColumns[0],
cidType,
bootEntityDescriptor,
declaredAttributeMappings::put,
creationProcess
);
}
Expand Down

0 comments on commit bb2b0a6

Please sign in to comment.