/** * INTERNAL: * This expression is built on a different base than the one we want. Rebuild it and * return the root of the new tree */ public Expression rebuildOn(Expression newBase) { Expression newLocalBase = getBaseExpression().rebuildOn(newBase); Vector newChildren = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(this.children.size()); for (int i = 1; i < this.children.size(); i++) {// Skip the first one, since it's also the base newChildren.addElement(((Expression)children.elementAt(i)).rebuildOn(newBase)); } newLocalBase.setSelectIfOrderedBy(getBaseExpression().selectIfOrderedBy()); FunctionExpression rebuilt = (FunctionExpression) newLocalBase.performOperator(getOperator(), newChildren); rebuilt.setResultType(this.getResultType()); //copy over result type. return rebuilt; }
/** * INTERNAL: * Compute a consistent hash-code for the expression. * This is used to allow dynamic expression's SQL to be cached. */ public int computeHashCode() { int hashCode = super.computeHashCode(); if (getOperator() != null) { hashCode = hashCode + getOperator().hashCode(); } List children = getChildren(); int size = children.size(); for (int index = 0; index < size; index++) { hashCode = hashCode + children.get(index).hashCode(); } return hashCode; }
/** * PUBLIC: * Function, Return the difference between the queried part of a date(i.e. years, days etc.) * and same part of the given date. The equivalent of the Sybase function DateDiff * <p>Example: * <blockquote><pre> * EclipseLink: employee.get("date").dateDifference("year", new Date(System.currentTimeMillis())) * Java: NA * SQL: DATEADD(date, 2, GETDATE) * </pre></blockquote> */ public Expression dateDifference(String datePart, Expression comparisonExpression) { ExpressionOperator anOperator = getOperator(ExpressionOperator.DateDifference); FunctionExpression expression = new FunctionExpression(); expression.setBaseExpression(this); expression.addChild(Expression.fromLiteral(datePart, this)); expression.addChild(comparisonExpression); expression.addChild(this); expression.setOperator(anOperator); return expression; }
/** * INTERNAL: */ public Expression create(Expression base, Object singleArgument, ExpressionOperator operator) { baseExpression = base; addChild(base); Expression arg = Expression.from(singleArgument, base); addChild(arg); setOperator(operator); return this; }
/** * INTERNAL: */ public Expression create(Expression base, Object singleArgument, ExpressionOperator anOperator) { baseExpression = base; addChild(base); Expression localBase = base; if(anOperator.isFunctionOperator()) { ExpressionBuilder builder = getBuilder(); if(builder != null) { localBase = builder; } } Expression arg = Expression.from(singleArgument, localBase); addChild(arg); setOperator(anOperator); return this; }
if (getBaseExpression().isDataExpression()) { DatabaseField field = ((DataExpression)getBaseExpression()).getField(); if (hasResultType()) { field.setType(getResultType()); } else { int selector = getOperator().getSelector(); if (selector != ExpressionOperator.Maximum && selector != ExpressionOperator.Minimum) { field.setType(null); field.setType(getResultType()); newFields.addElement(field); printSQL(printer);
validateNode(); if (this.children.isEmpty()) { return this; ExpressionBuilder builder = getBuilder(); if ((builder != null) && (builder.getSession() == null)) { builder.setSession(normalizer.getSession().getRootSession(null)); prepareObjectAttributeCount(normalizer, null, null, null); if (!isObjectComparison()) { for (int index = 0; index < this.children.size(); index++) { this.children.set(index, ((Expression)this.children.get(index)).normalize(normalizer)); ObjectExpression base = (ObjectExpression)getBaseExpression(); base = (ObjectExpression)getBaseExpression(); setBaseExpression(newBase); this.children.set(0, newBase); Expression right = (Expression)this.children.get(1); foreignKeyJoin = base.getDescriptor().getObjectBuilder().buildPrimaryKeyExpressionFromKeys(null, getSession()); foreignKeyJoin = foreignKeyJoin.rebuildOn(base); } else { foreignKeyJoin = base.getMapping().buildObjectJoinExpression(base, (Object)null, getSession());
validateNode(); if (this.children.isEmpty()) { return this; ExpressionBuilder builder = getBuilder(); if ((builder != null) && (builder.getSession() == null)) { builder.setSession(normalizer.getSession().getRootSession(null)); if (this.operator.getSelector() == ExpressionOperator.Count && getBaseExpression().isObjectExpression() && (!((ObjectExpression)getBaseExpression()).isAttribute())){ prepareObjectAttributeCount(normalizer); if (!isObjectComparison()) { for (int index = 0; index < this.children.size(); index++) { this.children.setElementAt(((Expression)this.children.elementAt(index)).normalize(normalizer), index); ObjectExpression base = (ObjectExpression)getBaseExpression(); Expression foreignKeyJoin = base.getMapping().buildObjectJoinExpression(base, (Object)null, getSession()); if (getOperator().getSelector() == ExpressionOperator.NotNull) { foreignKeyJoin = foreignKeyJoin.not();
/** * INTERNAL: * This expression is built on a different base than the one we want. Rebuild it and * return the root of the new tree */ public Expression rebuildOn(Expression newBase) { Expression newLocalBase = getBaseExpression().rebuildOn(newBase); Vector newChildren = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(this.children.size()); for (int i = 1; i < this.children.size(); i++) {// Skip the first one, since it's also the base newChildren.addElement(((Expression)children.elementAt(i)).rebuildOn(newBase)); } newLocalBase.setSelectIfOrderedBy(getBaseExpression().selectIfOrderedBy()); FunctionExpression rebuilt = (FunctionExpression) newLocalBase.performOperator(this.operator, newChildren); rebuilt.setResultType(this.getResultType()); //copy over result type. return rebuilt; }
/** * INTERNAL: Not to be confused with the public getField(String) * This returns a collection of all fields associated with this object. Really * only applies to query keys representing an object or to expression builders. * */ @Override public Vector getFields() { return getBaseExpression().getFields(); }
/** * INTERNAL: * Add a child and ensure it is the rightmost in the tree as long as it * is in the tree * If there is already a node that is set as therightmost node, replace it * @param argument */ public synchronized void addRightMostChild(Expression argument){ if (hasLastChild != null && hasLastChild.booleanValue()){ getChildren().remove(super.getChildren().size() - 1); super.addChild(argument); } else { this.addChild(argument); } this.hasLastChild = Boolean.TRUE; }
@Override public void postBuild(DescriptorEvent event) { FunctionExpression expression = (FunctionExpression)event.getObject(); for (int index = 0; index < expression.getChildren().size(); index++) { Expression child = expression.getChildren().get(index); if (child.isValueExpression()) { child.setLocalBase(new ExpressionBuilder()); } } if (expression.getChildren().size() > 0) { expression.setBaseExpression(expression.getChildren().get(0)); } else { expression.setBaseExpression(new ExpressionBuilder()); } } });
/** * INTERNAL: * Return if the represents an object comparison. */ protected boolean isObjectComparison() { if (this.children.size() != 1) { return false; } int selector = getOperator().getSelector(); if ((selector != ExpressionOperator.IsNull) && (selector != ExpressionOperator.NotNull)) { return false; } Expression base = getBaseExpression(); return (base.isObjectExpression() && (!((ObjectExpression)base).isAttribute())); }
/** * INTERNAL: * A utility method to build a SpatialExpression * * @param operator the ordinal of the operator * @param geom1 * @param geom2 * @param params * @return */ public static Expression getSpatialExpression(int operator, Expression geom1, Object geom2, String params) { Vector vParameters = new Vector(2); vParameters.add(geom2); //Bug 5885276, the empty string either like " " or "" needs to be substituted //by null prior to passing to Geometry call. if (params==null || params.trim().equals("")){ vParameters.add(null); }else{ vParameters.add(params); } ExpressionOperator anOperator = geom1.getOperator(operator); FunctionExpression expression = new FunctionExpression(); expression.create(geom1, vParameters, anOperator); Expression finalExpression = expression.equal("TRUE"); return finalExpression; } }
/** * INTERNAL: */ public void initializePlatformOperator(DatabasePlatform platform) { if (getOperator().isComplete()) { platformOperator = getOperator(); return; } platformOperator = platform.getOperator(getOperator().getSelector()); if (platformOperator == null) { throw QueryException.invalidOperator(getOperator().toString()); } }
public void addChild(Expression child) { getChildren().addElement(child); }
protected <T> SimpleCaseImpl (Metamodel metamodel, Class<R> resultClass, FunctionExpression expressionNode, List<Expression<?>> compoundExpressions, Expression<C> expression){ super(metamodel, resultClass, expressionNode, compoundExpressions); this.expression = expression; expressionNode.addChild(((InternalSelection)expression).getCurrentNode()); }
/** * INTERNAL: * Rebuild myself against the base, with the values of parameters supplied by the context * expression. This is used for transforming a standalone expression (e.g. the join criteria of a mapping) * into part of some larger expression. You normally would not call this directly, instead calling twist * See the comment there for more details" */ public Expression twistedForBaseAndContext(Expression newBase, Expression context) { if (this.children.isEmpty()) { return (Expression)clone(); } Vector newChildren = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(this.children.size()); // For functions the base is the first child, we only want the arguments so start at the second. for (int index = 1; index < this.children.size(); index++) { newChildren.addElement(((Expression)children.elementAt(index)).twistedForBaseAndContext(newBase, context)); } // Aply the function to the twisted old base. Expression oldBase = (Expression)this.children.elementAt(0); return oldBase.twistedForBaseAndContext(newBase, context).performOperator(getOperator(), newChildren); }
/** * INTERNAL: * Print java for project class generation */ public void printJava(ExpressionJavaPrinter printer) { ExpressionOperator realOperator = getPlatformOperator(printer.getPlatform()); realOperator.printJavaCollection(this.children, printer); }
private Class<?> getExpressionType(Expression expression) { if (expression instanceof SubSelectExpression) { return getReturnTypeFromSubSelectExpression((SubSelectExpression) expression); } else if (expression instanceof ParameterExpression) { return (Class<?>) ((ParameterExpression) expression).getType(); } else if (expression instanceof FunctionExpression) { return ((FunctionExpression) expression).getResultType(); } else if (expression instanceof FieldExpression) { return ((FieldExpression) expression).getField().getType(); } else if (expression instanceof FromSubSelectExpression) { return getExpressionType(((FromSubSelectExpression) expression).getSubSelect()); } else if (expression instanceof QueryKeyExpression) { final DatabaseMapping mapping = ((QueryKeyExpression) expression).getMapping(); return mapping == null ? null : mapping.getAttributeClassification(); } else if (expression instanceof ClassTypeExpression) { return ((ClassTypeExpression) expression).getField().getType(); } else if (expression instanceof ConstantExpression) { return ((ConstantExpression) expression).getValue().getClass(); } else if (expression instanceof CompoundExpression) { return Boolean.class; } else { return null; } }