/** * INTERNAL: */ public Expression performOperator(ExpressionOperator anOperator, Vector args) { return anOperator.expressionForArguments(this, args); }
/** * INTERNAL: * Create an expression for this operator, using the given base. */ public Expression expressionFor(Expression base) { return expressionForArguments(base, oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(0)); }
/** * ADVANCED: * This can be used for accessing user defined functions that have arguments. * The operator must be defined in ExpressionOperator to be able to reference it. * @see ExpressionOperator * <p> Example: * <pre><blockquote> * Vector arguments = new Vector(); * arguments.addElement("blee"); * builder.get("name").getFunction(MyFunctions.FOO_BAR, arguments).greaterThan(100); * </blockquote></pre> */ public Expression getFunction(int selector, Vector arguments) { ExpressionOperator anOperator = getOperator(selector); return anOperator.expressionForArguments(this, arguments); }
/** * PUBLIC: * Function, returns the string padded with the substring to the size. */ public Expression leftPad(Object size, Object substring) { ExpressionOperator anOperator = getOperator(ExpressionOperator.LeftPad); Vector args = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(2); args.addElement(size); args.addElement(substring); return anOperator.expressionForArguments(this, args); }
/** * PUBLIC: * Function, returns the string with occurances of the first substring replaced with the second substring. */ public Expression replace(Object stringToReplace, Object stringToReplaceWith) { ExpressionOperator anOperator = getOperator(ExpressionOperator.Replace); Vector args = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(2); args.addElement(stringToReplace); args.addElement(stringToReplaceWith); return anOperator.expressionForArguments(this, args); }
/** * PUBLIC: * Function, returns the string padded with the substring to the size. */ public Expression rightPad(Object size, Object substring) { ExpressionOperator anOperator = getOperator(ExpressionOperator.RightPad); Vector args = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(2); args.addElement(size); args.addElement(substring); return anOperator.expressionForArguments(this, args); }
/** * PUBLIC: * Function, returns the substring from the souce string. */ public Expression substring(Object startPosition, Object size) { ExpressionOperator anOperator = getOperator(ExpressionOperator.Substring); Vector args = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(2); args.addElement(startPosition); args.addElement(size); return anOperator.expressionForArguments(this, args); }
/** * PUBLIC: * Function, returns the string with each char from the from string converted to the char in the to string. */ public Expression translate(Object fromString, Object toString) { ExpressionOperator anOperator = getOperator(ExpressionOperator.Translate); Vector args = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(2); args.addElement(fromString); args.addElement(toString); return anOperator.expressionForArguments(this, args); }
/** * PUBLIC: * Return an expression that compares if the receivers value is like other value. * This is equivalent to the SQL "LIKE ESCAPE" operator that except wildcards. * The character "%" means any sequence of characters and the character "_" mean any character. * i.e. "B%" == "Bob", "B_B" == "BOB" * The escape sequence specifies a set of characters the may be used to indicate that * an one of the wildcard characters should be interpretted literally. * <p>Example: * <pre><blockquote> * TopLink: employee.get("firstName").like("B\_SMITH", "\") * Java: NA * SQL: F_NAME LIKE 'B\_SMITH ESCAPE '\'' * </blockquote></pre> */ public Expression like(Expression value, Expression escapeSequence) { ExpressionOperator anOperator = getOperator(ExpressionOperator.LikeEscape); Vector args = new Vector(); args.addElement(value); args.addElement(escapeSequence); return anOperator.expressionForArguments(this, args); }
/** * PUBLIC: * funcation return a date converted to a new timezone. Equivalent of the Oracle NEW_TIME function * <p>Example: * <pre><blockquote> * TopLink: employee.get("date").newTime("EST", "PST") * Java: NA * SQL: NEW_TIME(date, 'EST', 'PST') * </pre></blockquote> * */ public Expression newTime(String timeZoneFrom, String timeZoneTo) { ExpressionOperator anOperator = getOperator(ExpressionOperator.NewTime); Vector args = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(); args.addElement(timeZoneFrom); args.addElement(timeZoneTo); return anOperator.expressionForArguments(this, args); }
/** * PUBLIC: * Function, returns the position of <code>str</code> in <code>this</code>, * starting the search at <code>fromIndex</code>. * <p>Example: * <pre><blockquote> * TopLink: employee.get("firstName").locate("ob", 1) * Java: employee.getFirstName().indexOf("ob", 1) + 1 * SQL: LOCATE('ob', t0.F_NAME, 1) * </pre></blockquote> * <p> * Note that while in String.locate(str) -1 is returned if not found, and the * index starting at 0 if found, in SQL it is 0 if not found, and the index * starting at 1 if found. */ public Expression locate(Object str, Object fromIndex) { ExpressionOperator anOperator = getOperator(ExpressionOperator.Locate2); Vector args = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(2); args.addElement(str); args.addElement(fromIndex); return anOperator.expressionForArguments(this, args); }
/** * PUBLIC: * Return an expression that compares if the receiver's value is between two other values. * This means the receiver's value is greater than or equal to the leftValue argument and less than or equal to the * rightValue argument. * <p> * This is equivalent to the SQL "BETWEEN AND" operator and Java ">=", "<=;" operators. * <p>Example: * <pre> * TopLink: employee.get("age").between(19,50) * Java: (employee.getAge() >= 19) && (employee.getAge() <= 50) * SQL: AGE BETWEEN 19 AND 50 * </pre> */ public Expression between(Object leftValue, Object rightValue) { ExpressionOperator anOperator = getOperator(ExpressionOperator.Between); Vector args = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(); args.addElement(leftValue); args.addElement(rightValue); return anOperator.expressionForArguments(this, args); }
/** * PUBLIC: * Return an expression that compares if the receivers value is like other value. * This is equivalent to the SQL "LIKE ESCAPE" operator that except wildcards. * The character "%" means any sequence of characters and the character "_" mean any character. * i.e. "B%" == "Bob", "B_B" == "BOB" * The escape sequence specifies a set of characters the may be used to indicate that * an one of the wildcard characters should be interpretted literally. * <p>Example: * <pre><blockquote> * TopLink: employee.get("firstName").like("B\_SMITH", "\") * Java: NA * SQL: F_NAME LIKE 'B\_SMITH ESCAPE '\'' * </blockquote></pre> */ public Expression like(String value, String escapeSequence) { ExpressionOperator anOperator = getOperator(ExpressionOperator.LikeEscape); Vector args = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(); args.addElement(value); args.addElement(escapeSequence); return anOperator.expressionForArguments(this, args); }
/** * PUBLIC: * Function, returns the position of <code>str</code> in <code>this</code> * <p>Example: * <pre><blockquote> * TopLink: employee.get("firstName").locate("ob") * Java: employee.getFirstName().indexOf("ob") + 1 * SQL: LOCATE('ob', t0.F_NAME) * </pre></blockquote> * <p> * Note that while in String.locate(str) -1 is returned if not found, and the * index starting at 0 if found, in SQL it is 0 if not found, and the index * starting at 1 if found. */ public Expression locate(Object str) { ExpressionOperator anOperator = getOperator(ExpressionOperator.Locate); Vector args = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(1); args.addElement(str); return anOperator.expressionForArguments(this, args); }
/** * ADVANCED: * Return a user defined function accepting all of the arguments. * The function is assumed to be a normal prefix function like, CONCAT(base, value1, value2, value3, ...). */ public Expression getFunctionWithArguments(String functionName, Vector arguments) { ExpressionOperator anOperator = new ExpressionOperator(); anOperator.setType(ExpressionOperator.FunctionOperator); Vector v = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(arguments.size()); v.addElement(functionName + "("); for (int index = 0; index < arguments.size(); index++) { v.addElement(", "); } v.addElement(")"); anOperator.printsAs(v); anOperator.bePrefix(); anOperator.setNodeClass(ClassConstants.FunctionExpression_Class); return anOperator.expressionForArguments(this, arguments); }
/** * PUBLIC: * Return an expression that checks if the receivers value is contained in the collection. * The collection can be a collection of constants or expressions. * This is equivalent to the SQL "IN" operator and Java "contains" operator. * <p>Example: * <pre><blockquote> * TopLink: employee.get("age").in(agesVector) * Java: agesVector.contains(employee.getAge()) * SQL: AGE IN (55, 18, 30) * </blockquote></pre> */ public Expression in(Vector theObjects) { //If none of the elements in theObjects is expression, build a ConstantExpression with theObjects. if (!detectExpression(theObjects)) { return in(new ConstantExpression(theObjects, this)); } //Otherwise build a collection of expressions. ExpressionOperator anOperator = getOperator(ExpressionOperator.In); return anOperator.expressionForArguments(this, theObjects); }
/** * PUBLIC: * Return an expression that checks if the receivers value is contained in the collection. * The collection can be a collection of constants or expressions. * This is equivalent to the SQL "IN" operator and Java "contains" operator. * <p>Example: * <pre><blockquote> * TopLink: employee.get("age").in(agesVector) * Java: agesVector.contains(employee.getAge()) * SQL: AGE IN (55, 18, 30) * </blockquote></pre> */ public Expression notIn(Vector theObjects) { //If none of the elements in theObjects is expression, build a ConstantExpression with theObjects. if (!detectExpression(theObjects)) { return notIn(new ConstantExpression(theObjects, this)); } //Otherwise build a collection of expressions. ExpressionOperator anOperator = getOperator(ExpressionOperator.NotIn); return anOperator.expressionForArguments(this, theObjects); }