Beispiel #1
0
        /// <summary>
        /// general history event insert behavior </summary>
        protected internal virtual void insertOrUpdate(HistoryEvent historyEvent)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager dbEntityManager = getDbEntityManager();
            DbEntityManager dbEntityManager = DbEntityManager;

            if (isInitialEvent(historyEvent))
            {
                dbEntityManager.insert(historyEvent);
            }
            else
            {
                if (dbEntityManager.getCachedEntity(historyEvent.GetType(), historyEvent.Id) == null)
                {
                    if (historyEvent is HistoricScopeInstanceEvent)
                    {
                        // if this is a scope, get start time from existing event in DB
                        HistoricScopeInstanceEvent existingEvent = (HistoricScopeInstanceEvent)dbEntityManager.selectById(historyEvent.GetType(), historyEvent.Id);
                        if (existingEvent != null)
                        {
                            HistoricScopeInstanceEvent historicScopeInstanceEvent = (HistoricScopeInstanceEvent)historyEvent;
                            historicScopeInstanceEvent.StartTime = existingEvent.StartTime;
                        }
                    }
                    if (string.ReferenceEquals(historyEvent.Id, null))
                    {
                        //          dbSqlSession.insert(historyEvent);
                    }
                    else
                    {
                        dbEntityManager.merge(historyEvent);
                    }
                }
            }
        }
 private static void VerifyEqual(HistoryEvent expected, HistoryEvent actual)
 {
     Assert.IsNotNull(actual);
     Assert.AreEqual(expected.GetType(), actual.GetType());
     Assert.AreEqual(expected.EventId, actual.EventId);
     Assert.AreEqual(expected.EventType, actual.EventType);
     Assert.AreEqual(expected.IsPlayed, actual.IsPlayed);
     Assert.AreEqual(expected.Timestamp, actual.Timestamp);
     Assert.IsNotNull(actual.ExtensionData);
 }
Beispiel #3
0
        /// <summary>
        ///     general history event insert behavior
        /// </summary>
        protected internal virtual void InsertOrUpdate(HistoryEvent historyEvent)
        {
            log.LogDebug("InsertOrUpdateEF缓存:", historyEvent.GetType().Name + " id:" + historyEvent.Id, historyEvent);
            if (IsInitialEvent(historyEvent))
            {
                Insert(historyEvent);
            }
            else
            {
                //throw new NotImplementedException();
                //TODO CachedEntity改了原始逻辑
                //if (dbEntityManager.getCachedEntity(historyEvent.getClass(), historyEvent.getId()) == null)
                //if (repository.Get(historyEvent.Id) == null)
                //{
                if (historyEvent is HistoricScopeInstanceEvent)
                {
                    // if this is a scope, get start time from existing event in DB
                    HistoricScopeInstanceEvent existingEvent = Get(historyEvent);
                    if (existingEvent != null)
                    {
                        HistoricScopeInstanceEvent historicScopeInstanceEvent = (HistoricScopeInstanceEvent)historyEvent;
                        historicScopeInstanceEvent.StartTime = existingEvent.StartTime;
                    }
                }
                else
                {
                }

                if (historyEvent.Id == null)
                {
                    //源码如此
                    //dbSqlSession.insert(historyEvent);
                }
                else
                {
                    Update(historyEvent);
                    //throw new NotImplementedException();
                    //dbEntityManager.merge(historyEvent);
                }
            }
        }
Beispiel #4
0
        static public bool HistoryEventsEqual(HistoryEvent event1, HistoryEvent event2)
        {
            if (event1 == event2)
            {
                return(true);
            }

            if (event1 == null || event2 == null)
            {
                return(false);
            }

            if (event1.Id != event2.Id)
            {
                return(false);
            }

            if (event1.Children.Count != event2.Children.Count)
            {
                return(false);
            }

            if (event1.Ticks != event2.Ticks)
            {
                return(false);
            }

            // Should be implemented as a virtual Equals method.
            switch (event1)
            {
            case BookmarkHistoryEvent bookmarkEvent1:
                if (event2 is BookmarkHistoryEvent bookmarkEvent2)
                {
                    if (!BookmarksEqual(bookmarkEvent1.Bookmark, bookmarkEvent2.Bookmark))
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }

                break;

            case CoreActionHistoryEvent coreActionEvent1:
                if (event2 is CoreActionHistoryEvent coreActionEvent2)
                {
                    if (!CoreActionsEqual(coreActionEvent1.CoreAction, coreActionEvent2.CoreAction))
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
                break;

            case RootHistoryEvent _:
                if (!(event2 is RootHistoryEvent))
                {
                    return(false);
                }
                break;

            default:
                throw new Exception(String.Format("Unknown history event type {0}", event1.GetType().Name));
            }

            // This assumes the children are in the same order. Might need to change this in the future...
            for (int i = 0; i < event1.Children.Count; i++)
            {
                if (!HistoryEventsEqual(event1.Children[i], event2.Children[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #5
0
 private void Update(HistoryEvent historyEvent)
 {
     if (historyEvent is HistoricProcessInstanceEventEntity)
     {
         HistoricProcessInstanceEventEntity data = historyEvent as HistoricProcessInstanceEventEntity;
         //TODO 不在EF上下文,再次更新会异常
         log.LogDebug("Entity当前状态", Context.CommandContext.GetEntityStateInEF <HistoricProcessInstanceEventEntity>(data).ToString());
         if (Context.CommandContext.GetEntityStateInEF <HistoricProcessInstanceEventEntity>(data) != EntityState.Detached)
         {
             //TODO dbEntityManager.merge(historyEvent)
             //Context.CommandContext.GetDbEntityManager<HistoricProcessInstanceEventEntity>().Update(data);
             Context.CommandContext.HistoricProcessInstanceManager.Update(data);
         }
         else//不在当前上下文,已经被设置过
         {
             PropertyUpdateHelper.UpDate(Context.CommandContext.HistoricProcessInstanceManager.Get(data.Id), data);
             //PropertyUpdateHelper.UpDate<HistoricProcessInstanceEventEntity>(Context.CommandContext.GetDbEntityManager<HistoricProcessInstanceEventEntity>().Get(data.Id), data);
         }
     }
     else if
     (historyEvent is HistoricActivityInstanceEventEntity)
     {
         HistoricActivityInstanceEventEntity data = historyEvent as HistoricActivityInstanceEventEntity;
         log.LogDebug("Entity当前状态", Context.CommandContext.GetEntityStateInEF <HistoricActivityInstanceEventEntity>(data).ToString() + " " + data.Id + " " + data.ActivityInstanceState);
         if (Context.CommandContext.GetEntityStateInEF <HistoricActivityInstanceEventEntity>(data) != EntityState.Detached)
         {
             //Context.CommandContext.GetDbEntityManager<HistoricActivityInstanceEventEntity>().Update(data);
             Context.CommandContext.HistoricActivityInstanceManager.Update(data);
         }
         else
         {
             //log.LogDebug("EF更新缓存", typeof(HistoricActivityInstanceEventEntity) + " " + data.Id+" state:"+data.ActivityInstanceState);
             // Todo: Context.CommandContext.GetDbEntityManager<TEntity>()方法有问题
             //var cache = Context.CommandContext.HistoricActivityInstanceManager.Get(data.Id);
             PropertyUpdateHelper.UpDate(Context.CommandContext.HistoricActivityInstanceManager.Get(data.Id), data);
             //log.LogDebug("测试001", Context.CommandContext.GetDbEntityManager<HistoricActivityInstanceEventEntity>().Get(data.Id).ActivityInstanceState.ToString());
         }
     }
     else if (historyEvent is Event.HistoricTaskInstanceEventEntity)
     {
         Event.HistoricTaskInstanceEventEntity data = historyEvent as Event.HistoricTaskInstanceEventEntity;
         if (Context.CommandContext.GetEntityStateInEF <Event.HistoricTaskInstanceEventEntity>(data) != EntityState.Detached)
         {
             //Context.CommandContext.GetDbEntityManager<Event.HistoricTaskInstanceEventEntity>().Update(data);
             Context.CommandContext.HistoricTaskInstanceManager.Update(data);
         }
         else
         {
             //PropertyUpdateHelper.UpDate<Event.HistoricTaskInstanceEventEntity>(Context.CommandContext.GetDbEntityManager<Event.HistoricTaskInstanceEventEntity>().Get(data.Id), data);
             PropertyUpdateHelper.UpDate(Context.CommandContext.HistoricTaskInstanceManager.Get(data.Id), data);
         }
     }
     else if (historyEvent is HistoricIncidentEntity)
     {
         HistoricIncidentEntity data = (HistoricIncidentEntity)historyEvent;
         if (Context.CommandContext.GetEntityStateInEF <HistoricIncidentEntity>(data) != EntityState.Detached)
         {
             //Context.CommandContext.GetDbEntityManager<HistoricIncidentEntity>().Update(data);
             Context.CommandContext.HistoricIncidentManager.Update(data);
         }
         else
         {
             //PropertyUpdateHelper.UpDate<HistoricIncidentEntity>(Context.CommandContext.GetDbEntityManager<HistoricIncidentEntity>().Get(data.Id), data);
             PropertyUpdateHelper.UpDate(Context.CommandContext.HistoricIncidentManager.Get(data.Id), data);
         }
     }
     else
     {
         throw new NotImplementedException(string.Format("historyEvent类型:{0} 更新未实现", historyEvent.GetType().ToString()));
     }
 }
Beispiel #6
0
        private HistoricScopeInstanceEvent Get(HistoryEvent historyEvent)
        {
            if (historyEvent == null)
            {
                throw new NotImplementedException("historyEvent is null");
            }
            string id = historyEvent.Id;

            if (historyEvent is HistoricActivityInstanceEventEntity)
            {
                return(Context.CommandContext.HistoricActivityInstanceManager.Get(id));
                // Todo: Context.ComandContext.GetDbEntityManager<TEntity>()方法有问题
                //return Context.CommandContext.GetDbEntityManager<HistoricActivityInstanceEventEntity>().Get(id);
            }
            //else if (historyEvent is HistoricBatchEntity)
            //{
            //    return Context.CommandContext.HistoricBatchManager.Get(id);
            //    //return Context.CommandContext.GetDbEntityManager<HistoricBatchEntity>().Get(id);
            //}
            else if (historyEvent is HistoricCaseActivityInstanceEventEntity)
            {
                return(Context.CommandContext.HistoricCaseActivityInstanceManager.Get(id));
                //return Context.CommandContext.GetDbEntityManager<HistoricCaseActivityInstanceEventEntity>().Get(id);
            }
            else if (historyEvent is HistoricCaseInstanceEventEntity)
            {
                return(Context.CommandContext.HistoricCaseInstanceManager.Get(id));
                //return Context.CommandContext.GetDbEntityManager<HistoricCaseInstanceEventEntity>().Get(id);
            }
            //else if (historyEvent is HistoricDecisionInputInstanceEntity)
            //{
            //    return Context.CommandContext.GetDbEntityManager<HistoricDecisionInputInstanceEntity>().Get(id);
            //}
            //else if (historyEvent is HistoricDecisionInstanceEntity)
            //{
            //    return Context.CommandContext.GetDbEntityManager<HistoricDecisionInstanceEntity>().Get(id);
            //}
            //else if (historyEvent is HistoricDecisionOutputInstanceEntity)
            //{
            //    return Context.CommandContext.GetDbEntityManager<HistoricDecisionOutputInstanceEntity>().Get(id);
            //}
            //else if (historyEvent is HistoricDetailEventEntity)
            //{
            //    Context.CommandContext.GetDbEntityManager<HistoricDetailEventEntity>().Add(historyEvent as HistoricDetailEventEntity);
            //}
            //else if (historyEvent is HistoricExternalTaskLogEntity)
            //{
            //    Context.CommandContext.GetDbEntityManager<HistoricExternalTaskLogEntity>().Add(historyEvent as HistoricExternalTaskLogEntity);
            //}
            //else if (historyEvent is HistoricIdentityLinkLogEntity)
            //{
            //    Context.CommandContext.GetDbEntityManager<HistoricIdentityLinkLogEntity>().Add(historyEvent as HistoricIdentityLinkLogEntity);
            //}
            //else if (historyEvent is HistoricIncidentEntity)
            //{
            //    Context.CommandContext.GetDbEntityManager<HistoricIncidentEntity>().Add(historyEvent as HistoricIncidentEntity);
            //}
            //else if (historyEvent is HistoricJobLogEventEntity)
            //{
            //    return Context.CommandContext.GetDbEntityManager<HistoricJobLogEventEntity>().Get(id);
            //}
            else if (historyEvent is HistoricProcessInstanceEventEntity)
            {
                return(Context.CommandContext.HistoricProcessInstanceManager.Get(id));
                //return Context.CommandContext.GetDbEntityManager<HistoricProcessInstanceEventEntity>().Get(id);
            }
            else if (historyEvent is HistoricTaskInstanceEventEntity)
            {
                return(Context.CommandContext.HistoricTaskInstanceManager.Get(id));
                //return Context.CommandContext.GetDbEntityManager<Event.HistoricTaskInstanceEventEntity>().Get(id);
            }
            //}else if(historyEvent is HistoricVariableInstanceEntity)
            //{
            //    Context.CommandContext.GetDbEntityManager<HistoricVariableInstanceEntity>().Add(historyEvent as HistoricVariableInstanceEntity);
            //}
            else
            {
                throw new NotImplementedException("historyEvent类型错误:" + historyEvent.GetType().Name);
            }
        }
Beispiel #7
0
 private void Insert(HistoryEvent historyEvent)
 {
     if (historyEvent == null)
     {
         throw new NotImplementedException("historyEvent is null");
     }
     log.LogDebug("(dbHistoryEventHander)InsertEF缓存:", historyEvent.GetType().Name + " id:" + historyEvent.Id, historyEvent);
     Context.CommandContext.DbEntityCache.PutPersistent(historyEvent);
     if (historyEvent is HistoricActivityInstanceEventEntity)
     {
         //Context.CommandContext.GetDbEntityManager<HistoricActivityInstanceEventEntity>().Add(historyEvent as HistoricActivityInstanceEventEntity);
         Context.CommandContext.HistoricActivityInstanceManager.Add((HistoricActivityInstanceEventEntity)historyEvent);
     }
     else if (historyEvent is HistoricBatchEntity)
     {
         //Context.CommandContext.GetDbEntityManager<HistoricBatchEntity>().Add(historyEvent as HistoricBatchEntity);
         Context.CommandContext.HistoricBatchManager.Add((HistoricBatchEntity)historyEvent);
     }
     else if (historyEvent is HistoricCaseActivityInstanceEventEntity)
     {
         //Context.CommandContext.GetDbEntityManager<HistoricCaseActivityInstanceEventEntity>().Add(historyEvent as HistoricCaseActivityInstanceEventEntity);
         Context.CommandContext.HistoricCaseActivityInstanceManager.Add((HistoricCaseActivityInstanceEventEntity)historyEvent);
     }
     else if (historyEvent is HistoricCaseInstanceEventEntity)
     {
         //Context.CommandContext.GetDbEntityManager<HistoricCaseInstanceEventEntity>().Add(historyEvent as HistoricCaseInstanceEventEntity);
         Context.CommandContext.HistoricCaseInstanceManager.Add((HistoricCaseInstanceEventEntity)historyEvent);
     }
     else if (historyEvent is HistoricDecisionInputInstanceEntity)
     {
         //Context.CommandContext.GetDbEntityManager<HistoricDecisionInputInstanceEntity>().Add(historyEvent as HistoricDecisionInputInstanceEntity);
         Context.CommandContext.DbContext.Set <HistoricDecisionInputInstanceEntity>().Add((HistoricDecisionInputInstanceEntity)historyEvent);
     }
     else if (historyEvent is HistoricDecisionInstanceEntity)
     {
         //Context.CommandContext.GetDbEntityManager<HistoricDecisionInstanceEntity>().Add(historyEvent as HistoricDecisionInstanceEntity);
         Context.CommandContext.HistoricDecisionInstanceManager.Add((HistoricDecisionInstanceEntity)historyEvent);
     }
     else if (historyEvent is HistoricDecisionOutputInstanceEntity)
     {
         //Context.CommandContext.GetDbEntityManager<HistoricDecisionOutputInstanceEntity>().Add(historyEvent as HistoricDecisionOutputInstanceEntity);
         Context.CommandContext.DbContext.Set <HistoricDecisionOutputInstanceEntity>().Add((HistoricDecisionOutputInstanceEntity)historyEvent);
     }
     else if (historyEvent is HistoricDetailEventEntity)
     {
         //Context.CommandContext.GetDbEntityManager<HistoricDetailEventEntity>().Add(historyEvent as HistoricDetailEventEntity);
         Context.CommandContext.HistoricDetailManager.Add((HistoricDetailEventEntity)historyEvent);
     }
     else if (historyEvent is HistoricExternalTaskLogEntity)
     {
         //Context.CommandContext.GetDbEntityManager<HistoricExternalTaskLogEntity>().Add(historyEvent as HistoricExternalTaskLogEntity);
         Context.CommandContext.HistoricExternalTaskLogManager.Add((HistoricExternalTaskLogEntity)historyEvent);
     }
     else if (historyEvent is HistoricIdentityLinkLogEventEntity)
     {
         //Context.CommandContext.GetDbEntityManager<HistoricIdentityLinkLogEventEntity>().Add(historyEvent as HistoricIdentityLinkLogEventEntity);
         Context.CommandContext.HistoricIdentityLinkManager.Add((HistoricIdentityLinkLogEventEntity)historyEvent);
     }
     else if (historyEvent is HistoricIncidentEntity)
     {
         //Context.CommandContext.GetDbEntityManager<HistoricIncidentEntity>().Add(historyEvent as HistoricIncidentEntity);
         Context.CommandContext.HistoricIncidentManager.Add((HistoricIncidentEntity)historyEvent);
     }
     else if (historyEvent is HistoricJobLogEventEntity)
     {
         //Context.CommandContext.GetDbEntityManager<HistoricJobLogEventEntity>().Add(historyEvent as HistoricJobLogEventEntity);
         Context.CommandContext.HistoricJobLogManager.Add((HistoricJobLogEventEntity)historyEvent);
     }
     else if (historyEvent is HistoricProcessInstanceEventEntity)
     {
         //Context.CommandContext.GetDbEntityManager<HistoricProcessInstanceEventEntity>().Add(historyEvent as HistoricProcessInstanceEventEntity);
         Context.CommandContext.HistoricProcessInstanceManager.Add((HistoricProcessInstanceEventEntity)historyEvent);
     }
     else if (historyEvent is Event.HistoricTaskInstanceEventEntity)
     {
         //Context.CommandContext.GetDbEntityManager<Event.HistoricTaskInstanceEventEntity>().Add((HistoricTaskInstanceEventEntity)historyEvent);
         Context.CommandContext.HistoricTaskInstanceManager.Add((HistoricTaskInstanceEventEntity)historyEvent);
     }
     //else if (historyEvent is HistoricVariableInstanceEntity)
     //{
     //    Context.CommandContext.GetDbEntityManager<HistoricVariableInstanceEntity>().Add(historyEvent as HistoricVariableInstanceEntity);
     //}
     else
     {
         throw new NotImplementedException("historyEvent类型错误:" + historyEvent.GetType().Name);
     }
 }