From 62b98712d49723f79ac7b3a170f49eeb9004eb8f Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Fri, 26 Jul 2019 15:11:20 -0500 Subject: [PATCH] 6 - SQM based on JPA type system - SQM tests --- .../metamodel/internal/AttributeFactory.java | 2 +- .../metamodel/internal/MetadataContext.java | 40 ++++++++++++++++--- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java index 91f1de0bfd..22dd0b9177 100755 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java @@ -247,7 +247,7 @@ public class AttributeFactory { context.getJpaMetamodel() ); - context.registerEmbeddableType( embeddableType ); + context.registerEmbeddableType( embeddableType, component ); return embeddableType; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java index 86de425f37..c7bebd2dfd 100755 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java @@ -81,6 +81,8 @@ public class MetadataContext { private Map> entityTypesByPersistentClass = new HashMap<>(); private Map> embeddables = new HashMap<>(); + private Map> embeddablesToProcess = new HashMap<>(); + private Map,Component> componentByEmbeddable = new HashMap<>(); private Map> mappedSuperclassByMappedSuperclassMapping = new HashMap<>(); private Map, 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,9 +323,27 @@ public class MetadataContext { } } - if ( staticMetamodelScanEnabled ) { - for ( EmbeddableDomainType embeddable : embeddables.values() ) { - populateStaticMetamodel( embeddable ); + + while ( ! embeddablesToProcess.isEmpty() ) { + final ArrayList> processingEmbeddables = new ArrayList<>( embeddablesToProcess.values() ); + embeddablesToProcess.clear(); + + for ( EmbeddableDomainType embeddable : processingEmbeddables ) { + final Component component = componentByEmbeddable.get( embeddable ); + final Iterator 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 ) { + populateStaticMetamodel( embeddable ); + } } } } @@ -591,6 +614,11 @@ public class MetadataContext { public EmbeddableDomainType locateEmbeddable(Class embeddableClass) { //noinspection unchecked - return (EmbeddableDomainType) embeddables.get( embeddableClass ); + EmbeddableDomainType domainType = (EmbeddableDomainType) embeddables.get( embeddableClass ); + if ( domainType == null ) { + //noinspection unchecked + domainType = (EmbeddableDomainType) embeddablesToProcess.get( embeddableClass ); + } + return domainType; } }