Search in sources :

Example 1 with TupleType

use of org.hibernate.metamodel.model.domain.TupleType in project hibernate-orm by hibernate.

the class MappingMetamodelImpl method resolveMappingExpressible.

@Override
public MappingModelExpressible<?> resolveMappingExpressible(SqmExpressible<?> sqmExpressible, Function<NavigablePath, TableGroup> tableGroupLocator) {
    if (sqmExpressible instanceof SqmPath) {
        final SqmPath<?> sqmPath = (SqmPath<?>) sqmExpressible;
        final NavigablePath navigablePath = sqmPath.getNavigablePath();
        if (navigablePath.getParent() != null) {
            final TableGroup parentTableGroup = tableGroupLocator.apply(navigablePath.getParent());
            return parentTableGroup.getModelPart().findSubPart(navigablePath.getLocalName(), null);
        }
        return tableGroupLocator.apply(navigablePath.getParent()).getModelPart();
    }
    if (sqmExpressible instanceof BasicType<?>) {
        return (BasicType<?>) sqmExpressible;
    }
    if (sqmExpressible instanceof BasicSqmPathSource<?>) {
        return getTypeConfiguration().getBasicTypeForJavaType(((BasicSqmPathSource<?>) sqmExpressible).getJavaType());
    }
    if (sqmExpressible instanceof SqmFieldLiteral) {
        return getTypeConfiguration().getBasicTypeForJavaType(((SqmFieldLiteral<?>) sqmExpressible).getJavaType());
    }
    if (sqmExpressible instanceof CompositeSqmPathSource) {
        throw new NotYetImplementedFor6Exception("Resolution of embedded-valued SqmExpressible nodes not yet implemented");
    }
    if (sqmExpressible instanceof EmbeddableTypeImpl) {
        return (MappingModelExpressible<?>) sqmExpressible;
    }
    if (sqmExpressible instanceof EntityDomainType<?>) {
        return getEntityDescriptor(((EntityDomainType<?>) sqmExpressible).getHibernateEntityName());
    }
    if (sqmExpressible instanceof TupleType<?>) {
        final MappingModelExpressible<?> mappingModelExpressible = tupleTypeCache.get(sqmExpressible);
        if (mappingModelExpressible != null) {
            return mappingModelExpressible;
        }
        final TupleType<?> tupleType = (TupleType<?>) sqmExpressible;
        final MappingModelExpressible<?>[] components = new MappingModelExpressible<?>[tupleType.componentCount()];
        for (int i = 0; i < components.length; i++) {
            components[i] = resolveMappingExpressible(tupleType.get(i), tableGroupLocator);
        }
        final MappingModelExpressible<?> createdMappingModelExpressible = new TupleMappingModelExpressible(components);
        final MappingModelExpressible<?> existingMappingModelExpressible = tupleTypeCache.putIfAbsent(tupleType, createdMappingModelExpressible);
        return existingMappingModelExpressible == null ? createdMappingModelExpressible : existingMappingModelExpressible;
    }
    return null;
}
Also used : NavigablePath(org.hibernate.query.spi.NavigablePath) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) BasicType(org.hibernate.type.BasicType) MappingModelExpressible(org.hibernate.metamodel.mapping.MappingModelExpressible) SqmPath(org.hibernate.query.sqm.tree.domain.SqmPath) TupleType(org.hibernate.metamodel.model.domain.TupleType) NotYetImplementedFor6Exception(org.hibernate.NotYetImplementedFor6Exception) EntityDomainType(org.hibernate.metamodel.model.domain.EntityDomainType) SqmFieldLiteral(org.hibernate.query.sqm.tree.expression.SqmFieldLiteral)

Aggregations

NotYetImplementedFor6Exception (org.hibernate.NotYetImplementedFor6Exception)1 MappingModelExpressible (org.hibernate.metamodel.mapping.MappingModelExpressible)1 EntityDomainType (org.hibernate.metamodel.model.domain.EntityDomainType)1 TupleType (org.hibernate.metamodel.model.domain.TupleType)1 NavigablePath (org.hibernate.query.spi.NavigablePath)1 SqmPath (org.hibernate.query.sqm.tree.domain.SqmPath)1 SqmFieldLiteral (org.hibernate.query.sqm.tree.expression.SqmFieldLiteral)1 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)1 BasicType (org.hibernate.type.BasicType)1