protected internal virtual Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar CompileVar(Net.Vpc.Upa.Expressions.Var v, Net.Vpc.Upa.Impl.Uql.ExpressionTranslationManager manager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) { if (v == null) { return(null); } Net.Vpc.Upa.Expressions.CompiledExpression p = null; if (v.GetApplier() != null) { p = manager.TranslateAny(v.GetApplier(), declarations); } if (p == null) { return(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(v.GetName())); } else { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar r = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(v.GetName()); if (p is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar) { ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar)((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar)p).GetFinest()).SetChild(r); return((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar)p); } else { throw new Net.Vpc.Upa.Exceptions.UPAException("Unsupported"); } } }
public virtual bool Visit(Net.Vpc.Upa.Expressions.Expression expression, Net.Vpc.Upa.Expressions.ExpressionTag tag) { foreach (Net.Vpc.Upa.Expressions.TaggedExpression cc in expression.GetChildren()) { Net.Vpc.Upa.Expressions.Expression cce = cc.GetExpression(); if (cce != null) { if (cce is Net.Vpc.Upa.Expressions.UserExpression) { Net.Vpc.Upa.Expressions.Expression rr = expressionManager.ParseExpression(cce); rr.Visit(this); expression.SetChild(rr, cc.GetTag()); } else if (cce is Net.Vpc.Upa.Expressions.Var) { Net.Vpc.Upa.Expressions.Var v = (Net.Vpc.Upa.Expressions.Var)cce; if (v.GetApplier() == null && v.GetName().Equals("this")) { v.SetName(thisName); } } } } return(true); }
protected internal virtual Net.Vpc.Upa.Expressions.Expression EvalVar(Net.Vpc.Upa.Expressions.Var expression) { if (expression.GetApplier() == null) { //this is the very root string name = expression.GetName(); if (vars.ContainsKey(name)) { return(new Net.Vpc.Upa.Expressions.Literal(Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue <string, object>(vars, name), null)); } } else { Net.Vpc.Upa.Expressions.Expression x = expression.GetApplier(); // no need for evalVar() in post order DFS if (x is Net.Vpc.Upa.Expressions.Literal) { object v = ((Net.Vpc.Upa.Expressions.Literal)x).GetValue(); if (v == null) { return(Net.Vpc.Upa.Expressions.Literal.NULL); } else if (v is Net.Vpc.Upa.Record) { Net.Vpc.Upa.Record r = (Net.Vpc.Upa.Record)v; return(new Net.Vpc.Upa.Expressions.Literal(r.GetObject <object>(expression.GetName()), null)); } else if (v is System.Collections.IDictionary) { System.Collections.IDictionary r = (System.Collections.IDictionary)v; return(new Net.Vpc.Upa.Expressions.Literal(Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue0(r, expression.GetName()), null)); } else { Net.Vpc.Upa.Entity entity = pu.GetEntity(v.GetType()); Net.Vpc.Upa.Field field = entity.GetField(expression.GetName()); Net.Vpc.Upa.Record r = entity.GetBuilder().ObjectToRecord(v); return(new Net.Vpc.Upa.Expressions.Literal(r.GetObject <object>(field.GetName()), null)); } } } return(expression); }
public virtual bool Accept(Net.Vpc.Upa.Expressions.Expression expression) { if (expression is Net.Vpc.Upa.Expressions.Var) { Net.Vpc.Upa.Expressions.Var v = (Net.Vpc.Upa.Expressions.Var)expression; if (v.GetApplier() == null && "this".Equals(v.GetName())) { v.SetName(oldAlias); } } return(false); }
private void Init(Net.Vpc.Upa.Expressions.Expression ancestorExpression, Net.Vpc.Upa.Expressions.Expression childExpression, Net.Vpc.Upa.Expressions.Expression entityName) { if (entityName != null) { if (entityName is Net.Vpc.Upa.Expressions.EntityName) { this.entityName = (Net.Vpc.Upa.Expressions.EntityName)entityName; } else if (entityName is Net.Vpc.Upa.Expressions.Var) { Net.Vpc.Upa.Expressions.Var v = (Net.Vpc.Upa.Expressions.Var)entityName; if (v.GetApplier() != null) { throw new Net.Vpc.Upa.Exceptions.IllegalArgumentException("Invalid EntityName"); } this.entityName = new Net.Vpc.Upa.Expressions.EntityName(v.GetName()); } else if (entityName is Net.Vpc.Upa.Expressions.Literal) { Net.Vpc.Upa.Expressions.Literal v = (Net.Vpc.Upa.Expressions.Literal)entityName; if (!(v.GetValue() is string)) { throw new Net.Vpc.Upa.Exceptions.IllegalArgumentException("Invalid EntityName"); } this.entityName = new Net.Vpc.Upa.Expressions.EntityName((string)v.GetValue()); } else { throw new Net.Vpc.Upa.Exceptions.IllegalArgumentException("Invalid EntityName"); } } else { this.entityName = new Net.Vpc.Upa.Expressions.EntityName(""); } this.ancestorExpression = ancestorExpression; this.childExpression = childExpression; }
protected internal virtual System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.ResultField> CreateResultFields(Net.Vpc.Upa.Expressions.Expression expression, string alias, Net.Vpc.Upa.Filters.FieldFilter fieldFilter, System.Collections.Generic.IList <Net.Vpc.Upa.Expressions.QueryStatement> context) { expression = expressionManager.ParseExpression(expression); System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.ResultField> results = new System.Collections.Generic.List <Net.Vpc.Upa.Persistence.ResultField>(); if (expression is Net.Vpc.Upa.Expressions.Var) { Net.Vpc.Upa.Expressions.Var v = (Net.Vpc.Upa.Expressions.Var)expression; Net.Vpc.Upa.Expressions.Expression parent = v.GetApplier(); if (parent != null) { System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.ResultField> parentResults = CreateResultFields(parent, null, fieldFilter, context); int size = (parentResults).Count; foreach (Net.Vpc.Upa.Persistence.ResultField p in parentResults) { if (size > 1) { v = (Net.Vpc.Upa.Expressions.Var)v.Copy(); } if (p.GetExpression() != parent) { //change parent v.SetApplier((Net.Vpc.Upa.Expressions.Var)p.GetExpression()); } if (p.GetEntity() != null) { if (v.GetName().Equals("*")) { foreach (Net.Vpc.Upa.Field field in p.GetEntity().GetFields(fieldFilter)) { results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, field.GetDataType(), field, null)); } } else { Net.Vpc.Upa.Field field = p.GetEntity().GetField(v.GetName()); results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, field.GetDataType(), field, null)); } } else if (p.GetField() != null) { if (p.GetField().GetDataType() is Net.Vpc.Upa.Types.ManyToOneType) { Net.Vpc.Upa.Entity entity = ((Net.Vpc.Upa.Types.ManyToOneType)p.GetField().GetDataType()).GetTargetEntity(); if (v.GetName().Equals("*")) { foreach (Net.Vpc.Upa.Field field in entity.GetFields(fieldFilter)) { results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, field.GetDataType(), field, null)); } } else { Net.Vpc.Upa.Field field = entity.GetField(v.GetName()); results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, field.GetDataType(), field, null)); } } else { results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, Net.Vpc.Upa.Types.TypesFactory.OBJECT, null, null)); } } else { results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, Net.Vpc.Upa.Types.TypesFactory.OBJECT, null, null)); } } } else { string name = v.GetName(); System.Collections.Generic.IDictionary <string, Net.Vpc.Upa.Expressions.NameOrQuery> declarations = FindDeclarations(context); Net.Vpc.Upa.Expressions.NameOrQuery r = Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue <string, Net.Vpc.Upa.Expressions.NameOrQuery>(declarations, name); if (r != null) { if (r is Net.Vpc.Upa.Expressions.EntityName) { Net.Vpc.Upa.Entity entity = pu.GetEntity(((Net.Vpc.Upa.Expressions.EntityName)r).GetName()); results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, entity.GetDataType(), null, entity)); } else { results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, Net.Vpc.Upa.Types.TypesFactory.OBJECT, null, null)); } } else { if ("*".Equals(name)) { foreach (System.Collections.Generic.KeyValuePair <string, Net.Vpc.Upa.Expressions.NameOrQuery> entry in new System.Collections.Generic.HashSet <System.Collections.Generic.KeyValuePair <string, Net.Vpc.Upa.Expressions.NameOrQuery> >(declarations)) { r = (entry).Value; if (r is Net.Vpc.Upa.Expressions.EntityName) { Net.Vpc.Upa.Entity entity = pu.GetEntity(((Net.Vpc.Upa.Expressions.EntityName)r).GetName()); Net.Vpc.Upa.Field field = entity.FindField(name); results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, field.GetDataType(), field, null)); break; } } } else { Net.Vpc.Upa.Field field = null; foreach (System.Collections.Generic.KeyValuePair <string, Net.Vpc.Upa.Expressions.NameOrQuery> entry in new System.Collections.Generic.HashSet <System.Collections.Generic.KeyValuePair <string, Net.Vpc.Upa.Expressions.NameOrQuery> >(declarations)) { r = (entry).Value; if (r is Net.Vpc.Upa.Expressions.EntityName) { Net.Vpc.Upa.Entity entity = pu.GetEntity(((Net.Vpc.Upa.Expressions.EntityName)r).GetName()); field = entity.FindField(name); break; } } if (field != null) { results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, field.GetDataType(), field, null)); } else { results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(v, alias, Net.Vpc.Upa.Types.TypesFactory.OBJECT, null, null)); } } } } return(results); } results.Add(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(expression, alias, Net.Vpc.Upa.Types.TypesFactory.OBJECT, null, null)); return(results); }