Search in sources :

Example 6 with Expression

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;
}
Also used : ParameterExpression(jakarta.persistence.criteria.ParameterExpression) Expression(jakarta.persistence.criteria.Expression) SubSelectExpression(org.eclipse.persistence.internal.expressions.SubSelectExpression) ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression)

Example 7 with Expression

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;
}
Also used : ParameterExpression(jakarta.persistence.criteria.ParameterExpression) Expression(jakarta.persistence.criteria.Expression) SubSelectExpression(org.eclipse.persistence.internal.expressions.SubSelectExpression) ConstantExpression(org.eclipse.persistence.internal.expressions.ConstantExpression)

Example 8 with Expression

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;
}
Also used : Expression(jakarta.persistence.criteria.Expression) ArrayList(java.util.ArrayList) Predicate(jakarta.persistence.criteria.Predicate)

Example 9 with Expression

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);
    }
}
Also used : SqmFunctionDescriptor(org.hibernate.query.sqm.function.SqmFunctionDescriptor) AbstractSqmFunctionDescriptor(org.hibernate.query.sqm.function.AbstractSqmFunctionDescriptor) SqmBinaryArithmetic(org.hibernate.query.sqm.tree.expression.SqmBinaryArithmetic) SqmExpression(org.hibernate.query.sqm.tree.expression.SqmExpression) Expression(jakarta.persistence.criteria.Expression) SqmComparisonPredicate(org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate) SqmLiteral(org.hibernate.query.sqm.tree.expression.SqmLiteral)

Example 10 with Expression

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);
    }
}
Also used : CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) Employee(org.eclipse.persistence.testing.models.jpa21.advanced.Employee) Expression(jakarta.persistence.criteria.Expression) Predicate(jakarta.persistence.criteria.Predicate)

Aggregations

Expression (jakarta.persistence.criteria.Expression)19 Predicate (jakarta.persistence.criteria.Predicate)11 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)10 EntityManager (jakarta.persistence.EntityManager)9 ParameterExpression (jakarta.persistence.criteria.ParameterExpression)6 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)6 ConstantExpression (org.eclipse.persistence.internal.expressions.ConstantExpression)4 SubSelectExpression (org.eclipse.persistence.internal.expressions.SubSelectExpression)4 Employee (org.eclipse.persistence.testing.models.jpa21.advanced.Employee)4 Employee (org.eclipse.persistence.testing.models.jpa22.advanced.Employee)4 ArrayList (java.util.ArrayList)3 MatchFailedException (io.micronaut.data.processor.visitors.MatchFailedException)1 Root (jakarta.persistence.criteria.Root)1 Collection (java.util.Collection)1 ArgumentListFunctionExpression (org.eclipse.persistence.internal.expressions.ArgumentListFunctionExpression)1 FunctionExpression (org.eclipse.persistence.internal.expressions.FunctionExpression)1 MetamodelImpl (org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl)1 TypeImpl (org.eclipse.persistence.internal.jpa.metamodel.TypeImpl)1 CompoundExpressionImpl (org.eclipse.persistence.internal.jpa.querydef.CompoundExpressionImpl)1 JpaCriteriaBuilder (org.eclipse.persistence.jpa.JpaCriteriaBuilder)1