Search in sources :

Example 1 with SingleAttributeIdentifierMapping

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

the class SqmCteTable method createIdTable.

public static SqmCteTable createIdTable(String cteName, EntityMappingType entityDescriptor) {
    return new SqmCteTable(cteName, sqmCteTable -> {
        final int numberOfColumns = entityDescriptor.getIdentifierMapping().getJdbcTypeCount();
        final List<SqmCteTableColumn> columns = new ArrayList<>(numberOfColumns);
        final EntityIdentifierMapping identifierMapping = entityDescriptor.getIdentifierMapping();
        final String idName;
        if (identifierMapping instanceof SingleAttributeIdentifierMapping) {
            idName = ((SingleAttributeIdentifierMapping) identifierMapping).getAttributeName();
        } else {
            idName = "id";
        }
        columns.add(new SqmCteTableColumn(sqmCteTable, idName, identifierMapping));
        return columns;
    });
}
Also used : ArrayList(java.util.ArrayList) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) SingleAttributeIdentifierMapping(org.hibernate.metamodel.mapping.internal.SingleAttributeIdentifierMapping)

Example 2 with SingleAttributeIdentifierMapping

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

the class SqmCteTable method createEntityTable.

public static SqmCteTable createEntityTable(String cteName, EntityMappingType entityDescriptor) {
    return new SqmCteTable(cteName, sqmCteTable -> {
        final int numberOfColumns = entityDescriptor.getIdentifierMapping().getJdbcTypeCount();
        final List<SqmCteTableColumn> columns = new ArrayList<>(numberOfColumns);
        final EntityIdentifierMapping identifierMapping = entityDescriptor.getIdentifierMapping();
        final String idName;
        if (identifierMapping instanceof SingleAttributeIdentifierMapping) {
            idName = ((SingleAttributeIdentifierMapping) identifierMapping).getAttributeName();
        } else {
            idName = "id";
        }
        columns.add(new SqmCteTableColumn(sqmCteTable, idName, identifierMapping));
        final EntityDiscriminatorMapping discriminatorMapping = entityDescriptor.getDiscriminatorMapping();
        if (discriminatorMapping != null && discriminatorMapping.isPhysical() && !discriminatorMapping.isFormula()) {
            columns.add(new SqmCteTableColumn(sqmCteTable, "class", discriminatorMapping));
        }
        // Collect all columns for all entity subtype attributes
        entityDescriptor.visitSubTypeAttributeMappings(attribute -> {
            if (!(attribute instanceof PluralAttributeMapping)) {
                columns.add(new SqmCteTableColumn(sqmCteTable, attribute.getAttributeName(), attribute));
            }
        });
        // We add a special row number column that we can use to identify and join rows
        columns.add(new SqmCteTableColumn(sqmCteTable, "rn_", entityDescriptor.getEntityPersister().getFactory().getTypeConfiguration().getBasicTypeForJavaType(Integer.class)));
        return columns;
    });
}
Also used : ArrayList(java.util.ArrayList) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) SingleAttributeIdentifierMapping(org.hibernate.metamodel.mapping.internal.SingleAttributeIdentifierMapping) EntityDiscriminatorMapping(org.hibernate.metamodel.mapping.EntityDiscriminatorMapping)

Aggregations

ArrayList (java.util.ArrayList)2 EntityIdentifierMapping (org.hibernate.metamodel.mapping.EntityIdentifierMapping)2 SingleAttributeIdentifierMapping (org.hibernate.metamodel.mapping.internal.SingleAttributeIdentifierMapping)2 EntityDiscriminatorMapping (org.hibernate.metamodel.mapping.EntityDiscriminatorMapping)1 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)1