use of org.hibernate.metamodel.model.domain.PersistentAttribute 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()) {
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);
}
use of org.hibernate.metamodel.model.domain.PersistentAttribute in project hibernate-orm by hibernate.
the class MetadataContext method wrapUp.
@SuppressWarnings("unchecked")
public void wrapUp() {
if (LOG.isTraceEnabled()) {
LOG.trace("Wrapping up metadata context...");
}
boolean staticMetamodelScanEnabled = this.jpaStaticMetaModelPopulationSetting != JpaStaticMetaModelPopulationSetting.DISABLED;
// we need to process types from superclasses to subclasses
for (Object mapping : orderedMappings) {
if (PersistentClass.class.isAssignableFrom(mapping.getClass())) {
final PersistentClass safeMapping = (PersistentClass) mapping;
if (LOG.isTraceEnabled()) {
LOG.trace("Starting entity [" + safeMapping.getEntityName() + ']');
}
try {
final EntityDomainType<Object> jpaMapping = (EntityDomainType<Object>) entityTypesByPersistentClass.get(safeMapping);
applyIdMetadata(safeMapping, jpaMapping);
applyVersionAttribute(safeMapping, jpaMapping);
for (Property property : safeMapping.getDeclaredProperties()) {
if (property.getValue() == safeMapping.getIdentifierMapper()) {
// #buildIdClassAttributes
continue;
}
if (safeMapping.isVersioned() && property == safeMapping.getVersion()) {
// skip the version property, it was already handled previously.
continue;
}
final PersistentAttribute<Object, ?> attribute = attributeFactory.buildAttribute(jpaMapping, property);
if (attribute != null) {
addAttribute(jpaMapping, attribute);
if (property.isNaturalIdentifier()) {
((AttributeContainer<Object>) jpaMapping).getInFlightAccess().applyNaturalIdAttribute(attribute);
}
}
}
((AttributeContainer<?>) jpaMapping).getInFlightAccess().finishUp();
if (staticMetamodelScanEnabled) {
populateStaticMetamodel(jpaMapping);
}
} finally {
if (LOG.isTraceEnabled()) {
LOG.trace("Completed entity [" + safeMapping.getEntityName() + ']');
}
}
} else if (MappedSuperclass.class.isAssignableFrom(mapping.getClass())) {
final MappedSuperclass safeMapping = (MappedSuperclass) mapping;
if (LOG.isTraceEnabled()) {
LOG.trace("Starting mapped superclass [" + safeMapping.getMappedClass().getName() + ']');
}
try {
final MappedSuperclassDomainType<Object> jpaType = (MappedSuperclassDomainType<Object>) mappedSuperclassByMappedSuperclassMapping.get(safeMapping);
applyIdMetadata(safeMapping, jpaType);
applyVersionAttribute(safeMapping, jpaType);
for (Property property : safeMapping.getDeclaredProperties()) {
if (safeMapping.isVersioned() && property == safeMapping.getVersion()) {
// skip the version property, it was already handled previously.
continue;
}
final PersistentAttribute<Object, ?> attribute = attributeFactory.buildAttribute(jpaType, property);
if (attribute != null) {
addAttribute(jpaType, attribute);
if (property.isNaturalIdentifier()) {
((AttributeContainer<Object>) jpaType).getInFlightAccess().applyNaturalIdAttribute(attribute);
}
}
}
((AttributeContainer<?>) jpaType).getInFlightAccess().finishUp();
if (staticMetamodelScanEnabled) {
populateStaticMetamodel(jpaType);
}
} finally {
if (LOG.isTraceEnabled()) {
LOG.trace("Completed mapped superclass [" + safeMapping.getMappedClass().getName() + ']');
}
}
} else {
throw new AssertionFailure("Unexpected mapping type: " + mapping.getClass());
}
}
while (!embeddablesToProcess.isEmpty()) {
final ArrayList<EmbeddableDomainType<?>> processingEmbeddables = new ArrayList<>(embeddablesToProcess.size());
for (List<EmbeddableDomainType<?>> embeddableDomainTypes : embeddablesToProcess.values()) {
processingEmbeddables.addAll(embeddableDomainTypes);
}
embeddablesToProcess.clear();
for (EmbeddableDomainType<?> embeddable : processingEmbeddables) {
final Component component = componentByEmbeddable.get(embeddable);
for (Property property : component.getProperties()) {
final PersistentAttribute<Object, ?> attribute = attributeFactory.buildAttribute((ManagedDomainType<Object>) embeddable, property);
if (attribute != null) {
addAttribute(embeddable, attribute);
}
}
((AttributeContainer<?>) embeddable).getInFlightAccess().finishUp();
embeddables.put(embeddable.getJavaType(), embeddable);
if (staticMetamodelScanEnabled) {
populateStaticMetamodel(embeddable);
}
}
}
}
Aggregations