private static string GetInsertSql(WfPersistQueue pq) { ORMappingItemCollection mappingInfo = ORMapping.GetMappingInfo(pq.GetType()); string sql = string.Format("INSERT INTO {0}(PROCESS_ID, UPDATE_TAG, TENANT_CODE) SELECT INSTANCE_ID, UPDATE_TAG, TENANT_CODE FROM WF.PROCESS_INSTANCES WHERE INSTANCE_ID = {1}", mappingInfo.TableName, TSqlBuilder.Instance.CheckUnicodeQuotationMark(pq.ProcessID)); return(sql); }
public static WfPersistQueue FromProcess(IWfProcess process) { process.NullCheck("process"); WfPersistQueue result = new WfPersistQueue(); result.ProcessID = process.ID; return(result); }
private static string GetUpdatePersistQueueSql(WfPersistQueue pq) { StringBuilder sql = new StringBuilder(); //仅仅插入数据 //sql.Append(GetUpdateSql(pq)); //sql.Append(TSqlBuilder.Instance.DBStatementSeperator); //sql.Append("IF @@ROWCOUNT = 0"); //sql.Append(TSqlBuilder.Instance.DBStatementBegin); sql.Append(GetInsertSql(pq)); //sql.Append(TSqlBuilder.Instance.DBStatementEnd); return(sql.ToString()); }
public void UpdatePersistQueue(IWfProcess process) { process.NullCheck("process"); WfPersistQueue pq = WfPersistQueue.FromProcess(process); string sql = GetUpdatePersistQueueSql(pq); using (TransactionScope scope = TransactionScopeFactory.Create()) { DbHelper.RunSql(sql, GetConnectionName()); scope.Complete(); } }
/// <summary> /// 执行一项队列操作 /// </summary> /// <param name="pq"></param> public void DoQueueOperation(WfPersistQueue pq) { pq.NullCheck("pq"); Dictionary <object, object> context = new Dictionary <object, object>(); IWfProcess process = WfRuntime.GetProcessByProcessID(pq.ProcessID); try { WfQueuePersistenceSettings.GetConfig().GetPersisters().SaveData(process, context); } finally { WfRuntime.ClearCache(); } }
private static string GetUpdateSql(WfPersistQueue pq) { ORMappingItemCollection mappingInfo = ORMapping.GetMappingInfo(pq.GetType()); UpdateSqlClauseBuilder uBuilder = ORMapping.GetUpdateSqlClauseBuilder(pq, mappingInfo, "UpdateTag"); uBuilder.AppendItem("UPDATE_TAG", "WF.PROCESS_INSTANCES.UPDATE_TAG", "=", true); WhereSqlClauseBuilder wBuilder = new WhereSqlClauseBuilder(); wBuilder.AppendItem("PROCESS_ID", pq.ProcessID); wBuilder.AppendTenantCode(); string sql = string.Format("UPDATE {0} SET {1} FROM {0} INNER JOIN WF.PROCESS_INSTANCES ON INSTANCE_ID = PROCESS_ID WHERE {2}", mappingInfo.TableName, uBuilder.ToSqlString(TSqlBuilder.Instance), wBuilder.ToSqlString(TSqlBuilder.Instance)); return(sql); }
public void MoveQueueItemToArchived(WfPersistQueue pq) { pq.NullCheck("pq"); ORMappingItemCollection mappingInfo = ORMapping.GetMappingInfo(typeof(WfPersistQueue)); InsertSqlClauseBuilder builder = ORMapping.GetInsertSqlClauseBuilder(pq, mappingInfo); builder.AppendItem("SORT_ID", pq.SortID); builder.AppendItem("PROCESS_TIME", "GETUTCDATE()", "=", true); StringBuilder sql = new StringBuilder(); sql.AppendFormat("DELETE {0} WHERE SORT_ID = {1}", "WF.PERSIST_QUEUE_ARCHIEVED", pq.SortID); sql.Append(TSqlBuilder.Instance.DBStatementSeperator); sql.AppendFormat("INSERT INTO {0}{1}", "WF.PERSIST_QUEUE_ARCHIEVED", builder.ToSqlString(TSqlBuilder.Instance)); sql.Append(TSqlBuilder.Instance.DBStatementSeperator); sql.AppendFormat("DELETE {0} WHERE PROCESS_ID = {1}", mappingInfo.TableName, TSqlBuilder.Instance.CheckUnicodeQuotationMark(pq.ProcessID)); DbHelper.RunSqlWithTransaction(sql.ToString(), GetConnectionName()); }
/// <summary> /// 执行队列项的操作,并且移动到已完成中 /// </summary> /// <param name="pq"></param> public void DoQueueOperationAndMove(WfPersistQueue pq) { using (TransactionScope scope = TransactionScopeFactory.Create()) { try { DoQueueOperation(pq); } catch (System.Exception ex) { if (ex is TransactionException || ex is DbException) { throw; } pq.StatusText = ex.ToString(); } MoveQueueItemToArchived(pq); scope.Complete(); } }
public WfPersistQueue LoadArchived(string processID) { ORMappingItemCollection mappingInfo = ORMapping.GetMappingInfo(typeof(WfPersistQueue)); processID.CheckStringIsNullOrEmpty("processID"); string sql = string.Format("SELECT * FROM {0} WHERE PROCESS_ID = {1}", "WF.PERSIST_QUEUE_ARCHIEVED", TSqlBuilder.Instance.CheckUnicodeQuotationMark(processID) ); DataTable table = DbHelper.RunSqlReturnDS(sql, GetConnectionName()).Tables[0]; WfPersistQueue result = null; if (table.Rows.Count > 0) { result = new WfPersistQueue(); ORMapping.DataRowToObject(table.Rows[0], result); } return(result); }