/** * Enters the current node. */ public void enter(Value val) { if (val instanceof Parameter) { if (_parameterized != null) { _collected.add(_parameterized); } } else if (val instanceof Path) { _parameterized = ((Path)val).last(); } else { _parameterized = null; } }
@Override public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> c) { ClassMetaData meta = _member.fmd.getDeclaredTypeMetaData(); org.apache.openjpa.kernel.exps.Path path = null; SubqueryImpl<?> subquery = c.getDelegator(); PathImpl<?,?> parent = getInnermostParentPath(); Value val = c.getRegisteredValue(this); if (val != null) return val; else if (parent.inSubquery(subquery)) { org.apache.openjpa.kernel.exps.Subquery subQ = subquery.getSubQ(); path = factory.newPath(subQ); path.setMetaData(subQ.getMetaData()); path.setSchemaAlias(c.getAlias(this)); path.get(_member.fmd, allowNull); } else { path = (org.apache.openjpa.kernel.exps.Path) _parent.toValue(factory, c); path.get(_member.fmd, allowNull); path.setMetaData(meta); path.setImplicitType(meta.getDescribedType()); } return path; }
public static void setImplicitTypes(Value val1, Value val2, Class<?> expected, Resolver resolver, OrderedMap<Object,Class<?>> parameterTypes, String currentQuery) { AbstractExpressionBuilder.setImplicitTypes(val1, val2, expected, resolver); // as well as setting the types for conversions, we also need to // ensure that any parameters are declared with the correct type, // since the JPA spec expects that these will be validated Parameter param = val1 instanceof Parameter ? (Parameter) val1 : val2 instanceof Parameter ? (Parameter) val2 : null; Path path = val1 instanceof Path ? (Path) val1 : val2 instanceof Path ? (Path) val2 : null; // we only check for parameter-to-path comparisons if (param == null || path == null || parameterTypes == null) return; FieldMetaData fmd = path.last(); if (fmd == null) return; if (expected == null) checkEmbeddable(path, currentQuery); Class<?> type = path.getType(); if (type == null) return; Object paramKey = param.getParameterKey(); if (paramKey == null) return; // make sure we have already declared the parameter if (parameterTypes.containsKey(paramKey)) parameterTypes.put(paramKey, type); }
protected void setImplicitTypes(Value val1, Value val2, Class expected) { super.setImplicitTypes(val1, val2, expected); // as well as setting the types for conversions, we also need to // ensure that any parameters are declared with the correct type, // since the JPA spec expects that these will be validated Parameter param = val1 instanceof Parameter ? (Parameter) val1 : val2 instanceof Parameter ? (Parameter) val2 : null; Path path = val1 instanceof Path ? (Path) val1 : val2 instanceof Path ? (Path) val2 : null; // we only check for parameter-to-path comparisons if (param == null || path == null || parameterTypes == null) return; FieldMetaData fmd = path.last(); if (fmd == null) return; Class type = path.isXPath() ? path.getType() : fmd.getType(); if (type == null) return; String paramName = param.getParameterName(); if (paramName == null) return; // make sure we have already declared the parameter if (parameterTypes.containsKey(paramName)) parameterTypes.put(paramName, type); }
path = factory.newPath(subQ); path.setMetaData(meta); path.get(_member.fmd, allowNull); path.setSchemaAlias(c.getAlias(_parent)); path.setMetaData(meta); path.get(_member.fmd, allowNull); } else path = (org.apache.openjpa.kernel.exps.Path)toValue(factory, c); 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) parentPath.setSubqueryContext(c.ctx(), parentPath.getSchemaAlias()); path.setMetaData(meta);
ClassMetaData meta = path.getMetaData(); if (meta == null) throw parseException(EX_USER, "path-no-meta", new Object[]{ field, path.getType() }, null); if (meta != null) { addAccessPath(meta); path.setMetaData(meta); path.get(fmd, xmlmeta); return path; path.get(fmd, allowNull);
if (ctx().subquery != null) { path = factory.newPath(ctx().subquery); path.setMetaData(ctx().subquery.getMetaData()); } else { path = factory.newPath(); path.setMetaData(ctx().meta); new Object[]{ assemble(node), name }, null); path.setSchemaAlias(name); if (path.isXPath()) { for (int j = i; j <node.children.length; j++) path = (Path) traverseXPath(path, node.children[j].text); if (ctx().getParent() != null && ctx().getVariable(path.getSchemaAlias()) == null) { path.setSubqueryContext(ctx(), name);
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 Path getQualifiedPath(JPQLNode node, boolean pcOnly, boolean inner) { int nChild = node.getChildCount(); JPQLNode firstChild = firstChild(node); JPQLNode id = firstChild.id == JJTKEY ? onlyChild(firstChild) : firstChild; Path path = validateMapPath(firstChild, id); if (firstChild.id == JJTIDENTIFIER) return getPath(node); FieldMetaData fld = path.last(); path = (Path) factory.getKey(path); ClassMetaData meta = fld.getKey().getTypeMetaData(); if (meta == null) throw parseException(EX_USER, "bad-qualified-path", new Object[]{ id.text }, null); path.setMetaData(meta); // walk through the children and assemble the path boolean allowNull = !inner; for (int i = 1; i < nChild; i++) { path = (Path) traversePath(path, node.children[i].text, pcOnly, allowNull); // all traversals but the first one will always be inner joins allowNull = false; } return path; }
/** * Convert this path to a kernel path (value). */ @Override public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> c) { org.apache.openjpa.kernel.exps.Path path = null; SubqueryImpl<?> subquery = c.getDelegator(); PathImpl<?,?> parent = getInnermostParentPath(); Value var = c.getRegisteredVariable(this); if (var != null) { path = factory.newPath(var); } else if (parent.inSubquery(subquery)) { 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, c); path.get(_member.fmd, allowNull); } return path; }
protected Value traverseXPath(Path path, String field) { XMLMetaData meta = path.getXmlMapping(); if (meta.getFieldMapping(field) == null) { throw parseException(EX_USER, "no-field", new Object[]{ meta.getType(), field }, null); } else { // collection-valued xpath is not allowed int type = meta.getFieldMapping(field).getTypeCode(); switch (type) { case JavaTypes.ARRAY: case JavaTypes.COLLECTION: case JavaTypes.MAP: throw new UserException(_loc.get("collection-valued-path", field)); } } path.get(meta, field); return path; }
/** * Convert this path to a kernel path value. */ @Override public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> c) { SubqueryImpl<?> subquery = c.getDelegator(); Path var = null; Value val = null; String alias = c.getAlias(this); if (c.ctx() != null && !alias.equalsIgnoreCase(c.ctx().schemaAlias) && (val = c.getRegisteredRootVariable(this)) != null) { // this is cross join var = factory.newPath(val); } else if (inSubquery(subquery)) { Subquery subQ = subquery.getSubQ(); var = factory.newPath(subQ); } else { var = factory.newPath(); var.setSchemaAlias(alias); } var.setMetaData(_entity.meta); return var; }
private Path newPath(Value val, ClassMetaData meta) { Path path = val == null ? factory.newPath() : factory.newPath(val); if (meta != null) path.setMetaData(meta); return path; }
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; PathImpl<?,?> parent1 = parent._parent; if (parent1 == null || parent1.getCorrelatedPath() != null) { if (fmd != null) path.get(fmd, allowNull); return; } traversePath(parent1, path, fmd1); if (fmd != null) path.get(fmd, allowNull); }
if (ctx().subquery != null) { path = factory.newPath(ctx().subquery); path.setMetaData(ctx().subquery.getMetaData()); } else { path = factory.newPath(); path.setMetaData(ctx().meta); if (path.isXPath()) { for (int j = i; j <node.children.length; j++) path = (Path) traverseXPath(path, node.children[j].text);
thiz = factory.newPath(ctx().subquery); ((Path)thiz).setSchemaAlias(name); thiz.setMetaData(cmd); return thiz;
path = factory.newPath(subQ); path.setMetaData(meta); path.get(_member.fmd, allowNull); path.setSchemaAlias(c.getAlias(_parent)); path.setMetaData(meta); path.get(_member.fmd, allowNull); } else path = (org.apache.openjpa.kernel.exps.Path)toValue(factory, c); 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) parentPath.setSubqueryContext(c.ctx(), parentPath.getSchemaAlias()); path.setMetaData(meta);
ClassMetaData meta = path.getMetaData(); if (meta == null) throw parseException(EX_USER, "path-no-meta", new Object[]{ field, path.getType() }, null); if (val == null) { if (isMultiValuedTraversalAttempt(path, field)) { throw parseException(EX_USER, "multi-valued-travesal", new Object[]{field, path.last()}, null); if (meta != null) { addAccessPath(meta); path.setMetaData(meta); path.get(fmd, xmlmeta); return path; path.get(fmd, allowNull);
if (ctx().subquery != null) { path = factory.newPath(ctx().subquery); path.setMetaData(ctx().subquery.getMetaData()); } else { path = factory.newPath(); path.setMetaData(ctx().meta); new Object[]{ assemble(node), name }, null); path.setSchemaAlias(name); if (path.isXPath()) { for (int j = i; j <node.children.length; j++) path = (Path) traverseXPath(path, node.children[j].text); if (ctx().getParent() != null && ctx().getVariable(path.getSchemaAlias()) == null) { path.setSubqueryContext(ctx(), name);
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; }