Search in sources :

Example 1 with FakeSqmToSqlAstConverter

use of org.hibernate.query.sqm.sql.FakeSqmToSqlAstConverter in project hibernate-orm by hibernate.

the class OrderingExpression method applyCollation.

static Expression applyCollation(Expression expression, String collation, SqlAstCreationState creationState) {
    final Expression sortExpression;
    if (collation == null) {
        sortExpression = expression;
    } else {
        final QueryEngine queryEngine = creationState.getCreationContext().getSessionFactory().getQueryEngine();
        final SqmToSqlAstConverter converter;
        if (creationState instanceof SqmToSqlAstConverter) {
            converter = (SqmToSqlAstConverter) creationState;
        } else {
            converter = new FakeSqmToSqlAstConverter(creationState);
        }
        sortExpression = queryEngine.getSqmFunctionRegistry().findFunctionDescriptor("collate").generateSqmExpression(new SqmSelfRenderingExpression<>(walker -> expression, null, null), null, queryEngine, queryEngine.getTypeConfiguration()).convertToSqlAst(converter);
    }
    return sortExpression;
}
Also used : QueryEngine(org.hibernate.query.spi.QueryEngine) SqmSelfRenderingExpression(org.hibernate.query.sqm.tree.expression.SqmSelfRenderingExpression) FakeSqmToSqlAstConverter(org.hibernate.query.sqm.sql.FakeSqmToSqlAstConverter) SqlAstNode(org.hibernate.sql.ast.tree.SqlAstNode) Expression(org.hibernate.sql.ast.tree.expression.Expression) SqmToSqlAstConverter(org.hibernate.query.sqm.sql.SqmToSqlAstConverter) QuerySpec(org.hibernate.sql.ast.tree.select.QuerySpec) SortOrder(org.hibernate.query.sqm.SortOrder) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) NullPrecedence(org.hibernate.query.sqm.NullPrecedence) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) FakeSqmToSqlAstConverter(org.hibernate.query.sqm.sql.FakeSqmToSqlAstConverter) SqmSelfRenderingExpression(org.hibernate.query.sqm.tree.expression.SqmSelfRenderingExpression) Expression(org.hibernate.sql.ast.tree.expression.Expression) QueryEngine(org.hibernate.query.spi.QueryEngine) FakeSqmToSqlAstConverter(org.hibernate.query.sqm.sql.FakeSqmToSqlAstConverter) SqmToSqlAstConverter(org.hibernate.query.sqm.sql.SqmToSqlAstConverter)

Aggregations

QueryEngine (org.hibernate.query.spi.QueryEngine)1 NullPrecedence (org.hibernate.query.sqm.NullPrecedence)1 SortOrder (org.hibernate.query.sqm.SortOrder)1 FakeSqmToSqlAstConverter (org.hibernate.query.sqm.sql.FakeSqmToSqlAstConverter)1 SqmToSqlAstConverter (org.hibernate.query.sqm.sql.SqmToSqlAstConverter)1 SqmSelfRenderingExpression (org.hibernate.query.sqm.tree.expression.SqmSelfRenderingExpression)1 SqlAstCreationState (org.hibernate.sql.ast.spi.SqlAstCreationState)1 SqlAstNode (org.hibernate.sql.ast.tree.SqlAstNode)1 Expression (org.hibernate.sql.ast.tree.expression.Expression)1 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)1 QuerySpec (org.hibernate.sql.ast.tree.select.QuerySpec)1