Search in sources :

Example 1 with InFlightEntityMappingType

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));
    }
}
Also used : InFlightEntityMappingType(org.hibernate.metamodel.mapping.internal.InFlightEntityMappingType)

Example 2 with InFlightEntityMappingType

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;
    }
}
Also used : InFlightEntityMappingType(org.hibernate.metamodel.mapping.internal.InFlightEntityMappingType) OptimizableGenerator(org.hibernate.id.OptimizableGenerator) Optimizer(org.hibernate.id.enhanced.Optimizer) ReflectionOptimizer(org.hibernate.bytecode.spi.ReflectionOptimizer) BulkInsertionCapableIdentifierGenerator(org.hibernate.id.BulkInsertionCapableIdentifierGenerator) RuntimeModelCreationContext(org.hibernate.metamodel.spi.RuntimeModelCreationContext) NonIdentifierAttribute(org.hibernate.tuple.NonIdentifierAttribute) ReflectionOptimizer(org.hibernate.bytecode.spi.ReflectionOptimizer) EntityMetamodel(org.hibernate.tuple.entity.EntityMetamodel) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass)

Aggregations

InFlightEntityMappingType (org.hibernate.metamodel.mapping.internal.InFlightEntityMappingType)2 ReflectionOptimizer (org.hibernate.bytecode.spi.ReflectionOptimizer)1 BulkInsertionCapableIdentifierGenerator (org.hibernate.id.BulkInsertionCapableIdentifierGenerator)1 OptimizableGenerator (org.hibernate.id.OptimizableGenerator)1 Optimizer (org.hibernate.id.enhanced.Optimizer)1 PersistentClass (org.hibernate.mapping.PersistentClass)1 Property (org.hibernate.mapping.Property)1 RuntimeModelCreationContext (org.hibernate.metamodel.spi.RuntimeModelCreationContext)1 NonIdentifierAttribute (org.hibernate.tuple.NonIdentifierAttribute)1 EntityMetamodel (org.hibernate.tuple.entity.EntityMetamodel)1