示例#1
0
        public virtual Net.Vpc.Upa.Key ExtractKey(Net.Vpc.Upa.Record sourceRecord)
        {
            switch (GetSourceRole().GetRelationshipUpdateType())
            {
            case Net.Vpc.Upa.RelationshipUpdateType.COMPOSED:
            {
                object targetEntityVal = sourceRecord.GetObject <T>(GetSourceRole().GetEntityField().GetName());
                if (targetEntityVal == null)
                {
                    return(null);
                }
                Net.Vpc.Upa.EntityBuilder targetConverter = GetTargetRole().GetEntity().GetBuilder();
                return(targetConverter.ObjectToKey(targetEntityVal));
            }

            case Net.Vpc.Upa.RelationshipUpdateType.FLAT:
            {
                System.Collections.Generic.IList <Net.Vpc.Upa.Field> relFields = GetSourceRole().GetFields();
                System.Collections.Generic.List <object>             keys      = new System.Collections.Generic.List <object>((relFields).Count);
                foreach (Net.Vpc.Upa.Field field in relFields)
                {
                    object keyPart = sourceRecord.GetObject <T>(field.GetName());
                    if (keyPart == null)
                    {
                        return(null);
                    }
                    keys.Add(keyPart);
                }
                return(GetTargetRole().GetEntity().CreateKey(keys.ToArray()));
            }
            }
            return(null);
        }
示例#2
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);
        }
 public ComposedToFlatFieldPersister(Net.Vpc.Upa.Field field)
 {
     this.field = field;
     Net.Vpc.Upa.Types.ManyToOneType t       = (Net.Vpc.Upa.Types.ManyToOneType)field.GetDataType();
     Net.Vpc.Upa.Entity           master     = t.GetRelationship().GetTargetRole().GetEntity();
     Net.Vpc.Upa.RelationshipRole detailRole = t.GetRelationship().GetSourceRole();
     flatFields = detailRole.GetFields();
     relationshipTargetConverter = master.GetBuilder();
 }
示例#4
0
        public virtual object ExtractIdByEntityField(Net.Vpc.Upa.Record sourceRecord)
        {
            object targetEntityVal = sourceRecord.GetObject <T>(GetSourceRole().GetEntityField().GetName());

            if (targetEntityVal == null)
            {
                return(null);
            }
            Net.Vpc.Upa.EntityBuilder targetConverter = GetTargetRole().GetEntity().GetBuilder();
            return(targetConverter.ObjectToId(targetEntityVal));
        }
示例#5
0
        public TypeInfo(string binding, Net.Vpc.Upa.Entity entity)
        {
            this.binding = binding;
            int dotPos = binding == null ? -1 : binding.LastIndexOf('.');

            if (dotPos > 0)
            {
                this.parentBinding = binding.Substring(0, dotPos);
                this.bindingName   = binding.Substring(dotPos + 1);
            }
            this.entity = entity;
            if (entity != null)
            {
                entityFactory   = entity.GetBuilder();
                entityConverter = entity.GetBuilder();
                entityType      = entity.GetEntityType();
            }
        }
 public virtual int Update(Net.Vpc.Upa.Entity entity, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Record updates, Net.Vpc.Upa.Expressions.Expression condition) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Expressions.Update u = new Net.Vpc.Upa.Expressions.Update().Entity(entity.GetName());
     foreach (string fieldName in updates.KeySet())
     {
         Net.Vpc.Upa.Field f = entity.FindField(fieldName);
         if (f != null && Net.Vpc.Upa.Impl.Util.Filters.Fields2.UPDATE.Accept(f))
         {
             object @value = updates.GetObject <T>(fieldName);
             if ((f.GetDataType() is Net.Vpc.Upa.Types.ManyToOneType))
             {
                 Net.Vpc.Upa.Types.ManyToOneType e = (Net.Vpc.Upa.Types.ManyToOneType)f.GetDataType();
                 if (e.IsUpdatable())
                 {
                     Net.Vpc.Upa.Entity        masterEntity = context.GetPersistenceUnit().GetEntity(e.GetTargetEntityName());
                     Net.Vpc.Upa.EntityBuilder mbuilder     = masterEntity.GetBuilder();
                     if (@value is Net.Vpc.Upa.Expressions.Expression)
                     {
                         Net.Vpc.Upa.Expressions.Expression evalue;
                         System.Collections.Generic.IList <Net.Vpc.Upa.Field> sfields = e.GetRelationship().GetSourceRole().GetFields();
                         System.Collections.Generic.IList <Net.Vpc.Upa.Field> tfields = e.GetRelationship().GetTargetRole().GetFields();
                         for (int i = 0; i < (sfields).Count; i++)
                         {
                             Net.Vpc.Upa.Field fk  = sfields[i];
                             Net.Vpc.Upa.Field fid = tfields[i];
                             evalue = ((Net.Vpc.Upa.Expressions.Expression)@value).Copy();
                             evalue = context.GetPersistenceUnit().GetExpressionManager().ParseExpression(evalue);
                             if (evalue is Net.Vpc.Upa.Expressions.Select)
                             {
                                 Net.Vpc.Upa.Expressions.Select svalue = (Net.Vpc.Upa.Expressions.Select)evalue;
                                 if (svalue.CountFields() != 1)
                                 {
                                     throw new System.Exception("Invalid Expression " + svalue + " as formula for field " + f.GetAbsoluteName());
                                 }
                                 if (svalue.GetField(0).GetExpression() is Net.Vpc.Upa.Expressions.Var)
                                 {
                                     svalue.GetField(0).SetExpression(new Net.Vpc.Upa.Expressions.Var((Net.Vpc.Upa.Expressions.Var)svalue.GetField(0).GetExpression(), fid.GetName()));
                                 }
                                 else
                                 {
                                     throw new System.Exception("Invalid Expression " + svalue + " as formula for field " + f.GetAbsoluteName());
                                 }
                             }
                             else if (evalue is Net.Vpc.Upa.Expressions.Var)
                             {
                                 evalue = (new Net.Vpc.Upa.Expressions.Var((Net.Vpc.Upa.Expressions.Var)evalue, fk.GetName()));
                             }
                             else if (evalue is Net.Vpc.Upa.Expressions.Param)
                             {
                             }
                             else if (evalue is Net.Vpc.Upa.Expressions.Literal)
                             {
                             }
                             else
                             {
                                 throw new System.Exception("Invalid Expression " + evalue + " as formula for field " + f.GetAbsoluteName());
                             }
                             u.Set(fk.GetName(), evalue);
                         }
                     }
                     else
                     {
                         Net.Vpc.Upa.Key k = null;
                         if (@value is Net.Vpc.Upa.Record)
                         {
                             k = mbuilder.RecordToKey((Net.Vpc.Upa.Record)@value);
                         }
                         else
                         {
                             k = mbuilder.ObjectToKey(@value);
                         }
                         int x = 0;
                         foreach (Net.Vpc.Upa.Field fk in e.GetRelationship().GetSourceRole().GetFields())
                         {
                             u.Set(fk.GetName(), new Net.Vpc.Upa.Expressions.Param(fk.GetName(), k == null ? null : k.GetObjectAt(x)));
                             x++;
                         }
                     }
                 }
             }
             else
             {
                 Net.Vpc.Upa.Expressions.Expression expression = (@value is Net.Vpc.Upa.Expressions.Expression) ? ((Net.Vpc.Upa.Expressions.Expression)((Net.Vpc.Upa.Expressions.Expression)@value)) : new Net.Vpc.Upa.Expressions.Param(null, @value);
                 u.Set(fieldName, expression);
             }
         }
     }
     u.Where(condition);
     return(context.GetPersistenceStore().CreateQuery(u, context).ExecuteNonQuery());
 }