use of org.hibernate.metamodel.mapping.internal.InFlightEntityMappingType in project hibernate-orm by hibernate.
the class AbstractEntityPersister method linkWithSuperType.
@Override
public void linkWithSuperType(MappingModelCreationProcess creationProcess) {
if (getMappedSuperclass() == null) {
return;
}
this.superMappingType = creationProcess.getEntityPersister(getMappedSuperclass());
final InFlightEntityMappingType inFlightEntityMappingType = (InFlightEntityMappingType) superMappingType;
inFlightEntityMappingType.linkWithSubType(this, creationProcess);
if (subclassMappingTypes != null) {
subclassMappingTypes.values().forEach(sub -> inFlightEntityMappingType.linkWithSubType(sub, creationProcess));
}
}
use of org.hibernate.metamodel.mapping.internal.InFlightEntityMappingType in project hibernate-orm by hibernate.
the class AbstractEntityPersister method prepareMappingModel.
@Override
public void prepareMappingModel(MappingModelCreationProcess creationProcess) {
if (identifierMapping != null) {
return;
}
final RuntimeModelCreationContext creationContext = creationProcess.getCreationContext();
final PersistentClass bootEntityDescriptor = creationContext.getBootModel().getEntityBinding(getEntityName());
// EntityMappingType rootEntityDescriptor;
if (superMappingType != null) {
((InFlightEntityMappingType) superMappingType).prepareMappingModel(creationProcess);
if (shouldProcessSuperMapping()) {
this.discriminatorMapping = superMappingType.getDiscriminatorMapping();
this.identifierMapping = superMappingType.getIdentifierMapping();
this.naturalIdMapping = superMappingType.getNaturalIdMapping();
this.versionMapping = superMappingType.getVersionMapping();
this.rowIdMapping = superMappingType.getRowIdMapping();
} else {
prepareMappingModel(creationProcess, bootEntityDescriptor);
}
// rootEntityDescriptor = superMappingType.getRootEntityDescriptor();
} else {
prepareMappingModel(creationProcess, bootEntityDescriptor);
// rootEntityDescriptor = this;
}
final EntityMetamodel currentEntityMetamodel = this.getEntityMetamodel();
int stateArrayPosition = getStateArrayInitialPosition(creationProcess);
NonIdentifierAttribute[] properties = currentEntityMetamodel.getProperties();
for (int i = 0; i < currentEntityMetamodel.getPropertySpan(); i++) {
final NonIdentifierAttribute runtimeAttrDefinition = properties[i];
final Property bootProperty = bootEntityDescriptor.getProperty(runtimeAttrDefinition.getName());
if (superMappingType == null || superMappingType.findAttributeMapping(bootProperty.getName()) == null) {
declaredAttributeMappings.put(runtimeAttrDefinition.getName(), generateNonIdAttributeMapping(runtimeAttrDefinition, bootProperty, stateArrayPosition++, creationProcess));
}
// else {
// its defined on the supertype, skip it here
// }
}
getAttributeMappings();
postProcessAttributeMappings(creationProcess, bootEntityDescriptor);
final ReflectionOptimizer reflectionOptimizer = representationStrategy.getReflectionOptimizer();
if (reflectionOptimizer != null) {
accessOptimizer = reflectionOptimizer.getAccessOptimizer();
} else {
accessOptimizer = null;
}
// register a callback for after all `#prepareMappingModel` calls have finished. here we want to delay the
// generation of `staticFetchableList` because we need to wait until after all sub-classes have had their
// `#prepareMappingModel` called (and their declared attribute mappings resolved)
creationProcess.registerInitializationCallback("Entity(" + getEntityName() + ") `staticFetchableList` generator", () -> {
if (hasInsertGeneratedProperties()) {
insertGeneratedValuesProcessor = createGeneratedValuesProcessor(GenerationTiming.INSERT);
}
if (hasUpdateGeneratedProperties()) {
updateGeneratedValuesProcessor = createGeneratedValuesProcessor(GenerationTiming.ALWAYS);
}
staticFetchableList = new ArrayList<>(attributeMappings.size());
visitSubTypeAttributeMappings(attributeMapping -> staticFetchableList.add(attributeMapping));
return true;
});
boolean needsMultiTableInsert = hasMultipleTables();
if (needsMultiTableInsert) {
creationProcess.registerInitializationCallback("Entity(" + getEntityName() + ") `sqmMultiTableMutationStrategy` interpretation", () -> {
sqmMultiTableMutationStrategy = interpretSqmMultiTableStrategy(this, creationProcess);
if (sqmMultiTableMutationStrategy == null) {
return false;
}
sqmMultiTableMutationStrategy.prepare(creationProcess, creationContext.getSessionFactory().getJdbcServices().getBootstrapJdbcConnectionAccess());
return true;
});
} else {
sqmMultiTableMutationStrategy = null;
}
if (!needsMultiTableInsert && getIdentifierGenerator() instanceof BulkInsertionCapableIdentifierGenerator) {
if (getIdentifierGenerator() instanceof OptimizableGenerator) {
final Optimizer optimizer = ((OptimizableGenerator) getIdentifierGenerator()).getOptimizer();
needsMultiTableInsert = optimizer != null && optimizer.getIncrementSize() > 1;
}
}
if (needsMultiTableInsert) {
creationProcess.registerInitializationCallback("Entity(" + getEntityName() + ") `sqmMultiTableInsertStrategy` interpretation", () -> {
sqmMultiTableInsertStrategy = interpretSqmMultiTableInsertStrategy(this, creationProcess);
if (sqmMultiTableInsertStrategy == null) {
return false;
}
sqmMultiTableInsertStrategy.prepare(creationProcess, creationContext.getSessionFactory().getJdbcServices().getBootstrapJdbcConnectionAccess());
return true;
});
} else {
sqmMultiTableInsertStrategy = null;
}
}
Aggregations