6 - SQM based on JPA type system, RuntimeModelCreationProcess
This commit is contained in:
parent
52aff8055e
commit
638c217e8a
|
@ -75,6 +75,7 @@ public class InflightRuntimeMetamodel {
|
||||||
|
|
||||||
private final Map<String, String> nameToImportNameMap = new HashMap<>();
|
private final Map<String, String> nameToImportNameMap = new HashMap<>();
|
||||||
private final Set<EntityNameResolver> entityNameResolvers = new CopyOnWriteArraySet<>();
|
private final Set<EntityNameResolver> entityNameResolvers = new CopyOnWriteArraySet<>();
|
||||||
|
private final Map<String, String> imports = new ConcurrentHashMap<>( );
|
||||||
|
|
||||||
public InflightRuntimeMetamodel(TypeConfiguration typeConfiguration) {
|
public InflightRuntimeMetamodel(TypeConfiguration typeConfiguration) {
|
||||||
this.typeConfiguration = typeConfiguration;
|
this.typeConfiguration = typeConfiguration;
|
||||||
|
@ -88,6 +89,7 @@ public class InflightRuntimeMetamodel {
|
||||||
PersisterCreationContext persisterCreationContext,
|
PersisterCreationContext persisterCreationContext,
|
||||||
JpaMetaModelPopulationSetting jpaMetaModelPopulationSetting,
|
JpaMetaModelPopulationSetting jpaMetaModelPopulationSetting,
|
||||||
JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting) {
|
JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting) {
|
||||||
|
this.imports.putAll( bootMetamodel.getImports() );
|
||||||
processBootEntities(
|
processBootEntities(
|
||||||
bootMetamodel.getEntityBindings(),
|
bootMetamodel.getEntityBindings(),
|
||||||
cacheImplementor,
|
cacheImplementor,
|
||||||
|
@ -424,4 +426,7 @@ public class InflightRuntimeMetamodel {
|
||||||
return entityType;
|
return entityType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getImports() {
|
||||||
|
return imports;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import javax.persistence.metamodel.ManagedType;
|
||||||
|
|
||||||
import org.hibernate.EntityNameResolver;
|
import org.hibernate.EntityNameResolver;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
|
import org.hibernate.NotYetImplementedFor6Exception;
|
||||||
import org.hibernate.UnknownEntityTypeException;
|
import org.hibernate.UnknownEntityTypeException;
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
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.EntityDomainType;
|
||||||
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
||||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
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.DomainMetamodel;
|
||||||
import org.hibernate.metamodel.spi.MetamodelImplementor;
|
import org.hibernate.metamodel.spi.MetamodelImplementor;
|
||||||
import org.hibernate.persister.collection.CollectionPersister;
|
import org.hibernate.persister.collection.CollectionPersister;
|
||||||
|
@ -53,7 +55,6 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento
|
||||||
// todo : Integrate EntityManagerLogger into CoreMessageLogger
|
// todo : Integrate EntityManagerLogger into CoreMessageLogger
|
||||||
private static final EntityManagerMessageLogger log = HEMLogging.messageLogger( DomainMetamodelImpl.class );
|
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 INVALID_IMPORT = "";
|
||||||
private static final String[] EMPTY_IMPLEMENTORS = new String[0];
|
private static final String[] EMPTY_IMPLEMENTORS = new String[0];
|
||||||
|
|
||||||
|
@ -80,6 +81,8 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento
|
||||||
|
|
||||||
private final Set<EntityNameResolver> entityNameResolvers;
|
private final Set<EntityNameResolver> entityNameResolvers;
|
||||||
|
|
||||||
|
private final Map<String,String> imports;
|
||||||
|
|
||||||
|
|
||||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
// NOTE : Relational/mapping information is not part of the JPA metamodel
|
// 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.collectionRolesByEntityParticipant = runtimeMetamodel.getCollectionRolesByEntityParticipant();
|
||||||
this.entityNameResolvers = runtimeMetamodel.getEntityNameResolvers();
|
this.entityNameResolvers = runtimeMetamodel.getEntityNameResolvers();
|
||||||
this.entityProxyInterfaceMap = runtimeMetamodel.getEntityProxyInterfaceMap();
|
this.entityProxyInterfaceMap = runtimeMetamodel.getEntityProxyInterfaceMap();
|
||||||
|
this.imports = runtimeMetamodel.getImports();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -157,6 +161,11 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento
|
||||||
entityPersisterMap.values().forEach( action );
|
entityPersisterMap.values().forEach( action );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityPersister resolveEntityDescriptor(EntityDomainType<?> entityDomainType) {
|
||||||
|
throw new NotYetImplementedFor6Exception( getClass() );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityPersister getEntityDescriptor(String entityName) {
|
public EntityPersister getEntityDescriptor(String entityName) {
|
||||||
final EntityPersister entityPersister = entityPersisterMap.get( entityName );
|
final EntityPersister entityPersister = entityPersisterMap.get( entityName );
|
||||||
|
@ -166,6 +175,11 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento
|
||||||
return entityPersister;
|
return entityPersister;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityPersister getEntityDescriptor(NavigableRole name) {
|
||||||
|
throw new NotYetImplementedFor6Exception( getClass() );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityPersister findEntityDescriptor(String entityName) {
|
public EntityPersister findEntityDescriptor(String entityName) {
|
||||||
return entityPersisterMap.get( entityName );
|
return entityPersisterMap.get( entityName );
|
||||||
|
@ -254,6 +268,29 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento
|
||||||
return getJpaMetamodel().entity( entityName );
|
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
|
@Override
|
||||||
public String[] getImplementors(String className) throws MappingException {
|
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
|
// 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;
|
return entityPersister;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getImportedName(String name) {
|
||||||
|
throw new NotYetImplementedFor6Exception( getClass() );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitCollectionDescriptors(Consumer<CollectionPersister> action) {
|
public void visitCollectionDescriptors(Consumer<CollectionPersister> action) {
|
||||||
collectionPersisterMap.values().forEach( action );
|
collectionPersisterMap.values().forEach( action );
|
||||||
|
@ -337,6 +379,16 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento
|
||||||
return collectionPersister;
|
return collectionPersister;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CollectionPersister getCollectionDescriptor(NavigableRole role) {
|
||||||
|
throw new NotYetImplementedFor6Exception( getClass() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CollectionPersister findCollectionDescriptor(NavigableRole role) {
|
||||||
|
throw new NotYetImplementedFor6Exception( getClass() );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CollectionPersister findCollectionDescriptor(String role) {
|
public CollectionPersister findCollectionDescriptor(String role) {
|
||||||
return collectionPersisterMap.get( role );
|
return collectionPersisterMap.get( role );
|
||||||
|
@ -384,6 +436,46 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento
|
||||||
return findEntityGraphByName( name );
|
return findEntityGraphByName( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitNamedGraphs(Consumer<RootGraph<?>> 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<RootGraph<?>> findRootGraphsForType(Class baseEntityJavaType) {
|
||||||
|
throw new NotYetImplementedFor6Exception( getClass() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<RootGraph<?>> findRootGraphsForType(String baseEntityName) {
|
||||||
|
throw new NotYetImplementedFor6Exception( getClass() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<RootGraph<?>> findRootGraphsForType(EntityPersister baseEntityDescriptor) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
// anything to do ?
|
// anything to do ?
|
||||||
|
|
|
@ -56,7 +56,9 @@ public interface MetamodelImplementor extends DomainMetamodel, Metamodel {
|
||||||
*
|
*
|
||||||
* @throws org.hibernate.UnknownEntityTypeException If a matching EntityPersister cannot be located
|
* @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.
|
* Locate the entity persister by name.
|
||||||
|
|
Loading…
Reference in New Issue