Beispiel #1
0
        public virtual Net.Vpc.Upa.Impl.Persistence.QueryExecutor Execute() /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            int    c1       = 0;
            int    c2       = 0;
            string oldAlias = baseExpression.GetEntityAlias();

            if (oldAlias == null)
            {
                oldAlias = entity.GetName();
            }
            bool replaceThis = !"this".Equals(oldAlias);

            if (baseExpression.CountFields() > 0)
            {
                if (replaceThis)
                {
                    Net.Vpc.Upa.Impl.Uql.Util.UQLUtils.ReplaceThisVar(baseExpression, oldAlias, context.GetPersistenceUnit());
                }
                c1 = defaultPersistenceStore.CreateDefaultExecutor(baseExpression, parametersByName, parametersByIndex, updatable, defaultFieldFilter, context).Execute().GetResultCount();
            }
            if ((complexVals).Count > 0)
            {
                Net.Vpc.Upa.Expressions.Select q = new Net.Vpc.Upa.Expressions.Select();
                foreach (Net.Vpc.Upa.Field primaryField in entity.GetPrimaryFields())
                {
                    q.Field(primaryField.GetName());
                }
                foreach (Net.Vpc.Upa.Expressions.VarVal f in complexVals)
                {
                    Net.Vpc.Upa.Expressions.Expression fieldExpression = f.GetVal();
                    if (replaceThis)
                    {
                        Net.Vpc.Upa.Impl.Uql.Util.UQLUtils.ReplaceThisVar(fieldExpression, oldAlias, context.GetPersistenceUnit());
                    }
                    q.Field(fieldExpression, f.GetVar().GetName());
                }
                q.From(entity.GetName(), oldAlias);
                Net.Vpc.Upa.Expressions.Expression cond = baseExpression.GetCondition();
                q.SetWhere(cond == null ? null : cond.Copy());
                Net.Vpc.Upa.EntityBuilder eb = entity.GetBuilder();
                foreach (Net.Vpc.Upa.Record record in entity.GetPersistenceUnit().CreateQuery(q).GetRecordList())
                {
                    Net.Vpc.Upa.Expressions.Update u2 = new Net.Vpc.Upa.Expressions.Update();
                    u2.Entity(entityName);
                    foreach (Net.Vpc.Upa.Expressions.VarVal f in complexVals)
                    {
                        string fname = f.GetVar().GetName();
                        u2.Set(fname, record.GetObject <T>(fname));
                    }
                    Net.Vpc.Upa.Expressions.Expression exprId = eb.ObjectToIdExpression(record, oldAlias);
                    u2.Where(exprId);
                    c2 += defaultPersistenceStore.CreateDefaultExecutor(u2, parametersByName, parametersByIndex, updatable, defaultFieldFilter, context).Execute().GetResultCount();
                }
            }
            resultCount = System.Math.Max(c1, c2);
            return(this);
        }
 protected internal virtual Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledUpdate CompileUpdate(Net.Vpc.Upa.Expressions.Update 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.CompiledUpdate s = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledUpdate();
     s.Entity(v.GetEntity().GetName());
     Net.Vpc.Upa.Entity entity = manager.GetPersistenceUnit().GetEntity(v.GetEntity().GetName());
     for (int i = 0; i < v.CountFields(); i++)
     {
         Net.Vpc.Upa.Expressions.Var        fvar   = v.GetField(i);
         Net.Vpc.Upa.Expressions.Expression fvalue = v.GetFieldValue(i);
         s.Set(entity.GetField(fvar.GetName()), manager.TranslateAny(fvalue, declarations));
     }
     s.Where(manager.TranslateAny(v.GetCondition(), declarations));
     return(s);
 }