OPENJPA-1013: Refcator

1. Make implementaion non-public (mainly package scoped now)
   2. Promote to interface for contracts as much as possible
   3. Use more compact bridge pattern method signature

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@813956 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Pinaki Poddar 2009-09-11 17:53:07 +00:00
parent c534d29cb7
commit 677d34049c
20 changed files with 279 additions and 270 deletions

View File

@ -29,11 +29,9 @@ import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;
@ -47,7 +45,6 @@ import javax.persistence.Query;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.ParameterExpression;
import javax.persistence.criteria.QueryBuilder;
import javax.persistence.metamodel.Metamodel;
import org.apache.commons.lang.StringUtils;
@ -80,14 +77,12 @@ import org.apache.openjpa.meta.FieldMetaData;
import org.apache.openjpa.meta.QueryMetaData;
import org.apache.openjpa.meta.SequenceMetaData;
import org.apache.openjpa.persistence.criteria.CriteriaBuilder;
import org.apache.openjpa.persistence.criteria.CriteriaExpressionVisitor;
import org.apache.openjpa.persistence.criteria.CriteriaQueryImpl;
import org.apache.openjpa.persistence.criteria.OpenJPACriteriaQuery;
import org.apache.openjpa.persistence.validation.ValidationUtils;
import org.apache.openjpa.util.Exceptions;
import org.apache.openjpa.util.ImplHelper;
import org.apache.openjpa.util.RuntimeExceptionTranslator;
import org.apache.openjpa.util.UserException;
import org.apache.openjpa.util.WrappedException;
import serp.util.Strings;
@ -1543,12 +1538,11 @@ public class EntityManagerImpl
* Compile to register the parameters in this query.
*/
public <T> TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery) {
CriteriaQueryImpl<T> impl = (CriteriaQueryImpl<T>)criteriaQuery;
impl.compile(); // important to collect parameters to be set on executable query
((OpenJPACriteriaQuery<T>)criteriaQuery).compile();
org.apache.openjpa.kernel.Query kernelQuery =_broker.newQuery(CriteriaBuilder.LANG_CRITERIA, criteriaQuery);
QueryImpl<T> facadeQuery = new QueryImpl<T>(this, _ret, kernelQuery);
Set<ParameterExpression<?>> params = impl.getParameters();
Set<ParameterExpression<?>> params = criteriaQuery.getParameters();
for (ParameterExpression<?> param : params) {
facadeQuery.declareParameter(param, param);

View File

@ -22,15 +22,12 @@ import java.lang.reflect.Constructor;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.persistence.Tuple;
import javax.persistence.TupleElement;
import javax.persistence.criteria.CompoundSelection;
import javax.persistence.criteria.Selection;
import org.apache.openjpa.kernel.FillStrategy;
import org.apache.openjpa.kernel.ResultShape;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.persistence.TupleFactory;
import org.apache.openjpa.persistence.TupleImpl;
@ -43,13 +40,13 @@ import org.apache.openjpa.persistence.TupleImpl;
* @since 2.0.0
*
*/
public class CompoundSelections {
class CompoundSelections {
private static Localizer _loc = Localizer.forPackage(CompoundSelections.class);
/**
* Gets the strategy to fill a given compound selection.
*
*/
public static <X> FillStrategy<X> getFillStrategy(Selection<X> s) {
static <X> FillStrategy<X> getFillStrategy(Selection<X> s) {
if (s instanceof CompoundSelectionImpl) {
return ((CompoundSelectionImpl<X>)s).getFillStrategy();
} else {
@ -113,7 +110,7 @@ public class CompoundSelections {
*
* @param <X> type must be an array
*/
public static class Array<X> extends CompoundSelectionImpl<X> {
static class Array<X> extends CompoundSelectionImpl<X> {
public Array(Class<X> cls, Selection<?>... terms) {
super(cls, terms);
if (!cls.isArray()) {
@ -131,7 +128,7 @@ public class CompoundSelections {
*
* @param <X> type of the constructed instance
*/
public static class NewInstance<X> extends CompoundSelectionImpl<X> {
static class NewInstance<X> extends CompoundSelectionImpl<X> {
private FillStrategy.NewInstance<X> strategy;
public NewInstance(Class<X> cls, Selection<?>... selections) {
super(cls, selections);
@ -168,7 +165,7 @@ public class CompoundSelections {
* A compound selection which is a Tuple composed of its component terms.
*
*/
public static class Tuple extends CompoundSelectionImpl<javax.persistence.Tuple> {
static class Tuple extends CompoundSelectionImpl<javax.persistence.Tuple> {
public Tuple(final Selection<?>[] selections) {
super(javax.persistence.Tuple.class, selections);
}
@ -180,10 +177,16 @@ public class CompoundSelections {
}
}
public static class MultiSelection<T> extends CompoundSelectionImpl<T> {
/**
* A selection of terms that interprets its arguments based on target result type.
*
* @param <T> the target result type.
*/
static class MultiSelection<T> extends CompoundSelectionImpl<T> {
public MultiSelection(Class<T> result, final Selection<?>[] selections) {
super(result, selections);
}
public FillStrategy<T> getFillStrategy() {
Class<?> resultClass = getJavaType();
List<Selection<?>> terms = getCompoundSelectionItems();

View File

@ -36,7 +36,6 @@ import javax.persistence.criteria.From;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.ParameterExpression;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.QueryBuilder;
import javax.persistence.criteria.Selection;
import javax.persistence.criteria.Subquery;
import javax.persistence.metamodel.Attribute;
@ -498,12 +497,10 @@ public class CriteriaBuilder implements OpenJPACriteriaBuilder, ExpressionParser
public <Y> Expression<Y> nullif(Expression<Y> x, Expression<?> y) {
return new Expressions.Nullif(x, y);
}
public <Y> Expression<Y> nullif(Expression<Y> x, Y y) {
return new Expressions.Nullif(x, y);
}
public Predicate or(Predicate... restrictions) {
@ -688,7 +685,7 @@ public class CriteriaBuilder implements OpenJPACriteriaBuilder, ExpressionParser
}
public Predicate isNotNull(Expression<?> x) {
return new Expressions.IsNotNull((ExpressionImpl<?> )x);
return new Expressions.IsNotNull((ExpressionImpl<?>)x);
}
public Predicate isNull(Expression<?> x) {

View File

@ -24,7 +24,7 @@ package org.apache.openjpa.persistence.criteria;
* @author Pinaki Poddar
* @since 2.0.0
*/
public interface CriteriaExpression {
interface CriteriaExpression {
/**
* Accept visit from the given visitor. The receiver is responsible
* to propagate the visitor to the constituent sub-nodes if any.

View File

@ -51,7 +51,6 @@ import org.apache.openjpa.persistence.TupleImpl;
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;
/**
* Converts expressions of a CriteriaQuery to kernel Expression.
@ -62,25 +61,22 @@ import org.apache.openjpa.persistence.meta.Types;
*
* @since 2.0.0
*/
public class CriteriaExpressionBuilder {
class CriteriaExpressionBuilder {
public QueryExpressions getQueryExpressions(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
QueryExpressions exps = new QueryExpressions();
exps.setContexts(q.getContexts());
evalAccessPaths(exps, factory, q);
//exps.alias = null; // String
exps.alias = null; // String
evalDistinct(exps, factory, q);
evalFetchJoin(exps, factory, q);
evalCrossJoinRoots(exps, factory, q);
evalFilter(exps, factory, q);
evalGrouping(exps, factory, q);
evalOrderingAndProjection(exps, factory, q);
exps.operation = QueryOperations.OP_SELECT;
//exps.range = null; // Value[]
exps.range = QueryExpressions.EMPTY_VALUES;
exps.resultClass = q.getResultType();
exps.shape = evalResultShape(q);
exps.parameterTypes = q.getParameterTypes();
@ -141,7 +137,7 @@ public class CriteriaExpressionBuilder {
for (int i = 0; i < ordercount; i++) {
OrderImpl order = (OrderImpl)orders.get(i);
ExpressionImpl<?> expr = order.getExpression();
Value val = Expressions.toValue(expr, factory, model, q);
Value val = Expressions.toValue(expr, factory, q);
exps.ordering[i] = val;
String alias = expr.getAlias();
exps.orderingAliases[i] = alias;
@ -165,10 +161,10 @@ public class CriteriaExpressionBuilder {
exps.grouping = new Value[groupByCount];
for (int i = 0; i < groupByCount; i++) {
Expression<?> groupBy = groups.get(i);
exps.grouping[i] = Expressions.toValue((ExpressionImpl<?>)groupBy, factory, model, q);;
exps.grouping[i] = Expressions.toValue((ExpressionImpl<?>)groupBy, factory, q);;
}
exps.having = having == null ? null : having.toKernelExpression(factory, model, q);
exps.having = having == null ? null : having.toKernelExpression(factory, q);
}
protected void evalDistinct(QueryExpressions exps, ExpressionFactory factory, CriteriaQueryImpl<?> q) {
@ -203,7 +199,7 @@ public class CriteriaExpressionBuilder {
for (Root<?> root : roots) {
for (Join<?, ?> join : root.getJoins()) {
filter = Expressions.and(factory,
((ExpressionImpl<?>)join).toKernelExpression(factory, model, q), filter);
((ExpressionImpl<?>)join).toKernelExpression(factory, q), filter);
}
((RootImpl<?>)root).addToContext(factory, model, q);
}
@ -212,12 +208,12 @@ public class CriteriaExpressionBuilder {
List<Join<?,?>> corrJoins = subQuery.getCorrelatedJoins();
for (int i = 0; corrJoins != null && i < corrJoins.size(); i++) {
filter = Expressions.and(factory, ((ExpressionImpl<?>)corrJoins.get(i))
.toKernelExpression(factory, model, q), filter);
.toKernelExpression(factory, q), filter);
}
}
if (where != null) {
filter = Expressions.and(factory, where.toKernelExpression(factory, model, q), filter);
filter = Expressions.and(factory, where.toKernelExpression(factory, q), filter);
}
if (filter == null) {
filter = factory.emptyExpression();
@ -274,7 +270,7 @@ public class CriteriaExpressionBuilder {
clauses, factory, q, model, exp2Vals);
} else {
Value val = (exp2Vals != null && exp2Vals.containsKey(s)
? exp2Vals.get(s) : ((ExpressionImpl<?>)s).toValue(factory, model, q));
? exp2Vals.get(s) : ((ExpressionImpl<?>)s).toValue(factory, q));
String alias = s.getAlias();
val.setAlias(alias);
projections.add(val);

View File

@ -102,6 +102,5 @@ public interface CriteriaExpressionVisitor {
query.registerParameter((ParameterExpressionImpl<?>)expr);
}
}
}
}

View File

@ -65,7 +65,7 @@ import org.apache.openjpa.persistence.meta.Types;
*
* @since 2.0.0
*/
public class CriteriaQueryImpl<T> implements OpenJPACriteriaQuery<T>, AliasContext {
class CriteriaQueryImpl<T> implements OpenJPACriteriaQuery<T>, AliasContext {
private static final Localizer _loc = Localizer.forPackage(CriteriaQueryImpl.class);
private final MetamodelImpl _model;
@ -618,13 +618,14 @@ public class CriteriaQueryImpl<T> implements OpenJPACriteriaQuery<T>, AliasConte
* and, most importantly, collects all the parameters so that they can be bound to
* the executable query.
*/
public void compile() {
public OpenJPACriteriaQuery<T> compile() {
if (_compiled)
return;
return this;
assertRoot();
assertSelection();
collectParameters(new CriteriaExpressionVisitor.ParameterVisitor(this));
_compiled = true;
return this;
}
private void collectParameters(CriteriaExpressionVisitor visitor) {

View File

@ -26,17 +26,17 @@ import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.QueryBuilder.In;
import org.apache.openjpa.kernel.exps.ExpressionFactory;
import org.apache.openjpa.persistence.meta.MetamodelImpl;
/**
* Expression node for Criteria query.
* Acts a bridge pattern to equivalent kernel representation.
*
* @param <X> the type of the value this expression represents.
*
* @author Pinaki Poddar
* @since 2.0.0
*/
public abstract class ExpressionImpl<X> extends SelectionImpl<X> implements Expression<X> {
abstract class ExpressionImpl<X> extends SelectionImpl<X> implements Expression<X> {
/**
* @param cls the type of the evaluated result of the expression
*/
@ -106,11 +106,24 @@ public abstract class ExpressionImpl<X> extends SelectionImpl<X> implements Expr
return new Expressions.IsNull(this);
}
abstract org.apache.openjpa.kernel.exps.Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl<?> q);
// ------------------------------------------------------------------------------------
// Contract for bridge pattern to convert to an equivalent kernel representation.
// ------------------------------------------------------------------------------------
/**
* Bridge contract to convert this facade expression to a kernel value.
* @param factory creates the kernel expression
* @param q the query definition context of this expression
* @return an equivalent kernel value
*/
abstract org.apache.openjpa.kernel.exps.Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q);
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl<?> q) {
return factory.asExpression(toValue(factory, model, q));
/**
* Bridge contract to convert this facade expression to a kernel expression.
* @param factory creates the kernel expression
* @param q the query definition context of this expression
* @return an equivalent kernel expression
*/
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.asExpression(toValue(factory, q));
}
}

View File

@ -39,7 +39,6 @@ import org.apache.openjpa.kernel.exps.Value;
import org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder;
import org.apache.openjpa.meta.ClassMetaData;
import org.apache.openjpa.persistence.criteria.CriteriaExpressionVisitor.TraversalStyle;
import org.apache.openjpa.persistence.meta.MetamodelImpl;
import org.apache.openjpa.persistence.meta.Types;
/**
@ -53,7 +52,7 @@ import org.apache.openjpa.persistence.meta.Types;
* @since 2.0.0
*
*/
public class Expressions {
class Expressions {
static final String OPEN_BRACE = "(";
static final String CLOSE_BRACE = ")";
static final String COMMA = ",";
@ -63,8 +62,8 @@ public class Expressions {
* using the given ExpressionFactory.
* Handles null expression.
*/
static Value toValue(ExpressionImpl<?> e, ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
return (e == null) ? factory.getNull() : e.toValue(factory, model, q);
static Value toValue(ExpressionImpl<?> e, ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return (e == null) ? factory.getNull() : e.toValue(factory, q);
}
static void setImplicitTypes(Value v1, Value v2, Class<?> expected, CriteriaQueryImpl<?> q) {
@ -281,8 +280,8 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
return factory.abs(Expressions.toValue(e, factory, model, q));
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.abs(Expressions.toValue(e, factory, q));
}
public StringBuilder asValue(AliasContext q) {
@ -303,8 +302,8 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
Value v = factory.count(Expressions.toValue(e, factory, model, q));
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
Value v = factory.count(Expressions.toValue(e, factory, q));
return _distinct ? factory.distinct(v) : v;
}
@ -321,8 +320,8 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
return factory.avg(Expressions.toValue(e, factory, model, q));
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.avg(Expressions.toValue(e, factory, q));
}
@Override
@ -337,8 +336,8 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
return factory.sqrt(Expressions.toValue(e, factory, model, q));
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.sqrt(Expressions.toValue(e, factory, q));
}
public StringBuilder asValue(AliasContext q) {
@ -352,8 +351,8 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
return factory.max(Expressions.toValue(e, factory, model, q));
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.max(Expressions.toValue(e, factory, q));
}
public StringBuilder asValue(AliasContext q) {
@ -367,8 +366,8 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
return factory.min(Expressions.toValue(e, factory, model, q));
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.min(Expressions.toValue(e, factory, q));
}
public StringBuilder asValue(AliasContext q) {
@ -386,8 +385,8 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
Value val = Expressions.toValue(e, factory, model, q);
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
Value val = Expressions.toValue(e, factory, q);
if (val instanceof Literal && ((Literal)val).getParseType() == Literal.TYPE_COLLECTION)
return factory.newLiteral(((Collection)((Literal)val).getValue()).size(),
Literal.TYPE_NUMBER);
@ -411,9 +410,9 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.newFunction(functionName, getJavaType(),
new Expressions.ListArgument(resultType, args).toValue(factory, model, q));
new Expressions.ListArgument(resultType, args).toValue(factory, q));
}
public StringBuilder asValue(AliasContext q) {
@ -428,8 +427,8 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
return factory.type(Expressions.toValue(e, factory, model, q));
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.type(Expressions.toValue(e, factory, q));
}
@Override
@ -444,8 +443,8 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
return factory.cast(Expressions.toValue(e, factory, model, q), getJavaType());
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.cast(Expressions.toValue(e, factory, q), getJavaType());
}
@Override
@ -468,10 +467,10 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.concat(
Expressions.toValue(e1, factory, model, q),
Expressions.toValue(e2, factory, model, q));
Expressions.toValue(e1, factory, q),
Expressions.toValue(e2, factory, q));
}
@Override
@ -507,11 +506,11 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return JPQLExpressionBuilder.convertSubstringArguments(factory,
Expressions.toValue(e, factory, model, q),
from == null ? null : from.toValue(factory, model, q),
len == null ? null : len.toValue(factory, model, q));
Expressions.toValue(e, factory, q),
from == null ? null : from.toValue(factory, q),
len == null ? null : len.toValue(factory, q));
}
public void acceptVisit(CriteriaExpressionVisitor visitor) {
@ -554,10 +553,10 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
Value locateSearch = path.toValue(factory, model, q);
Value locateFromIndex = (from == null ? null : Expressions.toValue(from, factory, model, q));
Value locatePath = Expressions.toValue(pattern, factory, model, q);
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
Value locateSearch = path.toValue(factory, q);
Value locateFromIndex = (from == null ? null : Expressions.toValue(from, factory, q));
Value locatePath = Expressions.toValue(pattern, factory, q);
return factory.add(factory.indexOf(locateSearch,
locateFromIndex == null ? locatePath
@ -608,7 +607,7 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
Boolean spec = null;
if (ts != null) {
switch (ts) {
@ -618,8 +617,8 @@ public class Expressions {
}
}
return factory.trim(
Expressions.toValue(e1, factory, model, q),
Expressions.toValue(e2, factory, model, q), spec);
Expressions.toValue(e1, factory, q),
Expressions.toValue(e2, factory, q), spec);
}
@Override
@ -646,12 +645,12 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return (e2 == null)
? factory.sum(Expressions.toValue(e1, factory, model, q))
? factory.sum(Expressions.toValue(e1, factory, q))
: factory.add(
Expressions.toValue(e1, factory, model, q),
Expressions.toValue(e2, factory, model, q));
Expressions.toValue(e1, factory, q),
Expressions.toValue(e2, factory, q));
}
@Override
@ -676,10 +675,10 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.multiply(
Expressions.toValue(e1, factory, model, q),
Expressions.toValue(e2, factory, model, q));
Expressions.toValue(e1, factory, q),
Expressions.toValue(e2, factory, q));
}
@Override
@ -702,10 +701,10 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.subtract(
Expressions.toValue(e1, factory, model, q),
Expressions.toValue(e2, factory, model, q));
Expressions.toValue(e1, factory, q),
Expressions.toValue(e2, factory, q));
}
@Override
@ -729,10 +728,10 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.divide(
Expressions.toValue(e1, factory, model, q),
Expressions.toValue(e2, factory, model, q));
Expressions.toValue(e1, factory, q),
Expressions.toValue(e2, factory, q));
}
@Override
@ -753,10 +752,10 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.mod(
Expressions.toValue(e1, factory, model, q),
Expressions.toValue(e2, factory, model, q));
Expressions.toValue(e1, factory, q),
Expressions.toValue(e2, factory, q));
}
@Override
@ -771,7 +770,7 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.getCurrentDate();
}
@ -787,7 +786,7 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.getCurrentTime();
}
@ -803,7 +802,7 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.getCurrentTimestamp();
}
@ -828,10 +827,9 @@ public class Expressions {
}
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl<?> q) {
Value val1 = Expressions.toValue(e1, factory, model, q);
Value val2 = Expressions.toValue(e2, factory, model, q);
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, CriteriaQueryImpl<?> q){
Value val1 = Expressions.toValue(e1, factory, q);
Value val2 = Expressions.toValue(e2, factory, q);
Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q);
return factory.equal(val1, val2);
}
@ -857,10 +855,9 @@ public class Expressions {
}
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl<?> q) {
Value val1 = Expressions.toValue(e1, factory, model, q);
Value val2 = Expressions.toValue(e2, factory, model, q);
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, CriteriaQueryImpl<?> q){
Value val1 = Expressions.toValue(e1, factory, q);
Value val2 = Expressions.toValue(e2, factory, q);
Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q);
return factory.notEqual(val1, val2);
}
@ -886,10 +883,9 @@ public class Expressions {
}
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl<?> q) {
Value val1 = Expressions.toValue(e1, factory, model, q);
Value val2 = Expressions.toValue(e2, factory, model, q);
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, CriteriaQueryImpl<?> q){
Value val1 = Expressions.toValue(e1, factory, q);
Value val2 = Expressions.toValue(e2, factory, q);
Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q);
return factory.greaterThan(val1, val2);
}
@ -915,10 +911,9 @@ public class Expressions {
}
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl<?> q) {
Value val1 = Expressions.toValue(e1, factory, model, q);
Value val2 = Expressions.toValue(e2, factory, model, q);
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, CriteriaQueryImpl<?> q){
Value val1 = Expressions.toValue(e1, factory, q);
Value val2 = Expressions.toValue(e2, factory, q);
Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q);
return factory.greaterThanEqual(val1, val2);
}
@ -944,10 +939,9 @@ public class Expressions {
}
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl<?> q) {
Value val1 = Expressions.toValue(e1, factory, model, q);
Value val2 = Expressions.toValue(e2, factory, model, q);
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, CriteriaQueryImpl<?> q){
Value val1 = Expressions.toValue(e1, factory, q);
Value val2 = Expressions.toValue(e2, factory, q);
Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q);
return factory.lessThan(val1, val2);
}
@ -973,10 +967,9 @@ public class Expressions {
}
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl<?> q) {
Value val1 = Expressions.toValue(e1, factory, model, q);
Value val2 = Expressions.toValue(e2, factory, model, q);
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, CriteriaQueryImpl<?> q){
Value val1 = Expressions.toValue(e1, factory, q);
Value val2 = Expressions.toValue(e2, factory, q);
Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q);
return factory.lessThanEqual(val1, val2);
}
@ -1022,11 +1015,11 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
Object value = arg;
Class<?> literalClass = getJavaType();
if (arg instanceof ParameterExpressionImpl) {
return ((ParameterExpressionImpl)arg).toValue(factory, model, q);
return ((ParameterExpressionImpl)arg).toValue(factory, q);
}
int literalType = Literal.TYPE_UNKNOWN;
if (Number.class.isAssignableFrom(literalClass)) {
@ -1043,7 +1036,7 @@ public class Expressions {
ClassMetaData can = ((Types.Entity<X>)q.getRoot().getModel()).meta;
Class<?> candidate = can.getDescribedType();
if (candidate.isAssignableFrom((Class)value)) {
lit.setMetaData(model.getRepository().getMetaData((Class<?>)value, null, true));
lit.setMetaData(q.getMetamodel().getRepository().getMetaData((Class<?>)value, null, true));
} else {
lit.setMetaData(can);
}
@ -1094,14 +1087,13 @@ public class Expressions {
}
@Override
Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
return Expressions.toValue(collection, factory, model, q);
Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return Expressions.toValue(collection, factory, q);
}
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl<?> q) {
Value val = Expressions.toValue(collection, factory, model, q);
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, CriteriaQueryImpl<?> q){
Value val = Expressions.toValue(collection, factory, q);
return factory.isEmpty(val);
}
@ -1129,14 +1121,13 @@ public class Expressions {
}
@Override
Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
return Expressions.toValue(collection, factory, model, q);
Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return Expressions.toValue(collection, factory, q);
}
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl<?> q) {
Value val = Expressions.toValue(collection, factory, model, q);
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, CriteriaQueryImpl<?> q){
Value val = Expressions.toValue(collection, factory, q);
// factory.isNotEmpty() not used to match JPQL
return factory.not(factory.isEmpty(val));
}
@ -1159,9 +1150,8 @@ public class Expressions {
}
@Override
public org.apache.openjpa.kernel.exps.Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl<?> q) {
Value v = Expressions.toValue(e, factory, model, q);
public org.apache.openjpa.kernel.exps.Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
Value v = Expressions.toValue(e, factory, q);
ClassMetaData meta = ((PathImpl<?,?>)e)._member.fmd.getElement().getTypeMetaData();
v.setMetaData(meta);
return factory.index(v);
@ -1189,10 +1179,10 @@ public class Expressions {
@Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
ExpressionFactory factory, CriteriaQueryImpl<?> q) {
org.apache.openjpa.kernel.exps.Expression contains = factory.contains(
Expressions.toValue(collection, factory, model, q),
Expressions.toValue(element, factory, model, q));
Expressions.toValue(collection, factory, q),
Expressions.toValue(element, factory, q));
return contains;
}
@ -1245,14 +1235,14 @@ public class Expressions {
@Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
ExpressionFactory factory, CriteriaQueryImpl<?> q) {
String escapeStr = escapeChar == null ? null :
((Character)((Literal)Expressions.toValue(
escapeChar, factory, model, q)).getValue()).toString();
escapeChar, factory, q)).getValue()).toString();
return factory.matches(
Expressions.toValue(str, factory, model, q),
Expressions.toValue(pattern, factory, model, q),
Expressions.toValue(str, factory, q),
Expressions.toValue(pattern, factory, q),
MATCH_SINGLECHAR, MATCH_MULTICHAR, escapeStr);
}
@ -1285,11 +1275,11 @@ public class Expressions {
@Override
public org.apache.openjpa.kernel.exps.Value toValue(
ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
ExpressionFactory factory, CriteriaQueryImpl<?> q) {
Value[] vs = new Value[values.size()];
int i = 0;
for (Expression<?> e : values)
vs[i++] = Expressions.toValue((ExpressionImpl<?>)e, factory, model, q);
vs[i++] = Expressions.toValue((ExpressionImpl<?>)e, factory, q);
return factory.coalesceExpression(vs);
}
@ -1320,9 +1310,9 @@ public class Expressions {
@Override
public org.apache.openjpa.kernel.exps.Value toValue(
ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
Value value1 = Expressions.toValue((ExpressionImpl<?>)val1, factory, model, q);
Value value2 = Expressions.toValue((ExpressionImpl<?>)val2, factory, model, q);
ExpressionFactory factory, CriteriaQueryImpl<?> q) {
Value value1 = Expressions.toValue((ExpressionImpl<?>)val1, factory, q);
Value value2 = Expressions.toValue((ExpressionImpl<?>)val2, factory, q);
return factory.nullIfExpression(value1, value2);
}
@ -1350,9 +1340,9 @@ public class Expressions {
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.equal(
Expressions.toValue(e, factory, model, q),
Expressions.toValue(e, factory, q),
factory.getNull());
}
@ -1381,9 +1371,9 @@ public class Expressions {
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.notEqual(
Expressions.toValue(e, factory, model, q),
Expressions.toValue(e, factory, q),
factory.getNull());
}
@ -1432,15 +1422,15 @@ public class Expressions {
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
ExpressionFactory factory, CriteriaQueryImpl<?> q) {
org.apache.openjpa.kernel.exps.Expression inExpr = null;
if (_exps.size() == 1) {
Expressions.Equal e = (Expressions.Equal)_exps.get(0);
ExpressionImpl<?> e2 = e.e2;
ExpressionImpl<?> e1 = e.e1;
Value val2 = Expressions.toValue(e2, factory, model, q);
Value val2 = Expressions.toValue(e2, factory, q);
if (!(val2 instanceof Literal)) {
Value val1 = Expressions.toValue(e1, factory, model, q);
Value val1 = Expressions.toValue(e1, factory, q);
Expressions.setImplicitTypes(val1, val2, e1.getJavaType(), q);
inExpr = factory.contains(val2, val1);
return isNegated() ? factory.not(inExpr) : inExpr;
@ -1452,10 +1442,10 @@ public class Expressions {
}
}
}
inExpr = super.toKernelExpression(factory, model, q);
inExpr = super.toKernelExpression(factory, q);
IsNotNull notNull = new Expressions.IsNotNull(e);
return factory.and(inExpr, notNull.toKernelExpression(factory, model, q));
return factory.and(inExpr, notNull.toKernelExpression(factory, q));
}
public void acceptVisit(CriteriaExpressionVisitor visitor) {
@ -1503,17 +1493,17 @@ public class Expressions {
@Override
public org.apache.openjpa.kernel.exps.Value toValue(
ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
ExpressionFactory factory, CriteriaQueryImpl<?> q) {
int size = whens.size();
org.apache.openjpa.kernel.exps.Expression[] exps = new org.apache.openjpa.kernel.exps.Expression[size];
for (int i = 0; i < size; i++) {
org.apache.openjpa.kernel.exps.Expression expr =
((ExpressionImpl<?>)whens.get(i)).toKernelExpression(factory, model, q);
Value action = Expressions.toValue((ExpressionImpl<?>)thens.get(i), factory, model, q);
((ExpressionImpl<?>)whens.get(i)).toKernelExpression(factory, q);
Value action = Expressions.toValue((ExpressionImpl<?>)thens.get(i), factory, q);
exps[i] = factory.whenCondition(expr, action);
}
Value other = Expressions.toValue((ExpressionImpl<?>)otherwise, factory, model, q);
Value other = Expressions.toValue((ExpressionImpl<?>)otherwise, factory, q);
return factory.generalCaseExpression(exps, other);
}
@ -1583,17 +1573,17 @@ public class Expressions {
@Override
public org.apache.openjpa.kernel.exps.Value toValue(
ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
Value caseOperandExpr = Expressions.toValue((ExpressionImpl<?>)caseOperand, factory, model, q);
ExpressionFactory factory, CriteriaQueryImpl<?> q) {
Value caseOperandExpr = Expressions.toValue((ExpressionImpl<?>)caseOperand, factory, q);
int size = whens.size();
org.apache.openjpa.kernel.exps.Expression[] exps = new org.apache.openjpa.kernel.exps.Expression[size];
for (int i = 0; i < size; i++) {
Value when = Expressions.toValue((ExpressionImpl<C>)whens.get(i), factory, model, q);
Value action = Expressions.toValue((ExpressionImpl<?>)thens.get(i), factory, model, q);
Value when = Expressions.toValue((ExpressionImpl<C>)whens.get(i), factory, q);
Value action = Expressions.toValue((ExpressionImpl<?>)thens.get(i), factory, q);
exps[i] = factory.whenScalar(when, action);
}
Value other = Expressions.toValue((ExpressionImpl<?>)otherwise, factory, model, q);
Value other = Expressions.toValue((ExpressionImpl<?>)otherwise, factory, q);
return factory.simpleCaseExpression(caseOperandExpr, exps, other);
}
@ -1626,8 +1616,8 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
return factory.toLowerCase(Expressions.toValue(e, factory, model, q));
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.toLowerCase(Expressions.toValue(e, factory, q));
}
@Override
@ -1642,8 +1632,8 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
return factory.toUpperCase(Expressions.toValue(e, factory, model, q));
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.toUpperCase(Expressions.toValue(e, factory, q));
}
@Override
@ -1658,8 +1648,8 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
return factory.stringLength(Expressions.toValue(e, factory, model, q));
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.stringLength(Expressions.toValue(e, factory, q));
}
@Override
@ -1701,9 +1691,9 @@ public class Expressions {
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
ExpressionFactory factory, CriteriaQueryImpl<?> q) {
org.apache.openjpa.kernel.exps.Expression exists =
factory.isNotEmpty(Expressions.toValue(e, factory, model, q));
factory.isNotEmpty(Expressions.toValue(e, factory, q));
return exists;
}
@ -1719,9 +1709,8 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl<?> q) {
return factory.all(Expressions.toValue(e, factory, model, q));
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.all(Expressions.toValue(e, factory, q));
}
@Override
@ -1736,8 +1725,8 @@ public class Expressions {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
return factory.any(Expressions.toValue(e, factory, model, q));
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.any(Expressions.toValue(e, factory, q));
}
@Override
@ -1755,8 +1744,8 @@ public class Expressions {
@Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
return factory.not(e.toKernelExpression(factory, model, q));
ExpressionFactory factory, CriteriaQueryImpl<?> q) {
return factory.not(e.toKernelExpression(factory, q));
}
public void acceptVisit(CriteriaExpressionVisitor visitor) {
@ -1778,8 +1767,8 @@ public class Expressions {
@Override
public org.apache.openjpa.kernel.exps.Value toValue(
ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
org.apache.openjpa.kernel.exps.Value e = actual.toValue(factory, model, q);
ExpressionFactory factory, CriteriaQueryImpl<?> q) {
org.apache.openjpa.kernel.exps.Value e = actual.toValue(factory, q);
e.setImplicitType(getJavaType());
return e;
}
@ -1808,11 +1797,11 @@ public class Expressions {
@Override
public org.apache.openjpa.kernel.exps.Arguments toValue(
ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
ExpressionFactory factory, CriteriaQueryImpl<?> q) {
org.apache.openjpa.kernel.exps.Value[] kvs = new org.apache.openjpa.kernel.exps.Value[_args.length];
int i = 0;
for (ExpressionImpl<?> arg : _args) {
kvs[i++] = arg.toValue(factory, model, q);
kvs[i++] = arg.toValue(factory, q);
}
org.apache.openjpa.kernel.exps.Arguments e = factory.newArgumentList(kvs);
e.setImplicitType(getJavaType());

View File

@ -18,7 +18,6 @@
*/
package org.apache.openjpa.persistence.criteria;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
@ -39,7 +38,7 @@ import org.apache.openjpa.persistence.meta.Members;
* @param <Z> type of parent
* @param <X> type of this
*/
public class FetchPathImpl<Z,X> extends PathImpl<Z,X> implements Fetch<Z, X> {
class FetchPathImpl<Z,X> extends PathImpl<Z,X> implements Fetch<Z, X> {
protected Set<Fetch<?,?>> _fetches;
protected JoinType joinType;

View File

@ -53,7 +53,7 @@ import org.apache.openjpa.persistence.meta.Members;
* @param <X> the type represented by this receiver
*/
public class FromImpl<Z,X> extends PathImpl<Z,X> implements From<Z,X> {
class FromImpl<Z,X> extends PathImpl<Z,X> implements From<Z,X> {
private java.util.Set<Join<X, ?>> _joins;
private java.util.Set<Fetch<X, ?>> _fetches;
private Type<X> type;

View File

@ -44,7 +44,6 @@ 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.Members.KeyAttributeImpl;
import org.apache.openjpa.persistence.meta.Members.MapAttributeImpl;
import org.apache.openjpa.persistence.meta.Members.Member;
@ -58,7 +57,7 @@ import org.apache.openjpa.persistence.meta.Members.Member;
* @since 2.0.0
*
*/
public abstract class Joins {
abstract class Joins {
/**
* Join a single-valued attribute.
@ -67,7 +66,7 @@ public abstract class Joins {
* @param <Z> type from which joining
* @param <X> type of the attribute being joined
*/
public static class SingularJoin<Z,X> extends FromImpl<Z,X> implements Join<Z,X> {
static class SingularJoin<Z,X> extends FromImpl<Z,X> implements Join<Z,X> {
private final JoinType joinType;
private boolean allowNull = false;
@ -98,7 +97,7 @@ public abstract class Joins {
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> c) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> c) {
ClassMetaData meta = _member.fmd.getDeclaredTypeMetaData();
org.apache.openjpa.kernel.exps.Path path = null;
SubqueryImpl<?> subquery = c.getDelegator();
@ -113,7 +112,7 @@ public abstract class Joins {
path.setSchemaAlias(c.getAlias(this));
path.get(_member.fmd, allowNull);
} else {
path = (org.apache.openjpa.kernel.exps.Path) _parent.toValue(factory, model, c);
path = (org.apache.openjpa.kernel.exps.Path) _parent.toValue(factory, c);
path.get(_member.fmd, allowNull);
path.setMetaData(meta);
path.setImplicitType(meta.getDescribedType());
@ -123,7 +122,7 @@ public abstract class Joins {
@Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory,
MetamodelImpl model, CriteriaQueryImpl<?> c) {
CriteriaQueryImpl<?> c) {
ClassMetaData meta = _member.fmd.getDeclaredTypeMetaData();
org.apache.openjpa.kernel.exps.Path path = null;
SubqueryImpl<?> subquery = c.getDelegator();
@ -158,7 +157,7 @@ public abstract class Joins {
path.setMetaData(meta);
path.get(_member.fmd, false);
} else
path = (org.apache.openjpa.kernel.exps.Path)toValue(factory, model, c);
path = (org.apache.openjpa.kernel.exps.Path)toValue(factory, c);
Class<?> type = meta == null ? AbstractExpressionBuilder.TYPE_OBJECT : meta.getDescribedType();
Value var = null;
@ -176,7 +175,7 @@ public abstract class Joins {
if (getJoins() != null) {
for (Join<?, ?> join1 : getJoins()) {
filter = Expressions.and(factory,
((FromImpl<?,?>)join1).toKernelExpression(factory, model, c), filter);
((FromImpl<?,?>)join1).toKernelExpression(factory, c), filter);
}
}
org.apache.openjpa.kernel.exps.Expression expr = Expressions.and(factory, join, filter);
@ -188,9 +187,9 @@ public abstract class Joins {
if (corrJoins != null && corrJoins.contains(_parent)) {
Value var = getVariableForCorrPath(subquery, correlatedParentPath);
parentPath = factory.newPath(var);
} else
parentPath = (org.apache.openjpa.kernel.exps.Path)
correlatedParentPath.toValue(factory, model, c);
} else {
parentPath = (org.apache.openjpa.kernel.exps.Path)correlatedParentPath.toValue(factory, c);
}
parentPath.get(_member.fmd, allowNull);
parentPath.setSchemaAlias(c.getAlias(correlatedParentPath));
if (c.ctx().getParent() != null && c.ctx().getVariable(parentPath.getSchemaAlias()) == null)
@ -269,7 +268,7 @@ public abstract class Joins {
* @param E type of the element being joined to
*
*/
public static abstract class AbstractCollection<Z,C,E> extends FromImpl<Z,E> implements PluralJoin<Z, C, E> {
static abstract class AbstractCollection<Z,C,E> extends FromImpl<Z,E> implements PluralJoin<Z, C, E> {
private final JoinType joinType;
private boolean allowNull = false;
@ -309,7 +308,7 @@ public abstract class Joins {
* Convert this path to a kernel path (value).
*/
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> c) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> c) {
org.apache.openjpa.kernel.exps.Path path = null;
SubqueryImpl<?> subquery = c.getDelegator();
PathImpl<?,?> parent = getInnermostParentPath();
@ -323,7 +322,7 @@ public abstract class Joins {
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, c);
path.get(_member.fmd, allowNull);
}
return path;
@ -335,7 +334,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();
@ -374,7 +373,7 @@ public abstract class Joins {
path.setMetaData(meta);
path.get(_member.fmd, false);
} else {
path = (org.apache.openjpa.kernel.exps.Path)toValue(factory, model, c);
path = (org.apache.openjpa.kernel.exps.Path)toValue(factory, c);
}
Class<?> type = meta == null ? AbstractExpressionBuilder.TYPE_OBJECT : meta.getDescribedType();
if (bind) {
@ -386,7 +385,7 @@ public abstract class Joins {
if (getJoins() != null) {
for (Join<?, ?> join1 : getJoins()) {
filter = Expressions.and(factory,
((FromImpl<?,?>)join1).toKernelExpression(factory, model, c), filter);
((FromImpl<?,?>)join1).toKernelExpression(factory, c), filter);
}
}
org.apache.openjpa.kernel.exps.Expression expr = Expressions.and(factory, join, filter);
@ -398,8 +397,7 @@ public abstract class Joins {
Value var = getVariableForCorrPath(subquery, correlatedParentPath);
parentPath = factory.newPath(var);
} else {
parentPath = (org.apache.openjpa.kernel.exps.Path)
correlatedParentPath.toValue(factory, model, c);
parentPath = (org.apache.openjpa.kernel.exps.Path) correlatedParentPath.toValue(factory, c);
}
parentPath.get(_member.fmd, allowNull);
parentPath.setSchemaAlias(c.getAlias(correlatedParentPath));
@ -442,7 +440,7 @@ public abstract class Joins {
* @param <Z> the type from which being joined
* @param <E> the type of the the collection attribute elements
*/
public static class Collection<Z,E> extends AbstractCollection<Z,java.util.Collection<E>,E>
static class Collection<Z,E> extends AbstractCollection<Z,java.util.Collection<E>,E>
implements CollectionJoin<Z,E>{
public Collection(FromImpl<?,Z> parent, Members.CollectionAttributeImpl<? super Z, E> member, JoinType jt) {
super(parent, member, jt);
@ -459,7 +457,7 @@ public abstract class Joins {
* @param <Z> the type from which being joined
* @param <E> the type of the the set attribute elements
*/
public static class Set<Z,E> extends AbstractCollection<Z,java.util.Set<E>,E>
static class Set<Z,E> extends AbstractCollection<Z,java.util.Set<E>,E>
implements SetJoin<Z,E> {
public Set(FromImpl<?,Z> parent, Members.SetAttributeImpl<? super Z, E> member, JoinType jt) {
super(parent, member, jt);
@ -477,7 +475,7 @@ public abstract class Joins {
* @param <E> the type of the the list attribute elements
*/
public static class List<Z,E> extends AbstractCollection<Z,java.util.List<E>,E>
static class List<Z,E> extends AbstractCollection<Z,java.util.List<E>,E>
implements ListJoin<Z,E> {
public List(FromImpl<?,Z> parent, Members.ListAttributeImpl<? super Z, E> member, JoinType jt) {
@ -501,7 +499,7 @@ public abstract class Joins {
* @param <V> the type of the the map attribute values
*/
public static class Map<Z,K,V> extends AbstractCollection<Z,java.util.Map<K,V>,V>
static class Map<Z,K,V> extends AbstractCollection<Z,java.util.Map<K,V>,V>
implements MapJoin<Z,K,V> {
private KeyJoin<K,V> _keyJoin;
@ -544,15 +542,15 @@ public abstract class Joins {
@Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory,
MetamodelImpl model, CriteriaQueryImpl<?> c) {
CriteriaQueryImpl<?> c) {
return (_keyJoin == null)
? super.toKernelExpression(factory, model, c)
: _keyJoin.toKernelExpression(factory, model, c);
? super.toKernelExpression(factory, c)
: _keyJoin.toKernelExpression(factory, c);
}
}
public static class MapKey<Z,K> extends PathImpl<Z,K> {
static class MapKey<Z,K> extends PathImpl<Z,K> {
private final Map<?,K,?> map;
private final MapAttributeImpl<Z, K, ?> attr;
@ -572,7 +570,7 @@ public abstract class Joins {
*
*/
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> c) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> c) {
Value val = c.getRegisteredVariable(map);
org.apache.openjpa.kernel.exps.Path path = factory.newPath(val);
return factory.getKey(path);
@ -587,7 +585,7 @@ public abstract class Joins {
}
}
public static class MapEntry<K,V> extends ExpressionImpl<java.util.Map.Entry<K,V>> {
static class MapEntry<K,V> extends ExpressionImpl<java.util.Map.Entry<K,V>> {
private final Map<?,K,V> map;
public MapEntry(Map<?,K,V> joinMap){
@ -600,7 +598,7 @@ public abstract class Joins {
*
*/
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> c) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> c) {
Value val = c.getRegisteredVariable(map);
org.apache.openjpa.kernel.exps.Path path = factory.newPath(val);
org.apache.openjpa.kernel.exps.Path var = factory.newPath(val);
@ -624,15 +622,15 @@ public abstract class Joins {
* @param <K> the type of the key of the original java.util.Map attribute
* @param <V> the type of the value of the original java.util.Map attribute
*/
public static class KeyJoin<K,V> extends Joins.Set<java.util.Map<K, V>, K> {
static class KeyJoin<K,V> extends Joins.Set<java.util.Map<K, V>, K> {
public KeyJoin(FromImpl<?, java.util.Map<K, V>> parent, KeyAttributeImpl<? super java.util.Map<K, V>, K> member,
JoinType jt) {
super(parent, member, jt);
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> c) {
return factory.getKey(getParent().toValue(factory, model, c));
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> c) {
return factory.getKey(getParent().toValue(factory, c));
}
}
}

View File

@ -1,6 +1,7 @@
package org.apache.openjpa.persistence.criteria;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.metamodel.Metamodel;
/**
* OpenJPA-specific extension to JPA 2.0 Criteria Query API.
@ -18,4 +19,11 @@ public interface OpenJPACriteriaQuery<T> extends CriteriaQuery<T> {
* @return a JPQL-like string.
*/
public String toCQL();
/**
* Compile the query.
*
* @return the same instance compiled.
*/
public OpenJPACriteriaQuery<T> compile();
}

View File

@ -27,7 +27,7 @@ import javax.persistence.criteria.Order;
* @author Pinaki Poddar
*
*/
public class OrderImpl implements Order, CriteriaExpression {
class OrderImpl implements Order, CriteriaExpression {
private boolean _ascending;
private final ExpressionImpl<?> e;

View File

@ -24,7 +24,6 @@ import javax.persistence.criteria.ParameterExpression;
import org.apache.openjpa.kernel.exps.ExpressionFactory;
import org.apache.openjpa.kernel.exps.Value;
import org.apache.openjpa.persistence.meta.MetamodelImpl;
import org.apache.openjpa.util.InternalException;
/**
@ -39,7 +38,7 @@ import org.apache.openjpa.util.InternalException;
*
* @param <T> the type of value held by this parameter.
*/
public class ParameterExpressionImpl<T> extends ExpressionImpl<T>
class ParameterExpressionImpl<T> extends ExpressionImpl<T>
implements ParameterExpression<T> {
private String _name;
private int _index = 0; // index of the parameter as seen by the kernel, not position
@ -87,7 +86,7 @@ public class ParameterExpressionImpl<T> extends ExpressionImpl<T>
}
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
Class<?> clzz = getJavaType();
Object paramKey = _name == null ? _index : _name;
boolean isCollectionValued = Collection.class.isAssignableFrom(clzz);

View File

@ -36,7 +36,6 @@ import org.apache.openjpa.kernel.exps.Value;
import org.apache.openjpa.meta.ClassMetaData;
import org.apache.openjpa.meta.FieldMetaData;
import org.apache.openjpa.persistence.meta.Members;
import org.apache.openjpa.persistence.meta.MetamodelImpl;
/**
* Represents a simple or compound attribute path from a
@ -54,7 +53,7 @@ import org.apache.openjpa.persistence.meta.MetamodelImpl;
* @param <Z> the type of the parent path
* @param <X> the type of this path
*/
public class PathImpl<Z,X> extends ExpressionImpl<X> implements Path<X> {
class PathImpl<Z,X> extends ExpressionImpl<X> implements Path<X> {
protected final PathImpl<?,Z> _parent;
protected final Members.Member<? super Z,?> _member;
private boolean isEmbedded = false;
@ -151,7 +150,7 @@ public class PathImpl<Z,X> extends ExpressionImpl<X> implements Path<X> {
* Convert this path to a kernel path.
*/
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
if (q.isRegistered(this))
return q.getRegisteredValue(this);
org.apache.openjpa.kernel.exps.Path path = null;
@ -171,7 +170,7 @@ public class PathImpl<Z,X> extends ExpressionImpl<X> implements Path<X> {
path.setSchemaAlias(q.getAlias(_parent));
traversePath(_parent, path, _member.fmd);
} else if (_parent != null) {
Value val = _parent.toValue(factory, model, q);
Value val = _parent.toValue(factory, q);
if (val instanceof org.apache.openjpa.kernel.exps.Path) {
path = (org.apache.openjpa.kernel.exps.Path)val;
path.get(_member.fmd, allowNull);
@ -181,7 +180,7 @@ public class PathImpl<Z,X> extends ExpressionImpl<X> implements Path<X> {
}
} else if (_parent == null) {
path = factory.newPath();
path.setMetaData(model.getRepository().getCachedMetaData(getJavaType()));
path.setMetaData(q.getMetamodel().getRepository().getCachedMetaData(getJavaType()));
}
if (_member != null && !_member.isCollection()) {
path.setImplicitType(getJavaType());

View File

@ -26,7 +26,6 @@ import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;
import org.apache.openjpa.kernel.exps.ExpressionFactory;
import org.apache.openjpa.persistence.meta.MetamodelImpl;
/**
* Predicate is a expression that evaluates to true or false.
@ -39,9 +38,11 @@ import org.apache.openjpa.persistence.meta.MetamodelImpl;
* Negation of a Predicate creates a new Predicate.
*
* @author Pinaki Poddar
*
* @author Fay Wang
*
* @since 2.0.0
*/
public abstract class PredicateImpl extends ExpressionImpl<Boolean> implements Predicate {
abstract class PredicateImpl extends ExpressionImpl<Boolean> implements Predicate {
private static final ExpressionImpl<Integer> ONE = new Expressions.Constant<Integer>(1);
public static final Predicate TRUE = new Expressions.Equal(ONE,ONE);
public static final Predicate FALSE = new Expressions.NotEqual(ONE,ONE);
@ -51,14 +52,14 @@ public abstract class PredicateImpl extends ExpressionImpl<Boolean> implements P
private boolean _negated = false;
/**
* A predicate no arguments representing AND operator.
* An AND predicate with no arguments.
*/
protected PredicateImpl() {
this(BooleanOperator.AND);
}
/**
* A predicate representing given operator.
* A predicate with the given operator.
*/
protected PredicateImpl(BooleanOperator op) {
super(Boolean.class);
@ -96,14 +97,20 @@ public abstract class PredicateImpl extends ExpressionImpl<Boolean> implements P
return _op;
}
/**
* Is this predicate created by negating another predicate?
*/
public final boolean isNegated() {
return _negated;
}
/**
* Returns a new predicate as the negation of this predicate.
* <br>
* Note:
* Default negation creates a Not expression with this receiver as delegate.
* Derived predicates can return the inverse expression such as NotEqual
* for Equal or LessThan for GreaterThanEqual etc.
* Derived predicates can return the inverse expression, if exists.
* For example, NotEqual for Equal or LessThan for GreaterThanEqual etc.
*/
public PredicateImpl negate() {
return new Expressions.Not(this).markNegated();
@ -115,45 +122,45 @@ public abstract class PredicateImpl extends ExpressionImpl<Boolean> implements P
}
@Override
org.apache.openjpa.kernel.exps.Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl<?> q) {
org.apache.openjpa.kernel.exps.Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
throw new AbstractMethodError(this.getClass().getName());
}
@Override
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl<?> q) {
org.apache.openjpa.kernel.exps.Expression toKernelExpression(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
if (_exps.isEmpty()) {
Predicate nil = _op == BooleanOperator.AND ? TRUE : FALSE;
return ((PredicateImpl)nil).toKernelExpression(factory, model, q);
return ((PredicateImpl)nil).toKernelExpression(factory, q);
}
if (_exps.size() == 1) {
Predicate e0 = _exps.get(0);
if (isNegated())
e0 = e0.negate();
return ((PredicateImpl)e0).toKernelExpression(factory, model, q);
return ((PredicateImpl)e0).toKernelExpression(factory, q);
}
ExpressionImpl<?> e1 = (ExpressionImpl<?>)_exps.get(0);
ExpressionImpl<?> e2 = (ExpressionImpl<?>)_exps.get(1);
org.apache.openjpa.kernel.exps.Expression ke1 = e1.toKernelExpression(factory, model, q);
org.apache.openjpa.kernel.exps.Expression ke2 = e2.toKernelExpression(factory, model, q);
org.apache.openjpa.kernel.exps.Expression ke1 = e1.toKernelExpression(factory, q);
org.apache.openjpa.kernel.exps.Expression ke2 = e2.toKernelExpression(factory, q);
org.apache.openjpa.kernel.exps.Expression result = _op == BooleanOperator.AND
? factory.and(ke1,ke2) : factory.or(ke1, ke2);
for (int i = 2; i < _exps.size(); i++) {
PredicateImpl p = (PredicateImpl)_exps.get(i);
result = _op == BooleanOperator.AND
? factory.and(result, p.toKernelExpression(factory, model, q))
: factory.or(result, p.toKernelExpression(factory,model,q));
? factory.and(result, p.toKernelExpression(factory, q))
: factory.or(result, p.toKernelExpression(factory,q));
}
return _negated ? factory.not(result) : result;
}
@Override
public void acceptVisit(CriteriaExpressionVisitor visitor) {
Expressions.acceptVisit(visitor, this, _exps.toArray(new Expression<?>[_exps.size()]));
}
@Override
public StringBuilder asValue(AliasContext q) {
boolean braces = _exps.size() > 1;
StringBuilder buffer = Expressions.asValue(q, _exps.toArray(new Expression<?>[_exps.size()]), " " +_op + " ");
@ -166,7 +173,7 @@ public abstract class PredicateImpl extends ExpressionImpl<Boolean> implements P
* Concrete AND predicate.
*
*/
public static class And extends PredicateImpl {
static class And extends PredicateImpl {
public And(Expression<Boolean> x, Expression<Boolean> y) {
super(BooleanOperator.AND);
add(x).add(y);
@ -181,7 +188,7 @@ public abstract class PredicateImpl extends ExpressionImpl<Boolean> implements P
* Concrete OR predicate.
*
*/
public static class Or extends PredicateImpl {
static class Or extends PredicateImpl {
public Or(Expression<Boolean> x, Expression<Boolean> y) {
super(BooleanOperator.OR);
add(x).add(y);

View File

@ -34,11 +34,14 @@ import org.apache.openjpa.persistence.meta.Types;
/**
* A root path without a parent.
*
* @author Pinaki Poddar
*
* @param <X> the type of the entity
*
* @author Pinaki Poddar
* @author Fay Wang
*
* @since 2.0.0
*/
public class RootImpl<X> extends FromImpl<X,X> implements Root<X> {
class RootImpl<X> extends FromImpl<X,X> implements Root<X> {
private final Types.Entity<X> _entity;
public RootImpl(Types.Entity<X> type) {
@ -65,8 +68,7 @@ public class RootImpl<X> extends FromImpl<X,X> implements Root<X> {
* Convert this path to a kernel path value.
*/
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model,
CriteriaQueryImpl<?> c) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> c) {
SubqueryImpl<?> subquery = c.getDelegator();
Path var = null;
Value val = null;
@ -92,8 +94,8 @@ public class RootImpl<X> extends FromImpl<X,X> implements Root<X> {
*/
@Override
public org.apache.openjpa.kernel.exps.Expression toKernelExpression(
ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> c) {
Value path = toValue(factory, model, c);
ExpressionFactory factory, CriteriaQueryImpl<?> c) {
Value path = toValue(factory, c);
Value var = factory.newBoundVariable(c.getAlias(this),
_entity.meta.getDescribedType());
return factory.bindVariable(var, path);

View File

@ -23,17 +23,20 @@ import java.util.List;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Selection;
import org.apache.openjpa.kernel.exps.ExpressionFactory;
import org.apache.openjpa.persistence.util.ReservedWords;
/**
* An item selected in the projection clause of Criteria query.
* Base implementation for all concrete expressions.
*
* @param <X> the type this term evaluates to
*
* @author Pinaki Poddar
*
* @param <X>
* @since 2.0.0
*/
public abstract class SelectionImpl<X> implements Selection<X>, CriteriaExpression {
abstract class SelectionImpl<X> implements Selection<X>, CriteriaExpression {
private final Class<X> _cls;
private String _alias;
private Boolean _autoAliased;

View File

@ -54,12 +54,14 @@ import org.apache.openjpa.persistence.meta.Types;
* context of a parent query. A subquery delegates to a captive query for most
* of the operations but also maintains its own joins and correlated joins.
*
* @param <T> the type selected by this subquery.
*
* @author Pinaki Poddar
* @author Fay Wang
*
* @param <T> the type selected by this subquery.
* @since 2.0.0
*/
public class SubqueryImpl<T> extends ExpressionImpl<T> implements Subquery<T> {
class SubqueryImpl<T> extends ExpressionImpl<T> implements Subquery<T> {
private final AbstractQuery<?> _parent;
private final CriteriaQueryImpl<T> _delegate;
private final MetamodelImpl _model;
@ -299,7 +301,7 @@ public class SubqueryImpl<T> extends ExpressionImpl<T> implements Subquery<T> {
* Convert this path to a kernel path value.
*/
@Override
public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) {
final boolean subclasses = true;
CriteriaExpressionBuilder exprBuilder = new CriteriaExpressionBuilder();
String alias = q.getAlias(this);