/** * Set the implicit type of the given value to the given class. */ protected static void setImplicitType(Value val, Class<?> expected) { // we never expect a pc type, so no need to worry about metadata if (val.getType() == TYPE_OBJECT) val.setImplicitType(expected); }
if (!var.isVariable()) throw new RuntimeException(var.getClass() + " is not a variable"); if (var.getPath() != path) throw new RuntimeException(var + " does not match given " + path + " Variable path is " + var.getPath()); String alias = getAlias(node); if (!alias.equals(var.getAlias())) { if (var.getAlias() == null) var.setAlias(alias); else throw new RuntimeException("Variable alias " + var.getAlias() + " does not match expected selection alias " + alias); if (!alias.equals(path.getAlias())) { if (path.getAlias() == null) path.setAlias(alias); else throw new RuntimeException("Path alias " + path.getAlias() + " does not match expected selection alias " + alias); _aliases.put(node, alias); ctx().addSchema(alias, var.getMetaData()); ctx().addVariable(alias, var);
/** * Return whether the given values include projections. */ public static boolean isAggregate(Value[] vals) { if (vals.length == 0) return false; AggregateExpressionVisitor v = new AggregateExpressionVisitor(); for (int i = 0; i < vals.length && !v._agg; i++) vals[i].acceptVisit(v); return v._agg; }
public StringBuilder asValue(AliasContext q) { Value v = q.getRegisteredRootVariable(this); if (v != null) return new StringBuilder(v.getAlias()); v = q.getRegisteredValue(this); if (v != null) return new StringBuilder(v.getAlias()); if (q.isRegistered(this)) return new StringBuilder(q.getRegisteredValue(this).getName()); return new StringBuilder().append(Character.toLowerCase(_entity.getName().charAt(0))); }
/** * Registers a variable for the given root expression. * A root expression is registered only for cross join. * @param root * @param var */ void registerRoot(Root<?> root, Value var) { if (var == null || !var.isVariable()) throw new IllegalArgumentException("Attempt to register non-variable " + var); _rootVariables.put(root, var); String alias = var.getName(); ctx().addSchema(alias, var.getMetaData()); ctx().addVariable(alias, var); }
private void verifyTypeOperation(Value val, Value param, boolean isNotEqual) { if (val.getPath() == null) return; PCPath path = (PCPath) val.getPath(); Discriminator disc = ((Type) val).getDiscriminator(); if (disc == null || !(val.getMetaData().getPCSuperclass() != null || val.getMetaData().getPCSubclasses().length > 0)) throw new UserException(_loc. get("invalid-type-argument", path.last() != null ? path.getPCPathString() : path.getSchemaAlias())); if (disc.getColumns().length == 0) { if (disc.getStrategy() instanceof NoneDiscriminatorStrategy) { // limited support for table per class inheritance hierarchy if (path.last() != null) throw new UserException(_loc. get("type-argument-unsupported", path.last().getName())); if (isNotEqual) { if (param != null && param instanceof Null) throw new UserException(_loc. get("type-in-expression-unsupported", path.getSchemaAlias())); else throw new UserException(_loc. get("type-not-equal-unsupported", path.getSchemaAlias())); } } if (param != null && param instanceof CollectionParam) throw new UserException(_loc. get("collection-param-unsupported")); } }
public Expression bindKeyVariable(Value var, Value val) { // handle the strange case of using a constant path to bind a // variable; in these cases the variable acts like an unbound // variable that we limit by using an IN clause on the constant // value collection if (val instanceof Const) { PCPath path = new PCPath(_type, (Variable) var); path.setMetaData(var.getMetaData()); return new InKeyExpression(path, (Const) val); } return new BindVariableExpression((Variable) var, (PCPath) val, true); }
@Override public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) { Value value = factory.abs(Expressions.toValue(e, factory, q)); value.setImplicitType(getJavaType()); return value; }
/** * Throw proper exception if given value is a collection/map/array. */ protected void assertNotContainer(Value val, StoreQuery q) { // variables represent container elements, not the container itself if (val.isVariable()) return; Class<?> type; if (val instanceof Path) { FieldMetaData fmd = ((Path) val).last(); type = (fmd == null) ? val.getType() : fmd.getDeclaredType(); } else type = val.getType(); switch (JavaTypes.getTypeCode(type)) { case JavaTypes.ARRAY: case JavaTypes.COLLECTION: case JavaTypes.MAP: throw new UserException(_loc.get("container-projection", q.getContext().getQueryString())); } }
public Class getType() { if (_exps != null && _type == null) { if (_exps.projections.length == 0) return _candidate.getDescribedType(); if (_exps.projections.length == 1) return _exps.projections[0].getType(); } return _type; }
public void enter(Value val) { if (_agg) return; if (_sub == null) { if (val.isAggregate()) _agg = true; } else if (val instanceof Subquery) _sub = val; }
@Override 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); }
private Value getTypeLiteral(JPQLNode node) { JPQLNode type = onlyChild(node); final String name = type.text; final Value val = getVariable(name, false); if (val instanceof Value && val.isVariable()) { Class<?> c = resolver.classForName(name, null); if (c != null) { Value typeLit = factory.newTypeLiteral(c, Literal.TYPE_CLASS); typeLit.setMetaData(getClassMetaData(name, false)); return typeLit; } } throw parseException(EX_USER, "not-type-literal", new Object[]{ name }, null); }
? exp2Vals.get(s) : ((ExpressionImpl<?>)s).toValue(factory, q)); String alias = s.getAlias(); val.setAlias(alias); projections.add(val); aliases.add(alias);
public Object get(int i) { Object id = (ident && _idents != null) ? _idents.get(i) : _ids.get(i); Object alias = _aliases.get(id); if (id instanceof Column && ((Column) id).isXML()) alias = alias + _dict.getStringVal; String as = null; if (inner) { if (alias instanceof String) as = ((String) alias).replace('.', '_'); } else if (_selectAs != null) as = (String) _selectAs.get(id); else if (id instanceof Value) as = ((Value) id).getAlias(); if (as != null) { if (ident && _idents != null) return as; if (alias instanceof SQLBuffer) alias = new SQLBuffer((SQLBuffer) alias). append(" AS ").append(as); else alias = alias + " AS " + as; } return alias; } };
public void enter(Value val) { if (!val.isVariable()) return; throw new UnsupportedException(_loc.get("inmem-agg-proj-var", _ctx.getCandidateType(), _ctx.getQueryString())); } }
/** * Registers a variable for the given root expression. * A root expression is registered only for cross join. * @param root * @param var */ void registerRoot(Root<?> root, Value var) { if (var == null || !var.isVariable()) throw new IllegalArgumentException("Attempt to register non-variable " + var); _rootVariables.put(root, var); String alias = var.getName(); ctx().addSchema(alias, var.getMetaData()); ctx().addVariable(alias, var); }
private void verifyTypeOperation(Value val, Value param, boolean isNotEqual) { if (val.getPath() == null) return; PCPath path = (PCPath) val.getPath(); Discriminator disc = ((Type) val).getDiscriminator(); if (disc == null || !(val.getMetaData().getPCSuperclass() != null || val.getMetaData().getPCSubclasses().length > 0)) throw new UserException(_loc. get("invalid-type-argument", path.last() != null ? path.getPCPathString() : path.getSchemaAlias())); if (disc.getColumns().length == 0) { if (disc.getStrategy() instanceof NoneDiscriminatorStrategy) { // limited support for table per class inheritance hierarchy if (path.last() != null) throw new UserException(_loc. get("type-argument-unsupported", path.last().getName())); if (isNotEqual) { if (param != null && param instanceof Null) throw new UserException(_loc. get("type-in-expression-unsupported", path.getSchemaAlias())); else throw new UserException(_loc. get("type-not-equal-unsupported", path.getSchemaAlias())); } } if (param != null && param instanceof CollectionParam) throw new UserException(_loc. get("collection-param-unsupported")); } }
public Expression bindKeyVariable(Value var, Value val) { // handle the strange case of using a constant path to bind a // variable; in these cases the variable acts like an unbound // variable that we limit by using an IN clause on the constant // value collection if (val instanceof Const) { PCPath path = new PCPath(_type, (Variable) var); path.setMetaData(var.getMetaData()); return new InKeyExpression(path, (Const) val); } return new BindVariableExpression((Variable) var, (PCPath) val, true); }
@Override public Value toValue(ExpressionFactory factory, CriteriaQueryImpl<?> q) { Value value = factory.min(Expressions.toValue(e, factory, q)); value.setImplicitType(getJavaType()); return value; }