Search in sources :

Example 1 with SearchClauseSpecification

use of org.hibernate.sql.ast.tree.cte.SearchClauseSpecification in project hibernate-orm by hibernate.

the class BaseSqmToSqlAstConverter method visitSearchBySpecifications.

protected List<SearchClauseSpecification> visitSearchBySpecifications(CteTable cteTable, List<SqmSearchClauseSpecification> searchBySpecifications) {
    if (searchBySpecifications == null || searchBySpecifications.isEmpty()) {
        return null;
    }
    final int size = searchBySpecifications.size();
    final List<SearchClauseSpecification> searchClauseSpecifications = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        final SqmSearchClauseSpecification specification = searchBySpecifications.get(i);
        forEachCteColumn(cteTable, specification.getCteColumn(), cteColumn -> searchClauseSpecifications.add(new SearchClauseSpecification(cteColumn, specification.getSortOrder(), specification.getNullPrecedence())));
    }
    return searchClauseSpecifications;
}
Also used : SqmSearchClauseSpecification(org.hibernate.query.sqm.tree.cte.SqmSearchClauseSpecification) SqmSearchClauseSpecification(org.hibernate.query.sqm.tree.cte.SqmSearchClauseSpecification) SearchClauseSpecification(org.hibernate.sql.ast.tree.cte.SearchClauseSpecification) ArrayList(java.util.ArrayList)

Example 2 with SearchClauseSpecification

use of org.hibernate.sql.ast.tree.cte.SearchClauseSpecification in project hibernate-orm by hibernate.

the class AbstractSqlAstTranslator method renderSearchClause.

protected void renderSearchClause(CteStatement cte) {
    String separator;
    if (cte.getSearchClauseKind() != null) {
        appendSql(" search ");
        if (cte.getSearchClauseKind() == CteSearchClauseKind.DEPTH_FIRST) {
            appendSql(" depth ");
        } else {
            appendSql(" breadth ");
        }
        appendSql(" first by ");
        separator = "";
        for (SearchClauseSpecification searchBySpecification : cte.getSearchBySpecifications()) {
            appendSql(separator);
            appendSql(searchBySpecification.getCteColumn().getColumnExpression());
            if (searchBySpecification.getSortOrder() != null) {
                if (searchBySpecification.getSortOrder() == SortOrder.ASCENDING) {
                    appendSql(" asc");
                } else {
                    appendSql(" desc");
                }
                if (searchBySpecification.getNullPrecedence() != null) {
                    if (searchBySpecification.getNullPrecedence() == NullPrecedence.FIRST) {
                        appendSql(" nulls first");
                    } else {
                        appendSql(" nulls last");
                    }
                }
            }
            separator = COMA_SEPARATOR;
        }
    }
}
Also used : SearchClauseSpecification(org.hibernate.sql.ast.tree.cte.SearchClauseSpecification)

Aggregations

SearchClauseSpecification (org.hibernate.sql.ast.tree.cte.SearchClauseSpecification)2 ArrayList (java.util.ArrayList)1 SqmSearchClauseSpecification (org.hibernate.query.sqm.tree.cte.SqmSearchClauseSpecification)1