diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ExpressionImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ExpressionImpl.java index 5135cc18a..01dd0e84e 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ExpressionImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ExpressionImpl.java @@ -40,13 +40,13 @@ public class ExpressionImpl extends SelectionImpl implements Expression { 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()); } diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/Expressions.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/Expressions.java index e77bc52c4..1c00ba890 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/Expressions.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/Expressions.java @@ -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)); } } diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/Joins.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/Joins.java index 3041c7372..b0eb48dbe 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/Joins.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/Joins.java @@ -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 type from which joining * @param type of the attribute being joined */ - public static class SingularJoin extends FromImpl - implements Join{ + public static class SingularJoin extends FromImpl implements Join{ private final JoinType joinType; private boolean allowNull = false; - public SingularJoin(FromImpl from, - Members.SingularAttributeImpl member, JoinType jt) { + public SingularJoin(FromImpl from, Members.SingularAttributeImpl 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 getAttribute(); public Attribute getAttribute() { return (Attribute )_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 from, - Members.PluralAttributeImpl member, JoinType jt) { + public AbstractCollection(FromImpl from, Members.PluralAttributeImpl 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 * @param */ - public static class Collection - extends AbstractCollection,E> + public static class Collection extends AbstractCollection,E> implements CollectionJoin{ public Collection(FromImpl parent, Members.CollectionAttributeImpl member, JoinType jt) { @@ -341,8 +321,7 @@ public abstract class Joins { * @param * @param */ - public static class Set - extends AbstractCollection,E> + public static class Set extends AbstractCollection,E> implements SetJoin{ public Set(FromImpl parent, Members.SetAttributeImpl member, JoinType jt) { super(parent, member, jt); @@ -360,8 +339,7 @@ public abstract class Joins { * @param */ - public static class List - extends AbstractCollection,E> + public static class List extends AbstractCollection,E> implements ListJoin { public List(FromImpl parent, @@ -385,8 +363,7 @@ public abstract class Joins { * @param */ - public static class Map - extends AbstractCollection,V> + public static class Map extends AbstractCollection,V> implements MapJoin { public Map(FromImpl parent, Members.MapAttributeImpl 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 extends PathImpl { Map map; + public MapKey(Map joinMap){ - super(((MapAttribute)joinMap.getAttribute()) - .getKeyJavaType()); + super(((MapAttribute)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); } } diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ParameterImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ParameterImpl.java index 402a1e5b6..fcf50ffa9 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ParameterImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ParameterImpl.java @@ -59,7 +59,7 @@ public class ParameterImpl extends ExpressionImpl implements ParameterExpr @Override public Value toValue(ExpressionFactory factory, MetamodelImpl model, - CriteriaQueryImpl q) { + CriteriaQueryImpl q) { q.registerParameter(this); diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PathImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PathImpl.java index e4fe55f75..cb714bf71 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PathImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PathImpl.java @@ -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 extends ExpressionImpl implements Path { } 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 extends ExpressionImpl implements Path { 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 extends ExpressionImpl implements Path { */ @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 extends ExpressionImpl implements Path { 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 extends ExpressionImpl implements Path { 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 extends ExpressionImpl implements Path { * collection-valued attribute. * @param collection collection-valued attribute * @return expression corresponding to the referenced attribute -// > Expression get(PluralAttribute collection); */ - public > Expression - get(PluralAttribute coll) { - return new PathImpl(this, (Members.Member)coll, - coll.getJavaType()); + public > Expression get(PluralAttribute coll) { + return new PathImpl(this, (Members.Member)coll, coll.getJavaType()); } /** @@ -226,11 +218,8 @@ public class PathImpl extends ExpressionImpl implements Path { * @param map map-valued attribute * @return expression corresponding to the referenced attribute */ -// > Expression get(MapAttribute map); - public > Expression - get(MapAttribute map) { - return new PathImpl(this, (Members.MapAttributeImpl)map, - (Class)map.getJavaType()); + public > Expression get(MapAttribute map) { + return new PathImpl(this, (Members.MapAttributeImpl)map, (Class)map.getJavaType()); } public Path get(String attName) { @@ -239,8 +228,7 @@ public class PathImpl extends ExpressionImpl implements Path { switch (type.getPersistenceType()) { case BASIC: throw new RuntimeException(attName + " not navigable from " + this); - default: next = (Members.Member) - ((ManagedType)type).getAttribute(attName); + default: next = (Members.Member) ((ManagedType)type).getAttribute(attName); } return new PathImpl(this, next, (Class)type.getClass()); } diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PredicateImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PredicateImpl.java index 57c10b863..623821686 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PredicateImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PredicateImpl.java @@ -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) diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/RootImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/RootImpl.java index 847a8c1ba..d032b6b1c 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/RootImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/RootImpl.java @@ -68,7 +68,7 @@ public class RootImpl extends FromImpl implements Root { */ @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 extends FromImpl implements Root { */ @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()); diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SubqueryImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SubqueryImpl.java index e4ae8eac1..0c3ebbc1f 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SubqueryImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SubqueryImpl.java @@ -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 the type selected by this subquery. */ public class SubqueryImpl extends ExpressionImpl implements Subquery { - private final AbstractQuery _parent; - private final CriteriaQueryImpl _delegate; + private final AbstractQuery _parent; + private final CriteriaQueryImpl _delegate; private final MetamodelImpl _model; private java.util.Set> _joins; private Expression _select; private org.apache.openjpa.kernel.exps.Subquery _subq; - public SubqueryImpl(Class cls, AbstractQuery parent) { + public SubqueryImpl(Class 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(_model, this); } - public AbstractQuery getParent() { + public AbstractQuery getParent() { return _parent; } - public CriteriaQueryImpl getDelegate() { + public CriteriaQueryImpl getDelegate() { return _delegate; } @@ -90,9 +92,9 @@ public class SubqueryImpl extends ExpressionImpl implements Subquery { // 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 select(Expression expression) { @@ -172,8 +174,7 @@ public class SubqueryImpl extends ExpressionImpl implements Subquery { } public Root correlate(Root root) { - Types.Entity entity = - (Types.Entity)((RootImpl)root).getModel(); + Types.Entity entity = (Types.Entity)root.getModel(); RootImpl corrRoot = new RootImpl(entity); corrRoot.setCorrelatedParent((RootImpl)root); Set> roots = getRoots(); @@ -222,7 +223,7 @@ public class SubqueryImpl extends ExpressionImpl implements Subquery { */ @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 extends ExpressionImpl implements Subquery { 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; }