Search in sources :

Example 1 with Expression

use of javax.persistence.criteria.Expression in project hibernate-orm by hibernate.

the class CompoundPredicate method render.

public static String render(PredicateImplementor predicate, RenderingContext renderingContext) {
    if (!predicate.isJunction()) {
        throw new IllegalStateException("CompoundPredicate.render should only be used to render junctions");
    }
    if (predicate.getExpressions().isEmpty()) {
        boolean implicitTrue = predicate.getOperator() == BooleanOperator.AND;
        // AND is always true for empty; OR is always false
        return implicitTrue ? "1=1" : "0=1";
    }
    // single valued junction ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if (predicate.getExpressions().size() == 1) {
        return ((Renderable) predicate.getExpressions().get(0)).render(renderingContext);
    }
    final StringBuilder buffer = new StringBuilder();
    String sep = "";
    for (Expression expression : predicate.getExpressions()) {
        buffer.append(sep).append("( ").append(((Renderable) expression).render(renderingContext)).append(" )");
        sep = operatorTextWithSeparator(predicate.getOperator());
    }
    return buffer.toString();
}
Also used : Renderable(org.hibernate.query.criteria.internal.Renderable) Expression(javax.persistence.criteria.Expression)

Example 2 with Expression

use of javax.persistence.criteria.Expression in project hibernate-orm by hibernate.

the class CriteriaUpdateImpl method set.

@Override
@SuppressWarnings("unchecked")
public <Y, X extends Y> CriteriaUpdate<T> set(Path<Y> attributePath, X value) {
    final Expression valueExpression = value == null ? criteriaBuilder().nullLiteral(attributePath.getJavaType()) : criteriaBuilder().literal(value);
    addAssignment(attributePath, valueExpression);
    return this;
}
Also used : Expression(javax.persistence.criteria.Expression)

Example 3 with Expression

use of javax.persistence.criteria.Expression in project hibernate-orm by hibernate.

the class CriteriaUpdateImpl method set.

@Override
@SuppressWarnings("unchecked")
public CriteriaUpdate<T> set(String attributeName, Object value) {
    final Path attributePath = getRoot().get(attributeName);
    final Expression valueExpression = value == null ? criteriaBuilder().nullLiteral(attributePath.getJavaType()) : criteriaBuilder().literal(value);
    addAssignment(attributePath, valueExpression);
    return this;
}
Also used : SingularAttributePath(org.hibernate.query.criteria.internal.path.SingularAttributePath) Path(javax.persistence.criteria.Path) Expression(javax.persistence.criteria.Expression)

Example 4 with Expression

use of javax.persistence.criteria.Expression in project hibernate-orm by hibernate.

the class CriteriaUpdateImpl method set.

@Override
@SuppressWarnings("unchecked")
public <Y, X extends Y> CriteriaUpdate<T> set(SingularAttribute<? super T, Y> singularAttribute, X value) {
    final Path<Y> attributePath = getRoot().get(singularAttribute);
    final Expression valueExpression = value == null ? criteriaBuilder().nullLiteral(attributePath.getJavaType()) : criteriaBuilder().literal(value);
    addAssignment(attributePath, valueExpression);
    return this;
}
Also used : Expression(javax.persistence.criteria.Expression)

Example 5 with Expression

use of javax.persistence.criteria.Expression in project hibernate-orm by hibernate.

the class QueryStructure method render.

@SuppressWarnings({ "unchecked" })
public void render(StringBuilder jpaqlQuery, RenderingContext renderingContext) {
    jpaqlQuery.append("select ");
    if (isDistinct()) {
        jpaqlQuery.append("distinct ");
    }
    if (getSelection() == null) {
        jpaqlQuery.append(locateImplicitSelection().renderProjection(renderingContext));
    } else {
        jpaqlQuery.append(((Renderable) getSelection()).renderProjection(renderingContext));
    }
    renderFromClause(jpaqlQuery, renderingContext);
    if (getRestriction() != null) {
        jpaqlQuery.append(" where ").append(((Renderable) getRestriction()).render(renderingContext));
    }
    if (!getGroupings().isEmpty()) {
        jpaqlQuery.append(" group by ");
        String sep = "";
        for (Expression grouping : getGroupings()) {
            jpaqlQuery.append(sep).append(((Renderable) grouping).render(renderingContext));
            sep = ", ";
        }
        if (getHaving() != null) {
            jpaqlQuery.append(" having ").append(((Renderable) getHaving()).render(renderingContext));
        }
    }
}
Also used : ParameterExpression(javax.persistence.criteria.ParameterExpression) Expression(javax.persistence.criteria.Expression)

Aggregations

Expression (javax.persistence.criteria.Expression)9 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 ParameterExpression (javax.persistence.criteria.ParameterExpression)1 Path (javax.persistence.criteria.Path)1 Predicate (javax.persistence.criteria.Predicate)1 Subquery (javax.persistence.criteria.Subquery)1 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)1 Renderable (org.hibernate.query.criteria.internal.Renderable)1 LiteralExpression (org.hibernate.query.criteria.internal.expression.LiteralExpression)1 ParameterExpressionImpl (org.hibernate.query.criteria.internal.expression.ParameterExpressionImpl)1 SingularAttributePath (org.hibernate.query.criteria.internal.path.SingularAttributePath)1 Type (org.hibernate.type.Type)1