From 638c217e8aa3d03c0eb8ebd4d7661e3a9b97b2dd Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Sat, 1 Jun 2019 14:32:42 +0100 Subject: [PATCH] 6 - SQM based on JPA type system, RuntimeModelCreationProcess --- .../internal/InflightRuntimeMetamodel.java | 5 + .../domain/internal/DomainMetamodelImpl.java | 94 ++++++++++++++++++- .../metamodel/spi/MetamodelImplementor.java | 4 +- 3 files changed, 101 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/InflightRuntimeMetamodel.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/InflightRuntimeMetamodel.java index 690814581d..285ccce4dd 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/InflightRuntimeMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/InflightRuntimeMetamodel.java @@ -75,6 +75,7 @@ public class InflightRuntimeMetamodel { private final Map nameToImportNameMap = new HashMap<>(); private final Set entityNameResolvers = new CopyOnWriteArraySet<>(); + private final Map imports = new ConcurrentHashMap<>( ); public InflightRuntimeMetamodel(TypeConfiguration typeConfiguration) { this.typeConfiguration = typeConfiguration; @@ -88,6 +89,7 @@ public class InflightRuntimeMetamodel { PersisterCreationContext persisterCreationContext, JpaMetaModelPopulationSetting jpaMetaModelPopulationSetting, JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting) { + this.imports.putAll( bootMetamodel.getImports() ); processBootEntities( bootMetamodel.getEntityBindings(), cacheImplementor, @@ -424,4 +426,7 @@ public class InflightRuntimeMetamodel { return entityType; } + public Map getImports() { + return imports; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainMetamodelImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainMetamodelImpl.java index 908b4a68ef..3449567887 100755 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainMetamodelImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainMetamodelImpl.java @@ -21,6 +21,7 @@ import javax.persistence.metamodel.ManagedType; import org.hibernate.EntityNameResolver; import org.hibernate.MappingException; +import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.UnknownEntityTypeException; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; @@ -35,6 +36,7 @@ import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.metamodel.model.domain.ManagedDomainType; +import org.hibernate.metamodel.model.domain.NavigableRole; import org.hibernate.metamodel.spi.DomainMetamodel; import org.hibernate.metamodel.spi.MetamodelImplementor; import org.hibernate.persister.collection.CollectionPersister; @@ -53,7 +55,6 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento // todo : Integrate EntityManagerLogger into CoreMessageLogger private static final EntityManagerMessageLogger log = HEMLogging.messageLogger( DomainMetamodelImpl.class ); - private static final Object ENTITY_NAME_RESOLVER_MAP_VALUE = new Object(); private static final String INVALID_IMPORT = ""; private static final String[] EMPTY_IMPLEMENTORS = new String[0]; @@ -80,6 +81,8 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento private final Set entityNameResolvers; + private final Map imports; + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // NOTE : Relational/mapping information is not part of the JPA metamodel @@ -129,6 +132,7 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento this.collectionRolesByEntityParticipant = runtimeMetamodel.getCollectionRolesByEntityParticipant(); this.entityNameResolvers = runtimeMetamodel.getEntityNameResolvers(); this.entityProxyInterfaceMap = runtimeMetamodel.getEntityProxyInterfaceMap(); + this.imports = runtimeMetamodel.getImports(); } @Override @@ -157,6 +161,11 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento entityPersisterMap.values().forEach( action ); } + @Override + public EntityPersister resolveEntityDescriptor(EntityDomainType entityDomainType) { + throw new NotYetImplementedFor6Exception( getClass() ); + } + @Override public EntityPersister getEntityDescriptor(String entityName) { final EntityPersister entityPersister = entityPersisterMap.get( entityName ); @@ -166,6 +175,11 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento return entityPersister; } + @Override + public EntityPersister getEntityDescriptor(NavigableRole name) { + throw new NotYetImplementedFor6Exception( getClass() ); + } + @Override public EntityPersister findEntityDescriptor(String entityName) { return entityPersisterMap.get( entityName ); @@ -254,6 +268,29 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento return getJpaMetamodel().entity( entityName ); } + @Override + public String getImportedClassName(String className) { + String result = imports.get( className ); + if ( result == null ) { + try { + sessionFactory.getServiceRegistry().getService( ClassLoaderService.class ).classForName( className ); + imports.put( className, className ); + return className; + } + catch ( ClassLoadingException cnfe ) { + imports.put( className, INVALID_IMPORT ); + return null; + } + } + else if ( result == INVALID_IMPORT ) { + return null; + } + else { + return result; + } + } + + @Override public String[] getImplementors(String className) throws MappingException { // computeIfAbsent() can be a contention point and we expect all the values to be in the map at some point so @@ -323,6 +360,11 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento return entityPersister; } + @Override + public String getImportedName(String name) { + throw new NotYetImplementedFor6Exception( getClass() ); + } + @Override public void visitCollectionDescriptors(Consumer action) { collectionPersisterMap.values().forEach( action ); @@ -337,6 +379,16 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento return collectionPersister; } + @Override + public CollectionPersister getCollectionDescriptor(NavigableRole role) { + throw new NotYetImplementedFor6Exception( getClass() ); + } + + @Override + public CollectionPersister findCollectionDescriptor(NavigableRole role) { + throw new NotYetImplementedFor6Exception( getClass() ); + } + @Override public CollectionPersister findCollectionDescriptor(String role) { return collectionPersisterMap.get( role ); @@ -384,6 +436,46 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento return findEntityGraphByName( name ); } + @Override + public void visitNamedGraphs(Consumer> action) { + throw new NotYetImplementedFor6Exception( getClass() ); + } + + @Override + public RootGraph defaultGraph(String entityName) { + throw new NotYetImplementedFor6Exception( getClass() ); + } + + @Override + public RootGraph defaultGraph(Class entityJavaType) { + throw new NotYetImplementedFor6Exception( getClass() ); + } + + @Override + public RootGraph defaultGraph(EntityPersister entityDescriptor) { + throw new NotYetImplementedFor6Exception( getClass() ); + } + + @Override + public RootGraph defaultGraph(EntityDomainType entityDomainType) { + return null; + } + + @Override + public List> findRootGraphsForType(Class baseEntityJavaType) { + throw new NotYetImplementedFor6Exception( getClass() ); + } + + @Override + public List> findRootGraphsForType(String baseEntityName) { + throw new NotYetImplementedFor6Exception( getClass() ); + } + + @Override + public List> findRootGraphsForType(EntityPersister baseEntityDescriptor) { + return null; + } + @Override public void close() { // anything to do ? diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetamodelImplementor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetamodelImplementor.java index 6e7a91e52d..6da72623ee 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetamodelImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetamodelImplementor.java @@ -56,7 +56,9 @@ public interface MetamodelImplementor extends DomainMetamodel, Metamodel { * * @throws org.hibernate.UnknownEntityTypeException If a matching EntityPersister cannot be located */ - EntityPersister locateEntityPersister(Class byClass); + default EntityPersister locateEntityPersister(Class byClass){ + return locateEntityDescriptor( byClass ); + } /** * Locate the entity persister by name.