diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/helper/BasicTypeHelperImpl.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/helper/BasicTypeHelperImpl.java index 345ae2dc90f..b83f3d88595 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/helper/BasicTypeHelperImpl.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/helper/BasicTypeHelperImpl.java @@ -32,19 +32,19 @@ public class BasicTypeHelperImpl { /** Set of numeric types and its wrapper classes. */ - private static Set numericTypes = new HashSet(); + private static final Set> numericTypes = new HashSet<>(); /** Set of integral types and its wrapper classes. */ - private static Set integralTypes = new HashSet(); + private static final Set> integralTypes = new HashSet<>(); /** Set of floating point types and its wrapper classes. */ - private static Set floatingPointTypes = new HashSet(); + private static final Set> floatingPointTypes = new HashSet<>(); /** Set of date classes. */ - private static Set dateClasses = new HashSet(); + private static final Set> dateClasses = new HashSet<>(); /** Set of time classes. */ - private static Set timeClasses = new HashSet(); + private static final Set> timeClasses = new HashSet<>(); /** Maps primtives types to their wrapper classes. */ - private static Map, Class> primitiveToWrapper = new HashMap<>(); + private static final Map, Class> primitiveToWrapper = new HashMap<>(); /** Maps wrapper classes to their primitive types. */ - private static Map, Class> wrapperToPrimitive = new HashMap<>(); + private static final Map, Class> wrapperToPrimitive = new HashMap<>(); static { // Initialize set of integral types plus their wrapper classes @@ -123,7 +123,7 @@ public String getTypeName(Object type) { public Class getJavaClass(Object type) { Class clazz = null; if (type instanceof Class) { - clazz = (Class)type; + clazz = (Class)type; } else if (type instanceof ClassDescriptor) { clazz = ((ClassDescriptor)type).getJavaClass(); } @@ -131,127 +131,127 @@ public Class getJavaClass(Object type) { } /** Returns the Object type representation.*/ - public Object getObjectType() { + public Class getObjectType() { return Object.class; } /** Returns the boolean type representation.*/ - public Object getBooleanType() { + public Class getBooleanType() { return boolean.class; } /** Returns the Boolean class representation.*/ - public Object getBooleanClassType() { + public Class getBooleanClassType() { return Boolean.class; } /** Returns the char type representation.*/ - public Object getCharType() { + public Class getCharType() { return char.class; } /** Returns the Date type representation.*/ - public Object getSQLDateType() { + public Class getSQLDateType() { return java.sql.Date.class; } /** Returns the Time type representation.*/ - public Object getTimeType() { + public Class getTimeType() { return java.sql.Time.class; } /** Returns the timestamp type representation.*/ - public Object getTimestampType() { + public Class getTimestampType() { return java.sql.Timestamp.class; } /** Returns the Character class representation.*/ - public Object getCharacterClassType() { + public Class getCharacterClassType() { return Character.class; } /** Returns the byte type representation.*/ - public Object getByteType() { + public Class getByteType() { return byte.class; } /** Returns the Byte class representation.*/ - public Object getByteClassType() { + public Class getByteClassType() { return Byte.class; } /** Returns the short type representation.*/ - public Object getShortType() { + public Class getShortType() { return short.class; } /** Returns the Short class representation.*/ - public Object getShortClassType() { + public Class getShortClassType() { return Short.class; } /** Returns the int type representation.*/ - public Object getIntType() { + public Class getIntType() { return int.class; } /** Returns the Inter class representation.*/ - public Object getIntegerClassType() { + public Class getIntegerClassType() { return Integer.class; } /** Returns the long type representation.*/ - public Object getLongType() { + public Class getLongType() { return long.class; } /** Returns the type representation of class Long.*/ - public Object getLongClassType() { + public Class getLongClassType() { return Long.class; } /** Returns the type representation of class Map.Entry.*/ - public Object getMapEntryType(){ + public Class getMapEntryType(){ return Map.Entry.class; } /** Returns the float type representation.*/ - public Object getFloatType() { + public Class getFloatType() { return float.class; } /** Returns the type representation of class Float.*/ - public Object getFloatClassType() { + public Class getFloatClassType() { return Float.class; } /** Returns the double type representation.*/ - public Object getDoubleType() { + public Class getDoubleType() { return double.class; } /** Returns the type representation of class Double.*/ - public Object getDoubleClassType() { + public Class getDoubleClassType() { return Double.class; } /** Returns the String type representation.*/ - public Object getStringType() { + public Class getStringType() { return String.class; } /** Returns the BigInteger type representation.*/ - public Object getBigIntegerType() { + public Class getBigIntegerType() { return BigInteger.class; } /** Returns the BigDecimal type representation.*/ - public Object getBigDecimalType() { + public Class getBigDecimalType() { return BigDecimal.class; } /** Returns the java.util.Date type representation.*/ - public Object getDateType() { + public Class getDateType() { return Date.class; } @@ -327,7 +327,7 @@ public boolean isIntType(Object type) { /** * Returns true if type is the int primitive type or the Integer wrapper class */ - public boolean isIntegerType(Object type) { + public boolean isIntegerType(Class type) { return isIntType(type); } @@ -477,6 +477,12 @@ public Object extendedBinaryNumericPromotion(Object left, Object right) { return promoted; } + // extendedBinaryNumericPromotion with class cast, shortcut for CriteriaBuilderImpl + @SuppressWarnings("unchecked") + public Class extendedBinaryNumericPromotionClass(Class left, Class right) { + return (Class) extendedBinaryNumericPromotion(left, right); + } + // Helper methods /** Returns the primitive for the specified wrapper class. */ @@ -494,7 +500,7 @@ protected Object binaryNumericPromotion(Object left, Object right) { if ((left == null) || (right == null)) { return null; } - Object type = null; + Class type = null; if (left == getDoubleType() || right == getDoubleType()) { type = getDoubleType(); @@ -507,5 +513,6 @@ protected Object binaryNumericPromotion(Object left, Object right) { } return type; } + } diff --git a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/AbstractQueryImpl.java b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/AbstractQueryImpl.java index fbabc45d440..3b613d0fc2c 100644 --- a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/AbstractQueryImpl.java +++ b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/AbstractQueryImpl.java @@ -19,7 +19,9 @@ // - New Jakarta Persistence 3.2 Features package org.eclipse.persistence.internal.jpa.querydef; +import java.io.Serial; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Objects; @@ -31,7 +33,6 @@ import jakarta.persistence.criteria.Root; import jakarta.persistence.metamodel.EntityType; import jakarta.persistence.metamodel.Metamodel; - import org.eclipse.persistence.expressions.ExpressionBuilder; /** @@ -50,6 +51,7 @@ */ public abstract class AbstractQueryImpl extends CommonAbstractCriteriaImpl implements AbstractQuery { + @Serial private static final long serialVersionUID = -5270020290752637882L; protected ResultType queryResult; @@ -65,7 +67,7 @@ protected enum ResultType{ public AbstractQueryImpl(Metamodel metamodel, ResultType queryResult, CriteriaBuilderImpl queryBuilder, Class resultType){ super(metamodel, queryBuilder, resultType); - this.roots = new HashSet>(); + this.roots = new HashSet<>(); this.queryResult = queryResult; this.baseExpression = new ExpressionBuilder(); } @@ -98,10 +100,8 @@ public AbstractQuery groupBy(List> grouping){ */ @Override public AbstractQuery groupBy(Expression... grouping){ - this.groupBy = new ArrayList>(); - for (Expression exp : grouping){ - this.groupBy.add(exp); - } + this.groupBy = new ArrayList<>(); + Collections.addAll(this.groupBy, grouping); return this; } @@ -147,7 +147,7 @@ public AbstractQuery having(List restrictions) { return this; } - public abstract void addJoin(FromImpl join); + public abstract void addJoin(FromImpl join); /** * Specify whether duplicate query results will be eliminated. A true value @@ -173,15 +173,15 @@ protected org.eclipse.persistence.expressions.Expression getBaseExpression() { return getBaseExpression(null); } - protected org.eclipse.persistence.expressions.Expression getBaseExpression(Root root) { + protected org.eclipse.persistence.expressions.Expression getBaseExpression(Root root) { if (this.roots.isEmpty()) { baseExpression = new ExpressionBuilder(); } else if (this.roots.size() == 1) { - baseExpression = ((RootImpl) this.roots.iterator().next()).getCurrentNode(); + baseExpression = ((RootImpl) this.roots.iterator().next()).getCurrentNode(); } else if (root != null) { - for (Root r : this.roots) { + for (Root r : this.roots) { if (r == root) { - baseExpression = ((RootImpl) r).getCurrentNode(); + baseExpression = ((RootImpl) r).getCurrentNode(); } } } @@ -195,7 +195,7 @@ protected org.eclipse.persistence.expressions.Expression getBaseExpression(Root @Override public List> getGroupList(){ if (this.groupBy == null){ - this.groupBy = new ArrayList>(); + this.groupBy = new ArrayList<>(); } return this.groupBy; } @@ -222,10 +222,8 @@ public Set> getRoots(){ } @Override - protected void integrateRoot(RootImpl root) { - if (!this.roots.contains(root)) { - this.roots.add(root); - } + protected void integrateRoot(RootImpl root) { + this.roots.add(root); } /** @@ -239,7 +237,7 @@ public boolean isDistinct(){ return this.distinct; } - protected void findJoins(FromImpl root) { + protected void findJoins(FromImpl root) { root.findJoins(this); } diff --git a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/CommonAbstractCriteriaImpl.java b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/CommonAbstractCriteriaImpl.java index 331ea8f1f41..5c9cf5083dd 100644 --- a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/CommonAbstractCriteriaImpl.java +++ b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/CommonAbstractCriteriaImpl.java @@ -18,6 +18,7 @@ // - New Jakarta Persistence 3.2 Features package org.eclipse.persistence.internal.jpa.querydef; +import java.io.Serial; import java.io.Serializable; import java.util.HashSet; import java.util.List; @@ -33,7 +34,6 @@ import jakarta.persistence.criteria.Subquery; import jakarta.persistence.metamodel.EntityType; import jakarta.persistence.metamodel.Metamodel; - import org.eclipse.persistence.expressions.ExpressionBuilder; import org.eclipse.persistence.internal.expressions.ConstantExpression; import org.eclipse.persistence.queries.DatabaseQuery; @@ -54,6 +54,7 @@ */ public abstract class CommonAbstractCriteriaImpl implements CommonAbstractCriteria, Serializable { + @Serial private static final long serialVersionUID = -2729946665208116620L; protected Metamodel metamodel; @@ -79,7 +80,7 @@ public Predicate getRestriction(){ if (this.where == null) { return null; } - if (((ExpressionImpl)this.where).isPredicate()) { + if (((ExpressionImpl)this.where).isPredicate()) { return (Predicate)this.where; } return this.queryBuilder.isTrue(this.where); @@ -106,8 +107,13 @@ public Class getResultType(){ * metamodel entity representing the entity of type X * @return query root corresponding to the given entity */ - public Root internalFrom(EntityType entity) { - RootImpl root = new RootImpl(entity, this.metamodel, entity.getBindableJavaType(), new ExpressionBuilder(entity.getBindableJavaType()), entity); + public Root internalFrom(EntityType entity) { + RootImpl root = new RootImpl<>( + entity, + this.metamodel, + entity.getBindableJavaType(), + new ExpressionBuilder(entity.getBindableJavaType()), + entity); integrateRoot(root); return root; } @@ -120,8 +126,8 @@ public Root internalFrom(EntityType entity) { * the entity class * @return query root corresponding to the given entity */ - public Root internalFrom(Class entityClass) { - EntityType entity = this.metamodel.entity(entityClass); + public Root internalFrom(Class entityClass) { + EntityType entity = this.metamodel.entity(entityClass); return this.internalFrom(entity); } @@ -176,7 +182,7 @@ public CommonAbstractCriteria where(List restrictions) { */ @Override public Subquery subquery(Class type) { - return new SubQueryImpl(metamodel, type, queryBuilder, this); + return new SubQueryImpl<>(metamodel, type, queryBuilder, this); } @Override @@ -187,7 +193,7 @@ public Subquery subquery(EntityType type) { /** * Used to use a root from a different query. */ - protected abstract void integrateRoot(RootImpl root); + protected abstract void integrateRoot(RootImpl root); protected void findRootAndParameters(Expression predicate) { Objects.requireNonNull(predicate, "Predicate expression is null"); @@ -203,7 +209,7 @@ protected void findRootAndParameters(Order order) { public void addParameter(ParameterExpression parameter) { if (this.parameters == null) { - this.parameters = new HashSet>(); + this.parameters = new HashSet<>(); } this.parameters.add(parameter); } @@ -218,7 +224,7 @@ public void addParameter(ParameterExpression parameter) { @Override public Set> getParameters() { if (this.parameters == null) { - this.parameters = new HashSet>(); + this.parameters = new HashSet<>(); } return this.parameters; } @@ -230,7 +236,7 @@ public Set> getParameters() { public DatabaseQuery translate() { DatabaseQuery query = getDatabaseQuery(); for (ParameterExpression parameter : getParameters()) { - query.addArgument(((ParameterExpressionImpl)parameter).getInternalName(), parameter.getJavaType()); + query.addArgument(((ParameterExpressionImpl)parameter).getInternalName(), parameter.getJavaType()); } if (this.where != null) { if (((InternalExpression) this.where).isJunction()) { diff --git a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/CompoundSelectionImpl.java b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/CompoundSelectionImpl.java index 2d2e9defa19..cd8b7b0a983 100644 --- a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/CompoundSelectionImpl.java +++ b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/CompoundSelectionImpl.java @@ -22,7 +22,6 @@ import jakarta.persistence.criteria.CompoundSelection; import jakarta.persistence.criteria.Selection; - import org.eclipse.persistence.internal.localization.ExceptionLocalization; /** @@ -32,31 +31,31 @@ *

* Description: The Selection is the expression describing what should be returned by the query. * + * @param the type of the selection item * @see jakarta.persistence.criteria Join * * @author gyorke * @since EclipseLink 1.2 * */ - -public class CompoundSelectionImpl extends SelectionImpl implements CompoundSelection{ +public class CompoundSelectionImpl extends SelectionImpl implements CompoundSelection { protected ArrayList> subSelections; //bug 366386 - track items using duplicate alias names protected ArrayList duplicateAliasNames; - public CompoundSelectionImpl(Class javaType, Selection[] subSelections) { + public CompoundSelectionImpl(Class javaType, Selection[] subSelections) { this(javaType, subSelections, false); } - public CompoundSelectionImpl(Class javaType, Selection[] subSelections, boolean validate) { + public CompoundSelectionImpl(Class javaType, Selection[] subSelections, boolean validate) { super(javaType, null); this.subSelections = new ArrayList<>(); //used to validate that an alias is only used once - Map tempMap = new TreeMap<>(); - for (Selection sel : subSelections) { + Map> tempMap = new TreeMap<>(); + for (Selection sel : subSelections) { if (validate) { - if (sel.isCompoundSelection() && !((SelectionImpl)sel).isConstructor()) { + if (sel.isCompoundSelection() && !((SelectionImpl)sel).isConstructor()) { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("jpa_criteriaapi_illegal_tuple_or_array_value", new Object[] { sel })); } } @@ -64,7 +63,7 @@ public CompoundSelectionImpl(Class javaType, Selection[] subSelections, boole if (alias != null) { if (tempMap.containsKey(alias)) { if (duplicateAliasNames == null) { - duplicateAliasNames=new ArrayList(); + duplicateAliasNames=new ArrayList<>(); } duplicateAliasNames.add(alias); } else { @@ -104,8 +103,8 @@ protected List getDuplicateAliasNames() { } @Override - public void findRootAndParameters(CommonAbstractCriteriaImpl criteriaQuery){ - for (Selection selection: getCompoundSelectionItems()){ + public void findRootAndParameters(CommonAbstractCriteriaImpl criteriaQuery){ + for (Selection selection: getCompoundSelectionItems()){ ((InternalSelection)selection).findRootAndParameters(criteriaQuery); } } diff --git a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/ConstructorSelectionImpl.java b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/ConstructorSelectionImpl.java index b1076540d50..34e404d85fa 100644 --- a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/ConstructorSelectionImpl.java +++ b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/ConstructorSelectionImpl.java @@ -18,7 +18,6 @@ import java.lang.reflect.Constructor; import jakarta.persistence.criteria.Selection; - import org.eclipse.persistence.internal.queries.ReportItem; import org.eclipse.persistence.queries.ConstructorReportItem; @@ -29,17 +28,18 @@ *

* Description: The Selection is the expression describing what should be returned by the query. * + * @param the type of the selection item * @see jakarta.persistence.criteria Join * * @author gyorke * @since EclipseLink 1.2 */ -public class ConstructorSelectionImpl extends CompoundSelectionImpl { +public class ConstructorSelectionImpl extends CompoundSelectionImpl { - protected transient Constructor constructor; + protected transient Constructor constructor; protected Class[] constructorArgTypes; - public ConstructorSelectionImpl(Class javaType, Selection[] subSelections) { + public ConstructorSelectionImpl(Class javaType, Selection[] subSelections) { super(javaType, subSelections, true);//need to validate selection items } @@ -47,12 +47,12 @@ public ConstructorReportItem translate(){ ConstructorReportItem item = new ConstructorReportItem(this.getAlias()); item.setResultType(this.getJavaType()); item.setConstructor(constructor); - for(Selection selection : this.getCompoundSelectionItems()){ + for(Selection selection : this.getCompoundSelectionItems()) { if (selection.isCompoundSelection()){ - item.addItem(((ConstructorSelectionImpl)selection).translate()); + item.addItem(((ConstructorSelectionImpl)selection).translate()); }else{ ReportItem reportItem = new ReportItem(item.getName()+item.getReportItems().size(), - ((SelectionImpl)selection).getCurrentNode()); + ((SelectionImpl)selection).getCurrentNode()); //bug: 297385 - set type here because the selection already knows the type reportItem.setResultType(selection.getJavaType()); item.addItem(reportItem); @@ -71,7 +71,7 @@ public boolean isConstructor(){ * INTERNAL: * Set the constructor. */ - public void setConstructor(Constructor constructor){ + public void setConstructor(Constructor constructor){ this.constructor = constructor; } diff --git a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/CriteriaBuilderImpl.java b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/CriteriaBuilderImpl.java index 4b16d34ea73..2cc0ca86316 100644 --- a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/CriteriaBuilderImpl.java +++ b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/CriteriaBuilderImpl.java @@ -56,7 +56,6 @@ 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; @@ -100,12 +99,13 @@ public CriteriaQuery createQuery(){ * @return query object */ @Override + @SuppressWarnings("unchecked") 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); + 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()) { @@ -119,9 +119,9 @@ public CriteriaQuery createQuery(Class resultClass) { } 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); + return new CriteriaQueryImpl<>(this.metamodel, ResultType.ENTITY, resultClass, this); } else { - return new CriteriaQueryImpl(this.metamodel, ResultType.CONSTRUCTOR, resultClass, this); + return new CriteriaQueryImpl<>(this.metamodel, ResultType.CONSTRUCTOR, resultClass, this); } } } @@ -150,13 +150,13 @@ public CriteriaQuery createTupleQuery(){ */ @Override public CompoundSelection construct(Class result, Selection... selections){ - return new ConstructorSelectionImpl(result, selections); + return new ConstructorSelectionImpl<>(result, selections); } @Override public CompoundSelection tuple(Selection... selections){ - return new CompoundSelectionImpl(Tuple.class, selections, true); + return new CompoundSelectionImpl<>(Tuple.class, selections, true); } /** @@ -168,7 +168,7 @@ public CompoundSelection tuple(Selection... selections){ */ @Override public CompoundSelection array(Selection... selections){ - return new CompoundSelectionImpl(ClassConstants.AOBJECT, selections, true); + return new CompoundSelectionImpl<>((Class) ClassConstants.AOBJECT, selections, true); } @Override @@ -209,7 +209,7 @@ public Order desc(Expression expression, Nulls nullPrecedence) { */ @Override public Expression avg(Expression x){ - return new FunctionExpressionImpl(this.metamodel, ClassConstants.DOUBLE,((InternalSelection)x).getCurrentNode().average(), buildList(x),"AVG"); + return new FunctionExpressionImpl(this.metamodel, ClassConstants.DOUBLE,currentNode(x).average(), buildList(x),"AVG"); } /** @@ -221,7 +221,7 @@ public Expression avg(Expression x){ */ @Override public Expression sum(Expression x){ - return new FunctionExpressionImpl(this.metamodel, (Class) x.getJavaType(), ((InternalSelection)x).getCurrentNode().sum(), buildList(x),"SUM"); + return new FunctionExpressionImpl(this.metamodel, x.getJavaType(), currentNode(x).sum(), buildList(x),"SUM"); } /** @@ -233,7 +233,7 @@ public Expression sum(Expression x){ */ @Override public Expression max(Expression x){ - return new FunctionExpressionImpl(this.metamodel, (Class) x.getJavaType(), ((InternalSelection)x).getCurrentNode().maximum(), buildList(x),"MAX"); + return new FunctionExpressionImpl(this.metamodel, x.getJavaType(), currentNode(x).maximum(), buildList(x),"MAX"); } /** @@ -245,7 +245,7 @@ public Expression max(Expression x){ */ @Override public Expression min(Expression x){ - return new FunctionExpressionImpl(this.metamodel, (Class) x.getJavaType(), ((InternalSelection)x).getCurrentNode().minimum(), buildList(x),"MIN"); + return new FunctionExpressionImpl(this.metamodel, x.getJavaType(), currentNode(x).minimum(), buildList(x),"MIN"); } /** @@ -258,10 +258,10 @@ public Expression min(Expression x){ */ @Override public > Expression greatest(Expression x){ - if (((InternalSelection)x).getCurrentNode() == null){ + if (currentNode(x) == null){ throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION")); } - return new ExpressionImpl<>(this.metamodel, x.getJavaType(), ((InternalSelection)x).getCurrentNode().maximum()); + return new ExpressionImpl<>(this.metamodel, x.getJavaType(), currentNode(x).maximum()); } /** @@ -274,10 +274,10 @@ public > Expression greatest(Expression x) */ @Override public > Expression least(Expression x){ - if (((InternalSelection)x).getCurrentNode() == null){ + if (currentNode(x) == null){ throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION")); } - return new ExpressionImpl<>(this.metamodel, x.getJavaType(),((InternalSelection)x).getCurrentNode().minimum()); + return new ExpressionImpl<>(this.metamodel, x.getJavaType(),currentNode(x).minimum()); } /** @@ -289,10 +289,10 @@ public > Expression least(Expression x){ */ @Override public Expression count(Expression x){ - if (((InternalSelection)x).getCurrentNode() == null){ + if (currentNode(x) == null){ throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION")); } - return new FunctionExpressionImpl(this.metamodel, ClassConstants.LONG, ((InternalSelection)x).getCurrentNode().count(), buildList(x),"COUNT"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.LONG, currentNode(x).count(), buildList(x),"COUNT"); } /** @@ -305,10 +305,10 @@ public Expression count(Expression x){ */ @Override public Expression countDistinct(Expression x){ - if (((InternalSelection)x).getCurrentNode() == null){ + if (currentNode(x) == 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"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.LONG, currentNode(x).distinct().count(), buildList(x),"COUNT"); } // subqueries: @@ -322,7 +322,12 @@ public Expression countDistinct(Expression x){ @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). - return new CompoundExpressionImpl(metamodel, org.eclipse.persistence.expressions.Expression.getOperator(ExpressionOperator.Exists).expressionFor(((SubQueryImpl)subquery).getCurrentNode()), buildList(subquery), "exists"); + return new CompoundExpressionImpl( + metamodel, + org.eclipse.persistence.expressions.Expression.getOperator(ExpressionOperator.Exists) + .expressionFor(((SubQueryImpl)subquery).getCurrentNode()), + buildList(subquery), + "exists"); } /** @@ -333,7 +338,7 @@ public Predicate exists(Subquery subquery){ */ @Override public Expression all(Subquery subquery){ - return new FunctionExpressionImpl(metamodel, (Class) subquery.getJavaType(), new ExpressionBuilder().all(((InternalSelection)subquery).getCurrentNode()), buildList(subquery), "all"); + return new FunctionExpressionImpl<>(metamodel, subquery.getJavaType(), new ExpressionBuilder().all(currentNode(subquery)), buildList(subquery), "all"); } /** @@ -344,7 +349,7 @@ public Expression all(Subquery subquery){ */ @Override public Expression some(Subquery subquery){ - return new FunctionExpressionImpl(metamodel, (Class) subquery.getJavaType(), new ExpressionBuilder().some(((InternalSelection)subquery).getCurrentNode()), buildList(subquery), "some"); + return new FunctionExpressionImpl(metamodel, subquery.getJavaType(), new ExpressionBuilder().some(currentNode(subquery)), buildList(subquery), "some"); } /** @@ -355,7 +360,7 @@ public Expression some(Subquery subquery){ */ @Override public Expression any(Subquery subquery){ - return new FunctionExpressionImpl(metamodel, (Class) subquery.getJavaType(), new ExpressionBuilder().any(((InternalSelection)subquery).getCurrentNode()), buildList(subquery), "any"); + return new FunctionExpressionImpl(metamodel, subquery.getJavaType(), new ExpressionBuilder().any(currentNode(subquery)), buildList(subquery), "any"); } // boolean functions: @@ -527,13 +532,13 @@ public Predicate not(Expression restriction){ List> compoundExpressions = null; String name = "not"; if (((InternalExpression)restriction).isCompoundExpression() && ((CompoundExpressionImpl)restriction).getOperation().equals("exists")){ - FunctionExpression exp = (FunctionExpression) ((InternalSelection)restriction).getCurrentNode(); + FunctionExpression exp = (FunctionExpression) currentNode(restriction); 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(); + parentNode = currentNode(restriction).not(); compoundExpressions = buildList(restriction); } CompoundExpressionImpl expr = new CompoundExpressionImpl(this.metamodel, parentNode, compoundExpressions, name); @@ -575,13 +580,13 @@ public Predicate disjunction(){ @Override public Predicate isTrue(Expression x){ if (((InternalExpression)x).isPredicate()){ - if (((InternalSelection)x).getCurrentNode() == null){ + if (currentNode(x) == 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"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).equal(true), buildList(x), "equals"); } /** @@ -594,7 +599,7 @@ public Predicate isTrue(Expression x){ @Override public Predicate isFalse(Expression x){ if (((InternalExpression)x).isPredicate()){ - if (((InternalSelection)x).getCurrentNode() == null){ + if (currentNode(x) == null){ if (((Predicate)x).getOperator() == BooleanOperator.AND){ return (Predicate)x; }else{ @@ -604,7 +609,7 @@ public Predicate isFalse(Expression x){ throw new IllegalArgumentException(ExceptionLocalization.buildMessage("PREDICATE_PASSED_TO_EVALUATION")); } } - return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().equal(false), buildList(x), "equals"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).equal(false), buildList(x), "equals"); } //null tests: @@ -615,7 +620,7 @@ public Predicate isFalse(Expression x){ */ @Override public Predicate isNull(Expression x){ - return new PredicateImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().isNull(), buildList(x), BooleanOperator.AND); + return new PredicateImpl(this.metamodel, currentNode(x).isNull(), buildList(x), BooleanOperator.AND); } /** @@ -625,7 +630,7 @@ public Predicate isNull(Expression x){ */ @Override public Predicate isNotNull(Expression x){ - return new PredicateImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().notNull(), buildList(x), BooleanOperator.AND); + return new PredicateImpl(this.metamodel, currentNode(x).notNull(), buildList(x), BooleanOperator.AND); } // equality: @@ -640,7 +645,7 @@ public Predicate isNotNull(Expression x){ */ @Override public Predicate equal(Expression x, Expression y){ - return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().equal(((InternalSelection)y).getCurrentNode()), buildList(x, y), "equals"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).equal(currentNode(y)), buildList(x, y), "equals"); } /** @@ -654,10 +659,10 @@ public Predicate equal(Expression x, Expression y){ */ @Override public Predicate notEqual(Expression x, Expression y){ - if (((InternalSelection)x).getCurrentNode() == null || ((InternalSelection)y).getCurrentNode() == null){ + if (currentNode(x) == null || currentNode(y) == 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"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).notEqual(currentNode(y)), buildList(x, y), "not equal"); } /** @@ -672,13 +677,13 @@ public Predicate notEqual(Expression x, Expression y){ @Override public Predicate equal(Expression x, Object y){ //parameter is not an expression. - if (((InternalSelection)x).getCurrentNode() == null){ + if (currentNode(x) == 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"); + if (y instanceof ParameterExpression) { + return this.equal(x, (ParameterExpression) y); + } + return new CompoundExpressionImpl(this.metamodel, currentNode(x).equal(y), buildList(x, internalLiteral(y)), "equal"); } /** @@ -692,13 +697,13 @@ public Predicate equal(Expression x, Object y){ */ @Override public Predicate notEqual(Expression x, Object y){ - if (((InternalSelection)x).getCurrentNode() == null){ + if (currentNode(x) == null){ throw new IllegalArgumentException(ExceptionLocalization.buildMessage("OPERATOR_EXPRESSION_IS_CONJUNCTION")); } if (y instanceof ParameterExpression) - return this.notEqual(x, (ParameterExpression)y); + return this.notEqual(x, (ParameterExpression)y); - return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().notEqual(y), buildList(x, internalLiteral(y)), "not equal"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).notEqual(y), buildList(x, internalLiteral(y)), "not equal"); } // comparisons for generic (non-numeric) operands: @@ -714,10 +719,10 @@ public Predicate notEqual(Expression x, Object y){ */ @Override public > Predicate greaterThan(Expression x, Expression y){ - if (((InternalSelection)x).getCurrentNode() == null || ((InternalSelection)y).getCurrentNode() == null){ + if (currentNode(x) == null || currentNode(y) == 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"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).greaterThan(currentNode(y)), buildList(x, y), "greaterThan"); } /** @@ -732,10 +737,10 @@ public > Predicate greaterThan(Expression> Predicate lessThan(Expression x, Expression y){ - if (((InternalSelection)x).getCurrentNode() == null || ((InternalSelection)y).getCurrentNode() == null){ + if (currentNode(x) == null || currentNode(y) == 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"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).lessThan(currentNode(y)), buildList(x,y), "lessThan"); } /** @@ -750,10 +755,10 @@ public > Predicate lessThan(Expression> Predicate greaterThanOrEqualTo(Expression x, Expression y){ - if (((ExpressionImpl)x).getCurrentNode() == null || ((ExpressionImpl)y).getCurrentNode() == null){ + if (currentNode(x) == null || currentNode(y) == 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"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).greaterThanEqual(currentNode(y)), buildList(x, y), "greaterThanEqual"); } /** @@ -768,10 +773,10 @@ public > Predicate greaterThanOrEqualTo(Expressi */ @Override public > Predicate lessThanOrEqualTo(Expression x, Expression y){ - if (((ExpressionImpl)x).getCurrentNode() == null || ((ExpressionImpl)y).getCurrentNode() == null){ + if (currentNode(x) == null || currentNode(y) == 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"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).lessThanEqual(currentNode(y)), buildList(x, y), "lessThanEqual"); } /** @@ -788,7 +793,7 @@ public > Predicate lessThanOrEqualTo(Expression< */ @Override public > Predicate between(Expression v, Expression x, Expression y){ - return new CompoundExpressionImpl(this.metamodel, ((ExpressionImpl)v).getCurrentNode().between(((ExpressionImpl)x).getCurrentNode(), ((ExpressionImpl)y).getCurrentNode()), buildList(v, x, y), "between"); + return new CompoundExpressionImpl(this.metamodel, currentNode(v).between(currentNode(x), currentNode(y)), buildList(v, x, y), "between"); } /** @@ -803,11 +808,11 @@ public > Predicate between(Expression> Predicate greaterThan(Expression x, Y y){ - if (((ExpressionImpl)x).getCurrentNode() == null ){ + if (currentNode(x) == 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"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).greaterThan(currentNode(expressionY)), buildList(x, expressionY), "greaterThan"); } /** @@ -822,11 +827,11 @@ public > Predicate greaterThan(Expression> Predicate lessThan(Expression x, Y y){ - if (((ExpressionImpl)x).getCurrentNode() == null ){ + if (currentNode(x) == 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"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).lessThan(currentNode(expressionY)), buildList(x, expressionY), "lessThan"); } /** @@ -841,11 +846,11 @@ public > Predicate lessThan(Expression> Predicate greaterThanOrEqualTo(Expression x, Y y){ - if (((ExpressionImpl)x).getCurrentNode() == null ){ + if (currentNode(x) == 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"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).greaterThanEqual(currentNode(expressionY)), buildList(x, expressionY), "greaterThanEqual"); } /** @@ -860,11 +865,11 @@ public > Predicate greaterThanOrEqualTo(Expressi */ @Override public > Predicate lessThanOrEqualTo(Expression x, Y y){ - if (((ExpressionImpl)x).getCurrentNode() == null ){ + if (currentNode(x) == 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"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).lessThanEqual(currentNode(expressionY)), buildList(x, expressionY), "lessThanEqual"); } /** @@ -881,7 +886,7 @@ public > Predicate lessThanOrEqualTo(Expression< */ @Override public > Predicate between(Expression v, Y x, Y y){ - return new CompoundExpressionImpl(this.metamodel, ((ExpressionImpl)v).getCurrentNode().between(x, y), buildList(v, internalLiteral(x), internalLiteral(y)), "between"); + return new CompoundExpressionImpl(this.metamodel, currentNode(v).between(x, y), buildList(v, internalLiteral(x), internalLiteral(y)), "between"); } protected List> buildList(Expression... expressions) { @@ -905,7 +910,7 @@ protected List> buildList(Expression... expressions) { */ @Override public Predicate gt(Expression x, Expression y){ - return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().greaterThan(((InternalSelection)y).getCurrentNode()), buildList(x, y), "gt"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).greaterThan(currentNode(y)), buildList(x, y), "gt"); } /** @@ -920,7 +925,7 @@ public Predicate gt(Expression x, Expression */ @Override public Predicate lt(Expression x, Expression y){ - return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().lessThan(((InternalSelection)y).getCurrentNode()), buildList(x,y), "lessThan"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).lessThan(currentNode(y)), buildList(x,y), "lessThan"); } /** @@ -935,7 +940,7 @@ public Predicate lt(Expression x, Expression */ @Override public Predicate ge(Expression x, Expression y){ - return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().greaterThanEqual(((InternalSelection)y).getCurrentNode()), buildList(x, y), "ge"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).greaterThanEqual(currentNode(y)), buildList(x, y), "ge"); } /** @@ -950,7 +955,7 @@ public Predicate ge(Expression x, Expression */ @Override public Predicate le(Expression x, Expression y){ - return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().lessThanEqual(((InternalSelection)y).getCurrentNode()), buildList(x, y), "le"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).lessThanEqual(currentNode(y)), buildList(x, y), "le"); } /** @@ -965,7 +970,7 @@ public Predicate le(Expression x, Expression */ @Override public Predicate gt(Expression x, Number y){ - return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().greaterThan(y), buildList(x, internalLiteral(y)), "gt"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).greaterThan(y), buildList(x, internalLiteral(y)), "gt"); } /** @@ -980,7 +985,7 @@ public Predicate gt(Expression x, Number y){ */ @Override public Predicate lt(Expression x, Number y){ - return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().lessThan(y), buildList(x, internalLiteral(y)), "lt"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).lessThan(y), buildList(x, internalLiteral(y)), "lt"); } /** @@ -995,7 +1000,7 @@ public Predicate lt(Expression x, Number y){ */ @Override public Predicate ge(Expression x, Number y){ - return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().greaterThanEqual(y), buildList(x, internalLiteral(y)), "ge"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).greaterThanEqual(y), buildList(x, internalLiteral(y)), "ge"); } /** @@ -1010,7 +1015,7 @@ public Predicate ge(Expression x, Number y){ */ @Override public Predicate le(Expression x, Number y){ - return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().lessThanEqual(y), buildList(x, internalLiteral(y)), "le"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).lessThanEqual(y), buildList(x, internalLiteral(y)), "le"); } // numerical operations: @@ -1024,7 +1029,7 @@ public Predicate le(Expression x, Number y){ */ @Override public Expression neg(Expression x){ - return new FunctionExpressionImpl(this.metamodel, (Class) x.getJavaType(), ExpressionMath.negate(((InternalSelection)x).getCurrentNode()), buildList(x), "neg"); + return new FunctionExpressionImpl<>(this.metamodel, x.getJavaType(), ExpressionMath.negate(currentNode(x)), buildList(x), "neg"); } /** @@ -1036,7 +1041,7 @@ public Expression neg(Expression x){ */ @Override public Expression abs(Expression x){ - return new FunctionExpressionImpl(metamodel, (Class) x.getJavaType(), ExpressionMath.abs(((InternalSelection)x).getCurrentNode()), buildList(x),"ABS"); + return new FunctionExpressionImpl(metamodel, x.getJavaType(), ExpressionMath.abs(currentNode(x)), buildList(x),"ABS"); } /** @@ -1050,7 +1055,12 @@ public Expression abs(Expression x){ */ @Override public Expression sum(Expression x, Expression 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"); + return new FunctionExpressionImpl<>( + this.metamodel, + BasicTypeHelperImpl.getInstance().extendedBinaryNumericPromotionClass(x.getJavaType(), y.getJavaType()), + ExpressionMath.add(currentNode(x),currentNode(y)), + buildList(x,y), + "sum"); } /** * Create an aggregate expression applying the sum operation to an @@ -1060,7 +1070,7 @@ public Expression sum(Expression x, Expressio */ @Override public Expression sumAsLong(Expression x) { - return new FunctionExpressionImpl(this.metamodel, ClassConstants.LONG, ((InternalSelection)x).getCurrentNode().sum(), buildList(x),"SUM"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.LONG, currentNode(x).sum(), buildList(x),"SUM"); } /** @@ -1071,7 +1081,7 @@ public Expression sumAsLong(Expression x) { */ @Override public Expression sumAsDouble(Expression x){ - return new FunctionExpressionImpl(this.metamodel, ClassConstants.DOUBLE, ((InternalSelection)x).getCurrentNode().sum(), buildList(x),"SUM"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.DOUBLE, currentNode(x).sum(), buildList(x),"SUM"); } /** * Create an expression that returns the product of its arguments. @@ -1084,7 +1094,12 @@ public Expression sumAsDouble(Expression x){ */ @Override public Expression prod(Expression x, Expression 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"); + return new FunctionExpressionImpl<>( + this.metamodel, + BasicTypeHelperImpl.getInstance().extendedBinaryNumericPromotionClass(x.getJavaType(), y.getJavaType()), + ExpressionMath.multiply(currentNode(x),currentNode(y)), + buildList(x,y), + "prod"); } /** @@ -1098,7 +1113,7 @@ public Expression prod(Expression x, Expressi */ @Override public Expression diff(Expression x, Expression y){ - return new FunctionExpressionImpl(this.metamodel, x.getJavaType(), ExpressionMath.subtract(((InternalSelection)x).getCurrentNode(), ((InternalSelection)y).getCurrentNode()), buildList(x, y), "diff"); + return new FunctionExpressionImpl<>(this.metamodel, x.getJavaType(), ExpressionMath.subtract(currentNode(x), currentNode(y)), buildList(x, y), "diff"); } /** @@ -1112,7 +1127,12 @@ public Expression diff(Expression x, Expressi */ @Override public Expression sum(Expression 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"); + return new FunctionExpressionImpl<>( + this.metamodel, + BasicTypeHelperImpl.getInstance().extendedBinaryNumericPromotionClass(x.getJavaType(), y.getClass()), + ExpressionMath.add(currentNode(x),y), + buildList(x,internalLiteral(y)), + "sum"); } /** @@ -1126,7 +1146,12 @@ public Expression sum(Expression x, N y){ */ @Override public Expression prod(Expression 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"); + return new FunctionExpressionImpl<>( + this.metamodel, + BasicTypeHelperImpl.getInstance().extendedBinaryNumericPromotionClass(x.getJavaType(), y.getClass()), + ExpressionMath.multiply(currentNode(x),y), + buildList(x,internalLiteral(y)), + "prod"); } /** @@ -1139,8 +1164,14 @@ public Expression prod(Expression x, N y){ * @return difference */ @Override + @SuppressWarnings("unchecked") // y.getClass() cast public Expression diff(Expression x, N y){ - return new FunctionExpressionImpl(this.metamodel, y.getClass(), ExpressionMath.subtract(((InternalSelection)x).getCurrentNode(), y), buildList(x, internalLiteral(y)), "diff"); + return new FunctionExpressionImpl<>( + this.metamodel, + (Class) y.getClass(), + ExpressionMath.subtract(currentNode(x), y), + buildList(x, internalLiteral(y)), + "diff"); } /** @@ -1154,7 +1185,12 @@ public Expression diff(Expression x, N y){ */ @Override public Expression sum(N x, Expression 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"); + return new FunctionExpressionImpl<>( + this.metamodel, + BasicTypeHelperImpl.getInstance().extendedBinaryNumericPromotionClass(x.getClass(), y.getJavaType()), + ExpressionMath.add(new ConstantExpression(x, currentNode(y)),currentNode(y)), + buildList(internalLiteral(x),y), + "sum"); } /** @@ -1168,7 +1204,12 @@ public Expression sum(N x, Expression y){ */ @Override public Expression prod(N x, Expression 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"); + return new FunctionExpressionImpl<>( + this.metamodel, + BasicTypeHelperImpl.getInstance().extendedBinaryNumericPromotionClass(x.getClass(), y.getJavaType()), + ExpressionMath.multiply(new ConstantExpression(x, currentNode(y)),currentNode(y)), + buildList(internalLiteral(x),y), + "prod"); } /** @@ -1182,8 +1223,12 @@ public Expression prod(N x, Expression y){ */ @Override public Expression diff(N x, Expression y){ - Expression literal = internalLiteral(x); - return new FunctionExpressionImpl(this.metamodel, literal.getJavaType(), ExpressionMath.subtract(((InternalSelection)literal).getCurrentNode(), ((InternalSelection)y).getCurrentNode()), buildList(literal, y), "diff"); + Expression literal = internalLiteral(x); + return new FunctionExpressionImpl<>( + this.metamodel, + literal.getJavaType(), + ExpressionMath.subtract(currentNode(literal), currentNode(y)), + buildList(literal, y), "diff"); } /** @@ -1197,7 +1242,12 @@ public Expression diff(N x, Expression y){ */ @Override public Expression quot(Expression x, Expression 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"); + return new FunctionExpressionImpl<>( + this.metamodel, + BasicTypeHelperImpl.getInstance().extendedBinaryNumericPromotionClass(x.getJavaType(), y.getClass()), + ExpressionMath.divide(currentNode(x),currentNode(y)), + buildList(x,y), + "quot"); } /** @@ -1211,7 +1261,12 @@ public Expression quot(Expression x, Expression quot(Expression 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"); + return new FunctionExpressionImpl<>( + this.metamodel, + BasicTypeHelperImpl.getInstance().extendedBinaryNumericPromotionClass(x.getJavaType(), y.getClass()), + ExpressionMath.divide(currentNode(x),y), + buildList(x,internalLiteral(y)), + "quot"); } /** @@ -1225,7 +1280,7 @@ public Expression quot(Expression x, Number y){ */ @Override public Expression quot(Number x, Expression y){ - return new FunctionExpressionImpl(this.metamodel, ClassConstants.NUMBER, ExpressionMath.divide(new ConstantExpression(x, ((InternalSelection)y).getCurrentNode()),((InternalSelection)y).getCurrentNode()), buildList(internalLiteral(x),y), "quot"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.NUMBER, ExpressionMath.divide(new ConstantExpression(x, currentNode(y)),currentNode(y)), buildList(internalLiteral(x),y), "quot"); } /** @@ -1239,7 +1294,7 @@ public Expression quot(Number x, Expression y){ */ @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"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.INTEGER, ExpressionMath.mod(currentNode(x),currentNode(y)), buildList(x,y), "mod"); } /** @@ -1253,7 +1308,7 @@ public Expression mod(Expression x, Expression y){ */ @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"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.INTEGER, ExpressionMath.mod(currentNode(x),y), buildList(x,internalLiteral(y)), "mod"); } /** @@ -1268,7 +1323,7 @@ public Expression mod(Expression x, Integer y){ @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"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.INTEGER, ExpressionMath.mod(currentNode(xExp),currentNode(y)), buildList(xExp,y), "mod"); } /** @@ -1280,7 +1335,7 @@ public Expression mod(Integer x, Expression y){ */ @Override public Expression sqrt(Expression x){ - return new FunctionExpressionImpl(this.metamodel, ClassConstants.DOUBLE, ExpressionMath.sqrt(((InternalSelection)x).getCurrentNode()), buildList(x), "sqrt"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.DOUBLE, ExpressionMath.sqrt(currentNode(x)), buildList(x), "sqrt"); } /** @@ -1292,8 +1347,8 @@ public Expression sqrt(Expression x){ */ @Override public Expression sign(Expression x) { - return new FunctionExpressionImpl(this.metamodel, ClassConstants.INTEGER, - ExpressionMath.sign(((InternalSelection)x).getCurrentNode()), buildList(x), "sign"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.INTEGER, + ExpressionMath.sign(currentNode(x)), buildList(x), "sign"); } /** @@ -1305,8 +1360,8 @@ public Expression sign(Expression x) { */ @Override public Expression ceiling(Expression x) { - return new FunctionExpressionImpl(this.metamodel, x.getJavaType(), - ExpressionMath.ceil(((InternalSelection)x).getCurrentNode()), buildList(x), "ceiling"); + return new FunctionExpressionImpl<>(this.metamodel, x.getJavaType(), + ExpressionMath.ceil(currentNode(x)), buildList(x), "ceiling"); } /** @@ -1318,8 +1373,8 @@ public Expression ceiling(Expression x) { */ @Override public Expression floor(Expression x) { - return new FunctionExpressionImpl(this.metamodel, x.getJavaType(), - ExpressionMath.floor(((InternalSelection)x).getCurrentNode()), buildList(x), "floor"); + return new FunctionExpressionImpl<>(this.metamodel, x.getJavaType(), + ExpressionMath.floor(currentNode(x)), buildList(x), "floor"); } /** @@ -1331,8 +1386,8 @@ public Expression floor(Expression x) { */ @Override public Expression exp(Expression x) { - return new FunctionExpressionImpl(this.metamodel, ClassConstants.DOUBLE, - ExpressionMath.exp(((InternalSelection)x).getCurrentNode()), buildList(x), "exp"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.DOUBLE, + ExpressionMath.exp(currentNode(x)), buildList(x), "exp"); } /** * Create an expression that returns the natural logarithm of its argument. @@ -1342,8 +1397,8 @@ public Expression exp(Expression x) { */ @Override public Expression ln(Expression x) { - return new FunctionExpressionImpl(this.metamodel, ClassConstants.DOUBLE, - ExpressionMath.ln(((InternalSelection)x).getCurrentNode()), buildList(x), "ln"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.DOUBLE, + ExpressionMath.ln(currentNode(x)), buildList(x), "ln"); } /** @@ -1355,9 +1410,9 @@ public Expression ln(Expression x) { */ @Override public Expression power(Expression x, Expression y) { - return new FunctionExpressionImpl(this.metamodel, ClassConstants.DOUBLE, - ExpressionMath.power(((InternalSelection)x).getCurrentNode(), - ((InternalSelection)y).getCurrentNode()), buildList(x,y), "power"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.DOUBLE, + ExpressionMath.power(currentNode(x), + currentNode(y)), buildList(x,y), "power"); } /** @@ -1369,8 +1424,8 @@ public Expression power(Expression x, Expression power(Expression x, Number y) { - return new FunctionExpressionImpl(this.metamodel, ClassConstants.DOUBLE, - ExpressionMath.power(((InternalSelection)x).getCurrentNode(), y), + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.DOUBLE, + ExpressionMath.power(currentNode(x), y), buildList(x, internalLiteral(y)), "power"); } @@ -1384,8 +1439,8 @@ public Expression power(Expression x, Number y) { */ @Override public Expression round(Expression x, Integer n) { - return new FunctionExpressionImpl(this.metamodel, x.getJavaType(), - ExpressionMath.round(((InternalSelection)x).getCurrentNode(), n), + return new FunctionExpressionImpl<>(this.metamodel, x.getJavaType(), + ExpressionMath.round(currentNode(x), n), buildList(x, internalLiteral(n)), "round"); } @@ -1398,6 +1453,7 @@ public Expression round(Expression x, Integer n) { * @return Expression<Long> */ @Override + @SuppressWarnings("unchecked") public Expression toLong(Expression number){ return (Expression) number; } @@ -1410,6 +1466,7 @@ public Expression toLong(Expression number){ * @return Expression<Integer> */ @Override + @SuppressWarnings("unchecked") public Expression toInteger(Expression number){ return (Expression) number; } @@ -1422,6 +1479,7 @@ public Expression toInteger(Expression number){ * @return Expression<Float> */ @Override + @SuppressWarnings("unchecked") public Expression toFloat(Expression number){ return (Expression) number; } @@ -1434,6 +1492,7 @@ public Expression toFloat(Expression number){ * @return Expression<Double> */ @Override + @SuppressWarnings("unchecked") public Expression toDouble(Expression number){ return (Expression) number; } @@ -1446,6 +1505,7 @@ public Expression toDouble(Expression number){ * @return Expression<BigDecimal> */ @Override + @SuppressWarnings("unchecked") public Expression toBigDecimal(Expression number){ return (Expression) number; } @@ -1458,6 +1518,7 @@ public Expression toBigDecimal(Expression number){ * @return Expression<BigInteger> */ @Override + @SuppressWarnings("unchecked") public Expression toBigInteger(Expression number){ return (Expression) number; } @@ -1470,9 +1531,9 @@ public Expression toBigInteger(Expression number){ * @return Expression<String> */ @Override - public Expression toString(Expression character){ - ExpressionImpl impl = (ExpressionImpl) character; - return impl; + @SuppressWarnings("unchecked") + public Expression toString(Expression character) { + return (Expression)(Expression) character; } // literals: @@ -1545,13 +1606,13 @@ public ParameterExpression parameter(Class paramClass, String name){ @Override public > Predicate isEmpty(Expression collection){ if (((InternalExpression)collection).isLiteral()){ - if (((Collection)((ConstantExpression)((InternalSelection)collection).getCurrentNode()).getValue()).isEmpty()){ + if (((Collection)((ConstantExpression)currentNode(collection)).getValue()).isEmpty()){ return conjunction(); }else{ return disjunction(); } } - return new CompoundExpressionImpl(metamodel, ((InternalSelection)collection).getCurrentNode().size(ClassConstants.INTEGER).equal(0), buildList(collection), "isEmpty"); + return new CompoundExpressionImpl(metamodel, currentNode(collection).size(ClassConstants.INTEGER).equal(0), buildList(collection), "isEmpty"); } /** @@ -1563,7 +1624,7 @@ public > Predicate isEmpty(Expression collection){ */ @Override public > Predicate isNotEmpty(Expression collection){ - return new CompoundExpressionImpl(metamodel, ((InternalSelection)collection).getCurrentNode().size(ClassConstants.INTEGER).equal(0).not(), buildList(collection), "isNotEmpty"); + return new CompoundExpressionImpl(metamodel, currentNode(collection).size(ClassConstants.INTEGER).equal(0).not(), buildList(collection), "isNotEmpty"); } /** @@ -1585,7 +1646,7 @@ public > Expression size(C collection){ */ @Override public > Expression size(Expression collection){ - return new FunctionExpressionImpl(metamodel, ClassConstants.INTEGER, ((InternalSelection)collection).getCurrentNode().size(ClassConstants.INTEGER), buildList(collection), SIZE); + return new FunctionExpressionImpl<>(metamodel, ClassConstants.INTEGER, currentNode(collection).size(ClassConstants.INTEGER), buildList(collection), SIZE); } /** @@ -1601,7 +1662,7 @@ public > Expression size(Expression> Predicate isMember(E elem, Expression collection){ - return new CompoundExpressionImpl(metamodel, ((InternalSelection)collection).getCurrentNode().equal(elem), buildList(collection, internalLiteral(elem)), "isMember"); + return new CompoundExpressionImpl(metamodel, currentNode(collection).equal(elem), buildList(collection, internalLiteral(elem)), "isMember"); } /** @@ -1616,7 +1677,7 @@ public > Predicate isMember(E elem, Expression col */ @Override public > Predicate isNotMember(E elem, Expression collection){ - return new CompoundExpressionImpl(metamodel, ((InternalSelection)collection).getCurrentNode().notEqual(elem), buildList(collection, internalLiteral(elem)), "isMember"); + return new CompoundExpressionImpl(metamodel, currentNode(collection).notEqual(elem), buildList(collection, internalLiteral(elem)), "isMember"); } @@ -1632,7 +1693,7 @@ public > Predicate isNotMember(E elem, Expression */ @Override public > Predicate isMember(Expression elem, Expression collection){ - return new CompoundExpressionImpl(metamodel, ((InternalSelection)collection).getCurrentNode().equal(((InternalSelection)elem).getCurrentNode()), buildList(collection, elem), "isMember"); + return new CompoundExpressionImpl(metamodel, currentNode(collection).equal(currentNode(elem)), buildList(collection, elem), "isMember"); } /** @@ -1648,16 +1709,16 @@ public > Predicate isMember(Expression elem, Expre @Override public > Predicate isNotMember(Expression elem, Expression collection){ ReportQuery subQuery = new ReportQuery(); - subQuery.setReferenceClass(((ExpressionImpl)elem).getJavaType()); + 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(); + org.eclipse.persistence.expressions.Expression collectionExp =currentNode(collection); + org.eclipse.persistence.expressions.Expression elemExp =currentNode(elem); 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"); + return new CompoundExpressionImpl(metamodel, currentNode(elem).notExists(subQuery), buildList(elem, collection), "isNotMemeber"); } // get the values and keys collections of the Map, which may then @@ -1696,7 +1757,7 @@ public > Expression> values(M map){ @Override public Predicate like(Expression x, Expression pattern){ return new CompoundExpressionImpl(this.metamodel, - ((InternalSelection)x).getCurrentNode().like(((InternalSelection)pattern).getCurrentNode()), buildList(x, pattern), "like"); + currentNode(x).like(currentNode(pattern)), buildList(x, pattern), "like"); } /** @@ -1714,7 +1775,7 @@ public Predicate like(Expression x, Expression pattern){ @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"); + currentNode(x).like(currentNode(pattern), currentNode(escapeChar)), buildList(x, pattern, escapeChar), "like"); } /** @@ -1746,7 +1807,7 @@ public Predicate like(Expression x, Expression pattern, char esc */ @Override public Predicate like(Expression x, String pattern){ - return new CompoundExpressionImpl(this.metamodel, ((InternalSelection)x).getCurrentNode().like(pattern), buildList(x, internalLiteral(pattern)), "like"); + return new CompoundExpressionImpl(this.metamodel, currentNode(x).like(pattern), buildList(x, internalLiteral(pattern)), "like"); } /** @@ -1783,7 +1844,7 @@ 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"); + currentNode(x).like(pattern, escapeString), buildList(x, internalLiteral(pattern), internalLiteral(escapeChar)), "like"); } /** @@ -1799,7 +1860,7 @@ public Predicate like(Expression x, String pattern, char escapeChar){ @Override public Predicate notLike(Expression x, Expression pattern){ return new CompoundExpressionImpl(this.metamodel, - ((InternalSelection)x).getCurrentNode().notLike(((InternalSelection)pattern).getCurrentNode()), buildList(x, pattern), "notLike"); + currentNode(x).notLike(currentNode(pattern)), buildList(x, pattern), "notLike"); } /** @@ -1817,8 +1878,8 @@ public Predicate notLike(Expression x, Expression pattern){ @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"); + currentNode(x).notLike(currentNode(pattern), + currentNode(escapeChar)), buildList(x, pattern, escapeChar), "like"); } /** @@ -1851,7 +1912,7 @@ public Predicate notLike(Expression x, Expression pattern, char @Override public Predicate notLike(Expression x, String pattern){ return new CompoundExpressionImpl(this.metamodel, - ((InternalSelection)x).getCurrentNode().notLike(pattern), buildList(x, internalLiteral(pattern)), "notLike"); + currentNode(x).notLike(pattern), buildList(x, internalLiteral(pattern)), "notLike"); } /** @@ -1917,14 +1978,14 @@ public Expression concat(List> expressions) { */ @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(); + org.eclipse.persistence.expressions.Expression xNode = currentNode(x); + org.eclipse.persistence.expressions.Expression yNode = currentNode(y); 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); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.STRING, xNode.concat(yNode), buildList(x, y), CONCAT); } /** @@ -1938,7 +1999,7 @@ public Expression concat(Expression x, Expression y){ */ @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); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.STRING, currentNode(x).concat(y), buildList(x, internalLiteral(y)), CONCAT); } @@ -1953,8 +2014,8 @@ public Expression concat(Expression x, String y){ */ @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); + Expression literal = internalLiteral(x); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.STRING, currentNode(literal).concat(currentNode(y)), buildList(literal, y), CONCAT); } /** @@ -1969,7 +2030,7 @@ public Expression concat(String x, Expression y){ */ @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"); + return new FunctionExpressionImpl<>(metamodel, ClassConstants.STRING, currentNode( x).substring(currentNode( from)), buildList(x, from), "subString"); } /** @@ -1985,7 +2046,6 @@ public Expression substring(Expression x, Expression fr @Override public Expression substring(Expression x, int from){ return substring(x, this.internalLiteral(from)); - } /** @@ -2002,7 +2062,7 @@ public Expression substring(Expression x, int from){ */ @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"); + return new FunctionExpressionImpl(metamodel, ClassConstants.STRING, currentNode( x).substring(currentNode( from), currentNode( len)), buildList(x, from, len), "subString"); } /** @@ -2019,7 +2079,7 @@ public Expression substring(Expression x, Expression fr */ @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"); + return new FunctionExpressionImpl(metamodel, ClassConstants.STRING, currentNode( x).substring(from, len), buildList(x, internalLiteral(from), internalLiteral(len)), "subString"); } /** @@ -2031,7 +2091,7 @@ public Expression substring(Expression x, int from, int len){ */ @Override public Expression trim(Expression x){ - return new FunctionExpressionImpl(this.metamodel, ClassConstants.STRING, ((InternalSelection)x).getCurrentNode().trim(), buildList(x), "trim"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.STRING, currentNode(x).trim(), buildList(x), "trim"); } /** @@ -2046,11 +2106,11 @@ public Expression trim(Expression x){ @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"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.STRING, currentNode(x).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, currentNode(x).rightTrim(), buildList(x), "rightTrim"); } - return new FunctionExpressionImpl(this.metamodel, ClassConstants.STRING, ((InternalSelection)x).getCurrentNode().rightTrim().leftTrim(), buildList(x), "bothTrim"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.STRING, currentNode(x).rightTrim().leftTrim(), buildList(x), "bothTrim"); } @@ -2065,7 +2125,7 @@ public Expression trim(Trimspec ts, Expression x){ */ @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"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.STRING, currentNode(x).trim(currentNode(t)), buildList(x, t), "trim"); } /** @@ -2082,14 +2142,14 @@ public Expression trim(Expression t, Expression x){ @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"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.STRING, + currentNode(x).leftTrim(currentNode(t)), 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, + currentNode(x).rightTrim(currentNode(t)), 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"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.STRING, + currentNode(x).rightTrim(currentNode(t)).leftTrim(currentNode(t)), buildList(x, t), "bothTrim"); } /** @@ -2131,7 +2191,7 @@ public Expression trim(Trimspec ts, char t, Expression x){ */ @Override public Expression lower(Expression x){ - return new FunctionExpressionImpl(this.metamodel, ClassConstants.STRING, ((InternalSelection)x).getCurrentNode().toLowerCase(), buildList(x), "lower"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.STRING, currentNode(x).toLowerCase(), buildList(x), "lower"); } /** @@ -2143,7 +2203,7 @@ public Expression lower(Expression x){ */ @Override public Expression upper(Expression x){ - return new FunctionExpressionImpl(this.metamodel, ClassConstants.STRING, ((InternalSelection)x).getCurrentNode().toUpperCase(), buildList(x), "upper"); + return new FunctionExpressionImpl<>(this.metamodel, ClassConstants.STRING, currentNode(x).toUpperCase(), buildList(x), "upper"); } /** @@ -2155,7 +2215,7 @@ public Expression upper(Expression x){ */ @Override public Expression length(Expression x){ - return new FunctionExpressionImpl(metamodel, ClassConstants.INTEGER, ((InternalSelection)x).getCurrentNode().length(), buildList(x), "length"); + return new FunctionExpressionImpl<>(metamodel, ClassConstants.INTEGER, currentNode(x).length(), buildList(x), "length"); } @Override @@ -2232,7 +2292,7 @@ public Expression replace(Expression expression, String substrin */ @Override public Expression locate(Expression x, Expression pattern){ - return new FunctionExpressionImpl(metamodel, ClassConstants.INTEGER, ((InternalSelection)x).getCurrentNode().locate(((InternalSelection)pattern).getCurrentNode()), buildList(x, pattern),"locate"); + return new FunctionExpressionImpl(metamodel, ClassConstants.INTEGER, currentNode(x).locate(currentNode(pattern)), buildList(x, pattern),"locate"); } /** @@ -2251,7 +2311,7 @@ public Expression locate(Expression x, Expression patte */ @Override public Expression locate(Expression x, Expression pattern, Expression from){ - return new FunctionExpressionImpl(metamodel, ClassConstants.INTEGER, ((InternalSelection)x).getCurrentNode().locate(((InternalSelection)pattern).getCurrentNode(), ((InternalSelection)from).getCurrentNode()), buildList(x, pattern, from),"locate"); + return new FunctionExpressionImpl(metamodel, ClassConstants.INTEGER, currentNode(x).locate(currentNode(pattern), currentNode(from)), buildList(x, pattern, from),"locate"); } /** @@ -2268,7 +2328,7 @@ public Expression locate(Expression x, Expression patte */ @Override public Expression locate(Expression x, String pattern){ - return new FunctionExpressionImpl(metamodel, ClassConstants.INTEGER, ((InternalSelection)x).getCurrentNode().locate(pattern), buildList(x, internalLiteral(pattern)),"locate"); + return new FunctionExpressionImpl(metamodel, ClassConstants.INTEGER, currentNode(x).locate(pattern), buildList(x, internalLiteral(pattern)),"locate"); } /** @@ -2287,7 +2347,7 @@ public Expression locate(Expression x, String pattern){ */ @Override public Expression locate(Expression x, String pattern, int from){ - return new FunctionExpressionImpl(metamodel, ClassConstants.INTEGER, ((InternalSelection)x).getCurrentNode().locate(pattern, from), buildList(x, internalLiteral(pattern), internalLiteral(from)),"locate"); + return new FunctionExpressionImpl(metamodel, ClassConstants.INTEGER, currentNode(x).locate(pattern, from), buildList(x, internalLiteral(pattern), internalLiteral(from)),"locate"); } // Date/time/timestamp functions: @@ -2370,8 +2430,9 @@ public Expression extract(TemporalField field, * @return in predicate */ @Override - public In in(Expression expression){ - return new InImpl(metamodel, (ExpressionImpl) expression, new ArrayList<>(), buildList(expression)); + @SuppressWarnings("unchecked") // Expression passed as ExpressionImpl to the constructor + public In in(Expression expression) { + return new InImpl<>(metamodel, (ExpressionImpl) expression, new ArrayList<>(), buildList(expression)); } // coalesce, nullif: @@ -2387,14 +2448,14 @@ public In in(Expression expression){ */ @Override public Expression coalesce(Expression x, Expression y) { - ArgumentListFunctionExpression coalesce = ((InternalSelection)x).getCurrentNode().coalesce(); - org.eclipse.persistence.expressions.Expression expX = ((InternalSelection)x).getCurrentNode(); + ArgumentListFunctionExpression coalesce = currentNode(x).coalesce(); + org.eclipse.persistence.expressions.Expression expX = currentNode(x); expX = org.eclipse.persistence.expressions.Expression.from(expX, coalesce); coalesce.addChild(expX); - org.eclipse.persistence.expressions.Expression expY = ((InternalSelection)y).getCurrentNode(); + org.eclipse.persistence.expressions.Expression expY = currentNode(y); expY = org.eclipse.persistence.expressions.Expression.from(expY, coalesce); coalesce.addChild(expY); - return new CoalesceImpl(metamodel, x.getJavaType(), coalesce, buildList(x, y), "coalesce"); + return new CoalesceImpl<>(metamodel, x.getJavaType(), coalesce, buildList(x, y), "coalesce"); } /** @@ -2409,13 +2470,13 @@ public Expression coalesce(Expression x, Expression Expression coalesce(Expression x, Y y) { - ArgumentListFunctionExpression coalesce = ((InternalSelection)x).getCurrentNode().coalesce(); - org.eclipse.persistence.expressions.Expression expX = ((InternalSelection)x).getCurrentNode(); + ArgumentListFunctionExpression coalesce = currentNode(x).coalesce(); + org.eclipse.persistence.expressions.Expression expX = currentNode(x); expX = org.eclipse.persistence.expressions.Expression.from(expX, coalesce); coalesce.addChild(expX); org.eclipse.persistence.expressions.Expression expY = org.eclipse.persistence.expressions.Expression.from(y, new ExpressionBuilder()); coalesce.addChild(expY); - return new CoalesceImpl(metamodel, x.getJavaType(), coalesce, buildList(x, internalLiteral(y)), "coalesce"); + return new CoalesceImpl<>(metamodel, x.getJavaType(), coalesce, buildList(x, internalLiteral(y)), "coalesce"); } /** @@ -2430,7 +2491,7 @@ public Expression coalesce(Expression x, Y y) { */ @Override public Expression nullif(Expression x, Expression y){ - return new FunctionExpressionImpl(metamodel, x.getJavaType(), ((InternalSelection)x).getCurrentNode().nullIf(((InternalSelection)y).getCurrentNode()), buildList(x, y), "nullIf"); + return new FunctionExpressionImpl<>(metamodel, x.getJavaType(), currentNode(x).nullIf(currentNode(y)), buildList(x, y), "nullIf"); } /** @@ -2445,7 +2506,7 @@ public Expression nullif(Expression x, Expression y){ */ @Override public Expression nullif(Expression x, Y y){ - return new FunctionExpressionImpl(metamodel, x.getJavaType(), ((InternalSelection)x).getCurrentNode().nullIf(y), buildList(x, internalLiteral(y)), "nullIf"); + return new FunctionExpressionImpl<>(metamodel, x.getJavaType(), currentNode(x).nullIf(y), buildList(x, internalLiteral(y)), "nullIf"); } /** @@ -2454,9 +2515,10 @@ public Expression nullif(Expression x, Y y){ * @return coalesce expression */ @Override - public Coalesce coalesce(){ + @SuppressWarnings("unchecked") // Java type cast + public Coalesce coalesce() { ArgumentListFunctionExpression coalesce = new ExpressionBuilder().coalesce(); - return new CoalesceImpl(metamodel, Object.class, coalesce, new ArrayList<>()); + return new CoalesceImpl<>(metamodel, (Class) Object.class, coalesce, new ArrayList<>()); } /** @@ -2467,9 +2529,10 @@ public Coalesce coalesce(){ * @return simple case expression */ @Override + @SuppressWarnings("unchecked") // Java type cast public SimpleCase selectCase(Expression expression){ ArgumentListFunctionExpression caseStatement = new ExpressionBuilder().caseStatement(); - return new SimpleCaseImpl(metamodel, Object.class, caseStatement, new ArrayList<>(), expression); + return new SimpleCaseImpl<>(metamodel, (Class) Object.class, caseStatement, new ArrayList<>(), expression); } /** @@ -2500,10 +2563,10 @@ public Expression function(String name, Class type, Expression... a List params = new ArrayList(); for (int index = 1; index < args.length; ++index){ Expression x = args[index]; - params.add(((InternalSelection)x).getCurrentNode()); + params.add(currentNode(x)); } - return new FunctionExpressionImpl(metamodel, type, ((InternalSelection)args[0]).getCurrentNode().getFunctionWithArguments(name, params), buildList(args), name); + return new FunctionExpressionImpl(metamodel, type, currentNode(args[0]).getFunctionWithArguments(name, params), buildList(args), name); }else{ return new FunctionExpressionImpl(metamodel, type, new ExpressionBuilder().getFunction(name), new ArrayList<>(0), name); } @@ -2526,7 +2589,7 @@ public Expression fromExpression(org.eclipse.persistence.expressions.Expr */ @Override public Expression fromExpression(org.eclipse.persistence.expressions.Expression expression) { - return new FunctionExpressionImpl(this.metamodel, Object.class, expression, new ArrayList<>(0)); + return new FunctionExpressionImpl<>(this.metamodel, Object.class, expression, new ArrayList<>(0)); } /** @@ -2548,11 +2611,11 @@ public org.eclipse.persistence.expressions.Expression toExpression(Expression ex */ public class CoalesceImpl extends FunctionExpressionImpl implements Coalesce { - protected CoalesceImpl (Metamodel metamodel, Class resultClass, org.eclipse.persistence.expressions.Expression expressionNode, List> compoundExpressions) { + protected CoalesceImpl (Metamodel metamodel, Class resultClass, org.eclipse.persistence.expressions.Expression expressionNode, List> compoundExpressions) { super(metamodel, resultClass, expressionNode, compoundExpressions); } - protected CoalesceImpl (Metamodel metamodel, Class resultClass, org.eclipse.persistence.expressions.Expression expressionNode, List> compoundExpressions, String operator) { + protected CoalesceImpl (Metamodel metamodel, Class resultClass, org.eclipse.persistence.expressions.Expression expressionNode, List> compoundExpressions, String operator) { super(metamodel, resultClass, expressionNode, compoundExpressions, operator); } @@ -2577,7 +2640,7 @@ public Coalesce value(X value) { */ @Override public Coalesce value(Expression value) { - org.eclipse.persistence.expressions.Expression exp = ((InternalSelection)value).getCurrentNode(); + org.eclipse.persistence.expressions.Expression exp = currentNode(value); exp = org.eclipse.persistence.expressions.Expression.from(exp, currentNode); ((FunctionExpression)currentNode).addChild(exp); this.expressions.add(value); @@ -2612,7 +2675,7 @@ protected CaseImpl (Metamodel metamodel, Class resultClass, org.eclipse.p */ @Override public Case when(Expression condition, R result) { - org.eclipse.persistence.expressions.Expression conditionExp = ((InternalSelection)condition).getCurrentNode(); + org.eclipse.persistence.expressions.Expression conditionExp = currentNode(condition); conditionExp = org.eclipse.persistence.expressions.Expression.from(conditionExp, currentNode); ((FunctionExpression)currentNode).addChild(conditionExp); this.expressions.add(condition); @@ -2622,7 +2685,7 @@ public Case when(Expression condition, R result) { Expression resultLiteral = internalLiteral(result); this.expressions.add(resultLiteral); - setJavaType((Class) resultLiteral.getJavaType()); + setJavaType(resultLiteral.getJavaType()); return this; } @@ -2634,17 +2697,17 @@ public Case when(Expression condition, R result) { */ @Override public Case when(Expression condition, Expression result) { - org.eclipse.persistence.expressions.Expression conditionExp = ((InternalSelection)condition).getCurrentNode(); + org.eclipse.persistence.expressions.Expression conditionExp = currentNode(condition); conditionExp = org.eclipse.persistence.expressions.Expression.from(conditionExp, currentNode); ((FunctionExpression)currentNode).addChild(conditionExp); this.expressions.add(condition); - org.eclipse.persistence.expressions.Expression resultExp = ((InternalSelection)result).getCurrentNode(); + org.eclipse.persistence.expressions.Expression resultExp = currentNode(result); resultExp = org.eclipse.persistence.expressions.Expression.from(resultExp, currentNode); ((FunctionExpression)currentNode).addChild(resultExp); this.expressions.add(result); - setJavaType((Class) result.getJavaType()); + setJavaType(result.getJavaType()); return this; } @@ -2660,7 +2723,7 @@ public Expression otherwise(R result) { Expression resultLiteral = internalLiteral(result); this.elseExpression = resultLiteral; - setJavaType((Class) resultLiteral.getJavaType()); + setJavaType(resultLiteral.getJavaType()); return this; } @@ -2671,17 +2734,17 @@ public Expression otherwise(R result) { */ @Override public Expression otherwise(Expression result) { - org.eclipse.persistence.expressions.Expression resultExp = ((InternalSelection)result).getCurrentNode(); + org.eclipse.persistence.expressions.Expression resultExp = currentNode(result); resultExp = org.eclipse.persistence.expressions.Expression.from(resultExp, currentNode); ((ArgumentListFunctionExpression)currentNode).addRightMostChild(resultExp); this.elseExpression = result; - setJavaType((Class) result.getJavaType()); + setJavaType(result.getJavaType()); return this; } @Override - public void findRootAndParameters(CommonAbstractCriteriaImpl query) { + public void findRootAndParameters(CommonAbstractCriteriaImpl query) { super.findRootAndParameters(query); if (this.elseExpression != null){ ((InternalSelection)elseExpression).findRootAndParameters(query); @@ -2696,23 +2759,23 @@ public void findRootAndParameters(CommonAbstractCriteriaImpl query) { * @param * @param */ - public class SimpleCaseImpl extends FunctionExpressionImpl implements SimpleCase { + public class SimpleCaseImpl extends FunctionExpressionImpl implements SimpleCase { - private Expression expression; + private final Expression expression; // Track the else expression separate to the when expressions as there should only be one private Expression elseExpression; - protected SimpleCaseImpl (Metamodel metamodel, Class resultClass, FunctionExpression expressionNode, List> compoundExpressions, Expression expression) { + protected SimpleCaseImpl(Metamodel metamodel, Class resultClass, FunctionExpression expressionNode, List> compoundExpressions, Expression expression) { super(metamodel, resultClass, expressionNode, compoundExpressions); this.expression = expression; - expressionNode.addChild(((InternalSelection)expression).getCurrentNode()); + expressionNode.addChild(currentNode(expression)); } - protected SimpleCaseImpl (Metamodel metamodel, Class resultClass, FunctionExpression expressionNode, List> compoundExpressions, String operator, Expression expression) { + protected SimpleCaseImpl(Metamodel metamodel, Class resultClass, FunctionExpression expressionNode, List> compoundExpressions, String operator, Expression expression) { super(metamodel, resultClass, expressionNode, compoundExpressions, operator); this.expression = expression; - expressionNode.addChild(((InternalSelection)expression).getCurrentNode()); + expressionNode.addChild(currentNode(expression)); } /** @@ -2721,8 +2784,9 @@ protected SimpleCaseImpl (Metamodel metamodel, Class resultClass, Functio * @return expression */ @Override + @SuppressWarnings("unchecked") // JPA API generics clash public Expression getExpression(){ - return expression; + return (Expression) expression; } /** @@ -2743,7 +2807,7 @@ public SimpleCase when(C condition, R result) { Expression resultLiteral = internalLiteral(result); this.expressions.add(resultLiteral); - setJavaType((Class) resultLiteral.getJavaType()); + setJavaType(resultLiteral.getJavaType()); return this; } @@ -2760,12 +2824,12 @@ public SimpleCase when(C condition, Expression result) { Expression conditionLiteral = internalLiteral(condition); this.expressions.add(conditionLiteral); - org.eclipse.persistence.expressions.Expression resultExp = ((InternalSelection)result).getCurrentNode(); + org.eclipse.persistence.expressions.Expression resultExp = currentNode(result); resultExp = org.eclipse.persistence.expressions.Expression.from(resultExp, currentNode); ((FunctionExpression)currentNode).addChild(resultExp); this.expressions.add(result); - setJavaType((Class) result.getJavaType()); + setJavaType(result.getJavaType()); return this; } @@ -2777,7 +2841,7 @@ public SimpleCase when(C condition, Expression result) { */ @Override public SimpleCase when(Expression condition, R result) { - org.eclipse.persistence.expressions.Expression conditionExp = ((InternalSelection)condition).getCurrentNode(); + org.eclipse.persistence.expressions.Expression conditionExp = currentNode(condition); conditionExp = org.eclipse.persistence.expressions.Expression.from(conditionExp, currentNode); ((FunctionExpression)currentNode).addChild(conditionExp); this.expressions.add(condition); @@ -2787,7 +2851,7 @@ public SimpleCase when(Expression condition, R result) { Expression resultLiteral = internalLiteral(result); this.expressions.add(resultLiteral); - setJavaType((Class) resultLiteral.getJavaType()); + setJavaType(resultLiteral.getJavaType()); return this; } @@ -2799,17 +2863,17 @@ public SimpleCase when(Expression condition, R result) { */ @Override public SimpleCase when(Expression condition, Expression result) { - org.eclipse.persistence.expressions.Expression conditionExp = ((InternalSelection)condition).getCurrentNode(); + org.eclipse.persistence.expressions.Expression conditionExp = currentNode(condition); conditionExp = org.eclipse.persistence.expressions.Expression.from(conditionExp, currentNode); ((FunctionExpression)currentNode).addChild(conditionExp); this.expressions.add(condition); - org.eclipse.persistence.expressions.Expression resultExp = ((InternalSelection)result).getCurrentNode(); + org.eclipse.persistence.expressions.Expression resultExp = currentNode(result); resultExp = org.eclipse.persistence.expressions.Expression.from(resultExp, currentNode); ((FunctionExpression)currentNode).addChild(resultExp); this.expressions.add(result); - setJavaType((Class) result.getJavaType()); + setJavaType(result.getJavaType()); return this; } @@ -2825,7 +2889,7 @@ public Expression otherwise(R result) { Expression resultLiteral = internalLiteral(result); this.elseExpression = resultLiteral; - setJavaType((Class) resultLiteral.getJavaType()); + setJavaType(resultLiteral.getJavaType()); return this; } @@ -2836,17 +2900,17 @@ public Expression otherwise(R result) { */ @Override public Expression otherwise(Expression result) { - org.eclipse.persistence.expressions.Expression resultExp = ((InternalSelection)result).getCurrentNode(); + org.eclipse.persistence.expressions.Expression resultExp = currentNode(result); resultExp = org.eclipse.persistence.expressions.Expression.from(resultExp, currentNode); ((ArgumentListFunctionExpression)currentNode).addRightMostChild(resultExp); this.elseExpression = result; - setJavaType((Class) result.getJavaType()); + setJavaType(result.getJavaType()); return this; } @Override - public void findRootAndParameters(CommonAbstractCriteriaImpl query) { + public void findRootAndParameters(CommonAbstractCriteriaImpl query) { super.findRootAndParameters(query); if(expression != null) { ((InternalSelection)expression).findRootAndParameters(query); @@ -2862,7 +2926,7 @@ public CriteriaDelete createCriteriaDelete(Class targetEntity) { if (targetEntity != null) { TypeImpl type = ((MetamodelImpl)this.metamodel).getType(targetEntity); if (type != null && type.getPersistenceType().equals(PersistenceType.ENTITY)) { - return new CriteriaDeleteImpl(this.metamodel, this, targetEntity); + return new CriteriaDeleteImpl<>(this.metamodel, this, targetEntity); } } throw new IllegalArgumentException(ExceptionLocalization.buildMessage("unknown_bean_class", new Object[] { targetEntity })); @@ -2873,7 +2937,7 @@ public CriteriaUpdate createCriteriaUpdate(Class targetEntity) { if (targetEntity != null) { TypeImpl type = ((MetamodelImpl)this.metamodel).getType(targetEntity); if (type != null && type.getPersistenceType().equals(PersistenceType.ENTITY)) { - return new CriteriaUpdateImpl(this.metamodel, this, targetEntity); + return new CriteriaUpdateImpl<>(this.metamodel, this, targetEntity); } } throw new IllegalArgumentException(ExceptionLocalization.buildMessage("unknown_bean_class", new Object[] { targetEntity })); diff --git a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/CriteriaQueryImpl.java b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/CriteriaQueryImpl.java index 37d63691058..eb1a46eebcc 100644 --- a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/CriteriaQueryImpl.java +++ b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/CriteriaQueryImpl.java @@ -19,7 +19,11 @@ import java.lang.reflect.Constructor; import java.security.AccessController; -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; import jakarta.persistence.Tuple; import jakarta.persistence.criteria.CriteriaQuery; @@ -30,7 +34,6 @@ import jakarta.persistence.criteria.Selection; import jakarta.persistence.metamodel.Metamodel; import jakarta.persistence.metamodel.Type.PersistenceType; - import org.eclipse.persistence.expressions.ExpressionBuilder; import org.eclipse.persistence.internal.helper.BasicTypeHelperImpl; import org.eclipse.persistence.internal.helper.ClassConstants; @@ -59,7 +62,7 @@ */ public class CriteriaQueryImpl extends AbstractQueryImpl implements CriteriaQuery { - protected SelectionImpl selection; + protected SelectionImpl selection; protected List orderBy; protected Set joins; @@ -83,7 +86,7 @@ public CriteriaQuery select(Selection selection) { this.queryType = (Class) Tuple.class; } else if (((InternalSelection) selection).isConstructor()) { Selection[] selectArray = selection.getCompoundSelectionItems().toArray(new Selection[selection.getCompoundSelectionItems().size()]); - populateAndSetConstructorSelection((ConstructorSelectionImpl)selection, this.selection.getJavaType(), selectArray); + populateAndSetConstructorSelection((ConstructorSelectionImpl)selection, (Class) this.selection.getJavaType(), selectArray); this.queryType = (Class) selection.getJavaType(); } else { this.queryResult = ResultType.OBJECT_ARRAY; @@ -154,10 +157,10 @@ public CriteriaQuery multiselect(Selection... selections) { ((SelectionImpl)select).findRootAndParameters(this); } if (this.queryResult == ResultType.CONSTRUCTOR) { - populateAndSetConstructorSelection(null, this.queryType, selections); + populateAndSetConstructorSelection((ConstructorSelectionImpl) null, this.queryType, selections); } else if (this.queryResult.equals(ResultType.ENTITY)) { if (selections.length == 1 && selections[0].getJavaType().equals(this.queryType)) { - this.selection = (SelectionImpl) selections[0]; + this.selection = (SelectionImpl) selections[0]; } else { try { populateAndSetConstructorSelection(null, this.queryType, selections);//throws IllegalArgumentException if it doesn't exist @@ -170,7 +173,7 @@ public CriteriaQuery multiselect(Selection... selections) { this.selection = new CompoundSelectionImpl(this.queryType, selections); } else if (this.queryResult.equals(ResultType.OTHER)) { if (selections.length == 1 && selections[0].getJavaType().equals(this.queryType)) { - this.selection = (SelectionImpl) selections[0]; + this.selection = (SelectionImpl) selections[0]; } else { if (!BasicTypeHelperImpl.getInstance().isDateClass(this.queryType)) { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("MULTIPLE_SELECTIONS_PASSED_TO_QUERY_WITH_PRIMITIVE_RESULT")); @@ -358,18 +361,20 @@ public CriteriaQuery orderBy(List o) { * Also sets the query result to ResultType.CONSTRUCTOR * */ - public void populateAndSetConstructorSelection(ConstructorSelectionImpl constructorSelection, Class class1, Selection... selections) throws IllegalArgumentException{ + public void populateAndSetConstructorSelection(ConstructorSelectionImpl constructorSelection, Class class1, Selection... selections) throws IllegalArgumentException{ Class[] constructorArgs = new Class[selections.length]; int count = 0; - for (Selection select : selections) { + for (Selection select : selections) { if(select instanceof ConstructorSelectionImpl) { - ConstructorSelectionImpl constructorSelect = (ConstructorSelectionImpl)select; - Selection[] selectArray = constructorSelect.getCompoundSelectionItems().toArray(new Selection[constructorSelect.getCompoundSelectionItems().size()]); - populateAndSetConstructorSelection(constructorSelect, constructorSelect.getJavaType(), selectArray); + @SuppressWarnings("unchecked") + ConstructorSelectionImpl constructorSelect = (ConstructorSelectionImpl)select; + @SuppressWarnings("unchecked") + Selection[] selectArray = constructorSelect.getCompoundSelectionItems().toArray(new Selection[constructorSelect.getCompoundSelectionItems().size()]); + populateAndSetConstructorSelection(constructorSelect, (Class) constructorSelect.getJavaType(), selectArray); } constructorArgs[count++] = select.getJavaType(); } - Constructor constructor = null; + Constructor constructor = null; try { // TODO: Remove AccessController.doPrivileged if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) { @@ -378,7 +383,7 @@ public void populateAndSetConstructorSelection(ConstructorSelectionImpl construc constructor = PrivilegedAccessHelper.getConstructorFor(class1, constructorArgs, false); } if (constructorSelection == null){ - constructorSelection = new ConstructorSelectionImpl(class1, selections); + constructorSelection = new ConstructorSelectionImpl<>(class1, selections); } this.queryResult = ResultType.CONSTRUCTOR; constructorSelection.setConstructor(constructor); @@ -565,7 +570,7 @@ protected ObjectLevelReadQuery createSimpleQuery() { // unknown type so let's figure this out. if (selection == null) { if (this.roots != null && !this.roots.isEmpty()) { - this.selection = (SelectionImpl) this.roots.iterator().next(); + this.selection = (SelectionImpl) this.roots.iterator().next(); query = new ReadAllQuery(((FromImpl) this.selection).getJavaType()); List list = ((FromImpl) this.roots.iterator().next()).findJoinFetches(); for (org.eclipse.persistence.expressions.Expression fetch : list) { diff --git a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/ExpressionImpl.java b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/ExpressionImpl.java index 65b353f5bce..70ddaec0c63 100644 --- a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/ExpressionImpl.java +++ b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/ExpressionImpl.java @@ -22,13 +22,9 @@ import jakarta.persistence.criteria.Expression; import jakarta.persistence.criteria.Predicate; import jakarta.persistence.metamodel.Metamodel; - -import org.eclipse.persistence.descriptors.ClassDescriptor; import org.eclipse.persistence.expressions.ExpressionBuilder; import org.eclipse.persistence.internal.expressions.ConstantExpression; -import org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl; import org.eclipse.persistence.internal.localization.ExceptionLocalization; -import org.eclipse.persistence.sessions.Project; /** *

@@ -138,10 +134,11 @@ public Predicate in(Object... values) { * @return predicate testing for membership */ @Override + @SuppressWarnings("unchecked") // (Expression>), values prototype in JPA is too common public Predicate in(Expression... values) { if (values != null) { if (values.length == 1 && ((InternalExpression) values[0]).isParameter() - && Collection.class.isAssignableFrom(((ParameterExpressionImpl) values[0]).getJavaType())) { + && Collection.class.isAssignableFrom(((ParameterExpressionImpl) values[0]).getJavaType())) { // bug 349477 - Collection from Expression was lost during compilation // and if we know that Collection is there we should help the runtime // and route the execution to the right method @@ -151,10 +148,10 @@ public Predicate in(Expression... values) { list.add(this); if (values.length == 1 && ((InternalExpression) values[0]).isSubquery()) { list.add(values[0]); - return new CompoundExpressionImpl(this.metamodel, this.currentNode.in(((SubQueryImpl) values[0]).subQuery), list, "in"); + return new CompoundExpressionImpl(this.metamodel, this.currentNode.in(((SubQueryImpl) values[0]).subQuery), list, "in"); } else { - List inValues = new ArrayList(); - for (Expression exp : values) { + List inValues = new ArrayList<>(); + for (Expression exp : values) { if (!((InternalExpression) exp).isLiteral() && !((InternalExpression) exp).isParameter()) { Object[] params = new Object[]{exp}; throw new IllegalArgumentException(ExceptionLocalization.buildMessage("CRITERIA_NON_LITERAL_PASSED_TO_IN",params)); @@ -180,7 +177,7 @@ public Predicate in(Expression... values) { public Predicate in(Collection values) { List> list = new ArrayList<>(); list.add(this); - return new InImpl(this.metamodel, this, values, list); + return new InImpl<>(this.metamodel, this, values, list); } /** * Apply a predicate to test whether the expression is a member @@ -193,7 +190,7 @@ public Predicate in(Expression> values) { List> list = new ArrayList<>(); list.add(values); list.add(this); - return new InImpl(metamodel, this, (ExpressionImpl)values, list); + return new InImpl<>(metamodel, this, (ExpressionImpl)values, list); } @Override @@ -243,13 +240,13 @@ public boolean isParameter(){ return false; } @Override - public void findRootAndParameters(CommonAbstractCriteriaImpl criteriaQuery){ + public void findRootAndParameters(CommonAbstractCriteriaImpl criteriaQuery){ //no-op because an expression will have no root } // Literal Expression factory method static Expression createLiteral(T value, Metamodel metamodel, Class resultClass) { - return new ExpressionImpl( + return new ExpressionImpl<>( metamodel, resultClass, new ConstantExpression(value, new ExpressionBuilder()), value); diff --git a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/FunctionExpressionImpl.java b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/FunctionExpressionImpl.java index 8b62aa7b575..4b9d07ffe15 100644 --- a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/FunctionExpressionImpl.java +++ b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/FunctionExpressionImpl.java @@ -37,18 +37,14 @@ public class FunctionExpressionImpl extends ExpressionImpl{ protected String operator; - protected List expressions; + protected List> expressions; - protected FunctionExpressionImpl (Metamodel metamodel, Class resultClass, org.eclipse.persistence.expressions.Expression expressionNode, List> compoundExpressions){ + protected FunctionExpressionImpl (Metamodel metamodel, Class resultClass, org.eclipse.persistence.expressions.Expression expressionNode, List> compoundExpressions){ super(metamodel, resultClass, expressionNode); - if (compoundExpressions != null){ - this.expressions = compoundExpressions; - }else{ - this.expressions = new ArrayList<>(); - } + this.expressions = compoundExpressions != null ? compoundExpressions : new ArrayList<>(); } - public FunctionExpressionImpl (Metamodel metamodel, Class resultClass, org.eclipse.persistence.expressions.Expression expressionNode, List> compoundExpressions, String operator){ + public FunctionExpressionImpl (Metamodel metamodel, Class resultClass, org.eclipse.persistence.expressions.Expression expressionNode, List> compoundExpressions, String operator){ this(metamodel, resultClass, expressionNode, compoundExpressions); this.operator = operator; } @@ -79,7 +75,7 @@ public boolean isExpression(){ } @Override - public void findRootAndParameters(CommonAbstractCriteriaImpl query){ + public void findRootAndParameters(CommonAbstractCriteriaImpl query){ if (this.expressions != null){ for (Object exp : this.expressions){ ((InternalSelection)exp).findRootAndParameters(query); diff --git a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/InImpl.java b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/InImpl.java index 9b481882126..7110c99b009 100644 --- a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/InImpl.java +++ b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/InImpl.java @@ -26,8 +26,8 @@ import jakarta.persistence.criteria.CriteriaBuilder.In; import jakarta.persistence.metamodel.Metamodel; -import org.eclipse.persistence.internal.expressions.CollectionExpression; import org.eclipse.persistence.internal.expressions.CompoundExpression; +import org.eclipse.persistence.internal.expressions.ConstantExpression; import org.eclipse.persistence.internal.expressions.FunctionExpression; import org.eclipse.persistence.internal.expressions.LogicalExpression; import org.eclipse.persistence.internal.expressions.RelationExpression; @@ -50,13 +50,13 @@ public class InImpl extends CompoundExpressionImpl implements In { protected org.eclipse.persistence.expressions.Expression parentNode; - public InImpl(Metamodel metamodel, ExpressionImpl leftExpression, Collection values, List expressions) { + public InImpl(Metamodel metamodel, ExpressionImpl leftExpression, Collection values, List> expressions) { super(metamodel, ((InternalSelection)leftExpression).getCurrentNode().in(values), expressions, "in"); this.leftExpression = leftExpression; } - public InImpl(Metamodel metamodel, ExpressionImpl leftExpression, ExpressionImpl rightExp, List expressions) { + public InImpl(Metamodel metamodel, ExpressionImpl leftExpression, ExpressionImpl rightExp, List> expressions) { super(metamodel, (rightExp.isParameter()? leftExpression.getCurrentNode().in(rightExp.getCurrentNode()): @@ -66,7 +66,7 @@ public InImpl(Metamodel metamodel, ExpressionImpl leftExpression, ExpressionImpl } - protected ExpressionImpl leftExpression; + protected ExpressionImpl leftExpression; /** * Returns the expression to be tested against the @@ -74,12 +74,13 @@ public InImpl(Metamodel metamodel, ExpressionImpl leftExpression, ExpressionImpl * @return expression */ @Override + @SuppressWarnings("unchecked") // JPA API generics clash public Expression getExpression(){ - return this.leftExpression; + return (Expression) this.leftExpression; } @Override - public void findRootAndParameters(CommonAbstractCriteriaImpl query){ + public void findRootAndParameters(CommonAbstractCriteriaImpl query) { super.findRootAndParameters(query); } @@ -94,8 +95,9 @@ public boolean isPredicate(){ * @return in predicate */ @Override + @SuppressWarnings("unchecked") // (Collection) ... public In value(T value){ - ((Collection)((CollectionExpression)((RelationExpression)this.currentNode).getSecondChild()).getValue()).add(value); + ((Collection) ((ConstantExpression) ((CompoundExpression) this.currentNode).getSecondChild()).getValue()).add(value); return this; } @@ -105,10 +107,11 @@ public In value(T value){ * @return in predicate */ @Override + @SuppressWarnings("unchecked") // (Collection) ... public In value(Expression value) { if (!(((InternalExpression) value).isLiteral() || ((InternalExpression) value).isParameter())) { RelationExpression baseIn = (RelationExpression) this.currentNode; - this.currentNode = baseIn.getFirstChild().in(((SubQueryImpl) value).subQuery); + this.currentNode = baseIn.getFirstChild().in(((SubQueryImpl) value).subQuery); if (this.parentNode != null) { if (this.parentNode.isCompoundExpression()) { CompoundExpression logExp = (LogicalExpression) this.parentNode; @@ -127,7 +130,7 @@ public In value(Expression value) { RelationExpression baseIn = (RelationExpression) this.currentNode; org.eclipse.persistence.expressions.Expression resultExp = ((InternalSelection)value).getCurrentNode(); resultExp = org.eclipse.persistence.expressions.Expression.from(resultExp, baseIn.getFirstChild()); - ((Collection) ((CollectionExpression) baseIn.getSecondChild()).getValue()).add(resultExp); + ((Collection) ((ConstantExpression) baseIn.getSecondChild()).getValue()).add(resultExp); // Add to the expression list for #findRootAndParameters() this.expressions.add(value); diff --git a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/InternalSelection.java b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/InternalSelection.java index 27b0f648c7e..9347525f134 100644 --- a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/InternalSelection.java +++ b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/InternalSelection.java @@ -15,8 +15,6 @@ // package org.eclipse.persistence.internal.jpa.querydef; -import jakarta.persistence.criteria.Expression; - /** *

* Purpose: Represents a Selection in the Criteria API implementation hierarchy. @@ -32,7 +30,7 @@ */ public interface InternalSelection { - void findRootAndParameters(CommonAbstractCriteriaImpl criteriaQuery); + void findRootAndParameters(CommonAbstractCriteriaImpl criteriaQuery); org.eclipse.persistence.expressions.Expression getCurrentNode(); diff --git a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/PredicateImpl.java b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/PredicateImpl.java index fd6453621d4..4bd9892e779 100644 --- a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/PredicateImpl.java +++ b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/PredicateImpl.java @@ -39,7 +39,7 @@ public class PredicateImpl extends CompoundExpressionImpl implements Predicate { protected BooleanOperator booloperator; - public PredicateImpl (Metamodel metamodel, org.eclipse.persistence.expressions.Expression expressionNode, List> parentExpressions, BooleanOperator operator){ + public PredicateImpl (Metamodel metamodel, org.eclipse.persistence.expressions.Expression expressionNode, List> parentExpressions, BooleanOperator operator){ super(metamodel, expressionNode, parentExpressions); this.booloperator = operator; } @@ -56,13 +56,13 @@ public Boolean getJunctionValue() { return this.getOperator() == BooleanOperator.AND; } - @Override /** * Return the boolean operator for the predicate. If the predicate is * simple, this is AND. * * @return boolean operator for the predicate */ + @Override public BooleanOperator getOperator(){ return this.booloperator; } @@ -73,8 +73,9 @@ public BooleanOperator getOperator(){ * @return list boolean expressions forming the predicate */ @Override + @SuppressWarnings("unchecked") // Otherwise generics won't match public List> getExpressions(){ - return this.expressions; + return (List>)(List) this.expressions; } /** @@ -84,7 +85,7 @@ public List> getExpressions(){ */ @Override public Predicate not(){ - PredicateImpl predicateImpl = null; + PredicateImpl predicateImpl; if (isJunction()) { if (getJunctionValue()) { predicateImpl = new PredicateImpl(this.metamodel, null, null, BooleanOperator.OR); diff --git a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/SelectionImpl.java b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/SelectionImpl.java index 610c1757490..dc9cd72e457 100644 --- a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/SelectionImpl.java +++ b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/querydef/SelectionImpl.java @@ -88,7 +88,7 @@ public Class getJavaType() { return this.javaType; } - public void setJavaType(Class javaType) { + public void setJavaType(Class javaType) { this.javaType = javaType; }