OPENJPA-1050: Use generic types where applicable

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@773180 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Pinaki Poddar 2009-05-09 08:27:44 +00:00
parent 23bd8aa147
commit dc39b6320f
1 changed files with 31 additions and 27 deletions

View File

@ -77,7 +77,7 @@ public class JPQLExpressionBuilder
private static final Localizer _loc = Localizer.forPackage private static final Localizer _loc = Localizer.forPackage
(JPQLExpressionBuilder.class); (JPQLExpressionBuilder.class);
private final Stack contexts = new Stack(); private final Stack<Context> contexts = new Stack<Context>();
private LinkedMap parameterTypes; private LinkedMap parameterTypes;
private int aliasCount = 0; private int aliasCount = 0;
@ -166,7 +166,7 @@ public class JPQLExpressionBuilder
// by the JPA spec, but is required in order to be able to execute // by the JPA spec, but is required in order to be able to execute
// JPQL queries from other facades (like JDO) that do not have // JPQL queries from other facades (like JDO) that do not have
// the concept of entity names or aliases // the concept of entity names or aliases
Class c = resolver.classForName(alias, null); Class<?> c = resolver.classForName(alias, null);
if (c != null) if (c != null)
cmd = repos.getMetaData(c, loader, assertValid); cmd = repos.getMetaData(c, loader, assertValid);
else if (assertValid) else if (assertValid)
@ -185,7 +185,7 @@ public class JPQLExpressionBuilder
return cmd; return cmd;
} }
private Class getCandidateType() { private Class<?> getCandidateType() {
return getCandidateMetaData().getDescribedType(); return getCandidateMetaData().getDescribedType();
} }
@ -433,9 +433,10 @@ public class JPQLExpressionBuilder
JPQLNode selectClause = selectNode. JPQLNode selectClause = selectNode.
findChildByID(JJTSELECTCLAUSE, false); findChildByID(JJTSELECTCLAUSE, false);
if (selectClause != null && selectClause.hasChildID(JJTDISTINCT)) if (selectClause != null && selectClause.hasChildID(JJTDISTINCT))
exps.distinct = exps.DISTINCT_TRUE | exps.DISTINCT_AUTO; exps.distinct = QueryExpressions.DISTINCT_TRUE
| QueryExpressions.DISTINCT_AUTO;
else else
exps.distinct = exps.DISTINCT_FALSE; exps.distinct = QueryExpressions.DISTINCT_FALSE;
JPQLNode constructor = selectNode.findChildByID(JJTCONSTRUCTOR, true); JPQLNode constructor = selectNode.findChildByID(JJTCONSTRUCTOR, true);
if (constructor != null) { if (constructor != null) {
@ -469,7 +470,7 @@ public class JPQLExpressionBuilder
return null; return null;
} }
// JPQL does not filter relational joins for projections // JPQL does not filter relational joins for projections
exps.distinct &= ~exps.DISTINCT_AUTO; exps.distinct &= ~QueryExpressions.DISTINCT_AUTO;
return assignProjections(expNode, exps); return assignProjections(expNode, exps);
} }
} }
@ -488,21 +489,22 @@ public class JPQLExpressionBuilder
Expression filter = null; Expression filter = null;
// handle JOIN FETCH // handle JOIN FETCH
Set joins = null; Set<String> joins = null;
Set innerJoins = null; Set<String> innerJoins = null;
JPQLNode[] outers = root().findChildrenByID(JJTOUTERFETCHJOIN); JPQLNode[] outers = root().findChildrenByID(JJTOUTERFETCHJOIN);
for (int i = 0; outers != null && i < outers.length; i++) for (int i = 0; outers != null && i < outers.length; i++)
(joins == null ? joins = new TreeSet() : joins). (joins == null ? joins = new TreeSet<String>() : joins).
add(getPath(onlyChild(outers[i])).last().getFullName(false)); add(getPath(onlyChild(outers[i])).last().getFullName(false));
JPQLNode[] inners = root().findChildrenByID(JJTINNERFETCHJOIN); JPQLNode[] inners = root().findChildrenByID(JJTINNERFETCHJOIN);
for (int i = 0; inners != null && i < inners.length; i++) { for (int i = 0; inners != null && i < inners.length; i++) {
String path = getPath(onlyChild(inners[i])).last() String path = getPath(onlyChild(inners[i])).last()
.getFullName(false); .getFullName(false);
(joins == null ? joins = new TreeSet() : joins).add(path); (joins == null ? joins = new TreeSet<String>() : joins).add(path);
(innerJoins == null ? innerJoins = new TreeSet() : innerJoins). (innerJoins == null
add(path); ? innerJoins = new TreeSet<String>()
: innerJoins).add(path);
} }
if (joins != null) if (joins != null)
@ -921,13 +923,13 @@ public class JPQLExpressionBuilder
case JJTIN: // x.field [NOT] IN ('a', 'b', 'c') case JJTIN: // x.field [NOT] IN ('a', 'b', 'c')
// TYPE(x...) [NOT] IN (entityTypeLiteral1,...) // TYPE(x...) [NOT] IN (entityTypeLiteral1,...)
Expression inExp = null; Expression inExp = null;
Iterator inIterator = node.iterator(); Iterator<JPQLNode> inIterator = node.iterator();
// the first child is the path // the first child is the path
JPQLNode first = (JPQLNode) inIterator.next(); JPQLNode first = inIterator.next();
val1 = getValue(first); val1 = getValue(first);
while (inIterator.hasNext()) { while (inIterator.hasNext()) {
JPQLNode next = (JPQLNode) inIterator.next(); JPQLNode next = inIterator.next();
if (first.id == JJTTYPE && next.id == JJTTYPELITERAL) if (first.id == JJTTYPE && next.id == JJTTYPELITERAL)
val2 = getTypeLiteral(next); val2 = getTypeLiteral(next);
else else
@ -1269,7 +1271,7 @@ public class JPQLExpressionBuilder
} }
} }
protected void setImplicitTypes(Value val1, Value val2, Class expected) { protected void setImplicitTypes(Value val1, Value val2, Class<?> expected) {
super.setImplicitTypes(val1, val2, expected); super.setImplicitTypes(val1, val2, expected);
// as well as setting the types for conversions, we also need to // as well as setting the types for conversions, we also need to
@ -1288,7 +1290,7 @@ public class JPQLExpressionBuilder
if (fmd == null) if (fmd == null)
return; return;
Class type = path.getType(); Class<?> type = path.getType();
if (type == null) if (type == null)
return; return;
@ -1309,7 +1311,7 @@ public class JPQLExpressionBuilder
return getTypeValue(node, TYPE_NUMBER); return getTypeValue(node, TYPE_NUMBER);
} }
private Value getTypeValue(JPQLNode node, Class implicitType) { private Value getTypeValue(JPQLNode node, Class<?> implicitType) {
Value val = getValue(node); Value val = getValue(node);
setImplicitType(val, implicitType); setImplicitType(val, implicitType);
return val; return val;
@ -1441,7 +1443,7 @@ public class JPQLExpressionBuilder
} else if (val instanceof Value) { } else if (val instanceof Value) {
if (val.isVariable()) { if (val.isVariable()) {
// can be an entity type literal // can be an entity type literal
Class c = resolver.classForName(name, null); Class<?> c = resolver.classForName(name, null);
if (c != null) { if (c != null) {
Value lit = factory.newTypeLiteral(c, Literal.TYPE_CLASS); Value lit = factory.newTypeLiteral(c, Literal.TYPE_CLASS);
Class<?> candidate = getCandidateType(); Class<?> candidate = getCandidateType();
@ -1556,7 +1558,7 @@ public class JPQLExpressionBuilder
final Value val = getVariable(name, false); final Value val = getVariable(name, false);
if (val instanceof Value && val.isVariable()) { if (val instanceof Value && val.isVariable()) {
Class c = resolver.classForName(name, null); Class<?> c = resolver.classForName(name, null);
if (c != null) { if (c != null) {
Value typeLit = factory.newTypeLiteral(c, Literal.TYPE_CLASS); Value typeLit = factory.newTypeLiteral(c, Literal.TYPE_CLASS);
typeLit.setMetaData(getClassMetaData(name, false)); typeLit.setMetaData(getClassMetaData(name, false));
@ -1572,7 +1574,7 @@ public class JPQLExpressionBuilder
// first check to see if the path is an enum or static field, and // first check to see if the path is an enum or static field, and
// if so, load it // if so, load it
String className = assemble(node, ".", 1); String className = assemble(node, ".", 1);
Class c = resolver.classForName(className, null); Class<?> c = resolver.classForName(className, null);
if (c != null) { if (c != null) {
String fieldName = lastChild(node).text; String fieldName = lastChild(node).text;
int type = (c.isEnum() ? Literal.TYPE_ENUM : Literal.TYPE_UNKNOWN); int type = (c.isEnum() ? Literal.TYPE_ENUM : Literal.TYPE_UNKNOWN);
@ -1679,7 +1681,7 @@ public class JPQLExpressionBuilder
return path; return path;
} }
protected Class getDeclaredVariableType(String name) { protected Class<?> getDeclaredVariableType(String name) {
ClassMetaData cmd = getMetaDataForAlias(name); ClassMetaData cmd = getMetaDataForAlias(name);
if (cmd != null) if (cmd != null)
return cmd.getDescribedType(); return cmd.getDescribedType();
@ -1798,7 +1800,7 @@ public class JPQLExpressionBuilder
//////////////////////////// ////////////////////////////
private Context ctx() { private Context ctx() {
return (Context) contexts.peek(); return contexts.peek();
} }
private JPQLNode root() { private JPQLNode root() {
@ -1807,7 +1809,7 @@ public class JPQLExpressionBuilder
private ClassMetaData getMetaDataForAlias(String alias) { private ClassMetaData getMetaDataForAlias(String alias) {
for (int i = contexts.size() - 1; i >= 0; i--) { for (int i = contexts.size() - 1; i >= 0; i--) {
Context context = (Context) contexts.get(i); Context context = contexts.get(i);
if (alias.equalsIgnoreCase(context.schemaAlias)) if (alias.equalsIgnoreCase(context.schemaAlias))
return context.meta; return context.meta;
} }
@ -1903,6 +1905,7 @@ public class JPQLExpressionBuilder
* @see Node * @see Node
* @see SimpleNode * @see SimpleNode
*/ */
@SuppressWarnings("serial")
protected abstract static class JPQLNode protected abstract static class JPQLNode
implements Node, Serializable { implements Node, Serializable {
@ -1995,7 +1998,7 @@ public class JPQLExpressionBuilder
return (JPQLNode) jjtGetChild(index); return (JPQLNode) jjtGetChild(index);
} }
public Iterator iterator() { public Iterator<JPQLNode> iterator() {
return Arrays.asList(children).iterator(); return Arrays.asList(children).iterator();
} }
@ -2060,6 +2063,7 @@ public class JPQLExpressionBuilder
* Public for unit testing purposes. * Public for unit testing purposes.
* @nojavadoc * @nojavadoc
*/ */
@SuppressWarnings("serial")
public static class ParsedJPQL public static class ParsedJPQL
implements Serializable { implements Serializable {
@ -2072,7 +2076,7 @@ public class JPQLExpressionBuilder
// cache of candidate type data. This is stored here in case this // cache of candidate type data. This is stored here in case this
// parse tree is reused in a context that does not know what the // parse tree is reused in a context that does not know what the
// candidate type is already. // candidate type is already.
private Class _candidateType; private Class<?> _candidateType;
ParsedJPQL(String jpql) { ParsedJPQL(String jpql) {
this(jpql, parse(jpql)); this(jpql, parse(jpql));
@ -2113,7 +2117,7 @@ public class JPQLExpressionBuilder
/** /**
* Public for unit testing purposes. * Public for unit testing purposes.
*/ */
public Class getCandidateType() { public Class<?> getCandidateType() {
return _candidateType; return _candidateType;
} }