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); }
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 void appendTo(Select sel, ExpContext ctx, ExpState state, SQLBuffer sql, int index) { if (!(_map instanceof PCPath)) throw new UnsupportedOperationException(); if (!(_key instanceof Const)) throw new UnsupportedOperationException(); GetMapValueExpState gstate = (GetMapValueExpState) state; PCPath map = (PCPath) _map; Object key = ((Const) _key).getValue(ctx, gstate.keyState); FieldMapping field = map.getFieldMapping(gstate.mapState); if (!(field.getStrategy() instanceof LRSMapFieldStrategy)) throw new UnsupportedOperationException(); LRSMapFieldStrategy strat = (LRSMapFieldStrategy) field.getStrategy(); ClassMapping[] clss = strat.getIndependentValueMappings(true); if (clss != null && clss.length > 1) throw RelationStrategies.unjoinable(field); ClassMapping cls = (clss == null || clss.length == 0) ? null : clss[0]; ForeignKey fk = strat.getJoinForeignKey(cls); // manually create a subselect for the Map's value sql.append("(SELECT "); Column[] values = field.getElementMapping().getColumns(); for (int i = 0; i < values.length; i++) { if (i > 0) sql.append(", "); sql.append(values[i].getTable()).append(".").append(values[i]); } sql.append(" FROM ").append(values[0].getTable()); sql.append(" WHERE "); // add in the joins ContainerFieldStrategy.appendUnaliasedJoin( sql, sel, null, ctx.store.getDBDictionary(), field, fk); sql.append(" AND "); key = strat.toKeyDataStoreValue(key, ctx.store); Column[] cols = strat.getKeyColumns(cls); Object[] vals = (cols.length == 1) ? null : (Object[]) key; for (int i = 0; i < cols.length; i++) { sql.append(cols[i].getTable()).append(".").append(cols[i]); if (vals == null) sql.append((key == null) ? " IS " : " = ").appendValue(key, cols[i]); else sql.append((vals[i] == null) ? " IS " : " = ").appendValue(vals[i], cols[i]); } sql.append(")"); }
public Value getKey(Value val) { ((PCPath) val).getKey(); return val; }
public Value index(Value val) { ((PCPath) val).verifyIndexedField(); return new Index((Val) val); }