use of jakarta.persistence.criteria.Expression in project eclipselink by eclipse-ee4j.
the class SubQueryImpl method groupBy.
/**
* Specify the expressions that are used to form groups over the query
* results. Replaces the previous specified grouping expressions, if any. If
* no grouping expressions are specified, any previously added grouping
* expressions are simply removed. This method only overrides the return
* type of the corresponding AbstractQuery method.
*
* @param grouping
* zero or more grouping expressions
* @return the modified query
*/
@Override
public Subquery<T> groupBy(Expression<?>... grouping) {
super.groupBy(grouping);
this.subQuery.getGroupByExpressions().clear();
for (Expression groupby : grouping) {
this.subQuery.addGrouping(((InternalSelection) groupby).getCurrentNode());
}
return this;
}
use of jakarta.persistence.criteria.Expression in project eclipselink by eclipse-ee4j.
the class SubQueryImpl method groupBy.
/**
* Specify the expressions that are used to form groups over the query
* results. Replaces the previous specified grouping expressions, if any. If
* no grouping expressions are specified, any previously added grouping
* expressions are simply removed. This method only overrides the return
* type of the corresponding AbstractQuery method.
*
* @param grouping
* zero or more grouping expressions
* @return the modified query
*/
@Override
public Subquery<T> groupBy(List<Expression<?>> grouping) {
super.groupBy(grouping);
this.subQuery.getGroupByExpressions().clear();
for (Expression groupby : grouping) {
this.subQuery.addGrouping(((InternalSelection) groupby).getCurrentNode());
}
return this;
}
use of jakarta.persistence.criteria.Expression in project eclipselink by eclipse-ee4j.
the class JoinImpl method on.
@Override
public JoinImpl<Z, X> on(Predicate... restrictions) {
org.eclipse.persistence.expressions.Expression onExp;
if (restrictions == null || restrictions.length == 0) {
this.on = null;
onExp = null;
} else {
// from criteriaQueryImpl.where(Predicate... restrictions)
Predicate a = restrictions[0];
for (int i = 1; i < restrictions.length; ++i) {
org.eclipse.persistence.expressions.Expression currentNode = ((CompoundExpressionImpl) a).getCurrentNode().and(((CompoundExpressionImpl) restrictions[i]).getCurrentNode());
((CompoundExpressionImpl) a).setParentNode(currentNode);
((CompoundExpressionImpl) restrictions[i]).setParentNode(currentNode);
List<Expression<?>> list = new ArrayList<>();
list.add(a);
list.add(restrictions[i]);
a = new PredicateImpl(this.metamodel, currentNode, list, BooleanOperator.AND);
}
this.on = a;
onExp = ((ExpressionImpl) a).getCurrentNode();
}
((PathImpl) this.pathParent).getCurrentNode().join(this.currentNode, onExp);
return this;
}
use of jakarta.persistence.criteria.Expression in project hibernate-orm by hibernate.
the class InsertSubstringOverlayEmulation method generateSqmFunctionExpression.
@Override
protected <T> SelfRenderingSqmFunction<T> generateSqmFunctionExpression(List<? extends SqmTypedNode<?>> arguments, ReturnableType<T> impliedResultType, QueryEngine queryEngine, TypeConfiguration typeConfiguration) {
final BasicType<Integer> intType = typeConfiguration.getBasicTypeForJavaType(Integer.class);
final BasicType<String> stringType = typeConfiguration.getBasicTypeForJavaType(String.class);
SqmTypedNode<?> string = arguments.get(0);
SqmTypedNode<?> replacement = arguments.get(1);
SqmTypedNode<?> start = arguments.get(2);
SqmTypedNode<?> length = arguments.size() > 3 ? arguments.get(3) : queryEngine.getSqmFunctionRegistry().findFunctionDescriptor("length").generateSqmExpression(replacement, intType, queryEngine, typeConfiguration);
SqmFunctionDescriptor insert = queryEngine.getSqmFunctionRegistry().findFunctionDescriptor("insert");
if (insert != null) {
return insert.generateSqmExpression(asList(string, start, length, replacement), impliedResultType, queryEngine, typeConfiguration);
} else {
SqmFunctionDescriptor lengthFunction = queryEngine.getSqmFunctionRegistry().findFunctionDescriptor("length");
SqmFunctionDescriptor substring = queryEngine.getSqmFunctionRegistry().findFunctionDescriptor("substring");
SqmFunctionDescriptor concat = queryEngine.getSqmFunctionRegistry().findFunctionDescriptor("concat");
SqmLiteral<Integer> one = new SqmLiteral<>(1, intType, queryEngine.getCriteriaBuilder());
SqmExpression<Integer> startPlusLength = new SqmBinaryArithmetic<>(BinaryArithmeticOperator.ADD, (SqmExpression<?>) start, (SqmExpression<?>) length, intType, queryEngine.getCriteriaBuilder());
SqmExpression<Integer> startMinusOne = new SqmBinaryArithmetic<>(BinaryArithmeticOperator.SUBTRACT, (SqmExpression<?>) start, one, intType, queryEngine.getCriteriaBuilder());
SqmTypedNode<?> restString = substring.generateSqmExpression(asList(string, startPlusLength), impliedResultType, queryEngine, typeConfiguration);
if (strictSubstring) {
restString = new SqmCaseSearched<>(stringType, start.nodeBuilder()).when(new SqmComparisonPredicate(startPlusLength, ComparisonOperator.GREATER_THAN, lengthFunction.generateSqmExpression(asList(string), intType, queryEngine, typeConfiguration), string.nodeBuilder()), new SqmLiteral<>("", stringType, string.nodeBuilder())).otherwise((Expression<? extends String>) restString);
}
return concat.generateSqmExpression(asList(substring.generateSqmExpression(asList(string, one, startMinusOne), impliedResultType, queryEngine, typeConfiguration), replacement, restString), impliedResultType, queryEngine, typeConfiguration);
}
}
use of jakarta.persistence.criteria.Expression in project eclipselink by eclipse-ee4j.
the class CriteriaQueryTestSuite method testInClauseSingleExpressionEmptyExpressionsList.
public void testInClauseSingleExpressionEmptyExpressionsList() {
EntityManager em = createEntityManager();
beginTransaction(em);
try {
CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaDelete<Employee> criteriaDelete = criteriaBuilder.createCriteriaDelete(Employee.class);
Root<Employee> employee = criteriaDelete.from(Employee.class);
CriteriaDelete<Employee> where = criteriaDelete.where(employee.get("firstName").in(Arrays.asList("Bob", "Bobby")));
Predicate restriction = where.getRestriction();
List<Expression<Boolean>> expressions = restriction.getExpressions();
assertTrue("An empty list should be returned", expressions.isEmpty());
} finally {
rollbackTransaction(em);
closeEntityManager(em);
}
}
Aggregations