OPENJPA-1143: refactor method signature to generic type CriteriaQuery<?> as input argument

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@788058 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Pinaki Poddar 2009-06-24 15:48:04 +00:00
parent e57f032626
commit 44443b3ebd
8 changed files with 141 additions and 183 deletions

View File

@ -40,13 +40,13 @@ public class ExpressionImpl<X> extends SelectionImpl<X>
implements Expression<X> {
Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
throw new AbstractMethodError(this.getClass().getName());
}
org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
throw new AbstractMethodError(this.getClass().getName());
}

View File

@ -126,7 +126,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.abs(Expressions.toValue(e, factory, model, q));
}
}
@ -145,7 +145,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
Value v = factory.count(Expressions.toValue(e, factory, model, q));
return _distinct ? factory.distinct(v) : v;
}
@ -158,7 +158,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.avg(Expressions.toValue(e, factory, model, q));
}
}
@ -170,7 +170,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.sqrt(Expressions.toValue(e, factory, model, q));
}
}
@ -182,7 +182,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.max(Expressions.toValue(e, factory, model, q));
}
}
@ -194,7 +194,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.min(Expressions.toValue(e, factory, model, q));
}
}
@ -210,7 +210,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.size(Expressions.toValue(e, factory, model, q));
}
}
@ -224,7 +224,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.type(Expressions.toValue(e, factory, model, q));
}
}
@ -237,7 +237,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.cast(Expressions.toValue(e, factory, model, q), b);
}
}
@ -256,7 +256,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.concat(
Expressions.toValue(e1, factory, model, q),
Expressions.toValue(e2, factory, model, q));
@ -292,7 +292,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return JPQLExpressionBuilder.convertSubstringArguments(factory,
Expressions.toValue(e, factory, model, q),
from == null ? null : from.toValue(factory, model, q),
@ -332,7 +332,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
Value locateSearch = path.toValue(factory, model, q);
Value locateFromIndex = (from == null ?
null : Expressions.toValue(from, factory, model, q));
@ -382,7 +382,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
Boolean spec = null;
if (ts != null) {
switch (ts) {
@ -418,7 +418,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return (e2 == null)
? factory.sum(Expressions.toValue(e1, factory, model, q))
: factory.add(
@ -444,7 +444,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.multiply(
Expressions.toValue(e1, factory, model, q),
Expressions.toValue(e2, factory, model, q));
@ -468,7 +468,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.subtract(
Expressions.toValue(e1, factory, model, q),
Expressions.toValue(e2, factory, model, q));
@ -493,7 +493,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.divide(
Expressions.toValue(e1, factory, model, q),
Expressions.toValue(e2, factory, model, q));
@ -513,7 +513,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.mod(
Expressions.toValue(e1, factory, model, q),
Expressions.toValue(e2, factory, model, q));
@ -527,7 +527,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.getCurrentDate();
}
}
@ -539,7 +539,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.getCurrentTime();
}
}
@ -552,7 +552,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.getCurrentTimestamp();
}
}
@ -574,7 +574,7 @@ public class Expressions {
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
Value val1 = Expressions.toValue(e1, factory, model, q);
Value val2 = Expressions.toValue(e2, factory, model, q);
Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q);
@ -595,7 +595,7 @@ public class Expressions {
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
Value val1 = Expressions.toValue(e1, factory, model, q);
Value val2 = Expressions.toValue(e2, factory, model, q);
Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q);
@ -615,7 +615,7 @@ public class Expressions {
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
Value val1 = Expressions.toValue(e1, factory, model, q);
Value val2 = Expressions.toValue(e2, factory, model, q);
Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q);
@ -635,7 +635,7 @@ public class Expressions {
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
Value val1 = Expressions.toValue(e1, factory, model, q);
Value val2 = Expressions.toValue(e2, factory, model, q);
Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q);
@ -655,7 +655,7 @@ public class Expressions {
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
Value val1 = Expressions.toValue(e1, factory, model, q);
Value val2 = Expressions.toValue(e2, factory, model, q);
Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q);
@ -688,7 +688,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
Object value = arg;
if (arg instanceof ParameterImpl) {
return ((ParameterImpl)arg).toValue(factory, model, q);
@ -731,7 +731,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.newTypeLiteral(arg, Literal.TYPE_CLASS);
}
}
@ -751,7 +751,7 @@ public class Expressions {
@Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
Value val = Expressions.toValue(collection, factory, model, q);
return (isNegated())
? factory.isNotEmpty(val) : factory.isEmpty(val);
@ -766,7 +766,7 @@ public class Expressions {
@Override
public org.apache.openjpa.kernel.exps.Value toValue(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
Value v = Expressions.toValue(e, factory, model, q);
ClassMetaData meta = ((PathImpl)e)._member.fmd.getElement()
.getTypeMetaData();
@ -801,7 +801,7 @@ public class Expressions {
@Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.contains(
Expressions.toValue(collection, factory, model, q),
Expressions.toValue(element, factory, model, q));
@ -850,7 +850,7 @@ public class Expressions {
@Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
String escapeStr = escapeChar == null ? null :
((Character)((Literal)Expressions.toValue(
escapeChar, factory, model, q)).getValue()).toString();
@ -888,7 +888,7 @@ public class Expressions {
@Override
public org.apache.openjpa.kernel.exps.Value toValue(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
Value[] vs = new Value[values.size()];
int i = 0;
for (Expression<?> e : values)
@ -917,7 +917,7 @@ public class Expressions {
@Override
public org.apache.openjpa.kernel.exps.Value toValue(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
Value value1 = Expressions.toValue((ExpressionImpl<?>)val1,
factory, model, q);
Value value2 = Expressions.toValue((ExpressionImpl<?>)val2,
@ -941,7 +941,7 @@ public class Expressions {
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.equal(
Expressions.toValue(e, factory, model, q),
factory.getNull());
@ -963,7 +963,7 @@ public class Expressions {
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.notEqual(
Expressions.toValue(e, factory, model, q),
factory.getNull());
@ -1002,7 +1002,7 @@ public class Expressions {
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
org.apache.openjpa.kernel.exps.Expression inExpr =
super.toKernelExpression(factory, model, q);
IsNotNull notNull = new Expressions.IsNotNull(e);
@ -1061,7 +1061,7 @@ public class Expressions {
@Override
public org.apache.openjpa.kernel.exps.Value toValue(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
int size = whens.size();
org.apache.openjpa.kernel.exps.Expression[] exps =
new org.apache.openjpa.kernel.exps.Expression[size];
@ -1135,7 +1135,7 @@ public class Expressions {
@Override
public org.apache.openjpa.kernel.exps.Value toValue(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
Value caseOperandExpr = Expressions.toValue(
(ExpressionImpl<?>)caseOperand, factory, model, q);
int size = whens.size();
@ -1162,7 +1162,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.toLowerCase(
Expressions.toValue(e, factory, model, q));
}
@ -1175,7 +1175,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.toUpperCase(
Expressions.toValue(e, factory, model, q));
}
@ -1188,7 +1188,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.stringLength(
Expressions.toValue(e, factory, model, q));
}
@ -1209,7 +1209,7 @@ public class Expressions {
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
org.apache.openjpa.kernel.exps.Expression exists =
factory.isNotEmpty(Expressions.toValue(e, factory, model, q));
return isNegated() ? factory.not(exists) : exists;
@ -1225,7 +1225,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.all(Expressions.toValue(e, factory, model, q));
}
}
@ -1239,7 +1239,7 @@ public class Expressions {
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
return factory.any(Expressions.toValue(e, factory, model, q));
}
}
@ -1258,7 +1258,7 @@ public class Expressions {
@Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl q) {
ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
return factory.not(super.toKernelExpression(factory, model, q));
}
}

View File

@ -42,7 +42,7 @@ import org.apache.openjpa.persistence.meta.MetamodelImpl;
import org.apache.openjpa.persistence.meta.Members.Member;
/**
*
* @author Fay Wang
* @author Pinaki Poddar
*
*/
@ -55,13 +55,11 @@ public abstract class Joins {
* @param <Z> type from which joining
* @param <X> type of the attribute being joined
*/
public static class SingularJoin<Z,X> extends FromImpl<Z,X>
implements Join<Z,X>{
public static class SingularJoin<Z,X> extends FromImpl<Z,X> implements Join<Z,X>{
private final JoinType joinType;
private boolean allowNull = false;
public SingularJoin(FromImpl<?,Z> from,
Members.SingularAttributeImpl<? super Z, X> member, JoinType jt) {
public SingularJoin(FromImpl<?,Z> from, Members.SingularAttributeImpl<? super Z, X> member, JoinType jt) {
super(from, member, member.getJavaType());
joinType = jt;
allowNull = joinType != JoinType.INNER;
@ -79,14 +77,12 @@ public abstract class Joins {
* Return the metamodel attribute corresponding to the join.
* @return metamodel attribute type corresponding to the join
*/
// Attribute<? super Z, ?> getAttribute();
public Attribute<? super Z, ?> getAttribute() {
return (Attribute<? super Z, ?> )_member;
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl c) {
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> c) {
ClassMetaData meta = _member.fmd.getDeclaredTypeMetaData();
org.apache.openjpa.kernel.exps.Path path = null;
SubqueryImpl<?> subquery = c.getDelegator();
@ -94,15 +90,12 @@ public abstract class Joins {
if (c.isRegistered(this))
return c.getValue(this);
else if (parent.inSubquery(subquery)) {
org.apache.openjpa.kernel.exps.Subquery subQ =
subquery.getSubQ();
org.apache.openjpa.kernel.exps.Subquery subQ = subquery.getSubQ();
path = factory.newPath(subQ);
path.setMetaData(subQ.getMetaData());
//path.setSchemaAlias(c.getAlias(this));
} else {
path =
(org.apache.openjpa.kernel.exps.Path)
_parent.toValue(factory, model, c);
path = (org.apache.openjpa.kernel.exps.Path) _parent.toValue(factory, model, c);
path.get(_member.fmd, allowNull);
path.setMetaData(meta);
path.setImplicitType(meta.getDescribedType());
@ -111,57 +104,52 @@ public abstract class Joins {
}
@Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl c) {
public org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory,
MetamodelImpl model, CriteriaQueryImpl<?> c) {
ClassMetaData meta = _member.fmd.getDeclaredTypeMetaData();
org.apache.openjpa.kernel.exps.Path path = null;
SubqueryImpl<?> subquery = c.getDelegator();
PathImpl<?,?> parent = getInnermostParentPath();
org.apache.openjpa.kernel.exps.Expression filter = null;
PathImpl correlatedParent = null;
PathImpl<?,?> correlatedParent = null;
boolean bind = true;
if (parent.inSubquery(subquery)) {
org.apache.openjpa.kernel.exps.Subquery subQ =
subquery.getSubQ();
org.apache.openjpa.kernel.exps.Subquery subQ = subquery.getSubQ();
path = factory.newPath(subQ);
correlatedParent = _parent.getCorrelatedParent();
if (correlatedParent == null) {
path.setMetaData(subQ.getMetaData());
path.get(_member.fmd, allowNull);
//path.setSchemaAlias(c.getAlias(_parent));
} else
} else {
bind = false;
}
} else if (c.isRegistered(_parent)) {
Value var = c.getVariable(_parent);
path = factory.newPath(var);
path.setMetaData(meta);
path.get(_member.fmd, false);
} else
path =
(org.apache.openjpa.kernel.exps.Path)toValue(factory, model, c);
} else {
path = (org.apache.openjpa.kernel.exps.Path)toValue(factory, model, c);
}
org.apache.openjpa.kernel.exps.Expression join = null;
if (bind) {
Value var = factory.newBoundVariable(c.getAlias(this),
meta.getDescribedType());
Value var = factory.newBoundVariable(c.getAlias(this), meta.getDescribedType());
join = factory.bindVariable(var, path);
c.registerVariable(this, var, path);
}
if (getJoins() != null) {
for (Join<?, ?> join1 : getJoins()) {
filter = CriteriaExpressionBuilder.and(factory,
((FromImpl<?,?>)join1).
toKernelExpression(factory, model, c), filter);
((FromImpl<?,?>)join1).toKernelExpression(factory, model, c), filter);
}
}
org.apache.openjpa.kernel.exps.Expression expr =
CriteriaExpressionBuilder.and(factory, join, filter);
org.apache.openjpa.kernel.exps.Expression expr = CriteriaExpressionBuilder.and(factory, join, filter);
if (correlatedParent == null)
if (correlatedParent == null) {
return expr;
else {
org.apache.openjpa.kernel.exps.Path parentPath =
(org.apache.openjpa.kernel.exps.Path)
} else {
org.apache.openjpa.kernel.exps.Path parentPath = (org.apache.openjpa.kernel.exps.Path)
correlatedParent.toValue(factory, model, c);
parentPath.get(_member.fmd, allowNull);
//parentPath.setSchemaAlias(c.getAlias(correlatedParent));
@ -186,8 +174,8 @@ public abstract class Joins {
final JoinType joinType;
boolean allowNull = false;
public AbstractCollection(FromImpl<?,Z> from,
Members.PluralAttributeImpl<? super Z, C, E> member, JoinType jt) {
public AbstractCollection(FromImpl<?,Z> from, Members.PluralAttributeImpl<? super Z, C, E> member,
JoinType jt) {
super(from, member, member.getBindableJavaType());
joinType = jt;
allowNull = joinType != JoinType.INNER;
@ -225,7 +213,7 @@ public abstract class Joins {
*/
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl c) {
CriteriaQueryImpl<?> c) {
ClassMetaData meta = getMemberClassMetaData();
org.apache.openjpa.kernel.exps.Path path = null;
SubqueryImpl<?> subquery = c.getDelegator();
@ -235,14 +223,12 @@ public abstract class Joins {
Value var = c.getVariable(this);
path = factory.newPath(var);
} else if (parent.inSubquery(subquery)) {
org.apache.openjpa.kernel.exps.Subquery subQ =
subquery.getSubQ();
org.apache.openjpa.kernel.exps.Subquery subQ = subquery.getSubQ();
path = factory.newPath(subQ);
path.setMetaData(subQ.getMetaData());
//path.setSchemaAlias(c.getAlias(this));
} else {
path = (org.apache.openjpa.kernel.exps.Path)
_parent.toValue(factory, model, c);
path = (org.apache.openjpa.kernel.exps.Path) _parent.toValue(factory, model, c);
path.get(_member.fmd, allowNull);
}
return path;
@ -255,7 +241,7 @@ public abstract class Joins {
@Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl c) {
CriteriaQueryImpl<?> c) {
ClassMetaData meta = getMemberClassMetaData();
org.apache.openjpa.kernel.exps.Path path = null;
SubqueryImpl<?> subquery = c.getDelegator();
@ -264,46 +250,41 @@ public abstract class Joins {
PathImpl correlatedParent = null;
boolean bind = true;
if (parent.inSubquery(subquery)) {
org.apache.openjpa.kernel.exps.Subquery subQ =
subquery.getSubQ();
org.apache.openjpa.kernel.exps.Subquery subQ = subquery.getSubQ();
path = factory.newPath(subQ);
correlatedParent = _parent.getCorrelatedParent();
if (correlatedParent == null) {
path.setMetaData(subQ.getMetaData());
path.get(_member.fmd, allowNull);
//path.setSchemaAlias(c.getAlias(_parent));
} else
} else {
bind = false;
}
} else if (c.isRegistered(_parent)) {
Value var = c.getVariable(_parent);
path = factory.newPath(var);
path.setMetaData(meta);
path.get(_member.fmd, false);
} else
path = (org.apache.openjpa.kernel.exps.Path)
toValue(factory, model, c);
} else {
path = (org.apache.openjpa.kernel.exps.Path)toValue(factory, model, c);
}
org.apache.openjpa.kernel.exps.Expression join = null;
if (bind) {
Value var = factory.newBoundVariable(c.getAlias(this),
meta.getDescribedType());
Value var = factory.newBoundVariable(c.getAlias(this), meta.getDescribedType());
join = factory.bindVariable(var, path);
c.registerVariable(this, var, path);
}
if (getJoins() != null) {
for (Join<?, ?> join1 : getJoins()) {
filter = CriteriaExpressionBuilder.and(factory,
((FromImpl<?,?>)join1).
toKernelExpression(factory, model, c), filter);
((FromImpl<?,?>)join1).toKernelExpression(factory, model, c), filter);
}
}
org.apache.openjpa.kernel.exps.Expression expr =
CriteriaExpressionBuilder.and(factory, join, filter);
if (correlatedParent == null)
org.apache.openjpa.kernel.exps.Expression expr = CriteriaExpressionBuilder.and(factory, join, filter);
if (correlatedParent == null) {
return expr;
else {
org.apache.openjpa.kernel.exps.Path parentPath =
(org.apache.openjpa.kernel.exps.Path)
} else {
org.apache.openjpa.kernel.exps.Path parentPath = (org.apache.openjpa.kernel.exps.Path)
correlatedParent.toValue(factory, model, c);
parentPath.get(_member.fmd, allowNull);
//parentPath.setSchemaAlias(c.getAlias(correlatedParent));
@ -321,8 +302,7 @@ public abstract class Joins {
* @param <Z>
* @param <E>
*/
public static class Collection<Z,E>
extends AbstractCollection<Z,java.util.Collection<E>,E>
public static class Collection<Z,E> extends AbstractCollection<Z,java.util.Collection<E>,E>
implements CollectionJoin<Z,E>{
public Collection(FromImpl<?,Z> parent,
Members.CollectionAttributeImpl<? super Z, E> member, JoinType jt) {
@ -341,8 +321,7 @@ public abstract class Joins {
* @param <Z>
* @param <E>
*/
public static class Set<Z,E>
extends AbstractCollection<Z,java.util.Set<E>,E>
public static class Set<Z,E> extends AbstractCollection<Z,java.util.Set<E>,E>
implements SetJoin<Z,E>{
public Set(FromImpl<?,Z> parent, Members.SetAttributeImpl<? super Z, E> member, JoinType jt) {
super(parent, member, jt);
@ -360,8 +339,7 @@ public abstract class Joins {
* @param <E>
*/
public static class List<Z,E>
extends AbstractCollection<Z,java.util.List<E>,E>
public static class List<Z,E> extends AbstractCollection<Z,java.util.List<E>,E>
implements ListJoin<Z,E> {
public List(FromImpl<?,Z> parent,
@ -385,8 +363,7 @@ public abstract class Joins {
* @param <E>
*/
public static class Map<Z,K,V>
extends AbstractCollection<Z,java.util.Map<K,V>,V>
public static class Map<Z,K,V> extends AbstractCollection<Z,java.util.Map<K,V>,V>
implements MapJoin<Z,K,V> {
public Map(FromImpl<?,Z> parent, Members.MapAttributeImpl<? super Z, K,V> member, JoinType jt) {
@ -418,20 +395,16 @@ public abstract class Joins {
}
@Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl c) {
org.apache.openjpa.kernel.exps.Value path = toValue
(factory, model, c);
public org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory,
MetamodelImpl model, CriteriaQueryImpl<?> c) {
org.apache.openjpa.kernel.exps.Value path = toValue(factory, model, c);
ClassMetaData meta = _member.fmd.isElementCollection()
? _member.fmd.getEmbeddedMetaData()
: _member.fmd.getElement().getDeclaredTypeMetaData();
Value var = factory.newBoundVariable(c.getAlias(this),
meta.getDescribedType());
org.apache.openjpa.kernel.exps.Expression join = factory
.bindValueVariable(var, path);
Value var = factory.newBoundVariable(c.getAlias(this), meta.getDescribedType());
org.apache.openjpa.kernel.exps.Expression join = factory.bindValueVariable(var, path);
c.registerVariable(this, var, path);
return join;
}
@ -440,9 +413,9 @@ public abstract class Joins {
public static class MapKey<Z,K> extends PathImpl<Z,K> {
Map<?,K,?> map;
public MapKey(Map<Z,K,?> joinMap){
super(((MapAttribute<Z, K, ?>)joinMap.getAttribute())
.getKeyJavaType());
super(((MapAttribute<Z, K, ?>)joinMap.getAttribute()).getKeyJavaType());
this.map = joinMap;
}
@ -451,10 +424,8 @@ public abstract class Joins {
*
*/
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl c) {
org.apache.openjpa.kernel.exps.Path path =
factory.newPath(c.getVariable(map));
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> c) {
org.apache.openjpa.kernel.exps.Path path = factory.newPath(c.getVariable(map));
return factory.getKey(path);
}
}

View File

@ -59,7 +59,7 @@ public class ParameterImpl<T> extends ExpressionImpl<T> implements ParameterExpr
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
q.registerParameter(this);

View File

@ -34,7 +34,6 @@ import org.apache.openjpa.kernel.exps.ExpressionFactory;
import org.apache.openjpa.kernel.exps.Value;
import org.apache.openjpa.meta.ClassMetaData;
import org.apache.openjpa.meta.FieldMetaData;
import org.apache.openjpa.meta.JavaTypes;
import org.apache.openjpa.persistence.meta.Members;
import org.apache.openjpa.persistence.meta.MetamodelImpl;
@ -107,7 +106,7 @@ public class PathImpl<Z,X> extends ExpressionImpl<X> implements Path<X> {
}
protected FieldMetaData getEmbeddedFieldMetaData(FieldMetaData fmd) {
Members.Member member = getInnermostMember(_parent,_member);
Members.Member<?,?> member = getInnermostMember(_parent,_member);
ClassMetaData embeddedMeta = member.fmd.getEmbeddedMetaData();
if (embeddedMeta != null)
return embeddedMeta.getField(fmd.getName());
@ -115,8 +114,7 @@ public class PathImpl<Z,X> extends ExpressionImpl<X> implements Path<X> {
return fmd;
}
protected Members.Member getInnermostMember(PathImpl parent,
Members.Member member) {
protected Members.Member<?,?> getInnermostMember(PathImpl<?,?> parent, Members.Member<?,?> member) {
return member != null ? member : getInnermostMember(parent._parent,
parent._member);
}
@ -134,7 +132,7 @@ public class PathImpl<Z,X> extends ExpressionImpl<X> implements Path<X> {
*/
@Override
public Value toValue(
ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl q) {
ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
if (q.isRegistered(this))
return q.getValue(this);
org.apache.openjpa.kernel.exps.Path path = null;
@ -161,10 +159,8 @@ public class PathImpl<Z,X> extends ExpressionImpl<X> implements Path<X> {
path = factory.newPath();
path.setMetaData(model.repos.getCachedMetaData(getJavaType()));
}
if (_member != null) {
int typeCode = _member.fmd.getDeclaredTypeCode();
if (typeCode != JavaTypes.COLLECTION && typeCode != JavaTypes.MAP)
path.setImplicitType(getJavaType());
if (_member != null && !_member.isCollection()) {
path.setImplicitType(getJavaType());
}
path.setAlias(q.getAlias(this));
return path;
@ -177,8 +173,7 @@ public class PathImpl<Z,X> extends ExpressionImpl<X> implements Path<X> {
return subquery != null && subquery.getRoots().contains(this);
}
protected void traversePath(PathImpl<?,?> parent,
org.apache.openjpa.kernel.exps.Path path, FieldMetaData fmd) {
protected void traversePath(PathImpl<?,?> parent, org.apache.openjpa.kernel.exps.Path path, FieldMetaData fmd) {
boolean allowNull = parent == null ? false : parent instanceof Join
&& ((Join<?,?>)parent).getJoinType() != JoinType.INNER;
FieldMetaData fmd1 = parent._member == null ? null : parent._member.fmd;
@ -212,12 +207,9 @@ public class PathImpl<Z,X> extends ExpressionImpl<X> implements Path<X> {
* collection-valued attribute.
* @param collection collection-valued attribute
* @return expression corresponding to the referenced attribute
// <E, C extends java.util.Collection<E>> Expression<C> get(PluralAttribute<X, C, E> collection);
*/
public <E, C extends java.util.Collection<E>> Expression<C>
get(PluralAttribute<X, C, E> coll) {
return new PathImpl<X,C>(this, (Members.Member<? super X, C>)coll,
coll.getJavaType());
public <E, C extends java.util.Collection<E>> Expression<C> get(PluralAttribute<X, C, E> coll) {
return new PathImpl<X,C>(this, (Members.Member<? super X, C>)coll, coll.getJavaType());
}
/**
@ -226,11 +218,8 @@ public class PathImpl<Z,X> extends ExpressionImpl<X> implements Path<X> {
* @param map map-valued attribute
* @return expression corresponding to the referenced attribute
*/
// <K, V, M extends java.util.Map<K, V>> Expression<M> get(MapAttribute<X, K, V> map);
public <K, V, M extends java.util.Map<K, V>> Expression<M>
get(MapAttribute<X, K, V> map) {
return new PathImpl<X,M>(this, (Members.MapAttributeImpl<? super X,K,V>)map,
(Class<M>)map.getJavaType());
public <K, V, M extends java.util.Map<K, V>> Expression<M> get(MapAttribute<X, K, V> map) {
return new PathImpl<X,M>(this, (Members.MapAttributeImpl<? super X,K,V>)map, (Class<M>)map.getJavaType());
}
public <Y> Path<Y> get(String attName) {
@ -239,8 +228,7 @@ public class PathImpl<Z,X> extends ExpressionImpl<X> implements Path<X> {
switch (type.getPersistenceType()) {
case BASIC:
throw new RuntimeException(attName + " not navigable from " + this);
default: next = (Members.Member<? super X, Y>)
((ManagedType<?>)type).getAttribute(attName);
default: next = (Members.Member<? super X, Y>) ((ManagedType<?>)type).getAttribute(attName);
}
return new PathImpl<X,Y>(this, next, (Class<Y>)type.getClass());
}

View File

@ -85,7 +85,7 @@ implements Predicate {
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
if (_exps == null || _exps.isEmpty())
return factory.emptyExpression();
if (_exps.size() == 1)

View File

@ -68,7 +68,7 @@ public class RootImpl<X> extends FromImpl<X,X> implements Root<X> {
*/
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl c) {
CriteriaQueryImpl<?> c) {
SubqueryImpl<?> subquery = c.getDelegator();
Path var = null;
if (inSubquery(subquery)) {
@ -87,7 +87,7 @@ public class RootImpl<X> extends FromImpl<X,X> implements Root<X> {
*/
@Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl c) {
ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> c) {
Value path = toValue(factory, model, c);
Value var = factory.newBoundVariable(c.getAlias(this),
_entity.meta.getDescribedType());

View File

@ -39,8 +39,10 @@ import org.apache.openjpa.kernel.exps.QueryExpressions;
import org.apache.openjpa.kernel.exps.Value;
import org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder;
import org.apache.openjpa.meta.ClassMetaData;
import org.apache.openjpa.meta.FieldMetaData;
import org.apache.openjpa.meta.JavaTypes;
import org.apache.openjpa.persistence.meta.AbstractManagedType;
import org.apache.openjpa.persistence.meta.Members;
import org.apache.openjpa.persistence.meta.MetamodelImpl;
import org.apache.openjpa.persistence.meta.Types;
@ -54,31 +56,31 @@ import org.apache.openjpa.persistence.meta.Types;
* @param <T> the type selected by this subquery.
*/
public class SubqueryImpl<T> extends ExpressionImpl<T> implements Subquery<T> {
private final AbstractQuery _parent;
private final CriteriaQueryImpl _delegate;
private final AbstractQuery<?> _parent;
private final CriteriaQueryImpl<T> _delegate;
private final MetamodelImpl _model;
private java.util.Set<Join<?,?>> _joins;
private Expression<T> _select;
private org.apache.openjpa.kernel.exps.Subquery _subq;
public SubqueryImpl(Class<T> cls, AbstractQuery parent) {
public SubqueryImpl(Class<T> cls, AbstractQuery<?> parent) {
super(cls);
_parent = parent;
if (parent instanceof CriteriaQueryImpl)
_model = ((CriteriaQueryImpl)parent).getMetamodel();
else if (parent instanceof SubqueryImpl)
_model = ((SubqueryImpl)parent).getMetamodel();
else
if (parent instanceof CriteriaQueryImpl) {
_model = ((CriteriaQueryImpl<?>)parent).getMetamodel();
} else if (parent instanceof SubqueryImpl) {
_model = ((SubqueryImpl<?>)parent).getMetamodel();
} else {
_model = null;
_delegate = new CriteriaQueryImpl(_model, this);
}
_delegate = new CriteriaQueryImpl<T>(_model, this);
}
public AbstractQuery getParent() {
public AbstractQuery<?> getParent() {
return _parent;
}
public CriteriaQueryImpl getDelegate() {
public CriteriaQueryImpl<T> getDelegate() {
return _delegate;
}
@ -90,9 +92,9 @@ public class SubqueryImpl<T> extends ExpressionImpl<T> implements Subquery<T> {
// return getInnermostParent().getContexts();
//}
public CriteriaQueryImpl getInnermostParent() {
return (CriteriaQueryImpl)(((_parent instanceof CriteriaQueryImpl)) ?
_parent : ((SubqueryImpl)_parent).getInnermostParent());
public CriteriaQueryImpl<?> getInnermostParent() {
return (CriteriaQueryImpl<?>)(((_parent instanceof CriteriaQueryImpl)) ?
_parent : ((SubqueryImpl<?>)_parent).getInnermostParent());
}
public Subquery<T> select(Expression<T> expression) {
@ -172,8 +174,7 @@ public class SubqueryImpl<T> extends ExpressionImpl<T> implements Subquery<T> {
}
public <Y> Root<Y> correlate(Root<Y> root) {
Types.Entity<Y> entity =
(Types.Entity<Y>)((RootImpl<Y>)root).getModel();
Types.Entity<Y> entity = (Types.Entity<Y>)root.getModel();
RootImpl<Y> corrRoot = new RootImpl<Y>(entity);
corrRoot.setCorrelatedParent((RootImpl<Y>)root);
Set<Root<?>> roots = getRoots();
@ -222,7 +223,7 @@ public class SubqueryImpl<T> extends ExpressionImpl<T> implements Subquery<T> {
*/
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) {
CriteriaQueryImpl<?> q) {
final boolean subclasses = true;
CriteriaExpressionBuilder queryEval = new CriteriaExpressionBuilder();
String alias = q.getAlias(this);
@ -250,15 +251,13 @@ public class SubqueryImpl<T> extends ExpressionImpl<T> implements Subquery<T> {
RootImpl<?> root = (RootImpl<?>)getRoot();
RootImpl<?> correlatedRoot = (RootImpl<?>)root.getCorrelatedParent();
if (correlatedRoot != null && root.getJoins() != null) {
FromImpl join = (FromImpl) root.getJoins().iterator().next();
if (join._member.fmd.getDeclaredTypeCode() ==
JavaTypes.COLLECTION ||
join._member.fmd.getDeclaredTypeCode() ==
JavaTypes.MAP)
return join._member.fmd.isElementCollection()
? join._member.fmd.getEmbeddedMetaData()
: join._member.fmd.getElement().getDeclaredTypeMetaData();
return join._member.fmd.getDeclaredTypeMetaData();
Join<?,?> join = root.getJoins().iterator().next();
FieldMetaData fmd = ((Members.Member<?, ?>)join.getAttribute()).fmd;
if (join.getAttribute().isCollection()) {
return fmd.isElementCollection() ? fmd.getEmbeddedMetaData(): fmd.getElement().getDeclaredTypeMetaData();
} else {
return fmd.getDeclaredTypeMetaData();
}
}
return ((AbstractManagedType<?>)root.getModel()).meta;
}