mirror of https://github.com/apache/openjpa.git
OPENJPA-617 Add support for calculating update value in QueryImpl.updateInMemory
Help comitting patch provided by Fay Wang Add support for in-memory math - sqrt, abs functions git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@661472 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d1aa6a2c48
commit
48b1fb5a37
|
@ -707,6 +707,10 @@ public class JDBCStoreQuery
|
|||
return handleTrimVal(value, ob, params, sm);
|
||||
case Val.INDEXOF_VAL:
|
||||
return handleIndexOfVal(value, ob, params, sm);
|
||||
case Val.ABS_VAL:
|
||||
return handleAbsVal(value, ob, params, sm);
|
||||
case Val.SQRT_VAL:
|
||||
return handleSqrtVal(value, ob, params, sm);
|
||||
default:
|
||||
throw new UnsupportedException();
|
||||
}
|
||||
|
@ -858,6 +862,42 @@ public class JDBCStoreQuery
|
|||
return strVal.indexOf(val1, idx);
|
||||
}
|
||||
|
||||
private Object handleAbsVal(Object value, Object ob, Object[] params,
|
||||
OpenJPAStateManager sm) {
|
||||
org.apache.openjpa.jdbc.kernel.exps.Abs absVal =
|
||||
(org.apache.openjpa.jdbc.kernel.exps.Abs) value;
|
||||
Object val = getValue(absVal.getValue(), ob, params, sm);
|
||||
Class c = val.getClass();
|
||||
if (c == Integer.class)
|
||||
return new Integer(java.lang.Math.abs(((Integer) val).intValue()));
|
||||
else if (c == Float.class)
|
||||
return new Float(java.lang.Math.abs(((Float) val).floatValue()));
|
||||
else if (c == Double.class)
|
||||
return new Double(java.lang.Math.abs(((Double) val).doubleValue()));
|
||||
else if (c == Long.class)
|
||||
return new Long(java.lang.Math.abs(((Long) val).longValue()));
|
||||
throw new UnsupportedException();
|
||||
}
|
||||
|
||||
private Object handleSqrtVal(Object value, Object ob, Object[] params,
|
||||
OpenJPAStateManager sm) {
|
||||
org.apache.openjpa.jdbc.kernel.exps.Sqrt sqrtVal =
|
||||
(org.apache.openjpa.jdbc.kernel.exps.Sqrt) value;
|
||||
Object val = getValue(sqrtVal.getValue(), ob, params, sm);
|
||||
Class c = val.getClass();
|
||||
if (c == Integer.class)
|
||||
return new Double(java.lang.Math.sqrt(((Integer) val).
|
||||
doubleValue()));
|
||||
else if (c == Float.class)
|
||||
return new Double(java.lang.Math.sqrt(((Float) val).floatValue()));
|
||||
else if (c == Double.class)
|
||||
return new Double(java.lang.Math.sqrt(((Double) val).
|
||||
doubleValue()));
|
||||
else if (c == Long.class)
|
||||
return new Double(java.lang.Math.sqrt(((Long) val).doubleValue()));
|
||||
throw new UnsupportedException();
|
||||
}
|
||||
|
||||
private Object getValue(Object value, Object ob, Object[] params,
|
||||
OpenJPAStateManager sm) {
|
||||
if (value instanceof PCPath) {
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.apache.openjpa.kernel.Filters;
|
|||
/**
|
||||
* Absolute value.
|
||||
*/
|
||||
class Abs
|
||||
public class Abs
|
||||
extends UnaryOp {
|
||||
|
||||
/**
|
||||
|
@ -51,5 +51,9 @@ class Abs
|
|||
protected String getOperator() {
|
||||
return "ABS";
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return Val.ABS_VAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -154,5 +154,9 @@ public class Math
|
|||
_val2.acceptVisit(visitor);
|
||||
visitor.exit(this);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return Val.MATH_VAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ package org.apache.openjpa.jdbc.kernel.exps;
|
|||
*
|
||||
* @author Abe White
|
||||
*/
|
||||
class Sqrt
|
||||
public class Sqrt
|
||||
extends UnaryOp {
|
||||
|
||||
/**
|
||||
|
@ -40,5 +40,9 @@ class Sqrt
|
|||
protected String getOperator() {
|
||||
return "SQRT";
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return Val.SQRT_VAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ abstract class UnaryOp
|
|||
_noParen = noParen;
|
||||
}
|
||||
|
||||
protected Val getValue() {
|
||||
public Val getValue() {
|
||||
return _val;
|
||||
}
|
||||
|
||||
|
|
|
@ -62,6 +62,8 @@ public interface Val
|
|||
public final int LOCATE_VAL = 8;
|
||||
public final int ARGS_VAL = 9;
|
||||
public final int INDEXOF_VAL = 10;
|
||||
public final int ABS_VAL = 11;
|
||||
public final int SQRT_VAL = 12;
|
||||
|
||||
/**
|
||||
* Initialize the value. This method should recursively initialize any
|
||||
|
|
Loading…
Reference in New Issue