示例#1
0
        protected internal virtual Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityStatement CreateCompiledEntityStatement()
        {
            Net.Vpc.Upa.Persistence.ExpressionCompilerConfig config = new Net.Vpc.Upa.Persistence.ExpressionCompilerConfig();
            string alias = null;
            string ent   = null;

            if (query is Net.Vpc.Upa.Expressions.Select)
            {
                Net.Vpc.Upa.Expressions.Select d = (Net.Vpc.Upa.Expressions.Select)query;
                string entityAlias = d.GetEntityAlias();
                Net.Vpc.Upa.Expressions.EntityName entityName = (d.GetEntity() is Net.Vpc.Upa.Expressions.EntityName) ? ((Net.Vpc.Upa.Expressions.EntityName)d.GetEntity()) : null;
                if (entityAlias != null)
                {
                    alias = entityAlias;
                    ent   = entityName == null ? null : entityName.GetName();
                }
                else
                {
                    ent   = entityName == null ? null : entityName.GetName();
                    alias = ent;
                }
            }
            if (alias != null)
            {
                config.SetThisAlias(alias);
            }
            config.SetExpandFields(false);
            config.SetExpandEntityFilter(false);
            config.SetValidate(false);
            return((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityStatement)context.GetPersistenceUnit().GetExpressionManager().CompileExpression(query, config));
        }
 private System.Collections.Generic.IDictionary <string, Net.Vpc.Upa.Expressions.NameOrQuery> FindDeclarations(Net.Vpc.Upa.Expressions.QueryStatement queryStatement)
 {
     System.Collections.Generic.IDictionary <string, Net.Vpc.Upa.Expressions.NameOrQuery> names = new System.Collections.Generic.Dictionary <string, Net.Vpc.Upa.Expressions.NameOrQuery>();
     if (queryStatement is Net.Vpc.Upa.Expressions.Select)
     {
         Net.Vpc.Upa.Expressions.Select s = (Net.Vpc.Upa.Expressions.Select)queryStatement;
         if (!Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(s.GetEntityAlias()))
         {
             names[s.GetEntityAlias()] = s.GetEntity();
         }
         else
         {
             string t = s.GetEntityName();
             if (!Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(t))
             {
                 names[s.GetEntityAlias()] = s.GetEntity();
             }
         }
         foreach (Net.Vpc.Upa.Expressions.JoinCriteria j in s.GetJoins())
         {
             if (!Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(j.GetEntityAlias()))
             {
                 names[j.GetEntityAlias()] = j.GetEntity();
             }
             else
             {
                 string t = j.GetEntityName();
                 if (!Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty(t))
                 {
                     names[j.GetEntityAlias()] = j.GetEntity();
                 }
             }
         }
     }
     else if (queryStatement is Net.Vpc.Upa.Expressions.Union)
     {
     }
     // do nothing
     return(names);
 }
示例#3
0
 public DefaultQuery(Net.Vpc.Upa.Expressions.EntityStatement query, Net.Vpc.Upa.Entity defaultEntity, Net.Vpc.Upa.Persistence.EntityExecutionContext context)
 {
     this.query = query;
     if (defaultEntity != null)
     {
         if (query is Net.Vpc.Upa.Expressions.Select)
         {
             Net.Vpc.Upa.Expressions.Select select = (Net.Vpc.Upa.Expressions.Select)query;
             if (select.GetEntity() == null)
             {
                 select.From(defaultEntity.GetName());
             }
         }
         else if (query is Net.Vpc.Upa.Expressions.Insert)
         {
             if (((Net.Vpc.Upa.Expressions.Insert)query).GetEntity() == null)
             {
                 ((Net.Vpc.Upa.Expressions.Insert)query).Into(defaultEntity.GetName());
             }
         }
         else if (query is Net.Vpc.Upa.Expressions.Update)
         {
             if (((Net.Vpc.Upa.Expressions.Update)query).GetEntity() == null)
             {
                 ((Net.Vpc.Upa.Expressions.Update)query).Entity(defaultEntity.GetName());
             }
         }
         else if (query is Net.Vpc.Upa.Expressions.Delete)
         {
             if (((Net.Vpc.Upa.Expressions.Delete)query).GetEntity() == null)
             {
                 ((Net.Vpc.Upa.Expressions.Delete)query).From(defaultEntity.GetName());
             }
         }
     }
     this.context = context;
     //        this.cquery = (CompiledEntityStatement) query.copy();
     //        this.defaultEntity = defaultEntity;
     store = (Net.Vpc.Upa.Impl.Persistence.DefaultPersistenceStore)context.GetPersistenceStore();
 }
 public virtual bool Accept(Net.Vpc.Upa.Expressions.Expression expression)
 {
     if (typeof(Net.Vpc.Upa.Expressions.Select).IsInstanceOfType(expression))
     {
         Net.Vpc.Upa.Expressions.Select ss = (Net.Vpc.Upa.Expressions.Select)expression;
         if (isUpdateComplexValuesStatementSupported)
         {
             if (ss.GetEntity() != null)
             {
                 bool   meFound      = false;
                 string ssentityName = ss.GetEntityName();
                 if (ssentityName != null && ssentityName.Equals(entityName))
                 {
                     meFound = true;
                 }
                 if (!meFound)
                 {
                     foreach (Net.Vpc.Upa.Expressions.JoinCriteria join in ss.GetJoins())
                     {
                         string jentityName = join.GetEntityName();
                         if (jentityName != null && jentityName.Equals(entityName))
                         {
                             meFound = true;
                         }
                     }
                 }
                 if (meFound)
                 {
                     return(true);
                 }
             }
         }
         else
         {
             return(true);
         }
     }
     return(false);
 }
示例#5
0
        protected internal virtual Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect CompileSelect(Net.Vpc.Upa.Expressions.Select v, Net.Vpc.Upa.Impl.Uql.ExpressionTranslationManager manager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations)
        {
            if (v == null)
            {
                return(null);
            }
            Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect s = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect();
            s.SetDistinct(v.IsDistinct());
            s.SetTop(v.GetTop());
            Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect nameOrSelect = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect)manager.TranslateAny(v.GetEntity(), declarations);
            string entityAlias = v.GetEntityAlias();

            System.Collections.Generic.HashSet <string> aliases = new System.Collections.Generic.HashSet <string>();
            if (entityAlias == null)
            {
                if (nameOrSelect is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName)
                {
                    entityAlias = ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName)nameOrSelect).GetName();
                }
                else
                {
                    entityAlias = "ALIAS";
                }
                int i = 0;
                while (true)
                {
                    string a2 = i == 0 ? entityAlias : (entityAlias + i);
                    if (!aliases.Contains(a2))
                    {
                        aliases.Add(a2);
                        entityAlias = a2;
                        break;
                    }
                    i++;
                }
            }
            s.From(nameOrSelect, entityAlias);
            for (int i = 0; i < v.CountJoins(); i++)
            {
                Net.Vpc.Upa.Expressions.JoinCriteria c = v.GetJoin(i);
                Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect jnameOrSelect = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect)manager.TranslateAny(c.GetEntity(), declarations);
                entityAlias = c.GetEntityAlias();
                if (entityAlias == null)
                {
                    if (nameOrSelect is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName)
                    {
                        entityAlias = ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName)nameOrSelect).GetName();
                    }
                    else
                    {
                        entityAlias = "ALIAS";
                    }
                    i = 0;
                    while (true)
                    {
                        string a2 = i == 0 ? entityAlias : (entityAlias + i);
                        if (!aliases.Contains(a2))
                        {
                            aliases.Add(a2);
                            entityAlias = a2;
                            break;
                        }
                        i++;
                    }
                }
                Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledJoinCriteria cc = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledJoinCriteria(c.GetJoinType(), jnameOrSelect, entityAlias, manager.TranslateAny(c.GetCondition(), declarations));
                s.Join(cc);
            }
            for (int i = 0; i < v.CountFields(); i++)
            {
                Net.Vpc.Upa.Expressions.QueryField field = v.GetField(i);
                s.Field(manager.TranslateAny(field.GetExpression(), declarations), field.GetAlias());
            }
            s.Where(manager.TranslateAny(v.GetWhere(), declarations));
            s.Having(manager.TranslateAny(v.GetHaving(), declarations));
            for (int i = 0; i < v.CountGroupByItems(); i++)
            {
                Net.Vpc.Upa.Expressions.Expression c = v.GetGroupBy(i);
                s.GroupBy(manager.TranslateAny(c, declarations));
            }
            for (int i = 0; i < v.CountOrderByItems(); i++)
            {
                Net.Vpc.Upa.Expressions.Expression c = v.GetOrderBy(i);
                s.OrderBy(manager.TranslateAny(c, declarations), v.IsOrderAscending(i));
            }
            return(s);
        }