Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.eclipse.persistence.internal.jpa.querydef.CriteriaBuilderImpl Maven / Gradle / Ivy
/*
* Copyright (c) 2009, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2022 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
// Contributors:
// Gordon Yorke - Initial development
//
// Contributors:
// 04/19/2022: Jody Grassel
// - Issue 579726: CriteriaBuilder neg() only returns Integer type, instead of it's argument expression type.
package org.eclipse.persistence.internal.jpa.querydef;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.CollectionJoin;
import jakarta.persistence.criteria.CompoundSelection;
import jakarta.persistence.criteria.CriteriaDelete;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.CriteriaUpdate;
import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.ListJoin;
import jakarta.persistence.criteria.MapJoin;
import jakarta.persistence.criteria.Order;
import jakarta.persistence.criteria.ParameterExpression;
import jakarta.persistence.criteria.Path;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Predicate.BooleanOperator;
import jakarta.persistence.criteria.Root;
import jakarta.persistence.criteria.Selection;
import jakarta.persistence.criteria.SetJoin;
import jakarta.persistence.criteria.Subquery;
import jakarta.persistence.metamodel.EntityType;
import jakarta.persistence.metamodel.Metamodel;
import jakarta.persistence.metamodel.Type.PersistenceType;
import org.eclipse.persistence.expressions.ExpressionBuilder;
import org.eclipse.persistence.expressions.ExpressionMath;
import org.eclipse.persistence.expressions.ExpressionOperator;
import org.eclipse.persistence.internal.expressions.ArgumentListFunctionExpression;
import org.eclipse.persistence.internal.expressions.ConstantExpression;
import org.eclipse.persistence.internal.expressions.FunctionExpression;
import org.eclipse.persistence.internal.expressions.SubSelectExpression;
import org.eclipse.persistence.internal.helper.BasicTypeHelperImpl;
import org.eclipse.persistence.internal.helper.ClassConstants;
import org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl;
import org.eclipse.persistence.internal.jpa.metamodel.TypeImpl;
import org.eclipse.persistence.internal.jpa.querydef.AbstractQueryImpl.ResultType;
import org.eclipse.persistence.internal.localization.ExceptionLocalization;
import org.eclipse.persistence.jpa.JpaCriteriaBuilder;
import org.eclipse.persistence.queries.ReportQuery;
public class CriteriaBuilderImpl implements JpaCriteriaBuilder, Serializable {
public static final String CONCAT = "concat";
public static final String SIZE = "size";
protected Metamodel metamodel;
public CriteriaBuilderImpl(Metamodel metamodel){
this.metamodel = metamodel;
}
/**
* Create a Criteria query object.
* @return query object
*/
@Override
public CriteriaQuery createQuery(){
return new CriteriaQueryImpl(this.metamodel, ResultType.UNKNOWN, ClassConstants.OBJECT, this);
}
/**
* Create a Criteria query object.
* @return query object
*/
@Override
public CriteriaQuery createQuery(Class resultClass) {
if (resultClass == null) {
return (CriteriaQuery) this.createQuery();
}
if (resultClass.equals(Tuple.class)) {
return new CriteriaQueryImpl(this.metamodel, ResultType.TUPLE, resultClass, this);
} else if (resultClass.equals(ClassConstants.AOBJECT)) {
return new CriteriaQueryImpl(this.metamodel, ResultType.OBJECT_ARRAY, resultClass, this);
} else if (resultClass.isArray()) {
return new CriteriaQueryImpl(this.metamodel, ResultType.OBJECT_ARRAY, resultClass, this);
} else {
if (resultClass.equals(ClassConstants.OBJECT)) {
return (CriteriaQuery) this.createQuery();
} else {
if (resultClass.isPrimitive() || resultClass.equals(ClassConstants.STRING)|| BasicTypeHelperImpl.getInstance().isWrapperClass(resultClass) || BasicTypeHelperImpl.getInstance().isDateClass(resultClass)) {
return new CriteriaQueryImpl(metamodel, ResultType.OTHER, resultClass, this);
} else {
TypeImpl type = ((MetamodelImpl)this.metamodel).getType(resultClass);
if (type != null && type.getPersistenceType().equals(PersistenceType.ENTITY)) {
return new CriteriaQueryImpl(this.metamodel, ResultType.ENTITY, resultClass, this);
} else {
return new CriteriaQueryImpl(this.metamodel, ResultType.CONSTRUCTOR, resultClass, this);
}
}
}
}
}
/**
* Create a Criteria query object that returns a tuple of
* objects as its result.
* @return query object
*/
@Override
public CriteriaQuery createTupleQuery(){
return new CriteriaQueryImpl(this.metamodel, ResultType.TUPLE, Tuple.class, this);
}
/**
* Define a select list item corresponding to a constructor.
*
* @param result
* class whose instance is to be constructed
* @param selections
* arguments to the constructor
* @return selection item
*/
@Override
public CompoundSelection construct(Class result, Selection>... selections){
return new ConstructorSelectionImpl(result, selections);
}
@Override
public CompoundSelection tuple(Selection>... selections){
return new CompoundSelectionImpl(Tuple.class, selections, true);
}
/**
* Create an array-valued selection item
* @param selections selection items
* @return array-valued compound selection
* @throws IllegalArgumentException if an argument is a tuple- or
* array-valued selection item
*/
@Override
public CompoundSelection array(Selection>... selections){
return new CompoundSelectionImpl(ClassConstants.AOBJECT, selections, true);
}
/**
* Create an ordering by the ascending value of the expression.
*
* @param x
* expression used to define the ordering
* @return ascending ordering corresponding to the expression
*/
@Override
public Order asc(Expression> x){
if (((InternalSelection)x).getCurrentNode() == null){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION"));
}
return new OrderImpl(x);
}
/**
* Create an ordering by the descending value of the expression.
*
* @param x
* expression used to define the ordering
* @return descending ordering corresponding to the expression
*/
@Override
public Order desc(Expression> x){
if (((InternalSelection)x).getCurrentNode() == null){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION"));
}
OrderImpl order = new OrderImpl(x, false);
return order;
}
// aggregate functions:
/**
* Create an expression applying the avg operation.
*
* @param x
* expression representing input value to avg operation
* @return avg expression
*/
@Override
public Expression avg(Expression x){
return new FunctionExpressionImpl(this.metamodel, ClassConstants.DOUBLE,((InternalSelection)x).getCurrentNode().average(), buildList(x),"AVG");
}
/**
* Create an expression applying the sum operation.
*
* @param x
* expression representing input value to sum operation
* @return sum expression
*/
@Override
public Expression sum(Expression x){
return new FunctionExpressionImpl(this.metamodel, (Class) x.getJavaType(), ((InternalSelection)x).getCurrentNode().sum(), buildList(x),"SUM");
}
/**
* Create an expression applying the numerical max operation.
*
* @param x
* expression representing input value to max operation
* @return max expression
*/
@Override
public Expression max(Expression x){
return new FunctionExpressionImpl(this.metamodel, (Class) x.getJavaType(), ((InternalSelection)x).getCurrentNode().maximum(), buildList(x),"MAX");
}
/**
* Create an expression applying the numerical min operation.
*
* @param x
* expression representing input value to min operation
* @return min expression
*/
@Override
public Expression min(Expression x){
return new FunctionExpressionImpl(this.metamodel, (Class) x.getJavaType(), ((InternalSelection)x).getCurrentNode().minimum(), buildList(x),"MIN");
}
/**
* Create an aggregate expression for finding the greatest of the values
* (strings, dates, etc).
*
* @param x
* expression representing input value to greatest operation
* @return greatest expression
*/
@Override
public > Expression greatest(Expression x){
if (((InternalSelection)x).getCurrentNode() == null){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION"));
}
return new ExpressionImpl(this.metamodel, x.getJavaType(),((InternalSelection)x).getCurrentNode().maximum());
}
/**
* Create an aggregate expression for finding the least of the values
* (strings, dates, etc).
*
* @param x
* expression representing input value to least operation
* @return least expression
*/
@Override
public > Expression least(Expression x){
if (((InternalSelection)x).getCurrentNode() == null){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION"));
}
return new ExpressionImpl(this.metamodel, x.getJavaType(),((InternalSelection)x).getCurrentNode().minimum());
}
/**
* Create an expression applying the count operation.
*
* @param x
* expression representing input value to count operation
* @return count expression
*/
@Override
public Expression count(Expression> x){
if (((InternalSelection)x).getCurrentNode() == null){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION"));
}
return new FunctionExpressionImpl(this.metamodel, ClassConstants.LONG, ((InternalSelection)x).getCurrentNode().count(), buildList(x),"COUNT");
}
/**
* Create an expression applying the count distinct operation.
*
* @param x
* expression representing input value to count distinct
* operation
* @return count distinct expression
*/
@Override
public Expression countDistinct(Expression> x){
if (((InternalSelection)x).getCurrentNode() == null){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION"));
}
return new FunctionExpressionImpl(this.metamodel, ClassConstants.LONG, ((InternalSelection)x).getCurrentNode().distinct().count(), buildList(x),"COUNT");
}
// subqueries:
/**
* Create a predicate testing the existence of a subquery result.
*
* @param subquery
* subquery whose result is to be tested
* @return exists predicate
*/
@Override
public Predicate exists(Subquery> subquery) {
// Setting SubQuery's SubSelectExpression as a base for the expression created by operator allows setting a new ExpressionBuilder later in the SubSelectExpression (see integrateRoot method in SubQueryImpl).
ExpressionOperator operator = org.eclipse.persistence.expressions.Expression.getOperator(ExpressionOperator.Exists);
return new CompoundExpressionImpl(metamodel, operator.expressionFor(((SubQueryImpl)subquery).getCurrentNode()), buildList(subquery), "exists");
}
/**
* Create a predicate corresponding to an all expression over the subquery
* results.
*
* @param subquery
* @return all expression
*/
@Override
public Expression all(Subquery subquery){
return new FunctionExpressionImpl(metamodel, (Class) subquery.getJavaType(), new ExpressionBuilder().all(((InternalSelection)subquery).getCurrentNode()), buildList(subquery), "all");
}
/**
* Create a predicate corresponding to a some expression over the subquery
* results. This is equivalent to an any expression.
*
* @param subquery
* @return all expression
*/
@Override
public Expression some(Subquery subquery){
return new FunctionExpressionImpl(metamodel, (Class) subquery.getJavaType(), new ExpressionBuilder().some(((InternalSelection)subquery).getCurrentNode()), buildList(subquery), "some");
}
/**
* Create a predicate corresponding to an any expression over the subquery
* results. This is equivalent to a some expression.
*
* @param subquery
* @return any expression
*/
@Override
public Expression any(Subquery subquery){
return new FunctionExpressionImpl(metamodel, (Class) subquery.getJavaType(), new ExpressionBuilder().any(((InternalSelection)subquery).getCurrentNode()), buildList(subquery), "any");
}
// boolean functions:
/**
* Create a conjunction of the given boolean expressions.
*
* @param x
* boolean expression
* @param y
* boolean expression
* @return and predicate
*/
@Override
public Predicate and(Expression x, Expression y){
CompoundExpressionImpl xp = null;
CompoundExpressionImpl yp = null;
if (((InternalExpression)x).isExpression()){
xp = (CompoundExpressionImpl)this.isTrue(x);
}else{
xp = (CompoundExpressionImpl)x;
}
if (((InternalExpression)y).isExpression()){
yp = (CompoundExpressionImpl)this.isTrue(y);
}else{
yp = (CompoundExpressionImpl)y;
}
//bug 413084
if (yp.isJunction()){
if ( ((PredicateImpl)yp).getJunctionValue()){
return xp;//yp is true and so can be ignored/extracted
}else{
return yp;//yp is false so the statement is false
}
}
if (xp.isJunction()){
if (((PredicateImpl)xp).getJunctionValue()){
return yp;
}else{
return xp;
}
}
org.eclipse.persistence.expressions.Expression currentNode = xp.getCurrentNode().and(yp.getCurrentNode());
xp.setParentNode(currentNode);
yp.setParentNode(currentNode);
return new PredicateImpl(this.metamodel, currentNode, buildList(xp,yp), BooleanOperator.AND);
}
/**
* Create a disjunction of the given boolean expressions.
*
* @param x
* boolean expression
* @param y
* boolean expression
* @return or predicate
*/
@Override
public Predicate or(Expression x, Expression y){
CompoundExpressionImpl xp = null;
CompoundExpressionImpl yp = null;
if (((InternalExpression)x).isExpression()){
xp = (CompoundExpressionImpl)this.isTrue(x);
}else{
xp = (CompoundExpressionImpl)x;
}
if (((InternalExpression)y).isExpression()){
yp = (CompoundExpressionImpl)this.isTrue(y);
}else{
yp = (CompoundExpressionImpl)y;
}
//bug 413084
if (yp.isJunction()){
if (((PredicateImpl)yp).getJunctionValue()){
return yp;//yp is true so the statement is true
}
return xp;//yp is false so can be extracted.
}
if (xp.isJunction()){
if (((PredicateImpl)xp).getJunctionValue()){
return xp;
}
return yp;
}
org.eclipse.persistence.expressions.Expression parentNode = xp.getCurrentNode().or(yp.getCurrentNode());
xp.setParentNode(parentNode);
yp.setParentNode(parentNode);
return new PredicateImpl(this.metamodel, parentNode, buildList(xp,yp), BooleanOperator.OR);
}
/**
* Create a conjunction of the given restriction predicates. A conjunction
* of zero predicates is true.
*
* @param restrictions
* zero or more restriction predicates
* @return and predicate
*/
@Override
public Predicate and(Predicate... restrictions){
int max = restrictions.length;
if (max == 0){
return this.conjunction();
}
Predicate a = restrictions[0];
for (int i = 1; i < max; ++i){
a = this.and(a, restrictions[i]);
}
return a;
}
/**
* Create a disjunction of the given restriction predicates. A disjunction
* of zero predicates is false.
*
* @param restrictions
* zero or more restriction predicates
* @return and predicate
*/
@Override
public Predicate or(Predicate... restrictions){
int max = restrictions.length;
if (max == 0){
return this.disjunction();
}
Predicate a = restrictions[0];
for (int i = 1; i < max; ++i){
a = this.or(a, restrictions[i]);
}
return a;
}
/**
* Create a negation of the given restriction.
*
* @param restriction
* restriction expression
* @return not predicate
*/
@Override
public Predicate not(Expression restriction) {
if (((InternalExpression)restriction).isPredicate()){
return ((Predicate)restriction).not();
}
org.eclipse.persistence.expressions.Expression parentNode = null;
List> compoundExpressions = null;
String name = "not";
if (((InternalExpression)restriction).isCompoundExpression() && ((CompoundExpressionImpl)restriction).getOperation().equals("exists")){
FunctionExpression exp = (FunctionExpression) ((InternalSelection)restriction).getCurrentNode();
SubSelectExpression sub = (SubSelectExpression) exp.getChildren().get(0);
parentNode = org.eclipse.persistence.expressions.Expression.getOperator(ExpressionOperator.NotExists).expressionFor(sub);
name = "notExists";
compoundExpressions = ((CompoundExpressionImpl)restriction).getChildExpressions();
} else {
parentNode = ((InternalSelection)restriction).getCurrentNode().not();
compoundExpressions = buildList(restriction);
}
CompoundExpressionImpl expr = new CompoundExpressionImpl(this.metamodel, parentNode, compoundExpressions, name);
expr.setIsNegated(true);
return expr;
}
/**
* Create a conjunction (with zero conjuncts). A conjunction with zero
* conjuncts is true.
*
* @return and predicate
*/
@Override
public Predicate conjunction(){
return new PredicateImpl(this.metamodel, null, null, BooleanOperator.AND);
}
/**
* Create a disjunction (with zero disjuncts). A disjunction with zero
* disjuncts is false.
*
* @return or predicate
*/
@Override
public Predicate disjunction(){
return new PredicateImpl(this.metamodel, null, null, BooleanOperator.OR);
}
// turn Expression into a Predicate
// useful for use with varargs methods
/**
* Create a predicate testing for a true value.
*
* @param x
* expression to be tested if true
* @return predicate
*/
@Override
public Predicate isTrue(Expression x){
if (((InternalExpression)x).isPredicate()){
if (((InternalSelection)x).getCurrentNode() == null){
return (Predicate)x;
}else{
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("PREDICATE_PASSED_TO_EVALUATION"));
}
}
return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().equal(true), buildList(x), "equals");
}
/**
* Create a predicate testing for a false value.
*
* @param x
* expression to be tested if false
* @return predicate
*/
@Override
public Predicate isFalse(Expression x){
if (((InternalExpression)x).isPredicate()){
if (((InternalSelection)x).getCurrentNode() == null){
if (((Predicate)x).getOperator() == BooleanOperator.AND){
return (Predicate)x;
}else{
return this.conjunction();
}
}else{
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("PREDICATE_PASSED_TO_EVALUATION"));
}
}
return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().equal(false), buildList(x), "equals");
}
//null tests:
/**
* Create a predicate to test whether the expression is null.
* @param x expression
* @return predicate
*/
@Override
public Predicate isNull(Expression> x) {
return new PredicateImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().isNull(), buildList(x), BooleanOperator.AND);
}
/**
* Create a predicate to test whether the expression is not null.
* @param x expression
* @return predicate
*/
@Override
public Predicate isNotNull(Expression> x) {
return new PredicateImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().notNull(), buildList(x), BooleanOperator.AND);
}
// equality:
/**
* Create a predicate for testing the arguments for equality.
*
* @param x
* expression
* @param y
* expression
* @return equality predicate
*/
@Override
public Predicate equal(Expression> x, Expression> y){
return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().equal(((InternalSelection)y).getCurrentNode()), buildList(x, y), "equals");
}
/**
* Create a predicate for testing the arguments for inequality.
*
* @param x
* expression
* @param y
* expression
* @return inequality predicate
*/
@Override
public Predicate notEqual(Expression> x, Expression> y){
if (((InternalSelection)x).getCurrentNode() == null || ((InternalSelection)y).getCurrentNode() == null){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION"));
}
return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().notEqual(((InternalSelection)y).getCurrentNode()), buildList(x, y), "not equal");
}
/**
* Create a predicate for testing the arguments for equality.
*
* @param x
* expression
* @param y
* object
* @return equality predicate
*/
@Override
public Predicate equal(Expression> x, Object y){
//parameter is not an expression.
if (((InternalSelection)x).getCurrentNode() == null){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION"));
}
if (y instanceof ParameterExpression)
return this.equal(x, (ParameterExpression)y);
return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().equal(y), buildList(x, internalLiteral(y)), "equal");
}
/**
* Create a predicate for testing the arguments for inequality.
*
* @param x
* expression
* @param y
* object
* @return inequality predicate
*/
@Override
public Predicate notEqual(Expression> x, Object y){
if (((InternalSelection)x).getCurrentNode() == null){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION"));
}
if (y instanceof ParameterExpression)
return this.notEqual(x, (ParameterExpression)y);
return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().notEqual(y), buildList(x, internalLiteral(y)), "not equal");
}
// comparisons for generic (non-numeric) operands:
/**
* Create a predicate for testing whether the first argument is greater than
* the second.
*
* @param x
* expression
* @param y
* expression
* @return greater-than predicate
*/
@Override
public > Predicate greaterThan(Expression extends Y> x, Expression extends Y> y){
if (((InternalSelection)x).getCurrentNode() == null || ((InternalSelection)y).getCurrentNode() == null){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION"));
}
return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().greaterThan(((InternalSelection)y).getCurrentNode()), buildList(x, y), "greaterThan");
}
/**
* Create a predicate for testing whether the first argument is less than
* the second.
*
* @param x
* expression
* @param y
* expression
* @return less-than predicate
*/
@Override
public > Predicate lessThan(Expression extends Y> x, Expression extends Y> y){
if (((InternalSelection)x).getCurrentNode() == null || ((InternalSelection)y).getCurrentNode() == null){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION"));
}
return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().lessThan(((InternalSelection)y).getCurrentNode()), buildList(x,y), "lessThan");
}
/**
* Create a predicate for testing whether the first argument is greater than
* or equal to the second.
*
* @param x
* expression
* @param y
* expression
* @return greater-than-or-equal predicate
*/
@Override
public > Predicate greaterThanOrEqualTo(Expression extends Y> x, Expression extends Y> y){
if (((ExpressionImpl)x).getCurrentNode() == null || ((ExpressionImpl)y).getCurrentNode() == null){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION"));
}
return new CompoundExpressionImpl(this.metamodel, ((ExpressionImpl)x).getCurrentNode().greaterThanEqual(((ExpressionImpl)y).getCurrentNode()), buildList(x, y), "greaterThanEqual");
}
/**
* Create a predicate for testing whether the first argument is less than or
* equal to the second.
*
* @param x
* expression
* @param y
* expression
* @return less-than-or-equal predicate
*/
@Override
public > Predicate lessThanOrEqualTo(Expression extends Y> x, Expression extends Y> y){
if (((ExpressionImpl)x).getCurrentNode() == null || ((ExpressionImpl)y).getCurrentNode() == null){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION"));
}
return new CompoundExpressionImpl(this.metamodel, ((ExpressionImpl)x).getCurrentNode().lessThanEqual(((ExpressionImpl)y).getCurrentNode()), buildList(x, y), "lessThanEqual");
}
/**
* Create a predicate for testing whether the first argument is between the
* second and third arguments in value.
*
* @param v
* expression
* @param x
* expression
* @param y
* expression
* @return between predicate
*/
@Override
public > Predicate between(Expression extends Y> v, Expression extends Y> x, Expression extends Y> y){
return new CompoundExpressionImpl(this.metamodel, ((ExpressionImpl)v).getCurrentNode().between(((ExpressionImpl)x).getCurrentNode(), ((ExpressionImpl)y).getCurrentNode()), buildList(v, x, y), "between");
}
/**
* Create a predicate for testing whether the first argument is greater than
* the second.
*
* @param x
* expression
* @param y
* value
* @return greater-than predicate
*/
@Override
public > Predicate greaterThan(Expression extends Y> x, Y y){
if (((ExpressionImpl)x).getCurrentNode() == null ){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION"));
}
Expression expressionY = internalLiteral(y);
return new CompoundExpressionImpl(this.metamodel, ((ExpressionImpl)x).getCurrentNode().greaterThan(((ExpressionImpl)expressionY).getCurrentNode()), buildList(x, expressionY), "greaterThan");
}
/**
* Create a predicate for testing whether the first argument is less than
* the second.
*
* @param x
* expression
* @param y
* value
* @return less-than predicate
*/
@Override
public > Predicate lessThan(Expression extends Y> x, Y y){
if (((ExpressionImpl)x).getCurrentNode() == null ){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION"));
}
Expression expressionY = internalLiteral(y);
return new CompoundExpressionImpl(this.metamodel, ((ExpressionImpl)x).getCurrentNode().lessThan(((ExpressionImpl)expressionY).getCurrentNode()), buildList(x, expressionY), "lessThan");
}
/**
* Create a predicate for testing whether the first argument is greater than
* or equal to the second.
*
* @param x
* expression
* @param y
* value
* @return greater-than-or-equal predicate
*/
@Override
public > Predicate greaterThanOrEqualTo(Expression extends Y> x, Y y){
if (((ExpressionImpl)x).getCurrentNode() == null ){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION"));
}
Expression expressionY = internalLiteral(y);
return new CompoundExpressionImpl(this.metamodel, ((ExpressionImpl)x).getCurrentNode().greaterThanEqual(((ExpressionImpl)expressionY).getCurrentNode()), buildList(x, expressionY), "greaterThanEqual");
}
/**
* Create a predicate for testing whether the first argument is less than or
* equal to the second.
*
* @param x
* expression
* @param y
* value
* @return less-than-or-equal predicate
*/
@Override
public > Predicate lessThanOrEqualTo(Expression extends Y> x, Y y){
if (((ExpressionImpl)x).getCurrentNode() == null ){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION"));
}
Expression expressionY = internalLiteral(y);
return new CompoundExpressionImpl(this.metamodel, ((ExpressionImpl)x).getCurrentNode().lessThanEqual(((ExpressionImpl)expressionY).getCurrentNode()), buildList(x, expressionY), "lessThanEqual");
}
/**
* Create a predicate for testing whether the first argument is between the
* second and third arguments in value.
*
* @param v
* expression
* @param x
* value
* @param y
* value
* @return between predicate
*/
@Override
public > Predicate between(Expression extends Y> v, Y x, Y y){
return new CompoundExpressionImpl(this.metamodel, ((ExpressionImpl)v).getCurrentNode().between(x, y), buildList(v, internalLiteral(x), internalLiteral(y)), "between");
}
protected List> buildList(Expression>... expressions){
List> list = new ArrayList>();
for(Expression> exp : expressions){
list.add(exp);
}
return list;
}
// comparisons for numeric operands:
/**
* Create a predicate for testing whether the first argument is greater than
* the second.
*
* @param x
* expression
* @param y
* expression
* @return greater-than predicate
*/
@Override
public Predicate gt(Expression extends Number> x, Expression extends Number> y){
return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().greaterThan(((InternalSelection)y).getCurrentNode()), buildList(x, y), "gt");
}
/**
* Create a predicate for testing whether the first argument is less than
* the second.
*
* @param x
* expression
* @param y
* expression
* @return less-than predicate
*/
@Override
public Predicate lt(Expression extends Number> x, Expression extends Number> y){
return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().lessThan(((InternalSelection)y).getCurrentNode()), buildList(x,y), "lessThan");
}
/**
* Create a predicate for testing whether the first argument is greater than
* or equal to the second.
*
* @param x
* expression
* @param y
* expression
* @return greater-than-or-equal predicate
*/
@Override
public Predicate ge(Expression extends Number> x, Expression extends Number> y){
return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().greaterThanEqual(((InternalSelection)y).getCurrentNode()), buildList(x, y), "ge");
}
/**
* Create a predicate for testing whether the first argument is less than or
* equal to the second.
*
* @param x
* expression
* @param y
* expression
* @return less-than-or-equal predicate
*/
@Override
public Predicate le(Expression extends Number> x, Expression extends Number> y){
return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().lessThanEqual(((InternalSelection)y).getCurrentNode()), buildList(x, y), "le");
}
/**
* Create a predicate for testing whether the first argument is greater than
* the second.
*
* @param x
* expression
* @param y
* value
* @return greater-than predicate
*/
@Override
public Predicate gt(Expression extends Number> x, Number y){
return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().greaterThan(y), buildList(x, internalLiteral(y)), "gt");
}
/**
* Create a predicate for testing whether the first argument is less than
* the second.
*
* @param x
* expression
* @param y
* value
* @return less-than predicate
*/
@Override
public Predicate lt(Expression extends Number> x, Number y){
return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().lessThan(y), buildList(x,internalLiteral(y)), "lt");
}
/**
* Create a predicate for testing whether the first argument is greater than
* or equal to the second.
*
* @param x
* expression
* @param y
* value
* @return greater-than-or-equal predicate
*/
@Override
public Predicate ge(Expression extends Number> x, Number y){
return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().greaterThanEqual(y), buildList(x, internalLiteral(y)), "ge");
}
/**
* Create a predicate for testing whether the first argument is less than or
* equal to the second.
*
* @param x
* expression
* @param y
* value
* @return less-than-or-equal predicate
*/
@Override
public Predicate le(Expression extends Number> x, Number y){
return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().lessThanEqual(y), buildList(x, internalLiteral(y)), "le");
}
// numerical operations:
/**
* Create an expression that returns the arithmetic negation of its
* argument.
*
* @param x
* expression
* @return negated expression
*/
@Override
public Expression neg(Expression x){
return new FunctionExpressionImpl(this.metamodel, (Class) x.getJavaType(), ExpressionMath.negate(((InternalSelection)x).getCurrentNode()), buildList(x), "neg");
}
/**
* Create an expression that returns the absolute value of its argument.
*
* @param x
* expression
* @return absolute value
*/
@Override
public Expression abs(Expression x){
return new FunctionExpressionImpl(metamodel, (Class) x.getJavaType(), ExpressionMath.abs(((InternalSelection)x).getCurrentNode()), buildList(x),"ABS");
}
/**
* Create an expression that returns the sum of its arguments.
*
* @param x
* expression
* @param y
* expression
* @return sum
*/
@Override
public Expression sum(Expression extends N> x, Expression extends N> y){
return new FunctionExpressionImpl(this.metamodel, (Class)BasicTypeHelperImpl.getInstance().extendedBinaryNumericPromotion(x.getJavaType(), y.getJavaType()), ExpressionMath.add(((InternalSelection)x).getCurrentNode(),((InternalSelection)y).getCurrentNode()), buildList(x,y), "sum");
}
/**
* Create an aggregate expression applying the sum operation to an
* Integer-valued expression, returning a Long result.
* @param x expression representing input value to sum operation
* @return sum expression
*/
@Override
public Expression sumAsLong(Expression x) {
return new FunctionExpressionImpl(this.metamodel, ClassConstants.LONG, ((InternalSelection)x).getCurrentNode().sum(), buildList(x),"SUM");
}
/**
* Create an aggregate expression applying the sum operation to a
* Float-valued expression, returning a Double result.
* @param x expression representing input value to sum operation
* @return sum expression
*/
@Override
public Expression sumAsDouble(Expression x){
return new FunctionExpressionImpl(this.metamodel, ClassConstants.DOUBLE, ((InternalSelection)x).getCurrentNode().sum(), buildList(x),"SUM");
}
/**
* Create an expression that returns the product of its arguments.
*
* @param x
* expression
* @param y
* expression
* @return product
*/
@Override
public Expression prod(Expression extends N> x, Expression extends N> y){
return new FunctionExpressionImpl(this.metamodel, (Class)BasicTypeHelperImpl.getInstance().extendedBinaryNumericPromotion(x.getJavaType(), y.getJavaType()), ExpressionMath.multiply(((InternalSelection)x).getCurrentNode(),((InternalSelection)y).getCurrentNode()), buildList(x,y), "prod");
}
/**
* Create an expression that returns the difference between its arguments.
*
* @param x
* expression
* @param y
* expression
* @return difference
*/
@Override
public Expression diff(Expression extends N> x, Expression extends N> y){
return new FunctionExpressionImpl(this.metamodel, x.getJavaType(), ExpressionMath.subtract(((InternalSelection)x).getCurrentNode(), ((InternalSelection)y).getCurrentNode()), buildList(x, y), "diff");
}
/**
* Create an expression that returns the sum of its arguments.
*
* @param x
* expression
* @param y
* value
* @return sum
*/
@Override
public Expression sum(Expression extends N> x, N y){
return new FunctionExpressionImpl(this.metamodel, (Class)BasicTypeHelperImpl.getInstance().extendedBinaryNumericPromotion(x.getJavaType(), y.getClass()), ExpressionMath.add(((InternalSelection)x).getCurrentNode(),y), buildList(x,internalLiteral(y)), "sum");
}
/**
* Create an expression that returns the product of its arguments.
*
* @param x
* expression
* @param y
* value
* @return product
*/
@Override
public Expression prod(Expression extends N> x, N y){
return new FunctionExpressionImpl(this.metamodel, (Class)BasicTypeHelperImpl.getInstance().extendedBinaryNumericPromotion(x.getJavaType(), y.getClass()), ExpressionMath.multiply(((InternalSelection)x).getCurrentNode(),y), buildList(x,internalLiteral(y)), "prod");
}
/**
* Create an expression that returns the difference between its arguments.
*
* @param x
* expression
* @param y
* value
* @return difference
*/
@Override
public Expression diff(Expression extends N> x, N y){
return new FunctionExpressionImpl(this.metamodel, y.getClass(), ExpressionMath.subtract(((InternalSelection)x).getCurrentNode(), y), buildList(x, internalLiteral(y)), "diff");
}
/**
* Create an expression that returns the sum of its arguments.
*
* @param x
* value
* @param y
* expression
* @return sum
*/
@Override
public Expression sum(N x, Expression extends N> y){
return new FunctionExpressionImpl(this.metamodel, (Class)BasicTypeHelperImpl.getInstance().extendedBinaryNumericPromotion(x.getClass(), y.getJavaType()), ExpressionMath.add(new ConstantExpression(x, ((InternalSelection)y).getCurrentNode()),((InternalSelection)y).getCurrentNode()), buildList(internalLiteral(x),y), "sum");
}
/**
* Create an expression that returns the product of its arguments.
*
* @param x
* value
* @param y
* expression
* @return product
*/
@Override
public Expression prod(N x, Expression extends N> y){
return new FunctionExpressionImpl(this.metamodel, (Class)BasicTypeHelperImpl.getInstance().extendedBinaryNumericPromotion(x.getClass(), y.getJavaType()), ExpressionMath.multiply(new ConstantExpression(x, ((InternalSelection)y).getCurrentNode()),((InternalSelection)y).getCurrentNode()), buildList(internalLiteral(x),y), "prod");
}
/**
* Create an expression that returns the difference between its arguments.
*
* @param x
* value
* @param y
* expression
* @return difference
*/
@Override
public Expression diff(N x, Expression extends N> y){
Expression literal = internalLiteral(x);
return new FunctionExpressionImpl(this.metamodel, literal.getJavaType(), ExpressionMath.subtract(((InternalSelection)literal).getCurrentNode(), ((InternalSelection)y).getCurrentNode()), buildList(literal, y), "diff");
}
/**
* Create an expression that returns the quotient of its arguments.
*
* @param x
* expression
* @param y
* expression
* @return quotient
*/
@Override
public Expression quot(Expression extends Number> x, Expression extends Number> y){
return new FunctionExpressionImpl(this.metamodel, (Class)BasicTypeHelperImpl.getInstance().extendedBinaryNumericPromotion(x.getJavaType(), y.getClass()), ExpressionMath.divide(((InternalSelection)x).getCurrentNode(),((InternalSelection)y).getCurrentNode()), buildList(x,y), "quot");
}
/**
* Create an expression that returns the quotient of its arguments.
*
* @param x
* expression
* @param y
* value
* @return quotient
*/
@Override
public Expression quot(Expression extends Number> x, Number y){
return new FunctionExpressionImpl(this.metamodel, (Class)BasicTypeHelperImpl.getInstance().extendedBinaryNumericPromotion(x.getJavaType(), y.getClass()), ExpressionMath.divide(((InternalSelection)x).getCurrentNode(),y), buildList(x,internalLiteral(y)), "quot");
}
/**
* Create an expression that returns the quotient of its arguments.
*
* @param x
* value
* @param y
* expression
* @return quotient
*/
@Override
public Expression quot(Number x, Expression extends Number> y){
return new FunctionExpressionImpl(this.metamodel, ClassConstants.NUMBER, ExpressionMath.divide(new ConstantExpression(x, ((InternalSelection)y).getCurrentNode()),((InternalSelection)y).getCurrentNode()), buildList(internalLiteral(x),y), "quot");
}
/**
* Create an expression that returns the modulus of its arguments.
*
* @param x
* expression
* @param y
* expression
* @return modulus
*/
@Override
public Expression mod(Expression x, Expression y){
return new FunctionExpressionImpl(this.metamodel, ClassConstants.INTEGER, ExpressionMath.mod(((InternalSelection)x).getCurrentNode(),((InternalSelection)y).getCurrentNode()), buildList(x,y), "mod");
}
/**
* Create an expression that returns the modulus of its arguments.
*
* @param x
* expression
* @param y
* value
* @return modulus
*/
@Override
public Expression mod(Expression x, Integer y){
return new FunctionExpressionImpl(this.metamodel, ClassConstants.INTEGER, ExpressionMath.mod(((InternalSelection)x).getCurrentNode(),y), buildList(x,internalLiteral(y)), "mod");
}
/**
* Create an expression that returns the modulus of its arguments.
*
* @param x
* value
* @param y
* expression
* @return modulus
*/
@Override
public Expression mod(Integer x, Expression y){
Expression xExp = internalLiteral(x);
return new FunctionExpressionImpl(this.metamodel, ClassConstants.INTEGER, ExpressionMath.mod(((InternalSelection)xExp).getCurrentNode(),((InternalSelection)y).getCurrentNode()), buildList(xExp,y), "mod");
}
/**
* Create an expression that returns the square root of its argument.
*
* @param x
* expression
* @return modulus
*/
@Override
public Expression sqrt(Expression extends Number> x){
return new FunctionExpressionImpl(this.metamodel, ClassConstants.DOUBLE, ExpressionMath.sqrt(((InternalSelection)x).getCurrentNode()), buildList(x), "sqrt");
}
// typecasts:
/**
* Typecast.
*
* @param number
* numeric expression
* @return Expression<Long>
*/
@Override
public Expression toLong(Expression extends Number> number){
return (Expression) number;
}
/**
* Typecast.
*
* @param number
* numeric expression
* @return Expression<Integer>
*/
@Override
public Expression toInteger(Expression extends Number> number){
return (Expression) number;
}
/**
* Typecast.
*
* @param number
* numeric expression
* @return Expression<Float>
*/
@Override
public Expression toFloat(Expression extends Number> number){
return (Expression) number;
}
/**
* Typecast.
*
* @param number
* numeric expression
* @return Expression<Double>
*/
@Override
public Expression toDouble(Expression extends Number> number){
return (Expression) number;
}
/**
* Typecast.
*
* @param number
* numeric expression
* @return Expression<BigDecimal>
*/
@Override
public Expression toBigDecimal(Expression extends Number> number){
return (Expression) number;
}
/**
* Typecast.
*
* @param number
* numeric expression
* @return Expression<BigInteger>
*/
@Override
public Expression toBigInteger(Expression extends Number> number){
return (Expression) number;
}
/**
* Typecast.
*
* @param character
* expression
* @return Expression<String>
*/
@Override
public Expression toString(Expression character){
ExpressionImpl impl = (ExpressionImpl) character;
return impl;
}
// literals:
/**
* Create an expression literal.
*
* @param value
* @return expression literal
*/
@Override
public Expression literal(T value){
if (value == null) {
throw new IllegalArgumentException( ExceptionLocalization.buildMessage("jpa_criteriaapi_null_literal_value", new Object[]{}));
}
return new ExpressionImpl(metamodel, (Class) (value.getClass()), new ConstantExpression(value, new ExpressionBuilder()), value);
}
/**
* Create an expression for a null literal with the given type.
*
* @param resultClass type of the null literal
* @return null expression literal
*/
@Override
public Expression nullLiteral(Class resultClass){
return new ExpressionImpl(metamodel, resultClass, new ConstantExpression(null, new ExpressionBuilder()), null);
}
/**
* Create an expression literal but without null validation.
*
* @param value
* @return expression literal
*/
protected Expression internalLiteral(T value){
return new ExpressionImpl(metamodel, (Class) (value == null? null: value.getClass()), new ConstantExpression(value, new ExpressionBuilder()), value);
}
// parameters:
/**
* Create a parameter.
*
* Create a parameter expression.
* @param paramClass parameter class
* @return parameter expression
*/
@Override
public ParameterExpression parameter(Class paramClass){
return new ParameterExpressionImpl(metamodel, paramClass);
}
/**
* Create a parameter expression with the given name.
*
* @param paramClass
* parameter class
* @param name
* @return parameter
*/
@Override
public ParameterExpression parameter(Class paramClass, String name){
return new ParameterExpressionImpl(metamodel, paramClass, name);
}
// collection operations:
/**
* Create a predicate that tests whether a collection is empty.
*
* @param collection
* expression
* @return predicate
*/
@Override
public > Predicate isEmpty(Expression collection){
if (((InternalExpression)collection).isLiteral()){
if (((Collection)((ConstantExpression)((InternalSelection)collection).getCurrentNode()).getValue()).isEmpty()){
return conjunction();
}else{
return disjunction();
}
}
return new CompoundExpressionImpl(metamodel, ((InternalSelection)collection).getCurrentNode().size(ClassConstants.INTEGER).equal(0), buildList(collection), "isEmpty");
}
/**
* Create a predicate that tests whether a collection is not empty.
*
* @param collection
* expression
* @return predicate
*/
@Override
public > Predicate isNotEmpty(Expression collection){
return new CompoundExpressionImpl(metamodel, ((InternalSelection)collection).getCurrentNode().size(ClassConstants.INTEGER).equal(0).not(), buildList(collection), "isNotEmpty");
}
/**
* Create an expression that tests the size of a collection.
*
* @param collection
* @return size expression
*/
@Override
public > Expression size(C collection){
return internalLiteral(collection.size());
}
/**
* Create an expression that tests the size of a collection.
*
* @param collection
* expression
* @return size expression
*/
@Override
public > Expression size(Expression collection){
return new FunctionExpressionImpl(metamodel, ClassConstants.INTEGER, ((InternalSelection)collection).getCurrentNode().size(ClassConstants.INTEGER), buildList(collection), SIZE);
}
/**
* Create a predicate that tests whether an element is a member of a
* collection.
*
* @param elem
* element
* @param collection
* expression
* @return predicate
*/
@Override
public > Predicate isMember(E elem, Expression collection){
return new CompoundExpressionImpl(metamodel, ((InternalSelection)collection).getCurrentNode().equal(elem), buildList(collection, internalLiteral(elem)), "isMember");
}
/**
* Create a predicate that tests whether an element is not a member of a
* collection.
*
* @param elem
* element
* @param collection
* expression
* @return predicate
*/
@Override
public > Predicate isNotMember(E elem, Expression collection){
return new CompoundExpressionImpl(metamodel, ((InternalSelection)collection).getCurrentNode().notEqual(elem), buildList(collection, internalLiteral(elem)), "isMember");
}
/**
* Create a predicate that tests whether an element is a member of a
* collection.
*
* @param elem
* element expression
* @param collection
* expression
* @return predicate
*/
@Override
public > Predicate isMember(Expression elem, Expression collection){
return new CompoundExpressionImpl(metamodel, ((InternalSelection)collection).getCurrentNode().equal(((InternalSelection)elem).getCurrentNode()), buildList(collection, elem), "isMember");
}
/**
* Create a predicate that tests whether an element is not a member of a
* collection.
*
* @param elem
* element expression
* @param collection
* expression
* @return predicate
*/
@Override
public > Predicate isNotMember(Expression elem, Expression collection){
ReportQuery subQuery = new ReportQuery();
subQuery.setReferenceClass(((ExpressionImpl)elem).getJavaType());
org.eclipse.persistence.expressions.ExpressionBuilder elemBuilder = new org.eclipse.persistence.expressions.ExpressionBuilder();
org.eclipse.persistence.expressions.Expression collectionExp =((InternalSelection)collection).getCurrentNode();
org.eclipse.persistence.expressions.Expression elemExp =((InternalSelection)elem).getCurrentNode();
subQuery.setExpressionBuilder(elemBuilder);
subQuery.setShouldRetrieveFirstPrimaryKey(true);
subQuery.setSelectionCriteria(elemBuilder.equal(collectionExp).and(collectionExp.equal(elemExp)));
return new CompoundExpressionImpl(metamodel, ((InternalSelection)elem).getCurrentNode().notExists(subQuery), buildList(elem, collection), "isNotMemeber");
}
// get the values and keys collections of the Map, which may then
// be passed to size(), isMember(), isEmpty(), etc
/**
* Create an expression that returns the values of a map.
*
* @param map
* @return collection expression
*/
@Override
public > Expression> values(M map){
return internalLiteral(map.values());
}
/**
* Create an expression that returns the keys of a map.
*
* @param map
* @return set expression
*/
@Override
public > Expression> keys(M map){
return internalLiteral(map.keySet());
}
// string functions:
/**
* Create a predicate for testing whether the expression satisfies the given
* pattern.
*
* @param x
* string expression
* @param pattern
* string expression
* @return like predicate
*/
@Override
public Predicate like(Expression x, Expression pattern){
return new CompoundExpressionImpl(this.metamodel,
((InternalSelection)x).getCurrentNode().like(((InternalSelection)pattern).getCurrentNode()), buildList(x, pattern), "like");
}
/**
* Create a predicate for testing whether the expression satisfies the given
* pattern.
*
* @param x
* string expression
* @param pattern
* string expression
* @param escapeChar
* escape character expression
* @return like predicate
*/
@Override
public Predicate like(Expression x, Expression pattern, Expression escapeChar){
return new CompoundExpressionImpl(this.metamodel,
((InternalSelection)x).getCurrentNode().like(((InternalSelection)pattern).getCurrentNode(), ((InternalSelection)escapeChar).getCurrentNode()), buildList(x, pattern, escapeChar), "like");
}
/**
* Create a predicate for testing whether the expression satisfies the given
* pattern.
*
* @param x
* string expression
* @param pattern
* string expression
* @param escapeChar
* escape character
* @return like predicate
*/
@Override
public Predicate like(Expression x, Expression pattern, char escapeChar){
return this.like(x, pattern, this.internalLiteral(escapeChar));
}
/**
* Create a predicate for testing whether the expression satisfies the given
* pattern.
*
* @param x
* string expression
* @param pattern
* string
* @return like predicate
*/
@Override
public Predicate like(Expression x, String pattern){
return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().like(pattern), buildList(x, internalLiteral(pattern)), "like");
}
/**
* Create a predicate for testing whether the expression satisfies the given
* pattern.
*
* @param x
* string expression
* @param pattern
* string
* @param escapeChar
* escape character expression
* @return like predicate
*/
@Override
public Predicate like(Expression x, String pattern, Expression escapeChar){
return this.like(x, this.internalLiteral(pattern), escapeChar);
}
/**
* Create a predicate for testing whether the expression satisfies the given
* pattern.
*
* @param x
* string expression
* @param pattern
* string
* @param escapeChar
* escape character
* @return like predicate
*/
@Override
public Predicate like(Expression x, String pattern, char escapeChar){
String escapeString = String.valueOf(escapeChar);
return new CompoundExpressionImpl(this.metamodel,
((InternalSelection)x).getCurrentNode().like(pattern, escapeString), buildList(x, internalLiteral(pattern), internalLiteral(escapeChar)), "like");
}
/**
* Create a predicate for testing whether the expression does not satisfy
* the given pattern.
*
* @param x
* string expression
* @param pattern
* string expression
* @return like predicate
*/
@Override
public Predicate notLike(Expression x, Expression pattern){
return new CompoundExpressionImpl(this.metamodel,
((InternalSelection)x).getCurrentNode().notLike(((InternalSelection)pattern).getCurrentNode()), buildList(x, pattern), "notLike");
}
/**
* Create a predicate for testing whether the expression does not satisfy
* the given pattern.
*
* @param x
* string expression
* @param pattern
* string expression
* @param escapeChar
* escape character expression
* @return like predicate
*/
@Override
public Predicate notLike(Expression x, Expression pattern, Expression escapeChar){
return new CompoundExpressionImpl(this.metamodel,
((InternalSelection)x).getCurrentNode().notLike(((InternalSelection)pattern).getCurrentNode(),
((InternalSelection)escapeChar).getCurrentNode()), buildList(x, pattern, escapeChar), "like");
}
/**
* Create a predicate for testing whether the expression does not satisfy
* the given pattern.
*
* @param x
* string expression
* @param pattern
* string expression
* @param escapeChar
* escape character
* @return like predicate
*/
@Override
public Predicate notLike(Expression x, Expression pattern, char escapeChar){
return this.notLike(x, pattern, this.internalLiteral(escapeChar));
}
/**
* Create a predicate for testing whether the expression does not satisfy
* the given pattern.
*
* @param x
* string expression
* @param pattern
* string
* @return like predicate
*/
@Override
public Predicate notLike(Expression x, String pattern){
return new CompoundExpressionImpl(this.metamodel,
((InternalSelection)x).getCurrentNode().notLike(pattern), buildList(x, internalLiteral(pattern)), "notLike");
}
/**
* Create a predicate for testing whether the expression does not satisfy
* the given pattern.
*
* @param x
* string expression
* @param pattern
* string
* @param escapeChar
* escape character expression
* @return like predicate
*/
@Override
public Predicate notLike(Expression x, String pattern, Expression escapeChar){
return this.notLike(x, this.internalLiteral(pattern), escapeChar);
}
/**
* Create a predicate for testing whether the expression does not satisfy
* the given pattern.
*
* @param x
* string expression
* @param pattern
* string
* @param escapeChar
* escape character
* @return like predicate
*/
@Override
public Predicate notLike(Expression x, String pattern, char escapeChar){
return this.notLike(x, this.internalLiteral(pattern), this.internalLiteral(escapeChar));
}
/**
* String concatenation operation.
*
* @param x
* string expression
* @param y
* string expression
* @return expression corresponding to concatenation
*/
@Override
public Expression concat(Expression x, Expression y){
org.eclipse.persistence.expressions.Expression xNode = ((InternalSelection)x).getCurrentNode();
org.eclipse.persistence.expressions.Expression yNode = ((InternalSelection)y).getCurrentNode();
if (xNode.isParameterExpression() && yNode.isParameterExpression()) {
//some database require the type when concatting two parameters.
((org.eclipse.persistence.internal.expressions.ParameterExpression)xNode).setType(ClassConstants.STRING);
}
return new FunctionExpressionImpl(this.metamodel, ClassConstants.STRING, xNode.concat(yNode), buildList(x, y), CONCAT);
}
/**
* String concatenation operation.
*
* @param x
* string expression
* @param y
* string
* @return expression corresponding to concatenation
*/
@Override
public Expression concat(Expression x, String y){
return new FunctionExpressionImpl(this.metamodel, ClassConstants.STRING, ((InternalSelection)x).getCurrentNode().concat(y), buildList(x, internalLiteral(y)), CONCAT);
}
/**
* String concatenation operation.
*
* @param x
* string
* @param y
* string expression
* @return expression corresponding to concatenation
*/
@Override
public Expression concat(String x, Expression y){
Expression literal = internalLiteral(x);
return new FunctionExpressionImpl(this.metamodel, ClassConstants.STRING, ((InternalSelection)literal).getCurrentNode().concat(((InternalSelection)y).getCurrentNode()), buildList(literal, y), CONCAT);
}
/**
* Substring extraction operation. Extracts a substring starting at
* specified position through to end of the string. First position is 1.
*
* @param x
* string expression
* @param from
* start position expression
* @return expression corresponding to substring extraction
*/
@Override
public Expression substring(Expression x, Expression from) {
return new FunctionExpressionImpl(metamodel, ClassConstants.STRING, ((InternalSelection) x).getCurrentNode().substring(((InternalSelection) from).getCurrentNode()), buildList(x, from), "subString");
}
/**
* Substring extraction operation. Extracts a substring starting at
* specified position through to end of the string. First position is 1.
*
* @param x
* string expression
* @param from
* start position
* @return expression corresponding to substring extraction
*/
@Override
public Expression substring(Expression x, int from){
return substring(x, this.internalLiteral(from));
}
/**
* Substring extraction operation. Extracts a substring of given length
* starting at specified position. First position is 1.
*
* @param x
* string expression
* @param from
* start position expression
* @param len
* length expression
* @return expression corresponding to substring extraction
*/
@Override
public Expression substring(Expression x, Expression from, Expression len){
return new FunctionExpressionImpl(metamodel, ClassConstants.STRING, ((InternalSelection) x).getCurrentNode().substring(((InternalSelection) from).getCurrentNode(), ((InternalSelection) len).getCurrentNode()), buildList(x, from, len), "subString");
}
/**
* Substring extraction operation. Extracts a substring of given length
* starting at specified position. First position is 1.
*
* @param x
* string expression
* @param from
* start position
* @param len
* length
* @return expression corresponding to substring extraction
*/
@Override
public Expression substring(Expression x, int from, int len){
return new FunctionExpressionImpl(metamodel, ClassConstants.STRING, ((InternalSelection) x).getCurrentNode().substring(from, len), buildList(x, internalLiteral(from), internalLiteral(len)), "subString");
}
/**
* Create expression to trim blanks from both ends of a string.
*
* @param x
* expression for string to trim
* @return trim expression
*/
@Override
public Expression trim(Expression x){
return new FunctionExpressionImpl(this.metamodel, ClassConstants.STRING, ((InternalSelection)x).getCurrentNode().trim(), buildList(x), "trim");
}
/**
* Create expression to trim blanks from a string.
*
* @param ts
* trim specification
* @param x
* expression for string to trim
* @return trim expression
*/
@Override
public Expression trim(Trimspec ts, Expression x){
if(ts == Trimspec.LEADING) {
return new FunctionExpressionImpl(this.metamodel, ClassConstants.STRING, ((InternalSelection)x).getCurrentNode().leftTrim(), buildList(x), "leftTrim");
} else if(ts == Trimspec.TRAILING) {
return new FunctionExpressionImpl(this.metamodel, ClassConstants.STRING, ((InternalSelection)x).getCurrentNode().rightTrim(), buildList(x), "rightTrim");
}
return new FunctionExpressionImpl(this.metamodel, ClassConstants.STRING, ((InternalSelection)x).getCurrentNode().rightTrim().leftTrim(), buildList(x), "bothTrim");
}
/**
* Create expression to trim character from both ends of a string.
*
* @param t
* expression for character to be trimmed
* @param x
* expression for string to trim
* @return trim expression
*/
@Override
public Expression trim(Expression t, Expression x){
return new FunctionExpressionImpl(this.metamodel, ClassConstants.STRING, ((InternalSelection)x).getCurrentNode().trim(((InternalSelection)t).getCurrentNode()), buildList(x, t), "trim");
}
/**
* Create expression to trim character from a string.
*
* @param ts
* trim specification
* @param t
* expression for character to be trimmed
* @param x
* expression for string to trim
* @return trim expression
*/
@Override
public Expression trim(Trimspec ts, Expression t, Expression x){
if(ts == Trimspec.LEADING) {
return new FunctionExpressionImpl(this.metamodel, ClassConstants.STRING,
((InternalSelection)x).getCurrentNode().leftTrim(((InternalSelection)t).getCurrentNode()), buildList(x, t), "leftTrim");
} else if(ts == Trimspec.TRAILING) {
return new FunctionExpressionImpl(this.metamodel, ClassConstants.STRING,
((InternalSelection)x).getCurrentNode().rightTrim(((InternalSelection)t).getCurrentNode()), buildList(x, t), "rightTrim");
}
return new FunctionExpressionImpl(this.metamodel, ClassConstants.STRING,
((InternalSelection)x).getCurrentNode().rightTrim(((InternalSelection)t).getCurrentNode()).leftTrim(((InternalSelection)t).getCurrentNode()), buildList(x, t), "bothTrim");
}
/**
* Create expression to trim character from both ends of a string.
*
* @param t
* character to be trimmed
* @param x
* expression for string to trim
* @return trim expression
*/
@Override
public Expression trim(char t, Expression x){
return trim(this.internalLiteral(t), x);
}
/**
* Create expression to trim character from a string.
*
* @param ts
* trim specification
* @param t
* character to be trimmed
* @param x
* expression for string to trim
* @return trim expression
*/
@Override
public Expression trim(Trimspec ts, char t, Expression x){
return trim(ts, this.internalLiteral(t), x);
}
/**
* Create expression for converting a string to lowercase.
*
* @param x
* string expression
* @return expression to convert to lowercase
*/
@Override
public Expression lower(Expression x){
return new FunctionExpressionImpl(this.metamodel, ClassConstants.STRING, ((InternalSelection)x).getCurrentNode().toLowerCase(), buildList(x), "lower");
}
/**
* Create expression for converting a string to uppercase.
*
* @param x
* string expression
* @return expression to convert to uppercase
*/
@Override
public Expression upper(Expression x){
return new FunctionExpressionImpl(this.metamodel, ClassConstants.STRING, ((InternalSelection)x).getCurrentNode().toUpperCase(), buildList(x), "upper");
}
/**
* Create expression to return length of a string.
*
* @param x
* string expression
* @return length expression
*/
@Override
public Expression