Fix for OPENJPA-554.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@645589 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
A. Abram White 2008-04-07 16:18:26 +00:00
parent 1b5aac791d
commit 9c19356c7c
2 changed files with 9 additions and 4 deletions

View File

@ -45,15 +45,17 @@ class GetMapValue
private final Val _map;
private final Val _key;
private final String _alias;
private ClassMetaData _meta = null;
private Class _cast = null;
/**
* Constructor. Provide the map and key to operate on.
*/
public GetMapValue(Val map, Val key) {
public GetMapValue(Val map, Val key, String alias) {
_map = map;
_key = key;
_alias = alias;
}
public ClassMetaData getMetaData() {
@ -111,7 +113,8 @@ class GetMapValue
public void select(Select sel, ExpContext ctx, ExpState state,
boolean pks) {
sel.select(newSQLBuffer(sel, ctx, state), this);
sel.select(newSQLBuffer(sel, ctx, state).append(" AS ").append(_alias),
this);
}
public void selectColumns(Select sel, ExpContext ctx, ExpState state,
@ -127,7 +130,7 @@ class GetMapValue
public void orderBy(Select sel, ExpContext ctx, ExpState state,
boolean asc) {
sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false);
sel.orderBy(_alias, asc, false);
}
private SQLBuffer newSQLBuffer(Select sel, ExpContext ctx, ExpState state) {

View File

@ -58,6 +58,7 @@ public class JDBCExpressionFactory
private final ClassMapping _type;
private final SelectConstructor _cons = new SelectConstructor();
private int _getMapValueAlias = 0;
/**
* Constructor. Supply the type we're querying against.
@ -396,6 +397,7 @@ public class JDBCExpressionFactory
}
public Value getMapValue(Value map, Value arg) {
return new GetMapValue((Val) map, (Val) arg);
return new GetMapValue((Val) map, (Val) arg,
"gmv" + _getMapValueAlias++);
}
}