6 - SQM based on JPA type system

- SQM tests
This commit is contained in:
Steve Ebersole 2019-07-26 15:11:20 -05:00 committed by Andrea Boriero
parent 1003ddf115
commit 62b98712d4
2 changed files with 35 additions and 7 deletions

View File

@ -247,7 +247,7 @@ public class AttributeFactory {
context.getJpaMetamodel()
);
context.registerEmbeddableType( embeddableType );
context.registerEmbeddableType( embeddableType, component );
return embeddableType;
}

View File

@ -81,6 +81,8 @@ public class MetadataContext {
private Map<PersistentClass, EntityDomainType<?>> entityTypesByPersistentClass = new HashMap<>();
private Map<Class, EmbeddableDomainType<?>> embeddables = new HashMap<>();
private Map<Class, EmbeddableDomainType<?>> embeddablesToProcess = new HashMap<>();
private Map<EmbeddableDomainType<?>,Component> componentByEmbeddable = new HashMap<>();
private Map<MappedSuperclass, MappedSuperclassDomainType<?>> mappedSuperclassByMappedSuperclassMapping = new HashMap<>();
private Map<MappedSuperclassDomainType<?>, PersistentClass> mappedSuperClassTypeToPersistentClass = new HashMap<>();
@ -166,11 +168,14 @@ public class MetadataContext {
orderedMappings.add( persistentClass );
}
public void registerEmbeddableType(EmbeddableDomainType<?> embeddableType) {
public void registerEmbeddableType(
EmbeddableDomainType<?> embeddableType,
Component bootDescriptor) {
assert embeddableType.getJavaType() != null;
assert ! Map.class.isAssignableFrom( embeddableType.getJavaType() );
embeddables.put( embeddableType.getJavaType(), embeddableType );
embeddablesToProcess.put( embeddableType.getJavaType(), embeddableType );
componentByEmbeddable.put( embeddableType, bootDescriptor );
}
public void registerMappedSuperclassType(
@ -318,12 +323,30 @@ public class MetadataContext {
}
}
while ( ! embeddablesToProcess.isEmpty() ) {
final ArrayList<EmbeddableDomainType<?>> processingEmbeddables = new ArrayList<>( embeddablesToProcess.values() );
embeddablesToProcess.clear();
for ( EmbeddableDomainType<?> embeddable : processingEmbeddables ) {
final Component component = componentByEmbeddable.get( embeddable );
final Iterator<Property> propertyItr = component.getPropertyIterator();
while ( propertyItr.hasNext() ) {
final Property property = propertyItr.next();
final PersistentAttribute attribute = attributeFactory.buildAttribute( embeddable, property );
if ( attribute != null ) {
( ( AttributeContainer) embeddable ).getInFlightAccess().addAttribute( attribute );
}
}
( ( AttributeContainer) embeddable ).getInFlightAccess().finishUp();
if ( staticMetamodelScanEnabled ) {
for ( EmbeddableDomainType embeddable : embeddables.values() ) {
populateStaticMetamodel( embeddable );
}
}
}
}
@SuppressWarnings("unchecked")
@ -591,6 +614,11 @@ public class MetadataContext {
public <J> EmbeddableDomainType<J> locateEmbeddable(Class<J> embeddableClass) {
//noinspection unchecked
return (EmbeddableDomainType<J>) embeddables.get( embeddableClass );
EmbeddableDomainType<J> domainType = (EmbeddableDomainType<J>) embeddables.get( embeddableClass );
if ( domainType == null ) {
//noinspection unchecked
domainType = (EmbeddableDomainType) embeddablesToProcess.get( embeddableClass );
}
return domainType;
}
}