Search in sources :

Example 1 with SqmCteTable

use of org.hibernate.query.sqm.tree.cte.SqmCteTable in project hibernate-orm by hibernate.

the class BaseSqmToSqlAstConverter method createCteTable.

public static CteTable createCteTable(SqmCteTable sqmCteTable, List<SqmCteTableColumn> sqmCteColumns, SessionFactoryImplementor factory) {
    final List<CteColumn> sqlCteColumns = new ArrayList<>(sqmCteColumns.size());
    for (int i = 0; i < sqmCteColumns.size(); i++) {
        final SqmCteTableColumn sqmCteTableColumn = sqmCteColumns.get(i);
        ValueMapping valueMapping = sqmCteTableColumn.getType();
        if (valueMapping instanceof Association) {
            valueMapping = ((Association) valueMapping).getForeignKeyDescriptor();
        }
        if (valueMapping instanceof EmbeddableValuedModelPart) {
            valueMapping.forEachJdbcType((index, jdbcMapping) -> sqlCteColumns.add(new CteColumn(sqmCteTableColumn.getColumnName() + "_" + index, jdbcMapping)));
        } else {
            sqlCteColumns.add(new CteColumn(sqmCteTableColumn.getColumnName(), ((BasicValuedMapping) valueMapping).getJdbcMapping()));
        }
    }
    return new CteTable(sqmCteTable.getCteName(), sqlCteColumns, factory);
}
Also used : CteColumn(org.hibernate.sql.ast.tree.cte.CteColumn) BasicValuedMapping(org.hibernate.metamodel.mapping.BasicValuedMapping) CteTable(org.hibernate.sql.ast.tree.cte.CteTable) SqmCteTable(org.hibernate.query.sqm.tree.cte.SqmCteTable) SqmCteTableColumn(org.hibernate.query.sqm.tree.cte.SqmCteTableColumn) Association(org.hibernate.metamodel.mapping.Association) ArrayList(java.util.ArrayList) EmbeddableValuedModelPart(org.hibernate.metamodel.mapping.EmbeddableValuedModelPart) ValueMapping(org.hibernate.metamodel.mapping.ValueMapping)

Aggregations

ArrayList (java.util.ArrayList)1 Association (org.hibernate.metamodel.mapping.Association)1 BasicValuedMapping (org.hibernate.metamodel.mapping.BasicValuedMapping)1 EmbeddableValuedModelPart (org.hibernate.metamodel.mapping.EmbeddableValuedModelPart)1 ValueMapping (org.hibernate.metamodel.mapping.ValueMapping)1 SqmCteTable (org.hibernate.query.sqm.tree.cte.SqmCteTable)1 SqmCteTableColumn (org.hibernate.query.sqm.tree.cte.SqmCteTableColumn)1 CteColumn (org.hibernate.sql.ast.tree.cte.CteColumn)1 CteTable (org.hibernate.sql.ast.tree.cte.CteTable)1