Search in sources :

Example 6 with EntityMappingType

use of org.hibernate.metamodel.mapping.EntityMappingType in project hibernate-orm by hibernate.

the class DiscriminatedAssociationAttributeMapping method disassemble.

@Override
public Object disassemble(Object value, SharedSessionContractImplementor session) {
    if (value == null) {
        return null;
    }
    final EntityMappingType concreteMappingType = determineConcreteType(value, session);
    final EntityIdentifierMapping identifierMapping = concreteMappingType.getIdentifierMapping();
    final Object discriminator = discriminatorMapping.getModelPart().resolveDiscriminatorForEntityType(concreteMappingType);
    final Object identifier = identifierMapping.getIdentifier(value);
    return new Object[] { discriminatorMapping.getDiscriminatorPart().disassemble(discriminator, session), identifierMapping.disassemble(identifier, session) };
}
Also used : EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType)

Example 7 with EntityMappingType

use of org.hibernate.metamodel.mapping.EntityMappingType in project hibernate-orm by hibernate.

the class DiscriminatedAssociationAttributeMapping method breakDownJdbcValues.

@Override
public void breakDownJdbcValues(Object domainValue, JdbcValueConsumer valueConsumer, SharedSessionContractImplementor session) {
    final EntityMappingType concreteMappingType = determineConcreteType(domainValue, session);
    final Object discriminator = discriminatorMapping.getModelPart().resolveDiscriminatorForEntityType(concreteMappingType);
    final Object disassembledDiscriminator = discriminatorMapping.getDiscriminatorPart().disassemble(discriminator, session);
    valueConsumer.consume(disassembledDiscriminator, discriminatorMapping.getDiscriminatorPart());
    final EntityIdentifierMapping identifierMapping = concreteMappingType.getIdentifierMapping();
    final Object identifier = identifierMapping.getIdentifier(domainValue);
    final Object disassembledKey = discriminatorMapping.getKeyPart().disassemble(identifier, session);
    valueConsumer.consume(disassembledKey, discriminatorMapping.getKeyPart());
}
Also used : EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType)

Example 8 with EntityMappingType

use of org.hibernate.metamodel.mapping.EntityMappingType in project hibernate-orm by hibernate.

the class DiscriminatedAssociationAttributeMapping method forEachDisassembledJdbcValue.

@Override
public int forEachDisassembledJdbcValue(Object value, Clause clause, int offset, JdbcValuesConsumer valuesConsumer, SharedSessionContractImplementor session) {
    if (value != null) {
        if (value.getClass().isArray()) {
            final Object[] values = (Object[]) value;
            valuesConsumer.consume(offset, values[0], discriminatorMapping.getDiscriminatorPart().getJdbcMapping());
            valuesConsumer.consume(offset + 1, values[1], discriminatorMapping.getKeyPart().getJdbcMapping());
        } else {
            final EntityMappingType concreteMappingType = determineConcreteType(value, session);
            final Object discriminator = discriminatorMapping.getModelPart().resolveDiscriminatorForEntityType(concreteMappingType);
            final Object disassembledDiscriminator = discriminatorMapping.getDiscriminatorPart().disassemble(discriminator, session);
            valuesConsumer.consume(offset, disassembledDiscriminator, discriminatorMapping.getDiscriminatorPart().getJdbcMapping());
            final EntityIdentifierMapping identifierMapping = concreteMappingType.getIdentifierMapping();
            final Object identifier = identifierMapping.getIdentifier(value);
            final Object disassembledKey = discriminatorMapping.getKeyPart().disassemble(identifier, session);
            valuesConsumer.consume(offset + 1, disassembledKey, discriminatorMapping.getKeyPart().getJdbcMapping());
        }
    }
    return 2;
}
Also used : EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType)

Example 9 with EntityMappingType

use of org.hibernate.metamodel.mapping.EntityMappingType in project hibernate-orm by hibernate.

the class ResultSetMappingProcessor method createSuffixedResultBuilder.

private DynamicResultBuilderEntityStandard createSuffixedResultBuilder(EntityMappingType entityMapping, String tableAlias, String suffix, LockMode lockMode, NavigablePath navigablePath) {
    final SQLLoadable loadable = (SQLLoadable) entityMapping.getEntityPersister();
    final DynamicResultBuilderEntityStandard resultBuilderEntity = new DynamicResultBuilderEntityStandard(entityMapping, tableAlias, navigablePath);
    resultBuilderEntity.setLockMode(lockMode);
    final String[] identifierAliases = loadable.getIdentifierAliases(suffix);
    resultBuilderEntity.addIdColumnAliases(identifierAliases);
    resultBuilderEntity.setDiscriminatorAlias(loadable.getDiscriminatorAlias(suffix));
    if (loadable.hasIdentifierProperty()) {
        resultBuilderEntity.addProperty(loadable.getIdentifierPropertyName(), identifierAliases);
    }
    for (String propertyName : loadable.getPropertyNames()) {
        final String[] columnAliases = loadable.getSubclassPropertyColumnAliases(propertyName, suffix);
        final Type propertyType = loadable.getPropertyType(propertyName);
        addFetchBuilder(suffix, loadable, resultBuilderEntity, tableAlias, identifierAliases, propertyName, columnAliases, propertyType);
    }
    return resultBuilderEntity;
}
Also used : CollectionType(org.hibernate.type.CollectionType) EntityType(org.hibernate.type.EntityType) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) ComponentType(org.hibernate.type.ComponentType) Type(org.hibernate.type.Type) SQLLoadable(org.hibernate.persister.entity.SQLLoadable) DynamicResultBuilderEntityStandard(org.hibernate.query.results.dynamic.DynamicResultBuilderEntityStandard)

Example 10 with EntityMappingType

use of org.hibernate.metamodel.mapping.EntityMappingType in project hibernate-orm by hibernate.

the class StandardEntityGraphTraversalStateImpl method appliesTo.

private boolean appliesTo(FetchParent fetchParent) {
    if (currentGraphContext == null || !(fetchParent instanceof EntityResultGraphNode)) {
        return false;
    }
    final EntityResultGraphNode entityFetchParent = (EntityResultGraphNode) fetchParent;
    final EntityMappingType entityFetchParentMappingType = entityFetchParent.getEntityValuedModelPart().getEntityMappingType();
    assert currentGraphContext.getGraphedType() instanceof EntityDomainType;
    final EntityDomainType entityDomainType = (EntityDomainType) currentGraphContext.getGraphedType();
    return entityDomainType.getHibernateEntityName().equals(entityFetchParentMappingType.getEntityName());
}
Also used : EntityResultGraphNode(org.hibernate.sql.results.graph.entity.EntityResultGraphNode) EntityDomainType(org.hibernate.metamodel.model.domain.EntityDomainType) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType)

Aggregations

EntityMappingType (org.hibernate.metamodel.mapping.EntityMappingType)56 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)19 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)16 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)16 Test (org.junit.jupiter.api.Test)16 EntityIdentifierMapping (org.hibernate.metamodel.mapping.EntityIdentifierMapping)15 EntityPersister (org.hibernate.persister.entity.EntityPersister)14 AttributeMapping (org.hibernate.metamodel.mapping.AttributeMapping)11 List (java.util.List)10 ModelPart (org.hibernate.metamodel.mapping.ModelPart)10 ArrayList (java.util.ArrayList)9 MappingMetamodel (org.hibernate.metamodel.MappingMetamodel)9 ColumnReference (org.hibernate.sql.ast.tree.expression.ColumnReference)8 TableReference (org.hibernate.sql.ast.tree.from.TableReference)8 BasicValuedModelPart (org.hibernate.metamodel.mapping.BasicValuedModelPart)7 StateArrayContributorMetadata (org.hibernate.metamodel.mapping.StateArrayContributorMetadata)7 ToOneAttributeMapping (org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping)7 NavigablePath (org.hibernate.query.spi.NavigablePath)7 NamedTableReference (org.hibernate.sql.ast.tree.from.NamedTableReference)7 SelectStatement (org.hibernate.sql.ast.tree.select.SelectStatement)7