public void setImplicitTypes(Value val1, Value val2, Class<?> expected) { String currQuery = currentQuery(); setImplicitTypes(val1, val2, expected, resolver, parameterTypes, currQuery); }
private void checkEmbeddable(Value val) { checkEmbeddable(val, currentQuery()); }
private Expression evalFromItem(Expression exp, JPQLNode node, boolean needsAlias) { ClassMetaData cmd = resolveClassMetaData(firstChild(node)); throw parseException(EX_USER, "alias-required", new Object[]{ cmd }, null); } else { alias = right(node).text; JPQLNode left = left(node); addSchemaToContext(alias, cmd); if (isPath(left)) { Path path = getPath(left); return getSubquery(alias, path, exp); } else { Value var = getVariable(alias, true); var.setMetaData(cmd); bind(var); if (ctx().schemaAlias == null) setCandidate(cmd, alias); else addAccessPath(cmd);
private void setCandidate(ClassMetaData cmd, String schemaAlias) { addAccessPath(cmd); if (cmd != null) ctx().meta = cmd; if (schemaAlias != null) ctx().schemaAlias = schemaAlias; }
/** * Returns the class name using the children of the JPQLNode. */ private String assertSchemaName(JPQLNode node) { if (node.id != JJTABSTRACTSCHEMANAME) throw parseException(EX_USER, "not-identifer", new Object[]{ node }, null); return assemble(node); }
return eval(onlyChild(node)); return getType(onlyChild(node)); return getTypeLiteral(node); return getPathOrConstant(node); return eval(onlyChild(node)); return getSimpleCaseExpression(node); return getGeneralCaseExpression(node); return getWhenCondition(node); return getWhenScalar(node); return getCoalesceExpression(node); return getNullIfExpression(node); return getExpression(onlyChild(node)); ? node.text.substring(0, node.text.length() - 1) : node.text). multiply(new BigDecimal(negative(node))); return factory.newLiteral(Long.valueOf(intlit.longValue()), Literal.TYPE_NUMBER);
return getExpression(onlyChild(node)); ? node.text.substring(0, node.text.length() - 1) : node.text). multiply(new BigDecimal(negative(node))); return factory.newLiteral(new Long(intlit.longValue()), Literal.TYPE_NUMBER); ? node.text.substring(0, node.text.length() - 1) : node.text). multiply(new BigDecimal(negative(node))); return factory.newLiteral(declit, Literal.TYPE_NUMBER); case JJTTRIMCHARACTER: case JJTESCAPECHARACTER: return factory.newLiteral(trimQuotes(node.text), Literal.TYPE_SQ_STRING); return eval(firstChild(node)); return getParameter(node.text, false); return getParameter(node.text, true); return factory.or(getExpression(left(node)), getExpression(right(node))); return and(getExpression(left(node)), getExpression(right(node)));
QueryExpressions getQueryExpressions() { QueryExpressions exps = new QueryExpressions(); evalQueryOperation(exps); Expression filter = null; filter = and(evalFromClause(root().id == JJTSELECT), filter); filter = and(evalWhereClause(), filter); filter = and(evalSelectClause(exps), filter); exps.filter = filter == null ? factory.emptyExpression() : filter; evalGroupingClause(exps); evalHavingClause(exps); evalFetchJoins(exps); evalSetClause(exps); evalOrderingClauses(exps); if (parameterTypes != null) exps.parameterTypes = parameterTypes; exps.accessPath = getAccessPath(); return exps; }
private Expression addJoin(Path path, JPQLNode aliasNode, Expression exp) { FieldMetaData fmd = path.last(); if (fmd == null) throw parseException(EX_USER, "path-no-meta", new Object[]{ path, null }, null); String alias = aliasNode != null ? aliasNode.text : nextAlias(); Value var = getVariable(alias, true); var.setMetaData(getFieldType(fmd)); Expression join = null; // if the variable is already bound, get the var's value and // do a regular contains with that boolean bound = isBound(var); if (bound) { var = getValue(aliasNode, VAR_PATH); } else { bind(var); join = and(join, factory.bindVariable(var, path)); } if (!fmd.isTypePC()) // multi-valued relation { if (bound) join = and(join, factory.contains(path, var)); setImplicitContainsTypes(path, var, CONTAINS_TYPE_ELEMENT); } return and(exp, join); }
private Expression evalFromItem(Expression exp, JPQLNode node, boolean needsAlias) { ClassMetaData cmd = resolveClassMetaData(firstChild(node)); throw parseException(EX_USER, "alias-required", new Object[]{ cmd }, null); } else { alias = right(node).text; JPQLNode left = left(node); if (isPath(left)) { Path path = getPath(left); setCandidate(getFieldType(path.last()), alias); Path subpath = factory.newPath(ctx().subquery); subpath.setMetaData(ctx().subquery.getMetaData()); return and(exp, factory.equal(path, subpath)); } else { Value var = getVariable(alias, true); var.setMetaData(cmd); bind(var); if (ctx().schemaAlias == null) setCandidate(cmd, alias);
protected void evalSetClause(QueryExpressions exps) { // handle SET field = value JPQLNode[] nodes = root().findChildrenByID(JJTUPDATEITEM); for (int i = 0; nodes != null && i < nodes.length; i++) { Path path = getPath(firstChild(nodes[i])); if (path.last().getValue().getEmbeddedMetaData() != null) throw parseException(EX_USER, "cant-bulk-update-embeddable", new Object[]{assemble(firstChild(nodes[i]))}, null); JPQLNode lastChild = lastChild(nodes[i]); Value val = (lastChild.children == null) ? null : getValue(onlyChild(lastChild)); exps.putUpdate(path, val); } }
/** * Adds a join condition to the given expression. * * @param node the node to check * @param inner whether or not the join should be an inner join * @param exp an existing expression to AND, or null if none * @return the Expression with the join condition added */ private Expression addJoin(JPQLNode node, boolean inner, Expression exp) { // the type will be the declared type for the field JPQLNode firstChild = firstChild(node); Path path = null; if (firstChild.id == JJTQUALIFIEDPATH) path = (Path) getQualifiedPath(firstChild); else path = getPath(firstChild, false, inner); JPQLNode alias = node.getChildCount() >= 2 ? right(node) : null; // OPENJPA-15 support subquery's from clause do not start with // identification_variable_declaration() if (inner && ctx().getParent() != null && ctx().schemaAlias == null) { return getSubquery(alias.text, path, exp); } return addJoin(path, alias, exp); }
private Value getSubquery(JPQLNode node) { final boolean subclasses = true; // parse the subquery ParsedJPQL parsed = new ParsedJPQL(node.parser.jpql, node); Context subContext = new Context(parsed, null, ctx()); contexts.push(subContext); ClassMetaData candidate = getCandidateMetaData(node); Subquery subq = subContext.getSubquery(); if (subq == null) { subq = factory.newSubquery(candidate, subclasses, nextAlias()); subContext.setSubquery(subq); } subq.setMetaData(candidate); // evaluate from clause for resolving variables defined in subquery JPQLNode from = node.getChild(1); subContext.from = evalFromClause(from, true); try { QueryExpressions subexp = getQueryExpressions(); subq.setQueryExpressions(subexp); if (subexp.projections.length > 0) checkEmbeddable(subexp.projections[0]); return subq; } finally { // remove the subquery parse context contexts.pop(); } }
return null; JPQLNode selectNode = root(); JPQLNode selectChild = firstChild(expNode); return assignSubselectProjection(onlyChild(selectChild), exps); onlyChild(selectChild) != null) { JPQLNode child = onlyChild(selectChild); if (child.id == JJTSCALAREXPRESSION) child = onlyChild(child); if (assertSchemaAlias().equalsIgnoreCase(child.text)) { return null; List<String> aliases = new ArrayList<String>(); List<String> clauses = new ArrayList<String>(); evalProjectionsResultShape(expNode, exps, projections, aliases, clauses); exps.projections = projections.toArray(new Value[projections.size()]); exps.projectionAliases = aliases.toArray(new String[aliases.size()]);
/** * Adds a join condition to the given expression. * * @param node the node to check * @param inner whether or not the join should be an inner join * @param exp an existing expression to AND, or null if none * @return the Expression with the join condition added */ private Expression addJoin(JPQLNode node, boolean inner, Expression exp) { // the type will be the declared type for the field Path path = getPath(firstChild(node), false, inner); JPQLNode alias = node.getChildCount() >= 2 ? right(node) : null; // OPENJPA-15 support subquery's from clause do not start with // identification_variable_declaration() if (inner && ctx().subquery != null && ctx().schemaAlias == null) { setCandidate(getFieldType(path.last()), alias.text); Path subpath = factory.newPath(ctx().subquery); subpath.setMetaData(ctx().subquery.getMetaData()); exp = and(exp, factory.equal(path, subpath)); } return addJoin(path, alias, exp); }
return null; JPQLNode selectNode = root(); String resultClassName = assemble(left(constructor)); exps.resultClass = resolver.classForName(resultClassName, null); return assignProjections(right(constructor), exps); } else { JPQLNode selectChild = firstChild(expNode); onlyChild(selectChild) != null && assertSchemaAlias(). equalsIgnoreCase(onlyChild(selectChild).text)) { return null; } else { return assignProjections(expNode, exps);
private Expression getSubquery(String alias, Path path, Expression exp) { Value var = getVariable(alias, true); // this bind is for validateMapPath to resolve alias Expression bindVar = factory.bindVariable(var, path); FieldMetaData fmd = path.last(); ClassMetaData candidate = getFieldType(fmd); if (candidate == null && fmd.isElementCollection()) candidate = fmd.getDefiningMetaData(); setCandidate(candidate, alias); Context subContext = ctx(); Subquery subquery = ctx().getSubquery(); if (subquery == null){ subquery = factory.newSubquery(candidate, true, alias); subContext.setSubquery(subquery); } else { subquery.setSubqAlias(alias); } Path subpath = factory.newPath(subquery); subpath.setSchemaAlias(path.getCorrelationVar()); subpath.setMetaData(candidate); subquery.setMetaData(candidate); if (fmd.isElementCollection()) exp = and(exp, bindVar); else exp = and(exp, factory.equal(path, subpath)); return exp; }
private Expression evalFromClause(JPQLNode from, boolean needsAlias) { Expression exp = null; for (int i = 0; i < from.children.length; i++) { JPQLNode node = from.children[i]; if (node.id == JJTFROMITEM) exp = evalFromItem(exp, node, needsAlias); else if (node.id == JJTOUTERJOIN) exp = addJoin(node, false, exp); else if (node.id == JJTINNERJOIN) exp = addJoin(node, true, exp); else if (node.id == JJTINNERFETCHJOIN) ; // we handle inner fetch joins in the evalFetchJoins() method else if (node.id == JJTOUTERFETCHJOIN) ; // we handle outer fetch joins in the evalFetchJoins() method else throw parseException(EX_USER, "not-schema-name", new Object[]{ node }, null); } return exp; }
private Expression evalFromClause(boolean needsAlias) { Expression exp = null; // build up the alias map in the FROM clause JPQLNode from = root().findChildByID(JJTFROM, false); if (from == null) throw parseException(EX_USER, "no-from-clause", null, null); for (int i = 0; i < from.children.length; i++) { JPQLNode node = from.children[i]; if (node.id == JJTFROMITEM) exp = evalFromItem(exp, node, needsAlias); else if (node.id == JJTOUTERJOIN) exp = addJoin(node, false, exp); else if (node.id == JJTINNERJOIN) exp = addJoin(node, true, exp); else if (node.id == JJTINNERFETCHJOIN) ; // we handle inner fetch joins in the evalFetchJoins() method else if (node.id == JJTOUTERFETCHJOIN) ; // we handle outer fetch joins in the evalFetchJoins() method else throw parseException(EX_USER, "not-schema-name", new Object[]{ node }, null); } return exp; }
private String projectionClause(JPQLNode node) { switch (node.id) { case JJTTYPE: return projectionClause(firstChild(node)); default: return assemble(node); } }