mirror of https://github.com/apache/openjpa.git
OPENJPA-2149: Criteria.function adds wrong casts to parameters making it unusable
git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.1.x@1376627 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6931082027
commit
a40e5ed39a
|
@ -171,11 +171,17 @@ public class Args
|
|||
return 0;
|
||||
}
|
||||
|
||||
public void appendTo(Select sel, ExpContext ctx, ExpState state,
|
||||
SQLBuffer sql, int index) {
|
||||
public void appendTo(Select sel, ExpContext ctx, ExpState state, SQLBuffer sql, int index) {
|
||||
appendTo(sel, ctx, state, sql, index, null);
|
||||
}
|
||||
|
||||
public void appendTo(Select sel, ExpContext ctx, ExpState state, SQLBuffer sql, int index, String operator) {
|
||||
ArgsExpState astate = (ArgsExpState) state;
|
||||
for (int i = 0; i < _args.length; i++) {
|
||||
_args[i].appendTo(sel, ctx, astate.states[i], sql, index);
|
||||
if( operator != null ) {
|
||||
sql.addCastForParam(operator, _args[i]);
|
||||
}
|
||||
if (i < _args.length-1)
|
||||
sql.append(", ");
|
||||
}
|
||||
|
|
|
@ -46,16 +46,12 @@ public class DatastoreFunction extends UnaryOp {
|
|||
public void appendTo(Select sel, ExpContext ctx, ExpState state,
|
||||
SQLBuffer sql, int index) {
|
||||
Args args = (Args) getValue();
|
||||
if (!ctx.store.getDBDictionary().requiresCastForMathFunctions || args.getValues().length == 1)
|
||||
if (!ctx.store.getDBDictionary().requiresCastForMathFunctions || args.getValues().length == 1) {
|
||||
super.appendTo(sel, ctx, state, sql, index);
|
||||
else {
|
||||
} else {
|
||||
sql.append(getOperator());
|
||||
sql.append("(");
|
||||
args.appendTo(sel, ctx, state, sql, 0);
|
||||
Val[] vals = args.getVals();
|
||||
for (int i = 1; i < vals.length; i++) {
|
||||
sql.addCastForParam(getOperator(), vals[i]);
|
||||
}
|
||||
args.appendTo(sel, ctx, state, sql, 0, getOperator());
|
||||
sql.append(")");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,7 +139,16 @@ abstract class UnaryOp
|
|||
sql.append(getOperator());
|
||||
sql.append(_noParen ? " " : "(");
|
||||
_val.appendTo(sel, ctx, state, sql, 0);
|
||||
sql.addCastForParam(getOperator(), _val);
|
||||
|
||||
// OPENJPA-2149: If _val (Val) is an 'Arg', we need to get the Val[]
|
||||
// from it, and the single element it contains because the
|
||||
// 'addCastForParam' method gets the 'type' from the Val it receives.
|
||||
// In the case where _val is an Arg, when addCastForParam gets the
|
||||
// type, it will be getting the type of the Val (an Object) rather
|
||||
// the type of the Arg.
|
||||
sql.addCastForParam(getOperator(),
|
||||
(_val instanceof Args) ? (((Args) _val).getVals())[0]
|
||||
: _val);
|
||||
if (!_noParen)
|
||||
sql.append(")");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue