public virtual Net.Vpc.Upa.Expressions.Expression RecordToExpression(Net.Vpc.Upa.Record record, string alias) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { if (record == null) { return(null); } Net.Vpc.Upa.Expressions.Expression a = null; foreach (System.Collections.Generic.KeyValuePair <string, object> entry in record.EntrySet()) { string key = (entry).Key; object @value = (entry).Value; Net.Vpc.Upa.Field field = GetEntity().GetField(key); if (!field.IsUnspecifiedValue(@value)) { Net.Vpc.Upa.Expressions.Expression e = null; Net.Vpc.Upa.Expressions.Var p = new Net.Vpc.Upa.Expressions.Var(Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(alias) ? GetEntity().GetName() : alias); switch (field.GetSearchOperator()) { case Net.Vpc.Upa.SearchOperator.DEFAULT: case Net.Vpc.Upa.SearchOperator.EQ: { if (field.GetDataType() is Net.Vpc.Upa.Types.ManyToOneType) { Net.Vpc.Upa.Types.ManyToOneType et = (Net.Vpc.Upa.Types.ManyToOneType)field.GetDataType(); Net.Vpc.Upa.Key foreignKey = et.GetRelationship().GetTargetRole().GetEntity().GetBuilder().ObjectToKey(@value); Net.Vpc.Upa.Expressions.Expression b = null; int i = 0; foreach (Net.Vpc.Upa.Field df in et.GetRelationship().GetSourceRole().GetFields()) { e = new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var((Net.Vpc.Upa.Expressions.Var)p.Copy(), df.GetName()), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(foreignKey.GetObjectAt(i))); b = b == null ? ((Net.Vpc.Upa.Expressions.Expression)(b)) : new Net.Vpc.Upa.Expressions.And(b, e); i++; } } else { e = new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value)); } break; } case Net.Vpc.Upa.SearchOperator.NE: { e = new Net.Vpc.Upa.Expressions.Different(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value)); break; } case Net.Vpc.Upa.SearchOperator.GT: { e = new Net.Vpc.Upa.Expressions.GreaterThan(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value)); break; } case Net.Vpc.Upa.SearchOperator.GTE: { e = new Net.Vpc.Upa.Expressions.GreaterEqualThan(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value)); break; } case Net.Vpc.Upa.SearchOperator.LT: { e = new Net.Vpc.Upa.Expressions.LessThan(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value)); break; } case Net.Vpc.Upa.SearchOperator.LTE: { e = new Net.Vpc.Upa.Expressions.LessEqualThan(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value)); break; } case Net.Vpc.Upa.SearchOperator.CONTAINS: { e = new Net.Vpc.Upa.Expressions.Like(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral("%" + @value + "%")); break; } case Net.Vpc.Upa.SearchOperator.STARTS_WITH: { e = new Net.Vpc.Upa.Expressions.Like(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(@value + "%")); break; } case Net.Vpc.Upa.SearchOperator.ENDS_WITH: { e = new Net.Vpc.Upa.Expressions.Like(new Net.Vpc.Upa.Expressions.Var(p, key), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral("%" + @value)); break; } } if (e != null) { a = a == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(a, e); } } } return(a); }
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); }
public override Net.Vpc.Upa.Expressions.Expression Copy() { Net.Vpc.Upa.Expressions.IdEnumerationExpression o = new Net.Vpc.Upa.Expressions.IdEnumerationExpression(new System.Collections.Generic.List <object>(ids), alias == null ? null : (Net.Vpc.Upa.Expressions.Var)alias.Copy()); return(o); }