Пример #1
0
 private static Net.Vpc.Upa.Expressions.QueryStatement CreateViewQuery(string name, string[] tables, string updatableTableFieldName, System.Collections.Generic.IList <string> viewFields, string[][] fieldsMapping)
 {
     //        StringBuilder sb=new StringBuilder("");
     if (tables.Length < 2)
     {
         if (tables.Length == 0)
         {
             throw new System.ArgumentException("UnionTableUpdatableView must be over at least a couple of entities");
         }
         System.Console.Error.WriteLine("[WARNING] UnionTableUpdatableView must be over at least a couple of tables");
     }
     if (fieldsMapping != null && tables.Length != fieldsMapping.Length)
     {
         throw new System.ArgumentException("tables.length!=fieldsMapping.length");
     }
     Net.Vpc.Upa.Expressions.Union u = new Net.Vpc.Upa.Expressions.Union();
     for (int i = 0; i < tables.Length; i++)
     {
         if (fieldsMapping != null && (viewFields).Count != fieldsMapping[i].Length)
         {
             throw new System.ArgumentException("UnionTableUpdatableView " + name + " requires " + (viewFields).Count + " fields but got " + fieldsMapping[i].Length + " for " + tables[i]);
         }
         Net.Vpc.Upa.Expressions.Select s = new Net.Vpc.Upa.Expressions.Select();
         s.Field(new Net.Vpc.Upa.Expressions.Literal(tables[i]), updatableTableFieldName);
         for (int j = 0; j < (viewFields).Count; j++)
         {
             string viewField = viewFields[j];
             string varName   = fieldsMapping == null ? viewField : fieldsMapping[i][j];
             s.Field(new Net.Vpc.Upa.Expressions.Var(varName), viewField);
         }
         s.From(tables[i]);
         u.Add(s);
     }
     return(u);
 }
Пример #2
0
 public static string[] ResolveEntityAndAlias(Net.Vpc.Upa.Expressions.QueryStatement select)
 {
     if (select is Net.Vpc.Upa.Expressions.Select)
     {
         return(ResolveEntityAndAlias((Net.Vpc.Upa.Expressions.Select)select));
     }
     if (select is Net.Vpc.Upa.Expressions.Union)
     {
         Net.Vpc.Upa.Expressions.Union u = (Net.Vpc.Upa.Expressions.Union)select;
         string[] last = null;
         foreach (Net.Vpc.Upa.Expressions.QueryStatement queryStatement in u.GetQueryStatements())
         {
             string[] s = ResolveEntityAndAlias(queryStatement);
             if (s == null)
             {
                 return(null);
             }
             else if (last == null)
             {
                 last = s;
             }
             else
             {
                 if (!Net.Vpc.Upa.Impl.FwkConvertUtils.ArraysEquals <string>(last, s))
                 {
                     return(null);
                 }
             }
         }
         return(last);
     }
     return(null);
 }
Пример #3
0
 public override Net.Vpc.Upa.Expressions.Expression Copy()
 {
     Net.Vpc.Upa.Expressions.Union o = new Net.Vpc.Upa.Expressions.Union();
     foreach (Net.Vpc.Upa.Expressions.QueryStatement queryStatement in queryStatements)
     {
         o.Add((Net.Vpc.Upa.Expressions.QueryStatement)queryStatement.Copy());
     }
     return(o);
 }
Пример #4
0
 public override bool Equals(object o)
 {
     if (this == o)
     {
         return(true);
     }
     if (o == null || GetType() != o.GetType())
     {
         return(false);
     }
     Net.Vpc.Upa.Expressions.Union union = (Net.Vpc.Upa.Expressions.Union)o;
     if (queryStatements != null ? !queryStatements.Equals(union.queryStatements) : union.queryStatements != null)
     {
         return(false);
     }
     return(true);
 }
 public virtual Net.Vpc.Upa.Persistence.ResultMetaData CreateResultMetaData(Net.Vpc.Upa.Expressions.Expression baseExpression, Net.Vpc.Upa.Filters.FieldFilter fieldFilter, System.Collections.Generic.IList <Net.Vpc.Upa.Expressions.QueryStatement> context)
 {
     baseExpression = Net.Vpc.Upa.Impl.Uql.Util.UQLUtils.ParseUserExpressions(baseExpression, pu);
     Net.Vpc.Upa.Impl.Persistence.DefaultResultMetaData m = new Net.Vpc.Upa.Impl.Persistence.DefaultResultMetaData();
     if (baseExpression is Net.Vpc.Upa.Expressions.NonQueryStatement)
     {
         m.SetStatement((Net.Vpc.Upa.Expressions.EntityStatement)baseExpression);
         m.AddField(new Net.Vpc.Upa.Impl.Persistence.DefaultResultField(null, "result", Net.Vpc.Upa.Types.TypesFactory.INT, null, null));
         return(m);
     }
     else
     {
         Net.Vpc.Upa.Expressions.QueryStatement q = (Net.Vpc.Upa.Expressions.QueryStatement)baseExpression;
         if (q is Net.Vpc.Upa.Expressions.Select)
         {
             Net.Vpc.Upa.Expressions.Select qs = (Net.Vpc.Upa.Expressions.Select)q;
             if ((qs.GetFields()).Count == 0)
             {
                 if (!Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(qs.GetEntityAlias()))
                 {
                     qs.Field(new Net.Vpc.Upa.Expressions.Var(qs.GetEntityAlias()));
                 }
                 else if (qs.GetEntityName() != null)
                 {
                     qs.Field(new Net.Vpc.Upa.Expressions.Var(qs.GetEntityName()));
                 }
                 else
                 {
                     throw new Net.Vpc.Upa.Exceptions.UPAException("MissingAlias");
                 }
                 foreach (Net.Vpc.Upa.Expressions.JoinCriteria joinCriteria in qs.GetJoins())
                 {
                     if (!Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(joinCriteria.GetEntityAlias()))
                     {
                         qs.Field(new Net.Vpc.Upa.Expressions.Var(joinCriteria.GetEntityAlias()));
                     }
                     else if (joinCriteria.GetEntityName() != null)
                     {
                         qs.Field(new Net.Vpc.Upa.Expressions.Var(joinCriteria.GetEntityName()));
                     }
                     else
                     {
                         throw new Net.Vpc.Upa.Exceptions.UPAException("MissingAlias");
                     }
                 }
             }
             System.Collections.Generic.IList <Net.Vpc.Upa.Expressions.QueryField>     oldFields  = new System.Collections.Generic.List <Net.Vpc.Upa.Expressions.QueryField>(q.GetFields());
             System.Collections.Generic.IList <Net.Vpc.Upa.Expressions.QueryField>     newFields  = new System.Collections.Generic.List <Net.Vpc.Upa.Expressions.QueryField>();
             System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.ResultField>    newResults = new System.Collections.Generic.List <Net.Vpc.Upa.Persistence.ResultField>();
             System.Collections.Generic.IList <Net.Vpc.Upa.Expressions.QueryStatement> context2   = new System.Collections.Generic.List <Net.Vpc.Upa.Expressions.QueryStatement>();
             Net.Vpc.Upa.Impl.FwkConvertUtils.ListAddRange(context2, context);
             context2.Add(q);
             foreach (Net.Vpc.Upa.Expressions.QueryField f in oldFields)
             {
                 Net.Vpc.Upa.Expressions.Expression expression = f.GetExpression();
                 string oldAlias = f.GetAlias();
                 System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.ResultField> newVal = CreateResultFields(expression, oldAlias, fieldFilter, context2);
                 Net.Vpc.Upa.Impl.FwkConvertUtils.ListAddRange(newResults, newVal);
                 if ((newVal).Count == 0)
                 {
                 }
                 else if ((newVal).Count == 1)
                 {
                     f.SetExpression(newVal[0].GetExpression());
                     f.SetAlias(Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(oldAlias) ? oldAlias : newVal[0].GetAlias());
                     newFields.Add(f);
                 }
                 else
                 {
                     foreach (Net.Vpc.Upa.Persistence.ResultField nf in newVal)
                     {
                         Net.Vpc.Upa.Expressions.QueryField f2 = new Net.Vpc.Upa.Expressions.QueryField(Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(oldAlias) ? oldAlias : nf.GetAlias(), nf.GetExpression());
                         newFields.Add(f2);
                     }
                 }
             }
             qs.ClearFields();
             foreach (Net.Vpc.Upa.Expressions.QueryField newField in newFields)
             {
                 qs.Field(newField);
             }
             m.SetStatement(qs);
             foreach (Net.Vpc.Upa.Persistence.ResultField newResult in newResults)
             {
                 m.AddField(newResult);
             }
         }
         else if (q is Net.Vpc.Upa.Expressions.Union)
         {
             System.Collections.Generic.IList <Net.Vpc.Upa.Expressions.QueryStatement> context2 = new System.Collections.Generic.List <Net.Vpc.Upa.Expressions.QueryStatement>();
             Net.Vpc.Upa.Impl.FwkConvertUtils.ListAddRange(context2, context);
             context2.Add(q);
             Net.Vpc.Upa.Expressions.Union         u0     = (Net.Vpc.Upa.Expressions.Union)q;
             Net.Vpc.Upa.Expressions.Union         u      = new Net.Vpc.Upa.Expressions.Union();
             Net.Vpc.Upa.Persistence.ResultField[] fields = null;
             foreach (Net.Vpc.Upa.Expressions.QueryStatement qs in u0.GetQueryStatements())
             {
                 Net.Vpc.Upa.Persistence.ResultMetaData resultMetaData = CreateResultMetaData(qs, fieldFilter, context2);
                 u.Add((Net.Vpc.Upa.Expressions.QueryStatement)resultMetaData.GetStatement());
                 System.Collections.Generic.IList <Net.Vpc.Upa.Persistence.ResultField> f = resultMetaData.GetFields();
                 if (fields == null)
                 {
                     fields = f.ToArray();
                 }
                 else
                 {
                     if (fields.Length != (f).Count)
                     {
                         throw new Net.Vpc.Upa.Exceptions.UPAException("InvalidUnion");
                     }
                     for (int i = 0; i < fields.Length; i++)
                     {
                         fields[i] = Merge(fields[i], f[i]);
                     }
                 }
             }
             m.SetStatement(u);
             if (fields != null)
             {
                 foreach (Net.Vpc.Upa.Persistence.ResultField field in fields)
                 {
                     m.AddField(field);
                 }
             }
         }
         else
         {
             throw new System.Exception();
         }
     }
     return(m);
 }