@Override public String getJDOQLForExpression(org.datanucleus.query.expression.Expression expr) { if (expr instanceof VariableExpression) { VariableExpression varExpr = (VariableExpression)expr; if (subqueries != null) { for (JDOQLTypedSubqueryImpl subq : subqueries) { if (varExpr.getId().equals(subq.getAlias())) { // This variable represents a subquery so return the subquery text, so we form a single-string including subqueries return "(" + subq.toString() + ")"; } } } } return super.getJDOQLForExpression(expr); }
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; }
} else if (expr instanceof VariableExpression) { VariableExpression varExpr = (VariableExpression) expr; if (varExpr.getSymbol() != null && varExpr.getSymbol().getQualifiedName() != null) { h.compilation.getCompilationForSubquery(varExpr.getSymbol().getQualifiedName()); if (subCompilation != null) { AbstractClassMetaData cmd = throw new NucleusUserException( "Unexpected expression type while parsing query. Are you certain that a field named " + varExpr.getId() + " exists on your object?");
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); }
} else if (expr instanceof VariableExpression) { VariableExpression varExpr = (VariableExpression) expr; if (varExpr.getSymbol() != null && varExpr.getSymbol().getQualifiedName() != null) { h.compilation.getCompilationForSubquery(varExpr.getSymbol().getQualifiedName()); if (subCompilation != null) { AbstractClassMetaData cmd = throw new NucleusUserException( "Unexpected expression type while parsing query. Are you certain that a field named " + varExpr.getId() + " exists on your object?");
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"); } } }
private AbstractClassMetaData getJoinClassMetaData(Expression expr, List<String> tuples, QueryData qd) { if (expr instanceof VariableExpression) { // Change the class meta data to the meta-data for the joined class if (qd.joinVariableExpression == null) { throw new NucleusFatalUserException( query.getSingleStringQuery() + ": Encountered a variable expression that isn't part of a join. Maybe you're " + "referencing a non-existent field of an embedded class."); } if (!((VariableExpression) expr).getId().equals(qd.joinVariableExpression.getId())) { throw new NucleusFatalUserException( query.getSingleStringQuery() + ": Encountered a variable (" + ((VariableExpression) expr).getId() + ") that doesn't match the join variable (" + qd.joinVariableExpression.getId() + ")"); } Class<?> joinedClass = getSymbolTable().getSymbol(qd.joinVariableExpression.getId()).getValueType(); return getMetaDataManager().getMetaDataForClass(joinedClass, getClassLoaderResolver()); } Symbol sym = getSymbolTable().getSymbol(tuples.get(0)); tuples.remove(0); return getMetaDataManager().getMetaDataForClass(sym.getValueType(), getClassLoaderResolver()); }
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; }
/** * 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); } }
return varExpr.getId();
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; }
return varExpr.getId();
QueryCompilation subCompilation = subDelegate.getCompilation(mmgr, clr); subCompilation.setQueryLanguage("JPQL"); compilation.addSubqueryCompilation(subqueryVar.getId(), subCompilation); QueryCompilation subCompilation = subDelegate.getCompilation(mmgr, clr); subCompilation.setQueryLanguage("JPQL"); compilation.addSubqueryCompilation(subVarExpr.getId(), subCompilation);
"Unexpected expression type while parsing query. Variables not supported by GAE (" + varExpr.getId() + ")"); } else { throw new UnsupportedDatastoreFeatureException(
exprCastName = "CAST_" + ((VariableExpression)expr.getLeft().getLeft()).getId(); SQLTableMapping varTblMapping = getSQLTableMappingForAlias(varExpr.getId()); if (varTblMapping == null) throw new NucleusUserException("Variable " + varExpr.getId() + " is not yet bound, so cannot get field " + expr.getId()); throw new NucleusUserException("Variable " + varExpr.getId() + " of type " + varType.getName() + " cannot evaluate " + expr.getId()); SQLTableMapping sqlMapping = getSQLTableMappingForPrimaryExpression(varSqlExpr.getSQLStatement(), varExpr.getId(), expr, Boolean.FALSE); sqlExpr = exprFactory.newExpression(sqlMapping.table.getSQLStatement(), sqlMapping.table, sqlMapping.mapping); stack.push(sqlExpr);