public SubqueryImpl(Class<T> type, CriteriaQuery<?> query) { super(type); this.parent = (CriteriaQueryImpl<?>) query; this.delegate = new CriteriaQueryImpl<T>((MetamodelImpl) parent.getMetamodel(), type); String variableName = "SUB" + random.nextInt(); this.queryExpr = new VariableExpression(variableName); }
public <Y> Expression<Y> all(Subquery<Y> sub) { ExpressionImpl<Y> allExpr = new ExpressionImpl<Y>((Class<Y>) sub.getJavaType()); org.datanucleus.query.expression.Expression subExpr = ((SubqueryImpl<Y>)sub).getQueryExpression(); String varName = null; if (subExpr instanceof VariableExpression) { varName = ((VariableExpression)subExpr).getId(); } else { varName = "SUB" + SubqueryImpl.random.nextInt(); } allExpr.queryExpr = new SubqueryExpression("ALL", new VariableExpression(varName)); return allExpr; }
public <Y> Expression<Y> some(Subquery<Y> sub) { ExpressionImpl<Y> allExpr = new ExpressionImpl<Y>((Class<Y>) sub.getJavaType()); org.datanucleus.query.expression.Expression subExpr = ((SubqueryImpl<Y>)sub).getQueryExpression(); String varName = null; if (subExpr instanceof VariableExpression) { varName = ((VariableExpression)subExpr).getId(); } else { varName = "SUB" + SubqueryImpl.random.nextInt(); } allExpr.queryExpr = new SubqueryExpression("SOME", new VariableExpression(varName)); return allExpr; }
public <Y> Expression<Y> any(Subquery<Y> sub) { ExpressionImpl<Y> allExpr = new ExpressionImpl<Y>((Class<Y>) sub.getJavaType()); org.datanucleus.query.expression.Expression subExpr = ((SubqueryImpl<Y>)sub).getQueryExpression(); String varName = null; if (subExpr instanceof VariableExpression) { varName = ((VariableExpression)subExpr).getId(); } else { varName = "SUB" + SubqueryImpl.random.nextInt(); } allExpr.queryExpr = new SubqueryExpression("ANY", new VariableExpression(varName)); return allExpr; }
protected Expression internalSelect(Expression expr, Class implClass) { discardCompiled(); this.result = new ArrayList<ExpressionImpl>(); this.result.add((ExpressionImpl)expr); VariableExpression varExpr = new VariableExpression(getAlias()); try { Constructor ctr = implClass.getConstructor(new Class[] {org.datanucleus.query.expression.Expression.class}); return (Expression)ctr.newInstance(new Object[] {varExpr}); } catch (NoSuchMethodException nsme) { throw new JDOException("Unable to create expression of type " + expr.getClass().getName() + " since required constructor doesnt exist"); } catch (InvocationTargetException ite) { throw new JDOException("Unable to create expression of type " + expr.getClass().getName() + " due to error in constructor"); } catch (IllegalAccessException iae) { throw new JDOException("Unable to create expression of type " + expr.getClass().getName() + " due to error in constructor"); } catch (InstantiationException ie) { throw new JDOException("Unable to create expression of type " + expr.getClass().getName() + " due to error in constructor"); } } }
/** * Constructor for a parameter or variable of this type. * @param cls The type of the parameter/variable * @param name Name of the member to access * @param type The type, whether parameter or variable */ public ExpressionImpl(Class cls, String name, ExpressionType type) { if (type == ExpressionType.PARAMETER || type == ExpressionType.VARIABLE) { exprType = type; } else { throw new JDOException("Should not have called this constructor of ExpressionImpl!"); } if (exprType == ExpressionType.PARAMETER) { queryExpr = new ParameterExpression(name, cls); } else if (exprType == ExpressionType.VARIABLE) { queryExpr = new VariableExpression(name, cls); } }