You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by mb...@apache.org on 2018/10/07 17:35:58 UTC
svn commit: r1843068 - in /db/jdo/trunk/api/src/main/java/javax/jdo:
JDOQLTypedQuery.java query/ComparableExpression.java
query/IfThenElseExpression.java query/NumericExpression.java
Author: mbo
Date: Sun Oct 7 17:35:57 2018
New Revision: 1843068
URL: http://svn.apache.org/viewvc?rev=1843068&view=rev
Log:
JDO-652: Added interface IfThenElseExpression and some signature changes in ComparableExpression and NumericExpression
Added:
db/jdo/trunk/api/src/main/java/javax/jdo/query/IfThenElseExpression.java
Modified:
db/jdo/trunk/api/src/main/java/javax/jdo/JDOQLTypedQuery.java
db/jdo/trunk/api/src/main/java/javax/jdo/query/ComparableExpression.java
db/jdo/trunk/api/src/main/java/javax/jdo/query/NumericExpression.java
Modified: db/jdo/trunk/api/src/main/java/javax/jdo/JDOQLTypedQuery.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api/src/main/java/javax/jdo/JDOQLTypedQuery.java?rev=1843068&r1=1843067&r2=1843068&view=diff
==============================================================================
--- db/jdo/trunk/api/src/main/java/javax/jdo/JDOQLTypedQuery.java (original)
+++ db/jdo/trunk/api/src/main/java/javax/jdo/JDOQLTypedQuery.java Sun Oct 7 17:35:57 2018
@@ -22,14 +22,13 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
-import javax.jdo.FetchPlan;
-import javax.jdo.PersistenceManager;
import javax.jdo.query.BooleanExpression;
import javax.jdo.query.CharacterExpression;
import javax.jdo.query.CollectionExpression;
import javax.jdo.query.DateExpression;
import javax.jdo.query.DateTimeExpression;
import javax.jdo.query.Expression;
+import javax.jdo.query.IfThenElseExpression;
import javax.jdo.query.ListExpression;
import javax.jdo.query.MapExpression;
import javax.jdo.query.NumericExpression;
@@ -170,6 +169,63 @@ public interface JDOQLTypedQuery<T> exte
JDOQLTypedQuery<T> filter(BooleanExpression expr);
/**
+ * Method to return an "IF (...) ... ELSE ..." expression for use in this query.
+ * @param type The type returned by the IfElse.
+ * @param cond The if condition
+ * @param thenValueExpr Expression for value to return when the if expression is met
+ * @param elseValueExpr Expression for value to return when the if expression is not met
+ * @return The IfThenElse expression
+ */
+ <V> IfThenElseExpression<V> ifThenElse(Class<V> type, BooleanExpression cond,
+ Expression<V> thenValueExpr, Expression<V> elseValueExpr);
+
+ /**
+ * Method to return an "IF (...) ... ELSE ..." expression for use in this query.
+ * @param cond The if condition
+ * @param thenValue Value to return when the if expression is met
+ * @param elseValueExpr Expression to return when the if expression is not met
+ * @return The IfThenElse expression
+ */
+ <V> IfThenElseExpression<V> ifThenElse(BooleanExpression cond, V thenValue, Expression<V> elseValueExpr);
+
+ /**
+ * Method to return an "IF (...) ... ELSE ..." expression for use in this query.
+ * @param cond The if condition
+ * @param thenValueExpr Expression to return when the if expression is met
+ * @param elseValue Value to return when the if expression is not met
+ * @return The IfThenElse expression
+ */
+ <V> IfThenElseExpression<V> ifThenElse(BooleanExpression cond, Expression<V> thenValueExpr, V elseValue);
+
+ /**
+ * Method to return an "IF (...) ... ELSE ..." expression for use in this query.
+ * @param cond The if condition
+ * @param thenValue Value to return when the if expression is met
+ * @param elseValue Value to return when the if expression is not met
+ * @return The IfThenElse expression
+ */
+ <V> IfThenElseExpression<V> ifThenElse(BooleanExpression cond, V thenValue, V elseValue);
+
+ /**
+ * Method to return an "IF (...) ... ELSE ..." expression for use in this query.
+ * @param type The type returned by the IfElse.
+ * @param cond The if condition
+ * @param thenValueExpr Expression for value to return when the if expression is met
+ * @param <V>
+ * @return
+ */
+ <V> IfThenElseExpression<V> ifThen(Class<V> type, BooleanExpression cond, Expression<V> thenValueExpr);
+
+ /**
+ * Method to return an "IF (...) ... ELSE ..." expression for use in this query.
+ * @param cond The if condition
+ * @param thenValue Value to return when the if expression is met
+ * @param <V>
+ * @return
+ */
+ <V> IfThenElseExpression<V> ifThen(BooleanExpression cond, V thenValue);
+
+ /**
* Method to set the grouping(s) for the query.
* @param exprs Grouping expression(s)
* @return The query
Modified: db/jdo/trunk/api/src/main/java/javax/jdo/query/ComparableExpression.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api/src/main/java/javax/jdo/query/ComparableExpression.java?rev=1843068&r1=1843067&r2=1843068&view=diff
==============================================================================
--- db/jdo/trunk/api/src/main/java/javax/jdo/query/ComparableExpression.java (original)
+++ db/jdo/trunk/api/src/main/java/javax/jdo/query/ComparableExpression.java Sun Oct 7 17:35:57 2018
@@ -28,7 +28,7 @@ public interface ComparableExpression<T>
* @param expr Other expression
* @return Whether this is less than the other
*/
- BooleanExpression lt(ComparableExpression<T> expr);
+ BooleanExpression lt(ComparableExpression<? extends T> expr);
/**
* Method returning whether this expression is less than the literal.
@@ -42,7 +42,7 @@ public interface ComparableExpression<T>
* @param expr Other expression
* @return Whether this is less than or equal the other
*/
- BooleanExpression lteq(ComparableExpression<T> expr);
+ BooleanExpression lteq(ComparableExpression<? extends T> expr);
/**
* Method returning whether this expression is less than or equal the literal.
@@ -56,7 +56,7 @@ public interface ComparableExpression<T>
* @param expr Other expression
* @return Whether this is greater than the other
*/
- BooleanExpression gt(ComparableExpression<T> expr);
+ BooleanExpression gt(ComparableExpression<? extends T> expr);
/**
* Method returning whether this expression is greater than the literal.
@@ -70,7 +70,7 @@ public interface ComparableExpression<T>
* @param expr Other expression
* @return Whether this is greater than or equal to the other
*/
- BooleanExpression gteq(ComparableExpression<T> expr);
+ BooleanExpression gteq(ComparableExpression<? extends T> expr);
/**
* Method returning whether this expression is greater than or equal the literal.
@@ -81,15 +81,15 @@ public interface ComparableExpression<T>
/**
* Method to return a numeric expression representing the aggregated minimum of this expression.
- * @return Numeric expression for the minimum
+ * @return expression for the minimum
*/
- NumericExpression<T> min();
+ ComparableExpression<T> min();
/**
* Method to return a numeric expression representing the aggregated maximum of this expression.
- * @return Numeric expression for the maximum
+ * @return expression for the maximum
*/
- NumericExpression<T> max();
+ ComparableExpression<T> max();
/**
* Method to return an order expression for this expression in ascending order.
Added: db/jdo/trunk/api/src/main/java/javax/jdo/query/IfThenElseExpression.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api/src/main/java/javax/jdo/query/IfThenElseExpression.java?rev=1843068&view=auto
==============================================================================
--- db/jdo/trunk/api/src/main/java/javax/jdo/query/IfThenElseExpression.java (added)
+++ db/jdo/trunk/api/src/main/java/javax/jdo/query/IfThenElseExpression.java Sun Oct 7 17:35:57 2018
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package javax.jdo.query;
+
+/**
+ * Representation of an IF-THEN-ELSE expression.
+ *
+ * @param <T> Java type
+ */
+public interface IfThenElseExpression<T> extends ComparableExpression<T> {
+
+ /**
+ * Method to add an "IF (...) ..." clause.
+ * If called multiple times, will add extra "IF (...) ..." or "ELSE IF (...) ..."
+ * @param cond The if expression
+ * @param thenValueExpr Expression to return when the if expression is met
+ * @return This expression
+ */
+ IfThenElseExpression<T> ifThen(BooleanExpression cond, Expression<T> thenValueExpr);
+
+ /**
+ * Method to add an "IF (...) ..." clause.
+ * If called multiple times, will add extra "IF (...) ..." or "ELSE IF (...) ..."
+ * @param cond The if condition
+ * @param thenValue Value to return when the if expression is met
+ * @return This expression
+ */
+ IfThenElseExpression<T> ifThen(BooleanExpression cond, T thenValue);
+
+ /**
+ * Method to add the "ELSE ..." clause.
+ * If called multiple times will replace the previous else clause
+ * @param elseValueExpr Expression for value to return when the if expression is not met
+ * @return This expression
+ */
+ IfThenElseExpression<T> elseEnd(Expression<T> elseValueExpr);
+
+ /**
+ * Method to add the "ELSE ..." clause.
+ * If called multiple times will replace the previous else clause
+ * @param elseValue Value to return when the if expression is not met
+ * @return This expression
+ */
+ IfThenElseExpression<T> elseEnd(T elseValue);
+
+}
Modified: db/jdo/trunk/api/src/main/java/javax/jdo/query/NumericExpression.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api/src/main/java/javax/jdo/query/NumericExpression.java?rev=1843068&r1=1843067&r2=1843068&view=diff
==============================================================================
--- db/jdo/trunk/api/src/main/java/javax/jdo/query/NumericExpression.java (original)
+++ db/jdo/trunk/api/src/main/java/javax/jdo/query/NumericExpression.java Sun Oct 7 17:35:57 2018
@@ -21,89 +21,89 @@ package javax.jdo.query;
*
* @param <T> Number type
*/
-public interface NumericExpression<T> extends ComparableExpression<Number>
+public interface NumericExpression<T> extends ComparableExpression<T>
{
/**
* Method to return an expression for this expression added to the passed expression.
* @param expr The other expression
* @return The summation
*/
- NumericExpression add(Expression expr);
+ NumericExpression<T> add(Expression<T> expr);
/**
* Method to return an expression for this expression added to the passed number.
* @param num Number to add
* @return The summation
*/
- NumericExpression add(Number num);
+ NumericExpression<T> add(Number num);
/**
* Method to return an expression for this expression subtracting the passed expression.
* @param expr The other expression
* @return The difference
*/
- NumericExpression sub(Expression expr);
+ NumericExpression<T> sub(Expression<T> expr);
/**
* Method to return an expression for this expression subtracting the passed number.
* @param num Number to subtract
* @return The difference
*/
- NumericExpression sub(Number num);
+ NumericExpression<T> sub(Number num);
/**
* Method to return an expression for this expression multiplied by the passed expression.
* @param expr The other expression
* @return The multiplication
*/
- NumericExpression mul(Expression expr);
+ NumericExpression<T> mul(Expression<T> expr);
/**
* Method to return an expression for this expression multiplied by the passed number.
* @param num Number
* @return The multiplication
*/
- NumericExpression mul(Number num);
+ NumericExpression<T> mul(Number num);
/**
* Method to return an expression for this expression divided by the passed expression.
* @param expr The other expression
* @return The division
*/
- NumericExpression div(Expression expr);
+ NumericExpression<T> div(Expression<T> expr);
/**
* Method to return an expression for this expression divided by the passed number.
* @param num Number to divide by
* @return The division
*/
- NumericExpression div(Number num);
+ NumericExpression<T> div(Number num);
/**
* Method to return an expression for this expression modulus the passed expression (<pre>a % b</pre>).
* @param expr The other expression
* @return The modulus
*/
- NumericExpression mod(Expression expr);
+ NumericExpression<T> mod(Expression<T> expr);
/**
* Method to return an expression for this expression modulus the passed number.
* @param num Number
* @return The modulus
*/
- NumericExpression mod(Number num);
+ NumericExpression<T> mod(Number num);
/**
* Method to return an expression that is the current expression negated.
* @return The negated expression
*/
- NumericExpression neg();
+ NumericExpression<T> neg();
/**
* Method to return an expression that is the complement of the current expression.
* @return The complement expression
*/
- NumericExpression com();
+ NumericExpression<T> com();
/**
* Method to return a numeric expression representing the aggregated average of this expression.
@@ -112,101 +112,113 @@ public interface NumericExpression<T> ex
NumericExpression<Double> avg();
/**
+ * Method to return a numeric expression representing the aggregated (distinct) average of this expression.
+ * @return Numeric expression for the average
+ */
+ NumericExpression<Double> avgDistinct();
+
+ /**
* Method to return a numeric expression representing the aggregated sum of this expression.
* @return Numeric expression for the sum
*/
- NumericExpression sum();
+ NumericExpression<T> sum();
+
+ /**
+ * Method to return a numeric expression representing the aggregated (distinct) sum of this expression.
+ * @return Numeric expression for the sum
+ */
+ NumericExpression<T> sumDistinct();
/**
* Method to return the absolute value expression of this expression.
* @return The absolute value expression
*/
- NumericExpression abs();
+ NumericExpression<T> abs();
/**
* Method to return the square-root value expression of this expression.
* @return The square-root value expression
*/
- NumericExpression sqrt();
+ NumericExpression<Double> sqrt();
/**
* Method to return the arc cosine value expression of this expression.
* @return The arc cosine value expression
*/
- NumericExpression acos();
+ NumericExpression<Double> acos();
/**
* Method to return the arc sine value expression of this expression.
* @return The arc sine value expression
*/
- NumericExpression asin();
+ NumericExpression<Double> asin();
/**
* Method to return the arc tangent value expression of this expression.
* @return The arc tangent value expression
*/
- NumericExpression atan();
+ NumericExpression<Double> atan();
/**
* Method to return the sine value expression of this expression.
* @return The sine value expression
*/
- NumericExpression sin();
+ NumericExpression<Double> sin();
/**
* Method to return the cosine value expression of this expression.
* @return The cosine value expression
*/
- NumericExpression cos();
+ NumericExpression<Double> cos();
/**
* Method to return the tangent value expression of this expression.
* @return The tangent value expression
*/
- NumericExpression tan();
+ NumericExpression<Double> tan();
/**
* Method to return the exponential value expression of this expression.
* @return The exponential value expression
*/
- NumericExpression exp();
+ NumericExpression<Double> exp();
/**
* Method to return the logarithm value expression of this expression.
* @return The logarithm value expression
*/
- NumericExpression log();
+ NumericExpression<Double> log();
/**
* Method to return the ceiling value expression of this expression.
* @return The ceiling value expression
*/
- NumericExpression ceil();
+ NumericExpression<T> ceil();
/**
* Method to return the floor value expression of this expression.
* @return The floor value expression
*/
- NumericExpression floor();
+ NumericExpression<T> floor();
/**
* Method to return a bitwise AND expression for this expression with the supplied bit path.
* @param bitExpr Bit expression
* @return Bitwise AND expression
*/
- NumericExpression bAnd(NumericExpression bitExpr);
+ NumericExpression<T> bAnd(NumericExpression<T> bitExpr);
/**
* Method to return a bitwise OR expression for this expression with the supplied bit path.
* @param bitExpr Bit expression
* @return Bitwise OR expression
*/
- NumericExpression bOr(NumericExpression bitExpr);
+ NumericExpression<T> bOr(NumericExpression<T> bitExpr);
/**
* Method to return a bitwise XOR expression for this expression with the supplied bit path.
* @param bitExpr Bit expression
* @return Bitwise XOR expression
*/
- NumericExpression bXor(NumericExpression bitExpr);
+ NumericExpression<T> bXor(NumericExpression<T> bitExpr);
}