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();
}
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;
}
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;
}
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;
}
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));
}
}
}
Aggregations