Beispiel #1
0
 public virtual Net.Vpc.Upa.Record ObjectToRecord(object @object, System.Collections.Generic.ISet <string> fields, bool ignoreUnspecified, bool ensureIncludeIds)
 {
     Net.Vpc.Upa.Record r = CreateRecord();
     Net.Vpc.Upa.Record allFieldsRecord = ObjectToRecord(@object, ignoreUnspecified);
     if (fields == null || (fields.Count == 0))
     {
         r.SetAll(r);
         return(r);
     }
     else
     {
         foreach (string k in fields)
         {
             r.SetObject(k, allFieldsRecord.GetObject <T>(k));
         }
         if (ensureIncludeIds)
         {
             foreach (Net.Vpc.Upa.Field o in GetEntity().GetPrimaryFields())
             {
                 string idname = o.GetName();
                 if (!r.IsSet(idname))
                 {
                     r.SetObject(idname, allFieldsRecord.GetObject <T>(idname));
                 }
             }
         }
         return(r);
     }
 }
Beispiel #2
0
 public virtual bool ResetToDefaultValue(object instance, string field) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Record r = (Net.Vpc.Upa.Record)instance;
     if (r.IsSet(field))
     {
         r.Remove(field);
         return(true);
     }
     return(false);
 }
 public virtual string Convert(string v)
 {
     if (v.Equals("#"))
     {
         return(System.Convert.ToString(replacement));
     }
     if (record != null && record.IsSet(v))
     {
         return(System.Convert.ToString(record.GetObject <T>(v)));
     }
     Net.Vpc.Upa.Expressions.Select s = new Net.Vpc.Upa.Expressions.Select();
     s.Field(new Net.Vpc.Upa.Expressions.UserExpression(v), "customValue");
     return(System.Convert.ToString(field.GetEntity().GetPersistenceUnit().CreateQuery(s).GetSingleValue()));
 }
Beispiel #4
0
        public override void OnPreUpdate(Net.Vpc.Upa.Callbacks.UpdateEvent @event) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            Net.Vpc.Upa.Persistence.EntityExecutionContext       executionContext = @event.GetContext();
            System.Collections.Generic.IList <Net.Vpc.Upa.Field> updateTreeFields = GetUpdateTreeFields();
            Net.Vpc.Upa.Record updates = @event.GetUpdatesRecord();
            if (!updates.IsSet(updateTreeFields[0].GetName()))
            {
                return;
            }
            object val = updates.GetObject <T>(updateTreeFields[0].GetName());

            if (val is Net.Vpc.Upa.Expressions.Literal)
            {
                val = ((Net.Vpc.Upa.Expressions.Literal)val).GetValue();
            }
            else if (val is Net.Vpc.Upa.Expressions.Expression)
            {
                //                    Log.bug("1232123");
                return;
            }
            if (val != null)
            {
                object parentId = relation.ExtractId(updates);
                if (parentId != null)
                {
                    Net.Vpc.Upa.Entity entity = @event.GetEntity();
                    string             k      = "recurse";
                    if (!executionContext.IsSet(k))
                    {
                        System.Collections.Generic.IList <object> idList = entity.CreateQueryBuilder().ByExpression(@event.GetFilterExpression()).OrderBy(entity.GetUpdateFormulasOrder()).GetIdList <K>();
                        executionContext.SetObject(k, idList);
                    }
                    System.Collections.Generic.IList <object> r = (System.Collections.Generic.IList <object>)executionContext.GetObject <T>("recurse");
                    foreach (object aR in r)
                    {
                        if (support.IsEqualOrIsParent(aR, parentId))
                        {
                            throw new Net.Vpc.Upa.Exceptions.UPAException("RedundancyProblem");
                        }
                    }
                }
            }
        }
Beispiel #5
0
 public virtual Net.Vpc.Upa.Key RecordToKey(Net.Vpc.Upa.Record record) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     if (record == null)
     {
         return(null);
     }
     Net.Vpc.Upa.Entity entity = GetEntity();
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> f = entity.GetPrimaryFields();
     object[] rawKey = new object[(f).Count];
     for (int i = 0; i < rawKey.Length; i++)
     {
         Net.Vpc.Upa.Field field = f[i];
         string            name  = field.GetName();
         if (record.IsSet(name))
         {
             rawKey[i] = record.GetObject <T>(name);
         }
         else
         {
             return(entity.GetBuilder().CreateKey((object[])null));
         }
     }
     return(entity.GetBuilder().CreateKey(rawKey));
 }
Beispiel #6
0
 public virtual bool IsDefaultValue(object o, string field) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Record r = (Net.Vpc.Upa.Record)o;
     return(!r.IsSet(field));
 }
        public virtual void CheckUpdate(Net.Vpc.Upa.Record updates, Net.Vpc.Upa.Expressions.Expression condition) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            if (!entity.GetPersistenceUnit().GetSecurityManager().IsAllowedUpdate(entity))
            {
                throw new Net.Vpc.Upa.Exceptions.UpdateRecordNotAllowedException(entity);
            }
            if (!IsUpdateSupported())
            {
                throw new Net.Vpc.Upa.Exceptions.UnupdatableRecordException(entity);
            }
            Net.Vpc.Upa.Expressions.Expression e = GetFullNonUpdatableRecordsExpression();
            if (e != null && e.IsValid())
            {
                Net.Vpc.Upa.Expressions.Expression a = (condition == null) ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(condition, e);
                if (entity.GetEntityCount(a) > 0)
                {
                    throw new Net.Vpc.Upa.Exceptions.UnupdatableRecordException(entity);
                }
            }
            long updated = 0;

            if ((updated = entity.GetEntityCount(condition)) == 0)
            {
                throw new Net.Vpc.Upa.Exceptions.UpdateRecordKeyNotFoundException(entity, condition);
            }
            //TODO c koa cet unique fields qui n'impose pas toutes les validations
            if (false)
            {
                return;
            }
            else if (updated == 1)
            {
                if (condition != null)
                {
                    if (updates != null)
                    {
                        Net.Vpc.Upa.Expressions.Expression or = null;
                        foreach (Net.Vpc.Upa.Index index in entity.GetIndexes(true))
                        {
                            Net.Vpc.Upa.Field[] f = index.GetFields();
                            Net.Vpc.Upa.Expressions.Expression a = null;
                            int found = 0;
                            foreach (Net.Vpc.Upa.Field aF in f)
                            {
                                if (updates.IsSet(aF.GetName()))
                                {
                                    found++;
                                    Net.Vpc.Upa.Expressions.Expression b = (new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(aF.GetName()), Net.Vpc.Upa.Expressions.ExpressionFactory.ToLiteral(updates.GetObject <T>(aF.GetName()))));
                                    a = a == null ? ((Net.Vpc.Upa.Expressions.Expression)(b)) : new Net.Vpc.Upa.Expressions.And(a, b);
                                }
                            }
                            if (found != 0 && found != f.Length)
                            {
                                throw new Net.Vpc.Upa.Exceptions.UPAException("NotFound");
                            }
                            else if (found == f.Length)
                            {
                                or = or == null ? ((Net.Vpc.Upa.Expressions.Expression)(a)) : new Net.Vpc.Upa.Expressions.Or(or, a);
                            }
                        }
                        if (or != null)
                        {
                            Net.Vpc.Upa.Expressions.And and = new Net.Vpc.Upa.Expressions.And(new Net.Vpc.Upa.Expressions.Not(condition), or);
                            if (entity.GetEntityCount(and) > 0)
                            {
                                throw new Net.Vpc.Upa.Exceptions.UpdateRecordDuplicateKeyException(entity);
                            }
                        }
                    }
                }
            }
            else
            {
                if (updates != null)
                {
                    foreach (Net.Vpc.Upa.Index index in entity.GetIndexes(true))
                    {
                        Net.Vpc.Upa.Field[] f = index.GetFields();
                        foreach (Net.Vpc.Upa.Field aF in f)
                        {
                            if (updates.IsSet(aF.GetName()))
                            {
                                throw new Net.Vpc.Upa.Exceptions.UpdateRecordDuplicateKeyException(entity);
                            }
                        }
                    }
                }
            }
            Net.Vpc.Upa.Entity p = entity.GetParentEntity();
            if (p != null)
            {
                Net.Vpc.Upa.Expressions.Expression ss = entity.ChildToParentExpression(condition);
                try {
                    p.GetShield().CheckUpdate(null, ss);
                } catch (Net.Vpc.Upa.Exceptions.UpdateRecordKeyNotFoundException ex) {
                    log.Warning(entity.GetName() + "'s parent seems not to be resolvable for condition (" + condition + "): " + ex);
                }
            }
            //ignore if parent not found!
            CheckVeto(Net.Vpc.Upa.VetoableOperation.checkUpdate, updates, condition);
        }