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> { implements Expression<X> {
Value toValue(ExpressionFactory factory, MetamodelImpl model, Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
throw new AbstractMethodError(this.getClass().getName()); throw new AbstractMethodError(this.getClass().getName());
} }
org.apache.openjpa.kernel.exps.Expression toKernelExpression( org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
throw new AbstractMethodError(this.getClass().getName()); throw new AbstractMethodError(this.getClass().getName());
} }

View File

@ -126,7 +126,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.abs(Expressions.toValue(e, factory, model, q)); return factory.abs(Expressions.toValue(e, factory, model, q));
} }
} }
@ -145,7 +145,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
Value v = factory.count(Expressions.toValue(e, factory, model, q)); Value v = factory.count(Expressions.toValue(e, factory, model, q));
return _distinct ? factory.distinct(v) : v; return _distinct ? factory.distinct(v) : v;
} }
@ -158,7 +158,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.avg(Expressions.toValue(e, factory, model, q)); return factory.avg(Expressions.toValue(e, factory, model, q));
} }
} }
@ -170,7 +170,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.sqrt(Expressions.toValue(e, factory, model, q)); return factory.sqrt(Expressions.toValue(e, factory, model, q));
} }
} }
@ -182,7 +182,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.max(Expressions.toValue(e, factory, model, q)); return factory.max(Expressions.toValue(e, factory, model, q));
} }
} }
@ -194,7 +194,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.min(Expressions.toValue(e, factory, model, q)); return factory.min(Expressions.toValue(e, factory, model, q));
} }
} }
@ -210,7 +210,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.size(Expressions.toValue(e, factory, model, q)); return factory.size(Expressions.toValue(e, factory, model, q));
} }
} }
@ -224,7 +224,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.type(Expressions.toValue(e, factory, model, q)); return factory.type(Expressions.toValue(e, factory, model, q));
} }
} }
@ -237,7 +237,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.cast(Expressions.toValue(e, factory, model, q), b); return factory.cast(Expressions.toValue(e, factory, model, q), b);
} }
} }
@ -256,7 +256,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.concat( return factory.concat(
Expressions.toValue(e1, factory, model, q), Expressions.toValue(e1, factory, model, q),
Expressions.toValue(e2, factory, model, q)); Expressions.toValue(e2, factory, model, q));
@ -292,7 +292,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return JPQLExpressionBuilder.convertSubstringArguments(factory, return JPQLExpressionBuilder.convertSubstringArguments(factory,
Expressions.toValue(e, factory, model, q), Expressions.toValue(e, factory, model, q),
from == null ? null : from.toValue(factory, model, q), from == null ? null : from.toValue(factory, model, q),
@ -332,7 +332,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
Value locateSearch = path.toValue(factory, model, q); Value locateSearch = path.toValue(factory, model, q);
Value locateFromIndex = (from == null ? Value locateFromIndex = (from == null ?
null : Expressions.toValue(from, factory, model, q)); null : Expressions.toValue(from, factory, model, q));
@ -382,7 +382,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
Boolean spec = null; Boolean spec = null;
if (ts != null) { if (ts != null) {
switch (ts) { switch (ts) {
@ -418,7 +418,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return (e2 == null) return (e2 == null)
? factory.sum(Expressions.toValue(e1, factory, model, q)) ? factory.sum(Expressions.toValue(e1, factory, model, q))
: factory.add( : factory.add(
@ -444,7 +444,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.multiply( return factory.multiply(
Expressions.toValue(e1, factory, model, q), Expressions.toValue(e1, factory, model, q),
Expressions.toValue(e2, factory, model, q)); Expressions.toValue(e2, factory, model, q));
@ -468,7 +468,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.subtract( return factory.subtract(
Expressions.toValue(e1, factory, model, q), Expressions.toValue(e1, factory, model, q),
Expressions.toValue(e2, factory, model, q)); Expressions.toValue(e2, factory, model, q));
@ -493,7 +493,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.divide( return factory.divide(
Expressions.toValue(e1, factory, model, q), Expressions.toValue(e1, factory, model, q),
Expressions.toValue(e2, factory, model, q)); Expressions.toValue(e2, factory, model, q));
@ -513,7 +513,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.mod( return factory.mod(
Expressions.toValue(e1, factory, model, q), Expressions.toValue(e1, factory, model, q),
Expressions.toValue(e2, factory, model, q)); Expressions.toValue(e2, factory, model, q));
@ -527,7 +527,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.getCurrentDate(); return factory.getCurrentDate();
} }
} }
@ -539,7 +539,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.getCurrentTime(); return factory.getCurrentTime();
} }
} }
@ -552,7 +552,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.getCurrentTimestamp(); return factory.getCurrentTimestamp();
} }
} }
@ -574,7 +574,7 @@ public class Expressions {
@Override @Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression( org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
Value val1 = Expressions.toValue(e1, factory, model, q); Value val1 = Expressions.toValue(e1, factory, model, q);
Value val2 = Expressions.toValue(e2, factory, model, q); Value val2 = Expressions.toValue(e2, factory, model, q);
Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q); Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q);
@ -595,7 +595,7 @@ public class Expressions {
@Override @Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression( org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
Value val1 = Expressions.toValue(e1, factory, model, q); Value val1 = Expressions.toValue(e1, factory, model, q);
Value val2 = Expressions.toValue(e2, factory, model, q); Value val2 = Expressions.toValue(e2, factory, model, q);
Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q); Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q);
@ -615,7 +615,7 @@ public class Expressions {
@Override @Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression( org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
Value val1 = Expressions.toValue(e1, factory, model, q); Value val1 = Expressions.toValue(e1, factory, model, q);
Value val2 = Expressions.toValue(e2, factory, model, q); Value val2 = Expressions.toValue(e2, factory, model, q);
Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q); Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q);
@ -635,7 +635,7 @@ public class Expressions {
@Override @Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression( org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
Value val1 = Expressions.toValue(e1, factory, model, q); Value val1 = Expressions.toValue(e1, factory, model, q);
Value val2 = Expressions.toValue(e2, factory, model, q); Value val2 = Expressions.toValue(e2, factory, model, q);
Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q); Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q);
@ -655,7 +655,7 @@ public class Expressions {
@Override @Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression( org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
Value val1 = Expressions.toValue(e1, factory, model, q); Value val1 = Expressions.toValue(e1, factory, model, q);
Value val2 = Expressions.toValue(e2, factory, model, q); Value val2 = Expressions.toValue(e2, factory, model, q);
Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q); Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q);
@ -688,7 +688,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
Object value = arg; Object value = arg;
if (arg instanceof ParameterImpl) { if (arg instanceof ParameterImpl) {
return ((ParameterImpl)arg).toValue(factory, model, q); return ((ParameterImpl)arg).toValue(factory, model, q);
@ -731,7 +731,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.newTypeLiteral(arg, Literal.TYPE_CLASS); return factory.newTypeLiteral(arg, Literal.TYPE_CLASS);
} }
} }
@ -751,7 +751,7 @@ public class Expressions {
@Override @Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression( public org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
Value val = Expressions.toValue(collection, factory, model, q); Value val = Expressions.toValue(collection, factory, model, q);
return (isNegated()) return (isNegated())
? factory.isNotEmpty(val) : factory.isEmpty(val); ? factory.isNotEmpty(val) : factory.isEmpty(val);
@ -766,7 +766,7 @@ public class Expressions {
@Override @Override
public org.apache.openjpa.kernel.exps.Value toValue( public org.apache.openjpa.kernel.exps.Value toValue(
ExpressionFactory factory, MetamodelImpl model, ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
Value v = Expressions.toValue(e, factory, model, q); Value v = Expressions.toValue(e, factory, model, q);
ClassMetaData meta = ((PathImpl)e)._member.fmd.getElement() ClassMetaData meta = ((PathImpl)e)._member.fmd.getElement()
.getTypeMetaData(); .getTypeMetaData();
@ -801,7 +801,7 @@ public class Expressions {
@Override @Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression( public org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.contains( return factory.contains(
Expressions.toValue(collection, factory, model, q), Expressions.toValue(collection, factory, model, q),
Expressions.toValue(element, factory, model, q)); Expressions.toValue(element, factory, model, q));
@ -850,7 +850,7 @@ public class Expressions {
@Override @Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression( public org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
String escapeStr = escapeChar == null ? null : String escapeStr = escapeChar == null ? null :
((Character)((Literal)Expressions.toValue( ((Character)((Literal)Expressions.toValue(
escapeChar, factory, model, q)).getValue()).toString(); escapeChar, factory, model, q)).getValue()).toString();
@ -888,7 +888,7 @@ public class Expressions {
@Override @Override
public org.apache.openjpa.kernel.exps.Value toValue( public org.apache.openjpa.kernel.exps.Value toValue(
ExpressionFactory factory, MetamodelImpl model, ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
Value[] vs = new Value[values.size()]; Value[] vs = new Value[values.size()];
int i = 0; int i = 0;
for (Expression<?> e : values) for (Expression<?> e : values)
@ -917,7 +917,7 @@ public class Expressions {
@Override @Override
public org.apache.openjpa.kernel.exps.Value toValue( public org.apache.openjpa.kernel.exps.Value toValue(
ExpressionFactory factory, MetamodelImpl model, ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
Value value1 = Expressions.toValue((ExpressionImpl<?>)val1, Value value1 = Expressions.toValue((ExpressionImpl<?>)val1,
factory, model, q); factory, model, q);
Value value2 = Expressions.toValue((ExpressionImpl<?>)val2, Value value2 = Expressions.toValue((ExpressionImpl<?>)val2,
@ -941,7 +941,7 @@ public class Expressions {
@Override @Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression( org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.equal( return factory.equal(
Expressions.toValue(e, factory, model, q), Expressions.toValue(e, factory, model, q),
factory.getNull()); factory.getNull());
@ -963,7 +963,7 @@ public class Expressions {
@Override @Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression( org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.notEqual( return factory.notEqual(
Expressions.toValue(e, factory, model, q), Expressions.toValue(e, factory, model, q),
factory.getNull()); factory.getNull());
@ -1002,7 +1002,7 @@ public class Expressions {
@Override @Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression( org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
org.apache.openjpa.kernel.exps.Expression inExpr = org.apache.openjpa.kernel.exps.Expression inExpr =
super.toKernelExpression(factory, model, q); super.toKernelExpression(factory, model, q);
IsNotNull notNull = new Expressions.IsNotNull(e); IsNotNull notNull = new Expressions.IsNotNull(e);
@ -1061,7 +1061,7 @@ public class Expressions {
@Override @Override
public org.apache.openjpa.kernel.exps.Value toValue( public org.apache.openjpa.kernel.exps.Value toValue(
ExpressionFactory factory, MetamodelImpl model, ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
int size = whens.size(); int size = whens.size();
org.apache.openjpa.kernel.exps.Expression[] exps = org.apache.openjpa.kernel.exps.Expression[] exps =
new org.apache.openjpa.kernel.exps.Expression[size]; new org.apache.openjpa.kernel.exps.Expression[size];
@ -1135,7 +1135,7 @@ public class Expressions {
@Override @Override
public org.apache.openjpa.kernel.exps.Value toValue( public org.apache.openjpa.kernel.exps.Value toValue(
ExpressionFactory factory, MetamodelImpl model, ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
Value caseOperandExpr = Expressions.toValue( Value caseOperandExpr = Expressions.toValue(
(ExpressionImpl<?>)caseOperand, factory, model, q); (ExpressionImpl<?>)caseOperand, factory, model, q);
int size = whens.size(); int size = whens.size();
@ -1162,7 +1162,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.toLowerCase( return factory.toLowerCase(
Expressions.toValue(e, factory, model, q)); Expressions.toValue(e, factory, model, q));
} }
@ -1175,7 +1175,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.toUpperCase( return factory.toUpperCase(
Expressions.toValue(e, factory, model, q)); Expressions.toValue(e, factory, model, q));
} }
@ -1188,7 +1188,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.stringLength( return factory.stringLength(
Expressions.toValue(e, factory, model, q)); Expressions.toValue(e, factory, model, q));
} }
@ -1209,7 +1209,7 @@ public class Expressions {
@Override @Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression( org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
org.apache.openjpa.kernel.exps.Expression exists = org.apache.openjpa.kernel.exps.Expression exists =
factory.isNotEmpty(Expressions.toValue(e, factory, model, q)); factory.isNotEmpty(Expressions.toValue(e, factory, model, q));
return isNegated() ? factory.not(exists) : exists; return isNegated() ? factory.not(exists) : exists;
@ -1225,7 +1225,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.all(Expressions.toValue(e, factory, model, q)); return factory.all(Expressions.toValue(e, factory, model, q));
} }
} }
@ -1239,7 +1239,7 @@ public class Expressions {
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl q) { CriteriaQueryImpl<?> q) {
return factory.any(Expressions.toValue(e, factory, model, q)); return factory.any(Expressions.toValue(e, factory, model, q));
} }
} }
@ -1258,7 +1258,7 @@ public class Expressions {
@Override @Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression( 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)); 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; import org.apache.openjpa.persistence.meta.Members.Member;
/** /**
* * @author Fay Wang
* @author Pinaki Poddar * @author Pinaki Poddar
* *
*/ */
@ -55,13 +55,11 @@ public abstract class Joins {
* @param <Z> type from which joining * @param <Z> type from which joining
* @param <X> type of the attribute being joined * @param <X> type of the attribute being joined
*/ */
public static class SingularJoin<Z,X> extends FromImpl<Z,X> public static class SingularJoin<Z,X> extends FromImpl<Z,X> implements Join<Z,X>{
implements Join<Z,X>{
private final JoinType joinType; private final JoinType joinType;
private boolean allowNull = false; private boolean allowNull = false;
public SingularJoin(FromImpl<?,Z> from, public SingularJoin(FromImpl<?,Z> from, Members.SingularAttributeImpl<? super Z, X> member, JoinType jt) {
Members.SingularAttributeImpl<? super Z, X> member, JoinType jt) {
super(from, member, member.getJavaType()); super(from, member, member.getJavaType());
joinType = jt; joinType = jt;
allowNull = joinType != JoinType.INNER; allowNull = joinType != JoinType.INNER;
@ -79,14 +77,12 @@ public abstract class Joins {
* Return the metamodel attribute corresponding to the join. * Return the metamodel attribute corresponding to the join.
* @return metamodel attribute type corresponding to the join * @return metamodel attribute type corresponding to the join
*/ */
// Attribute<? super Z, ?> getAttribute();
public Attribute<? super Z, ?> getAttribute() { public Attribute<? super Z, ?> getAttribute() {
return (Attribute<? super Z, ?> )_member; return (Attribute<? super Z, ?> )_member;
} }
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> c) {
CriteriaQueryImpl c) {
ClassMetaData meta = _member.fmd.getDeclaredTypeMetaData(); ClassMetaData meta = _member.fmd.getDeclaredTypeMetaData();
org.apache.openjpa.kernel.exps.Path path = null; org.apache.openjpa.kernel.exps.Path path = null;
SubqueryImpl<?> subquery = c.getDelegator(); SubqueryImpl<?> subquery = c.getDelegator();
@ -94,15 +90,12 @@ public abstract class Joins {
if (c.isRegistered(this)) if (c.isRegistered(this))
return c.getValue(this); return c.getValue(this);
else if (parent.inSubquery(subquery)) { else if (parent.inSubquery(subquery)) {
org.apache.openjpa.kernel.exps.Subquery subQ = org.apache.openjpa.kernel.exps.Subquery subQ = subquery.getSubQ();
subquery.getSubQ();
path = factory.newPath(subQ); path = factory.newPath(subQ);
path.setMetaData(subQ.getMetaData()); path.setMetaData(subQ.getMetaData());
//path.setSchemaAlias(c.getAlias(this)); //path.setSchemaAlias(c.getAlias(this));
} else { } else {
path = path = (org.apache.openjpa.kernel.exps.Path) _parent.toValue(factory, model, c);
(org.apache.openjpa.kernel.exps.Path)
_parent.toValue(factory, model, c);
path.get(_member.fmd, allowNull); path.get(_member.fmd, allowNull);
path.setMetaData(meta); path.setMetaData(meta);
path.setImplicitType(meta.getDescribedType()); path.setImplicitType(meta.getDescribedType());
@ -111,57 +104,52 @@ public abstract class Joins {
} }
@Override @Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression( public org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory,
ExpressionFactory factory, MetamodelImpl model, MetamodelImpl model, CriteriaQueryImpl<?> c) {
CriteriaQueryImpl c) {
ClassMetaData meta = _member.fmd.getDeclaredTypeMetaData(); ClassMetaData meta = _member.fmd.getDeclaredTypeMetaData();
org.apache.openjpa.kernel.exps.Path path = null; org.apache.openjpa.kernel.exps.Path path = null;
SubqueryImpl<?> subquery = c.getDelegator(); SubqueryImpl<?> subquery = c.getDelegator();
PathImpl<?,?> parent = getInnermostParentPath(); PathImpl<?,?> parent = getInnermostParentPath();
org.apache.openjpa.kernel.exps.Expression filter = null; org.apache.openjpa.kernel.exps.Expression filter = null;
PathImpl correlatedParent = null; PathImpl<?,?> correlatedParent = null;
boolean bind = true; boolean bind = true;
if (parent.inSubquery(subquery)) { if (parent.inSubquery(subquery)) {
org.apache.openjpa.kernel.exps.Subquery subQ = org.apache.openjpa.kernel.exps.Subquery subQ = subquery.getSubQ();
subquery.getSubQ();
path = factory.newPath(subQ); path = factory.newPath(subQ);
correlatedParent = _parent.getCorrelatedParent(); correlatedParent = _parent.getCorrelatedParent();
if (correlatedParent == null) { if (correlatedParent == null) {
path.setMetaData(subQ.getMetaData()); path.setMetaData(subQ.getMetaData());
path.get(_member.fmd, allowNull); path.get(_member.fmd, allowNull);
//path.setSchemaAlias(c.getAlias(_parent)); //path.setSchemaAlias(c.getAlias(_parent));
} else } else {
bind = false; bind = false;
}
} else if (c.isRegistered(_parent)) { } else if (c.isRegistered(_parent)) {
Value var = c.getVariable(_parent); Value var = c.getVariable(_parent);
path = factory.newPath(var); path = factory.newPath(var);
path.setMetaData(meta); path.setMetaData(meta);
path.get(_member.fmd, false); path.get(_member.fmd, false);
} else } else {
path = path = (org.apache.openjpa.kernel.exps.Path)toValue(factory, model, c);
(org.apache.openjpa.kernel.exps.Path)toValue(factory, model, c); }
org.apache.openjpa.kernel.exps.Expression join = null; org.apache.openjpa.kernel.exps.Expression join = null;
if (bind) { if (bind) {
Value var = factory.newBoundVariable(c.getAlias(this), Value var = factory.newBoundVariable(c.getAlias(this), meta.getDescribedType());
meta.getDescribedType());
join = factory.bindVariable(var, path); join = factory.bindVariable(var, path);
c.registerVariable(this, var, path); c.registerVariable(this, var, path);
} }
if (getJoins() != null) { if (getJoins() != null) {
for (Join<?, ?> join1 : getJoins()) { for (Join<?, ?> join1 : getJoins()) {
filter = CriteriaExpressionBuilder.and(factory, filter = CriteriaExpressionBuilder.and(factory,
((FromImpl<?,?>)join1). ((FromImpl<?,?>)join1).toKernelExpression(factory, model, c), filter);
toKernelExpression(factory, model, c), filter);
} }
} }
org.apache.openjpa.kernel.exps.Expression expr = org.apache.openjpa.kernel.exps.Expression expr = CriteriaExpressionBuilder.and(factory, join, filter);
CriteriaExpressionBuilder.and(factory, join, filter);
if (correlatedParent == null) if (correlatedParent == null) {
return expr; return expr;
else { } else {
org.apache.openjpa.kernel.exps.Path parentPath = org.apache.openjpa.kernel.exps.Path parentPath = (org.apache.openjpa.kernel.exps.Path)
(org.apache.openjpa.kernel.exps.Path)
correlatedParent.toValue(factory, model, c); correlatedParent.toValue(factory, model, c);
parentPath.get(_member.fmd, allowNull); parentPath.get(_member.fmd, allowNull);
//parentPath.setSchemaAlias(c.getAlias(correlatedParent)); //parentPath.setSchemaAlias(c.getAlias(correlatedParent));
@ -186,8 +174,8 @@ public abstract class Joins {
final JoinType joinType; final JoinType joinType;
boolean allowNull = false; boolean allowNull = false;
public AbstractCollection(FromImpl<?,Z> from, public AbstractCollection(FromImpl<?,Z> from, Members.PluralAttributeImpl<? super Z, C, E> member,
Members.PluralAttributeImpl<? super Z, C, E> member, JoinType jt) { JoinType jt) {
super(from, member, member.getBindableJavaType()); super(from, member, member.getBindableJavaType());
joinType = jt; joinType = jt;
allowNull = joinType != JoinType.INNER; allowNull = joinType != JoinType.INNER;
@ -225,7 +213,7 @@ public abstract class Joins {
*/ */
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl c) { CriteriaQueryImpl<?> c) {
ClassMetaData meta = getMemberClassMetaData(); ClassMetaData meta = getMemberClassMetaData();
org.apache.openjpa.kernel.exps.Path path = null; org.apache.openjpa.kernel.exps.Path path = null;
SubqueryImpl<?> subquery = c.getDelegator(); SubqueryImpl<?> subquery = c.getDelegator();
@ -235,14 +223,12 @@ public abstract class Joins {
Value var = c.getVariable(this); Value var = c.getVariable(this);
path = factory.newPath(var); path = factory.newPath(var);
} else if (parent.inSubquery(subquery)) { } else if (parent.inSubquery(subquery)) {
org.apache.openjpa.kernel.exps.Subquery subQ = org.apache.openjpa.kernel.exps.Subquery subQ = subquery.getSubQ();
subquery.getSubQ();
path = factory.newPath(subQ); path = factory.newPath(subQ);
path.setMetaData(subQ.getMetaData()); path.setMetaData(subQ.getMetaData());
//path.setSchemaAlias(c.getAlias(this)); //path.setSchemaAlias(c.getAlias(this));
} else { } else {
path = (org.apache.openjpa.kernel.exps.Path) path = (org.apache.openjpa.kernel.exps.Path) _parent.toValue(factory, model, c);
_parent.toValue(factory, model, c);
path.get(_member.fmd, allowNull); path.get(_member.fmd, allowNull);
} }
return path; return path;
@ -255,7 +241,7 @@ public abstract class Joins {
@Override @Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression( public org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl c) { CriteriaQueryImpl<?> c) {
ClassMetaData meta = getMemberClassMetaData(); ClassMetaData meta = getMemberClassMetaData();
org.apache.openjpa.kernel.exps.Path path = null; org.apache.openjpa.kernel.exps.Path path = null;
SubqueryImpl<?> subquery = c.getDelegator(); SubqueryImpl<?> subquery = c.getDelegator();
@ -264,46 +250,41 @@ public abstract class Joins {
PathImpl correlatedParent = null; PathImpl correlatedParent = null;
boolean bind = true; boolean bind = true;
if (parent.inSubquery(subquery)) { if (parent.inSubquery(subquery)) {
org.apache.openjpa.kernel.exps.Subquery subQ = org.apache.openjpa.kernel.exps.Subquery subQ = subquery.getSubQ();
subquery.getSubQ();
path = factory.newPath(subQ); path = factory.newPath(subQ);
correlatedParent = _parent.getCorrelatedParent(); correlatedParent = _parent.getCorrelatedParent();
if (correlatedParent == null) { if (correlatedParent == null) {
path.setMetaData(subQ.getMetaData()); path.setMetaData(subQ.getMetaData());
path.get(_member.fmd, allowNull); path.get(_member.fmd, allowNull);
//path.setSchemaAlias(c.getAlias(_parent)); //path.setSchemaAlias(c.getAlias(_parent));
} else } else {
bind = false; bind = false;
}
} else if (c.isRegistered(_parent)) { } else if (c.isRegistered(_parent)) {
Value var = c.getVariable(_parent); Value var = c.getVariable(_parent);
path = factory.newPath(var); path = factory.newPath(var);
path.setMetaData(meta); path.setMetaData(meta);
path.get(_member.fmd, false); path.get(_member.fmd, false);
} else } else {
path = (org.apache.openjpa.kernel.exps.Path) path = (org.apache.openjpa.kernel.exps.Path)toValue(factory, model, c);
toValue(factory, model, c); }
org.apache.openjpa.kernel.exps.Expression join = null; org.apache.openjpa.kernel.exps.Expression join = null;
if (bind) { if (bind) {
Value var = factory.newBoundVariable(c.getAlias(this), Value var = factory.newBoundVariable(c.getAlias(this), meta.getDescribedType());
meta.getDescribedType());
join = factory.bindVariable(var, path); join = factory.bindVariable(var, path);
c.registerVariable(this, var, path); c.registerVariable(this, var, path);
} }
if (getJoins() != null) { if (getJoins() != null) {
for (Join<?, ?> join1 : getJoins()) { for (Join<?, ?> join1 : getJoins()) {
filter = CriteriaExpressionBuilder.and(factory, filter = CriteriaExpressionBuilder.and(factory,
((FromImpl<?,?>)join1). ((FromImpl<?,?>)join1).toKernelExpression(factory, model, c), filter);
toKernelExpression(factory, model, c), filter);
} }
} }
org.apache.openjpa.kernel.exps.Expression expr = org.apache.openjpa.kernel.exps.Expression expr = CriteriaExpressionBuilder.and(factory, join, filter);
CriteriaExpressionBuilder.and(factory, join, filter); if (correlatedParent == null) {
if (correlatedParent == null)
return expr; return expr;
else { } else {
org.apache.openjpa.kernel.exps.Path parentPath = org.apache.openjpa.kernel.exps.Path parentPath = (org.apache.openjpa.kernel.exps.Path)
(org.apache.openjpa.kernel.exps.Path)
correlatedParent.toValue(factory, model, c); correlatedParent.toValue(factory, model, c);
parentPath.get(_member.fmd, allowNull); parentPath.get(_member.fmd, allowNull);
//parentPath.setSchemaAlias(c.getAlias(correlatedParent)); //parentPath.setSchemaAlias(c.getAlias(correlatedParent));
@ -321,8 +302,7 @@ public abstract class Joins {
* @param <Z> * @param <Z>
* @param <E> * @param <E>
*/ */
public static class Collection<Z,E> public static class Collection<Z,E> extends AbstractCollection<Z,java.util.Collection<E>,E>
extends AbstractCollection<Z,java.util.Collection<E>,E>
implements CollectionJoin<Z,E>{ implements CollectionJoin<Z,E>{
public Collection(FromImpl<?,Z> parent, public Collection(FromImpl<?,Z> parent,
Members.CollectionAttributeImpl<? super Z, E> member, JoinType jt) { Members.CollectionAttributeImpl<? super Z, E> member, JoinType jt) {
@ -341,8 +321,7 @@ public abstract class Joins {
* @param <Z> * @param <Z>
* @param <E> * @param <E>
*/ */
public static class Set<Z,E> public static class Set<Z,E> extends AbstractCollection<Z,java.util.Set<E>,E>
extends AbstractCollection<Z,java.util.Set<E>,E>
implements SetJoin<Z,E>{ implements SetJoin<Z,E>{
public Set(FromImpl<?,Z> parent, Members.SetAttributeImpl<? super Z, E> member, JoinType jt) { public Set(FromImpl<?,Z> parent, Members.SetAttributeImpl<? super Z, E> member, JoinType jt) {
super(parent, member, jt); super(parent, member, jt);
@ -360,8 +339,7 @@ public abstract class Joins {
* @param <E> * @param <E>
*/ */
public static class List<Z,E> public static class List<Z,E> extends AbstractCollection<Z,java.util.List<E>,E>
extends AbstractCollection<Z,java.util.List<E>,E>
implements ListJoin<Z,E> { implements ListJoin<Z,E> {
public List(FromImpl<?,Z> parent, public List(FromImpl<?,Z> parent,
@ -385,8 +363,7 @@ public abstract class Joins {
* @param <E> * @param <E>
*/ */
public static class Map<Z,K,V> public static class Map<Z,K,V> extends AbstractCollection<Z,java.util.Map<K,V>,V>
extends AbstractCollection<Z,java.util.Map<K,V>,V>
implements MapJoin<Z,K,V> { implements MapJoin<Z,K,V> {
public Map(FromImpl<?,Z> parent, Members.MapAttributeImpl<? super Z, K,V> member, JoinType jt) { public Map(FromImpl<?,Z> parent, Members.MapAttributeImpl<? super Z, K,V> member, JoinType jt) {
@ -418,20 +395,16 @@ public abstract class Joins {
} }
@Override @Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression( public org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory,
ExpressionFactory factory, MetamodelImpl model, MetamodelImpl model, CriteriaQueryImpl<?> c) {
CriteriaQueryImpl c) { org.apache.openjpa.kernel.exps.Value path = toValue(factory, model, c);
org.apache.openjpa.kernel.exps.Value path = toValue
(factory, model, c);
ClassMetaData meta = _member.fmd.isElementCollection() ClassMetaData meta = _member.fmd.isElementCollection()
? _member.fmd.getEmbeddedMetaData() ? _member.fmd.getEmbeddedMetaData()
: _member.fmd.getElement().getDeclaredTypeMetaData(); : _member.fmd.getElement().getDeclaredTypeMetaData();
Value var = factory.newBoundVariable(c.getAlias(this), Value var = factory.newBoundVariable(c.getAlias(this), meta.getDescribedType());
meta.getDescribedType()); org.apache.openjpa.kernel.exps.Expression join = factory.bindValueVariable(var, path);
org.apache.openjpa.kernel.exps.Expression join = factory
.bindValueVariable(var, path);
c.registerVariable(this, var, path); c.registerVariable(this, var, path);
return join; return join;
} }
@ -440,9 +413,9 @@ public abstract class Joins {
public static class MapKey<Z,K> extends PathImpl<Z,K> { public static class MapKey<Z,K> extends PathImpl<Z,K> {
Map<?,K,?> map; Map<?,K,?> map;
public MapKey(Map<Z,K,?> joinMap){ public MapKey(Map<Z,K,?> joinMap){
super(((MapAttribute<Z, K, ?>)joinMap.getAttribute()) super(((MapAttribute<Z, K, ?>)joinMap.getAttribute()).getKeyJavaType());
.getKeyJavaType());
this.map = joinMap; this.map = joinMap;
} }
@ -451,10 +424,8 @@ public abstract class Joins {
* *
*/ */
@Override @Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> c) {
CriteriaQueryImpl c) { org.apache.openjpa.kernel.exps.Path path = factory.newPath(c.getVariable(map));
org.apache.openjpa.kernel.exps.Path path =
factory.newPath(c.getVariable(map));
return factory.getKey(path); return factory.getKey(path);
} }
} }

View File

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

View File

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

View File

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