use of org.hibernate.metamodel.internal.JpaStaticMetaModelPopulationSetting in project hibernate-orm by hibernate.
the class MappingMetamodelImpl method finishInitialization.
public void finishInitialization(MetadataImplementor bootModel, BootstrapContext bootstrapContext, SessionFactoryImplementor sessionFactory) {
final RuntimeModelCreationContext runtimeModelCreationContext = new RuntimeModelCreationContext() {
@Override
public BootstrapContext getBootstrapContext() {
return bootstrapContext;
}
@Override
public SessionFactoryImplementor getSessionFactory() {
return sessionFactory;
}
@Override
public MetadataImplementor getBootModel() {
return bootModel;
}
@Override
public MappingMetamodel getDomainModel() {
return MappingMetamodelImpl.this;
}
};
final PersisterFactory persisterFactory = sessionFactory.getServiceRegistry().getService(PersisterFactory.class);
final JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting = determineJpaStaticMetaModelPopulationSetting(sessionFactory.getProperties());
final JpaMetaModelPopulationSetting jpaMetaModelPopulationSetting = determineJpaMetaModelPopulationSetting(sessionFactory.getProperties());
bootModel.visitRegisteredComponents(Component::prepareForMappingModel);
bootModel.getMappedSuperclassMappingsCopy().forEach(MappedSuperclass::prepareForMappingModel);
bootModel.getEntityBindings().forEach(PersistentClass::prepareForMappingModel);
processBootEntities(bootModel.getEntityBindings(), sessionFactory.getCache(), persisterFactory, runtimeModelCreationContext);
processBootCollections(bootModel.getCollectionBindings(), sessionFactory.getCache(), persisterFactory, runtimeModelCreationContext);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// after *all* persisters and named queries are registered
MappingModelCreationProcess.process(entityPersisterMap, sessionFactory.getQueryEngine().getSqmFunctionRegistry(), runtimeModelCreationContext);
for (EntityPersister persister : entityPersisterMap.values()) {
persister.postInstantiate();
registerEntityNameResolvers(persister, entityNameResolvers);
}
collectionPersisterMap.values().forEach(CollectionPersister::postInstantiate);
registerEmbeddableMappingType(bootModel);
((JpaMetamodelImpl) this.jpaMetamodel).processJpa(bootModel, this, entityProxyInterfaceMap, jpaStaticMetaModelPopulationSetting, jpaMetaModelPopulationSetting, bootModel.getNamedEntityGraphs().values(), runtimeModelCreationContext);
}
use of org.hibernate.metamodel.internal.JpaStaticMetaModelPopulationSetting in project hibernate-orm by hibernate.
the class JpaMetamodelImpl method processJpa.
public void processJpa(MetadataImplementor bootMetamodel, MappingMetamodel mappingMetamodel, Map<Class<?>, String> entityProxyInterfaceMap, JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting, JpaMetaModelPopulationSetting jpaMetaModelPopulationSetting, Collection<NamedEntityGraphDefinition> namedEntityGraphDefinitions, RuntimeModelCreationContext runtimeModelCreationContext) {
bootMetamodel.getImports().forEach((k, v) -> this.nameToImportMap.put(k, new ImportInfo<>(v, null)));
this.entityProxyInterfaceMap.putAll(entityProxyInterfaceMap);
final MetadataContext context = new MetadataContext(this, mappingMetamodel, bootMetamodel, jpaStaticMetaModelPopulationSetting, jpaMetaModelPopulationSetting, runtimeModelCreationContext);
for (PersistentClass entityBinding : bootMetamodel.getEntityBindings()) {
locateOrBuildEntityType(entityBinding, context, typeConfiguration);
}
handleUnusedMappedSuperclasses(context, typeConfiguration);
context.wrapUp();
for (Map.Entry<String, IdentifiableDomainType<?>> entry : context.getIdentifiableTypesByName().entrySet()) {
if (entry.getValue() instanceof EntityDomainType<?>) {
this.jpaEntityTypeMap.put(entry.getKey(), (EntityDomainType<?>) entry.getValue());
}
}
this.jpaManagedTypeMap.putAll(context.getEntityTypeMap());
this.jpaManagedTypeMap.putAll(context.getMappedSuperclassTypeMap());
switch(jpaMetaModelPopulationSetting) {
case IGNORE_UNSUPPORTED:
this.jpaManagedTypes.addAll(context.getEntityTypeMap().values());
this.jpaManagedTypes.addAll(context.getMappedSuperclassTypeMap().values());
break;
case ENABLED:
this.jpaManagedTypes.addAll(context.getIdentifiableTypesByName().values());
break;
}
for (EmbeddableDomainType<?> embeddable : context.getEmbeddableTypeSet()) {
// Do not register the embeddable types for id classes
if (embeddable.getExpressibleJavaType() instanceof EntityJavaType<?>) {
continue;
}
switch(jpaMetaModelPopulationSetting) {
case IGNORE_UNSUPPORTED:
if (embeddable.getJavaType() != null && embeddable.getJavaType() != Map.class) {
this.jpaEmbeddables.add(embeddable);
this.jpaManagedTypes.add(embeddable);
if (!(embeddable.getExpressibleJavaType() instanceof EntityJavaType<?>)) {
this.jpaManagedTypeMap.put(embeddable.getJavaType(), embeddable);
}
}
break;
case ENABLED:
this.jpaEmbeddables.add(embeddable);
this.jpaManagedTypes.add(embeddable);
if (embeddable.getJavaType() != null && !(embeddable.getExpressibleJavaType() instanceof EntityJavaType<?>)) {
this.jpaManagedTypeMap.put(embeddable.getJavaType(), embeddable);
}
break;
case DISABLED:
if (embeddable.getJavaType() == null) {
throw new UnsupportedOperationException("ANY not supported");
}
if (!(embeddable.getExpressibleJavaType() instanceof EntityJavaType<?>)) {
this.jpaManagedTypeMap.put(embeddable.getJavaType(), embeddable);
}
break;
}
}
final Consumer<PersistentAttribute<?, ?>> attributeConsumer = persistentAttribute -> {
if (persistentAttribute.getJavaType() != null && persistentAttribute.getJavaType().isEnum()) {
@SuppressWarnings("unchecked") final Class<Enum<?>> enumClass = (Class<Enum<?>>) persistentAttribute.getJavaType();
final Enum<?>[] enumConstants = enumClass.getEnumConstants();
for (Enum<?> enumConstant : enumConstants) {
final String qualifiedEnumLiteral = enumConstant.getDeclaringClass().getSimpleName() + "." + enumConstant.name();
this.allowedEnumLiteralTexts.computeIfAbsent(enumConstant.name(), k -> new HashMap<>()).put(enumClass, enumConstant);
this.allowedEnumLiteralTexts.computeIfAbsent(qualifiedEnumLiteral, k -> new HashMap<>()).put(enumClass, enumConstant);
}
}
};
domainTypeStream(context).forEach(managedDomainType -> managedDomainType.visitAttributes(attributeConsumer));
applyNamedEntityGraphs(namedEntityGraphDefinitions);
}
Aggregations