Ejemplo n.º 1
0
        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);
        }
 public virtual void Insert(Net.Vpc.Upa.Entity entity, Net.Vpc.Upa.Record originalRecord, Net.Vpc.Upa.Record record, Net.Vpc.Upa.Persistence.EntityExecutionContext context) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.PersistenceUnit    pu     = context.GetPersistenceUnit();
     Net.Vpc.Upa.Expressions.Insert insert = new Net.Vpc.Upa.Expressions.Insert().Into(entity.GetName());
     foreach (System.Collections.Generic.KeyValuePair <string, object> entry in record.EntrySet())
     {
         object            @value = (entry).Value;
         string            key    = (entry).Key;
         Net.Vpc.Upa.Field field  = entity.FindField(key);
         //should process specific entity fields
         if ((field.GetDataType() is Net.Vpc.Upa.Types.ManyToOneType))
         {
             Net.Vpc.Upa.Types.ManyToOneType e = (Net.Vpc.Upa.Types.ManyToOneType)field.GetDataType();
             if (e.IsUpdatable())
             {
                 Net.Vpc.Upa.Entity masterEntity = pu.GetEntity(e.GetTargetEntityName());
                 Net.Vpc.Upa.Key    k            = null;
                 if (@value is Net.Vpc.Upa.Record)
                 {
                     k = masterEntity.GetBuilder().RecordToKey((Net.Vpc.Upa.Record)@value);
                 }
                 else
                 {
                     k = masterEntity.GetBuilder().ObjectToKey(@value);
                 }
                 int x = 0;
                 foreach (Net.Vpc.Upa.Field fk in e.GetRelationship().GetSourceRole().GetFields())
                 {
                     insert.Set(fk.GetName(), new Net.Vpc.Upa.Expressions.Param(fk.GetName(), k.GetObjectAt(x)));
                     x++;
                 }
             }
         }
         else
         {
             Net.Vpc.Upa.Expressions.Expression valueExpression = (@value is Net.Vpc.Upa.Expressions.Expression) ? ((Net.Vpc.Upa.Expressions.Expression)((Net.Vpc.Upa.Expressions.Expression)@value)) : new Net.Vpc.Upa.Expressions.Param(field.GetName(), @value);
             insert.Set(key, valueExpression);
         }
     }
     context.GetPersistenceStore().CreateQuery(insert, context).ExecuteNonQuery();
 }