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);
        }
Example #2
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);
     }
 }
Example #3
0
        /**
         * {@inheritDoc}
         */

        public virtual void SetAll(Net.Vpc.Upa.Record other, params string [] keys)
        {
            if (other != null)
            {
                SetAll(other.ToMap(), keys);
            }
        }
Example #4
0
 public virtual void SetAll(Net.Vpc.Upa.Record other)
 {
     if (other != null)
     {
         SetAll(other.ToMap());
     }
 }
Example #5
0
        public override R RecordToObject <R>(Net.Vpc.Upa.Record record)
        {
            if (record is Net.Vpc.Upa.Impl.BeanAdapterRecord)
            {
                Net.Vpc.Upa.Impl.BeanAdapterRecord g = (Net.Vpc.Upa.Impl.BeanAdapterRecord)record;
                return((R)g.UserObject());
            }
            object obj = CreateObject <R>();

            Net.Vpc.Upa.Record ur = ObjectToRecord(obj, true);
            foreach (string k in record.KeySet())
            {
                object o = record.GetObject <T>(k);
                if (o is Net.Vpc.Upa.Record)
                {
                    Net.Vpc.Upa.Field          f  = entity.FindField(k);
                    Net.Vpc.Upa.Types.DataType dt = f.GetDataType();
                    if (dt is Net.Vpc.Upa.Types.ManyToOneType)
                    {
                        Net.Vpc.Upa.Entity oe = ((Net.Vpc.Upa.Types.ManyToOneType)dt).GetRelationship().GetTargetEntity();
                        o = oe.GetBuilder().RecordToObject <R>((Net.Vpc.Upa.Record)o);
                    }
                }
                ur.SetObject(k, o);
            }
            //        ur.setAll(unstructuredRecord);
            return((R)obj);
        }
Example #6
0
        public virtual R IdToObject <R>(object id) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            if (id == null)
            {
                return(default(R));
            }
            Net.Vpc.Upa.Entity entity = GetEntity();
            R r = CreateObject <R>();

            Net.Vpc.Upa.Record ur = ObjectToRecord(r, true);
            System.Collections.Generic.IList <Net.Vpc.Upa.Field> primaryFields = entity.GetPrimaryFields();
            if (id == null)
            {
                foreach (Net.Vpc.Upa.Field aF in primaryFields)
                {
                    ur.SetObject(aF.GetName(), null);
                }
            }
            else
            {
                object[] uk = entity.GetBuilder().GetKey(id).GetValue();
                for (int i = 0; i < (primaryFields).Count; i++)
                {
                    ur.SetObject(primaryFields[i].GetName(), uk[i]);
                }
            }
            return(r);
        }
Example #7
0
 public virtual Net.Vpc.Upa.Record KeyToRecord(Net.Vpc.Upa.Key key) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     if (key == null)
     {
         return(null);
     }
     Net.Vpc.Upa.Record ur = CreateRecord();
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> primaryFields = GetEntity().GetPrimaryFields();
     if (key == null)
     {
         foreach (Net.Vpc.Upa.Field aF in primaryFields)
         {
             ur.SetObject(aF.GetName(), null);
         }
     }
     else
     {
         object[] uk = key.GetValue();
         for (int i = 0; i < (primaryFields).Count; i++)
         {
             ur.SetObject(primaryFields[i].GetName(), uk[i]);
         }
     }
     return(ur);
 }
Example #8
0
 public virtual void Inject(object instance, string property, object @value)
 {
     Net.Vpc.Upa.Record r = (Net.Vpc.Upa.Record)instance;
     if (entity.Contains(property))
     {
         r.SetObject(property, @value);
     }
 }
        public virtual void BeforePersist(Net.Vpc.Upa.Record record, Net.Vpc.Upa.Persistence.EntityExecutionContext context) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            //K key = entity.getBuilder().recordToId(record);
            Net.Vpc.Upa.Entity entity = context.GetEntity();
            object             key    = entity.NextId <K>();

            entity.GetBuilder().SetRecordId(record, key);
        }
 public virtual void AfterPersist(Net.Vpc.Upa.Record record, Net.Vpc.Upa.Persistence.EntityExecutionContext context)
 {
     if (new System.Nullable <bool>(false).Equals(context.GetConnection().GetProperty(identityConstraintsEnabledProperty)))
     {
         return;
     }
     record.SetObject(field.GetName(), context.GetGeneratedValue(field.GetName()).GetValue());
 }
Example #11
0
 public virtual Net.Vpc.Upa.Record GetPlainRecord(bool create)
 {
     if (plainRecord == null && create)
     {
         plainRecord = new Net.Vpc.Upa.Impl.DefaultRecord();
     }
     return(plainRecord);
 }
Example #12
0
 public virtual object GetSingleValue(object defaultValue) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Record mergedRecord = GetRecord();
     if (mergedRecord == null)
     {
         return(defaultValue);
     }
     return(mergedRecord.GetSingleResult <T>());
 }
Example #13
0
 protected internal virtual void ValidateChildren(object key, Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Record r = GetEntity().CreateQueryBuilder().ByExpression(GetEntity().GetBuilder().IdToExpression(key, null)).SetFieldFilter(Net.Vpc.Upa.Filters.Fields.ByName(GetHierarchyPathField())).GetRecord();
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> lfs = GetTreeRelationship().GetSourceRole().GetFields();
     Net.Vpc.Upa.Expressions.Concat concat = new Net.Vpc.Upa.Expressions.Concat();
     concat.Add(new Net.Vpc.Upa.Expressions.Literal(r.GetString(GetHierarchyPathField()), GetEntity().GetField(GetHierarchyPathField()).GetDataType()));
     System.Collections.Generic.IList <Net.Vpc.Upa.Field> primaryFields = GetEntity().GetPrimaryFields();
     foreach (Net.Vpc.Upa.Field f in primaryFields)
     {
         concat.Add(new Net.Vpc.Upa.Expressions.Literal(GetHierarchyPathSeparator()));
         Net.Vpc.Upa.Types.DataType         t    = f.GetDataType();
         Net.Vpc.Upa.Expressions.Var        var  = new Net.Vpc.Upa.Expressions.Var(f.GetName());
         Net.Vpc.Upa.Expressions.Expression svar = null;
         if (t is Net.Vpc.Upa.Types.StringType)
         {
             svar = var;
         }
         else if (t is Net.Vpc.Upa.Types.IntType)
         {
             svar = new Net.Vpc.Upa.Expressions.I2V(var);
         }
         else if (t is Net.Vpc.Upa.Types.LongType)
         {
             svar = new Net.Vpc.Upa.Expressions.I2V(var);
         }
         else if (t is Net.Vpc.Upa.Types.DoubleType)
         {
             svar = new Net.Vpc.Upa.Expressions.D2V(var);
         }
         else if (t is Net.Vpc.Upa.Types.FloatType)
         {
             svar = new Net.Vpc.Upa.Expressions.D2V(var);
         }
         else
         {
             throw new System.ArgumentException("Unsupported ");
         }
         concat.Add(svar);
     }
     Net.Vpc.Upa.Record s = GetEntity().GetBuilder().CreateRecord();
     s.SetObject(GetHierarchyPathField(), concat);
     Net.Vpc.Upa.Expressions.Expression p   = null;
     Net.Vpc.Upa.Relationship           rel = GetTreeRelationship();
     object[] kvalue = GetEntity().GetBuilder().IdToKey(key).GetValue();
     for (int i = 0; i < rel.Size(); i++)
     {
         Net.Vpc.Upa.Field field = lfs[i];
         Net.Vpc.Upa.Expressions.Expression e = (new Net.Vpc.Upa.Expressions.Equals(new Net.Vpc.Upa.Expressions.Var(field.GetName()), new Net.Vpc.Upa.Expressions.Literal(kvalue[i], field.GetDataType())));
         p = p == null ? ((Net.Vpc.Upa.Expressions.Expression)(e)) : new Net.Vpc.Upa.Expressions.And(p, e);
     }
     GetEntity().UpdateCore(s, p, executionContext);
     System.Collections.Generic.IList <object> children = GetEntity().CreateQueryBuilder().ByExpression(p).GetIdList <K>();
     foreach (object aChildren in children)
     {
         ValidateChildren(aChildren, executionContext);
     }
 }
Example #14
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 void BeforePersist(Net.Vpc.Upa.Record record, Net.Vpc.Upa.Persistence.EntityExecutionContext context) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     if (new System.Nullable <bool>(false).Equals(context.GetConnection().GetProperty(identityConstraintsEnabledProperty)))
     {
         return;
     }
     context.AddGeneratedValue(field.GetName(), field.GetDataType());
     //manual id values are ignored
     record.Remove(field.GetName());
 }
Example #16
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));
        }
Example #17
0
 public virtual void SetRecord(string entityName, Net.Vpc.Upa.Record record)
 {
     if (record == null)
     {
         records.Remove(entityName);
     }
     else
     {
         records[entityName] = record;
     }
 }
 public override object Invoke(params object [] arguments)
 {
     Net.Vpc.Upa.Callbacks.UpdateEvent ev = (Net.Vpc.Upa.Callbacks.UpdateEvent)arguments[0];
     foreach (object id in ResolveIdList(ev, ev.GetFilterExpression()))
     {
         Net.Vpc.Upa.Record updatesRecord = ev.GetUpdatesRecord().Copy();
         ev.GetEntity().GetBuilder().SetObjectId(updatesRecord, id);
         Net.Vpc.Upa.Callbacks.UpdateObjectEvent oe = new Net.Vpc.Upa.Callbacks.UpdateObjectEvent(id, updatesRecord, ev.GetFilterExpression(), ev.GetContext(), GetPhase());
         InvokeSingle(oe);
     }
     return(null);
 }
Example #19
0
 public override R RecordToObject <R>(Net.Vpc.Upa.Record record)
 {
     if (recordType.IsInstanceOfType(record))
     {
         return((R)record);
     }
     else
     {
         object ur = CreateRecord();
         ((Net.Vpc.Upa.Record)ur).SetAll(record);
         return((R)ur);
     }
 }
        protected internal virtual object GetNewValue(Net.Vpc.Upa.Field field, Net.Vpc.Upa.Record record, Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            Net.Vpc.Upa.Entity entity           = field.GetEntity();
            Net.Vpc.Upa.Entity seq              = entity.GetPersistenceUnit().GetEntity(Net.Vpc.Upa.Impl.PrivateSequence.ENTITY_NAME);
            Net.Vpc.Upa.Impl.SequenceManager sm = new Net.Vpc.Upa.Impl.EntitySequenceManager(seq);
            string groupString = Eval(this.group, "{#}", record);
            //        String fieldName = field.getName();
            //        while (true) {
            object nextValue = GetNewValue(sm, groupString, record);

            //            long count = entity.getEntityCount(new Equals(new Var(fieldName), nextValue));
            //            if (count == 0) {
            return(nextValue);
        }
Example #21
0
 public virtual object ExtractIdByForeignFields(Net.Vpc.Upa.Record sourceRecord)
 {
     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().CreateId(keys.ToArray()));
 }
Example #22
0
 public virtual long GetNewValue(Net.Vpc.Upa.Field field) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     Net.Vpc.Upa.Entity             entity = field.GetEntity();
     Net.Vpc.Upa.Expressions.Select s      = new Net.Vpc.Upa.Expressions.Select().From(entity.GetName());
     s.Field(new Net.Vpc.Upa.Expressions.Plus(new Net.Vpc.Upa.Expressions.Coalesce(new Net.Vpc.Upa.Expressions.Max(new Net.Vpc.Upa.Expressions.Var(field.GetName())), new Net.Vpc.Upa.Expressions.Literal(0)), new Net.Vpc.Upa.Expressions.Literal(1)), "next");
     Net.Vpc.Upa.Record next = field.GetPersistenceUnit().CreateQuery(s).GetRecord();
     if (next != null)
     {
         return(next.GetLong("next"));
     }
     else
     {
         return(0);
     }
 }
Example #23
0
 public virtual Net.Vpc.Upa.Expressions.Expression ObjectToIdExpression(object entityOrRecord, string alias) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     if (entityOrRecord == null)
     {
         return(null);
     }
     Net.Vpc.Upa.Record r = null;
     if (entityOrRecord is Net.Vpc.Upa.Record)
     {
         r = (Net.Vpc.Upa.Record)entityOrRecord;
     }
     r = ObjectToRecord(entityOrRecord);
     Net.Vpc.Upa.Key k = RecordToKey(r);
     return(KeyToExpression(k, alias));
 }
Example #24
0
        public virtual object ExtractId(Net.Vpc.Upa.Record sourceRecord)
        {
            switch (GetSourceRole().GetRelationshipUpdateType())
            {
            case Net.Vpc.Upa.RelationshipUpdateType.COMPOSED:
            {
                object o = ExtractIdByEntityField(sourceRecord);
                return(o);
            }

            case Net.Vpc.Upa.RelationshipUpdateType.FLAT:
            {
                return(ExtractIdByForeignFields(sourceRecord));
            }
            }
            return(null);
        }
Example #25
0
        public virtual R CreateInitializedObject <R>()
        {
            object o = CreateObject <R>();

            Net.Vpc.Upa.Record r = ObjectToRecord(o, false);
            foreach (Net.Vpc.Upa.Field field in entity.GetFields())
            {
                object df = field.GetDefaultValue();
                if (field.IsId() && (field.GetModifiers().Contains(Net.Vpc.Upa.FieldModifier.PERSIST_FORMULA) || field.GetModifiers().Contains(Net.Vpc.Upa.FieldModifier.PERSIST_SEQUENCE)))
                {
                }
                else if (df != null)
                {
                    r.SetObject(field.GetName(), df);
                }
            }
            return(RecordToObject <R>(r));
        }
Example #26
0
 public virtual void FireBeforePersist(object objectId, Net.Vpc.Upa.Record record, Net.Vpc.Upa.Persistence.EntityExecutionContext context) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     //        Object methodExecId = Math.random();
     //        log.log(Level.FINE,"enter {} {}", new Object[]{key, record});
     //Log.method_enter(methodExecId, getName(), key, record);
     //        entity.preInsertRecord(key, record, context);
     Net.Vpc.Upa.Callbacks.PersistEvent @event = null;
     if (entity.GetPersistenceUnit().IsTriggersEnabled())
     {
         foreach (Net.Vpc.Upa.Callbacks.Trigger et in entity.GetSoftTriggers())
         {
             Net.Vpc.Upa.Impl.DefaultTrigger t = (Net.Vpc.Upa.Impl.DefaultTrigger)et;
             //                Log.log(EditorConstants.Logs.TRIGGER, "<START " + getName() + ".firePreInsertTable> " + t.toString());
             try {
                 Net.Vpc.Upa.Callbacks.EntityListener li = t.GetListener();
                 if (@event == null)
                 {
                     @event = new Net.Vpc.Upa.Callbacks.PersistEvent(objectId, record, context, Net.Vpc.Upa.EventPhase.BEFORE);
                 }
                 @event.SetTrigger(et);
                 li.OnPrePersist(@event);
             } catch (Net.Vpc.Upa.Exceptions.UPAException ex) {
                 //do some thing
                 log.TraceEvent(System.Diagnostics.TraceEventType.Error, 100, Net.Vpc.Upa.Impl.FwkConvertUtils.LogMessageExceptionFormatter("problem when executing trigger " + t.GetName() + ".onPrePersist(" + t.GetEntity().GetName() + "," + objectId + ")", ex));
                 //                    Log.bug(e);
                 throw ex;
             }
         }
     }
     //                Log.log(EditorConstants.Logs.TRIGGER, "<END   " + getName() + ".firePreInsertTable> " + t.toString());
     if (@event == null)
     {
         @event = new Net.Vpc.Upa.Callbacks.PersistEvent(objectId, record, context, Net.Vpc.Upa.EventPhase.BEFORE);
     }
     foreach (Net.Vpc.Upa.Callback invoker in persistenceUnitListenerManager.GetPreCallbacks(Net.Vpc.Upa.CallbackType.ON_PERSIST, Net.Vpc.Upa.ObjectType.ENTITY, @event.GetEntity().GetName(), Net.Vpc.Upa.Impl.Event.PersistenceUnitListenerManager.DEFAULT_SYSTEM))
     {
         invoker.Invoke(@event);
     }
     foreach (Net.Vpc.Upa.PreparedCallback invoker in persistenceUnitListenerManager.GetPostPreparedCallbacks(Net.Vpc.Upa.CallbackType.ON_PERSIST, Net.Vpc.Upa.ObjectType.ENTITY, @event.GetEntity().GetName(), Net.Vpc.Upa.Impl.Event.PersistenceUnitListenerManager.DEFAULT_SYSTEM))
     {
         invoker.Prepare(@event);
     }
 }
Example #27
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");
                        }
                    }
                }
            }
        }
 protected internal virtual Net.Vpc.Upa.Expressions.Expression EvalVar(Net.Vpc.Upa.Expressions.Var expression)
 {
     if (expression.GetApplier() == null)
     {
         //this is the very root
         string name = expression.GetName();
         if (vars.ContainsKey(name))
         {
             return(new Net.Vpc.Upa.Expressions.Literal(Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue <string, object>(vars, name), null));
         }
     }
     else
     {
         Net.Vpc.Upa.Expressions.Expression x = expression.GetApplier();
         // no need for evalVar() in post order DFS
         if (x is Net.Vpc.Upa.Expressions.Literal)
         {
             object v = ((Net.Vpc.Upa.Expressions.Literal)x).GetValue();
             if (v == null)
             {
                 return(Net.Vpc.Upa.Expressions.Literal.NULL);
             }
             else if (v is Net.Vpc.Upa.Record)
             {
                 Net.Vpc.Upa.Record r = (Net.Vpc.Upa.Record)v;
                 return(new Net.Vpc.Upa.Expressions.Literal(r.GetObject <object>(expression.GetName()), null));
             }
             else if (v is System.Collections.IDictionary)
             {
                 System.Collections.IDictionary r = (System.Collections.IDictionary)v;
                 return(new Net.Vpc.Upa.Expressions.Literal(Net.Vpc.Upa.Impl.FwkConvertUtils.GetMapValue0(r, expression.GetName()), null));
             }
             else
             {
                 Net.Vpc.Upa.Entity entity = pu.GetEntity(v.GetType());
                 Net.Vpc.Upa.Field  field  = entity.GetField(expression.GetName());
                 Net.Vpc.Upa.Record r      = entity.GetBuilder().ObjectToRecord(v);
                 return(new Net.Vpc.Upa.Expressions.Literal(r.GetObject <object>(field.GetName()), null));
             }
         }
     }
     return(expression);
 }
 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();
 }
Example #30
0
 public virtual void FireBeforeFormulasUpdate(Net.Vpc.Upa.Record updates, Net.Vpc.Upa.Expressions.Expression condition, Net.Vpc.Upa.Persistence.EntityExecutionContext context) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     //        Object methodExecId = Math.random();
     //        Log.method_enter(methodExecId, getName(), updates, condition);
     //        entity.preUpdateTable(updates, condition, context);
     Net.Vpc.Upa.Callbacks.UpdateFormulaEvent @event = null;
     if (entity.GetPersistenceUnit().IsTriggersEnabled())
     {
         foreach (Net.Vpc.Upa.Callbacks.Trigger et in entity.GetSoftTriggers())
         {
             Net.Vpc.Upa.Impl.DefaultTrigger t = (Net.Vpc.Upa.Impl.DefaultTrigger)et;
             //                Log.log(EditorConstants.Logs.TRIGGER, "<START " + getName() + ".fireBeforeUpdate> " + t.toString());
             try {
                 Net.Vpc.Upa.Callbacks.EntityListener li = t.GetListener();
                 if (@event == null)
                 {
                     @event = new Net.Vpc.Upa.Callbacks.UpdateFormulaEvent(updates, condition, context, Net.Vpc.Upa.EventPhase.BEFORE);
                 }
                 li.OnPreUpdateFormula(@event);
             } catch (Net.Vpc.Upa.Exceptions.UPAException ex) {
                 log.TraceEvent(System.Diagnostics.TraceEventType.Error, 100, Net.Vpc.Upa.Impl.FwkConvertUtils.LogMessageExceptionFormatter("problem when executing trigger " + t.GetName() + ".onPreUpdateFormula(" + t.GetEntity().GetName() + "," + condition + ")", ex));
                 //                    Log.bug("19987", "problem when executing trigger " + t.getName() + ".beforeUpdate(" + getName() + "," + condition + ")");
                 //                    Log.bug(e);
                 throw ex;
             }
         }
     }
     //                Log.log(EditorConstants.Logs.TRIGGER, "<END   " + getName() + ".fireBeforeUpdate> " + t.toString());
     if (@event == null)
     {
         @event = new Net.Vpc.Upa.Callbacks.UpdateFormulaEvent(updates, condition, context, Net.Vpc.Upa.EventPhase.BEFORE);
     }
     foreach (Net.Vpc.Upa.Callback invoker in persistenceUnitListenerManager.GetPreCallbacks(Net.Vpc.Upa.CallbackType.ON_UPDATE_FORMULAS, Net.Vpc.Upa.ObjectType.ENTITY, @event.GetEntity().GetName(), Net.Vpc.Upa.Impl.Event.PersistenceUnitListenerManager.DEFAULT_SYSTEM))
     {
         invoker.Invoke(@event);
     }
     foreach (Net.Vpc.Upa.PreparedCallback invoker in persistenceUnitListenerManager.GetPostPreparedCallbacks(Net.Vpc.Upa.CallbackType.ON_UPDATE_FORMULAS, Net.Vpc.Upa.ObjectType.ENTITY, @event.GetEntity().GetName(), Net.Vpc.Upa.Impl.Event.PersistenceUnitListenerManager.DEFAULT_SYSTEM))
     {
         invoker.Prepare(@event);
     }
 }