📄 adoworkflowstore.cs
字号:
connectionString = getInitProperty(props, "connectionString", "");
entrySequence = getInitProperty(props, "entry.sequence", "SELECT isnull(max("+this.entryId+"),0)+1 from "+this.entryTable);
stepSequence = getInitProperty(props, "step.sequence", "SELECT isnull(max("+this.stepId+"),0)+1 from "+this.historyTable);
}
public virtual IStep MarkFinished(IStep step, int actionId, DateTime finishDate, String status, String caller)
{
IDbConnection conn = null;
IDbCommand stmt = null;
try
{
conn = Connection;
String sql = "UPDATE " + currentTable + " SET " + stepStatus + " = " +
getParameterName("stepStatus") + ", " + stepActionId + " = " +
getParameterName("stepActionId") + ", " + stepFinishDate + " = " +
getParameterName("stepFinishDate") + ", " + stepCaller + " = " +
getParameterName("stepCaller") +
" WHERE " + stepId + " = " + getParameterName("stepId");
if (log.IsDebugEnabled)
{
log.Debug("Executing SQL statement: " + sql);
}
stmt = createDbCommand(conn, sql);
stmt.Parameters.Add(createDataParameter("stepStatus", status));
stmt.Parameters.Add(createDataParameter("stepActionId", actionId));
stmt.Parameters.Add(createDataParameter("stepFinishDate", finishDate));
stmt.Parameters.Add(createDataParameter("stepCaller", caller));
stmt.Parameters.Add(createDataParameter("stepId", step.Id));
stmt.ExecuteNonQuery();
SimpleStep theStep = (SimpleStep) step;
theStep.ActionId = actionId;
theStep.FinishDate = finishDate;
theStep.Status = status;
theStep.Caller = caller;
return theStep;
}
catch (Exception e)
{
throw new StoreException("Unable to mark step finished for #" + step.EntryId, e);
}
finally
{
cleanup(conn, stmt, null);
}
}
public virtual void MoveToHistory(IStep step)
{
IDbConnection conn = null;
IDbCommand stmt = null;
try
{
conn = Connection;
String sql = "INSERT INTO " + historyTable + " (" + stepId + "," + stepEntryId + ", " + stepStepId +
", " + stepActionId + ", " + stepOwner + ", " + stepStartDate +
", " + stepFinishDate + ", " + stepStatus + ", " + stepCaller + ") VALUES (" +
getParameterName(stepId) + "," +
getParameterName(stepEntryId) + "," +
getParameterName(stepStepId) + "," +
getParameterName(stepActionId) + "," +
getParameterName(stepOwner) + "," +
getParameterName(stepStartDate) + "," +
getParameterName(stepFinishDate) + "," +
getParameterName(stepStatus) + "," +
getParameterName(stepCaller) + ")";
if (log.IsDebugEnabled)
{
log.Debug("Executing SQL statement: " + sql);
}
stmt = createDbCommand(conn, sql);
stmt.Parameters.Add(createDataParameter(stepId, step.Id));
stmt.Parameters.Add(createDataParameter(stepEntryId, step.EntryId));
stmt.Parameters.Add(createDataParameter(stepStepId, step.StepId));
stmt.Parameters.Add(createDataParameter(stepActionId, step.ActionId));
stmt.Parameters.Add(createDataParameter(stepOwner, step.Owner));
stmt.Parameters.Add(createDataParameter(stepStartDate, step.StartDate));
stmt.Parameters.Add(createDataParameter(stepFinishDate, step.FinishDate));
stmt.Parameters.Add(createDataParameter(stepStatus, step.Status));
stmt.Parameters.Add(createDataParameter(stepCaller, step.Caller));
stmt.ExecuteNonQuery();
long[] previousIds = step.PreviousStepIds;
if ((previousIds != null) && (previousIds.Length > 0))
{
sql = "INSERT INTO " + historyPrevTable + " (" + stepId + ", " + stepPreviousId + ") VALUES (" +
getParameterName(stepId) + "," +
getParameterName(stepPreviousId) + ")";
log.Debug("Executing SQL statement: " + sql);
cleanup(null, stmt, null);
stmt = createDbCommand(conn, sql);
for (int i = 0; i < previousIds.Length; i++)
{
long previousId = previousIds[i];
stmt.Parameters.Clear();
stmt.Parameters.Add(createDataParameter(stepId, step.Id));
stmt.Parameters.Add(createDataParameter(stepPreviousId, previousId));
stmt.ExecuteNonQuery();
}
}
sql = "DELETE FROM " + currentPrevTable + " WHERE " + stepId + " = " + getParameterName(stepId);
if (log.IsDebugEnabled)
{
log.Debug("Executing SQL statement: " + sql);
}
cleanup(null, stmt, null);
stmt = createDbCommand(conn, sql);
stmt.Parameters.Add(createDataParameter(stepId, step.Id));
stmt.ExecuteNonQuery();
sql = "DELETE FROM " + currentTable + " WHERE " + stepId + " = " + getParameterName(stepId);
if (log.IsDebugEnabled)
{
log.Debug("Executing SQL statement: " + sql);
}
cleanup(null, stmt, null);
stmt = createDbCommand(conn, sql);
stmt.Parameters.Add(createDataParameter(stepId, step.Id));
stmt.ExecuteNonQuery();
}
catch (Exception e)
{
throw new StoreException("Unable to move current step to history step for #" + step.EntryId, e);
}
finally
{
cleanup(conn, stmt, null);
}
}
public virtual IList Query(WorkflowExpressionQuery query)
{
Expression expression = query.Expression;
StringBuilder sel = new StringBuilder();
IList values = new ArrayList();
String columnName = null;
if (expression.Nested)
{
columnName = buildNested((NestedExpression) expression, sel, values);
}
else
{
columnName = buildSimple((FieldExpression) expression, sel, values);
}
if (query.SortOrder != WorkflowExpressionQuery.SORT_NONE)
{
sel.Append(" ORDER BY ");
if (query.OrderBy != 0)
{
// Had the unexpected result of doing a "ORDER BY 1" w/o this in place
String fName = fieldName(query.OrderBy);
if (log.IsDebugEnabled)
{
log.Debug("Found fieldName as: " + fName);
}
sel.Append(fName);
// In MySQL and Informix, you have to select any field you order by -- others?
String current = sel.ToString();
// Remember that it will be surrounded by "DISTINCT (XXXX)"
// Should already be formatted as:
// SELECT DISTINCT(columnName) FROM table WHERE ......
// Want to be in the format:
// SELECT DISTINCT(columnName), fName FROM table WHERE .......
String entry = current.Substring(0, (current.IndexOf(columnName)) - (0)) + columnName + ") , " + fName + " ";
entry += current.Substring(current.IndexOf(columnName) + columnName.Length + 1);
sel = new StringBuilder(entry);
if (query.SortOrder == WorkflowExpressionQuery.SORT_ASC)
{
sel.Append(" ASC");
}
else
{
sel.Append(" DESC");
}
if (log.IsDebugEnabled)
{
log.Debug("Finalized query: " + sel.ToString());
}
}
else
{
// Order by is empty, so order by the columnName
sel.Append(columnName);
}
}
if (log.IsDebugEnabled)
{
log.Debug("Finished query is: " + sel.ToString());
}
IList results = doExpressionQuery(sel.ToString(), columnName, values);
return results;
}
public virtual IList Query(WorkflowQuery query)
{
IList results = new ArrayList();
// going to try to do all the comparisons in one query
String sel;
String table;
int qtype = query.Type;
if (qtype == 0)
{
// then not set, so look in sub queries
// todo: not sure if you would have a query that would look in both old and new, if so, i'll have to change this - TR
// but then again, why are there redundant tables in the first place? the data model should probably change
if (query.Left != null)
{
qtype = query.Left.Type;
}
}
if (qtype == WorkflowQuery.CURRENT)
{
table = currentTable;
}
else
{
table = historyTable;
}
sel = "SELECT DISTINCT(" + stepEntryId + ") FROM " + table + " WHERE ";
sel += queryWhere(query);
if (log.IsDebugEnabled)
{
log.Debug(sel);
}
IDbConnection conn = null;
IDbCommand stmt = null;
IDataReader rs = null;
try
{
conn = Connection;
stmt=createDbCommand(conn,sel);
rs = stmt.ExecuteReader();
while (rs.Read())
{
// get entryIds and add to results list
Int64 id = Convert.ToInt64(rs[(stepEntryId)]);
results.Add(id);
}
}
catch (Exception ex)
{
throw new StoreException("SQL Exception in query: " + ex.Message);
}
finally
{
cleanup(conn, stmt, rs);
}
return results;
}
protected internal virtual long getNextEntrySequence(IDbConnection c)
{
if (log.IsDebugEnabled)
{
log.Debug("Executing SQL statement: " + entrySequence);
}
IDbCommand stmt = null;
IDataReader rset = null;
try
{
stmt = createDbCommand(c, entrySequence);
rset = stmt.ExecuteReader();
rset.Read();
long id = rset.GetInt32(0);
return id;
}
finally
{
cleanup(null, stmt, rset);
}
}
protected internal virtual long getNextStepSequence(IDbConnection c)
{
if (log.IsDebugEnabled)
{
log.Debug("Executing SQL statement: " + stepSequence);
}
IDbCommand stmt = null;
IDataReader rset = null;
try
{
stmt = createDbCommand(c, stepSequence);
rset = stmt.ExecuteReader();
rset.Read();
long id = rset.GetInt32(0);
return id;
}
finally
{
cleanup(null, stmt, rset);
}
}
protected internal virtual void addPreviousSteps(IDbConnection conn, long id, long[] previousIds)
{
if ((previousIds != null) && (previousIds.Length > 0))
{
if (!((previousIds.Length == 1) && (previousIds[0] == 0)))
{
String sql = "INSERT INTO " + currentPrevTable + " (" + stepId + ", " + stepPreviousId + ") VALUES ("+
getParameterName("stepId")+","+
getParameterName("stepPreviousId")+")";
log.Debug("Executing SQL statement: " + sql);
IDbCommand stmt=createDbCommand(conn,sql);
for (int i = 0; i < previousIds.Length; i++)
{
long previousId = previousIds[i];
stmt.Parameters.Clear();
stmt.Parameters.Add(createDataParameter("stepId",id));
stmt.Parameters.Add(createDataParameter("stepPreviousId",previousId));
stmt.ExecuteNonQuery();
}
cleanup(null, stmt, null);
}
}
}
protected internal virtual void cleanup(IDbConnection connection, IDbCommand statement, IDataReader result)
{
if (result != null)
{
try
{
result.Close();
}
catch (Exception ex)
{
log.Error("Error closing resultset", ex);
}
}
if (statement != null)
{
try
{
statement.Dispose();
}
catch (Exception ex)
{
log.Error("Error closing statement", ex);
}
}
if ((connection != null) && closeConnWhenDone)
{
try
{
connection.Close();
}
catch (Exception ex)
{
log.Error("Error closing connection", ex);
}
}
}
protected internal virtual long createCurrentStep(IDbConnection conn, long entryId, int wfStepId, String owner, DateTime startDate, DateTime dueDate, String status)
{
String sql = "INSERT INTO " + currentTable + " (" + stepId + "," + stepEntryId + ", " +
stepStepId + ", " + stepActionId + ", " + stepOwner + ", " + stepStartDate + ", " + stepDueDate + ", " +
stepFinishDate + ", " + stepStatus + ", " + stepCaller + " ) VALUES (" +
getParameterName(stepId) + "," +
getParameterName(stepEntryId) + "," +
getParameterName(stepStepId) + "," +
getParameterName(stepActionId)+"," +
getParameterName(stepOwner) + "," +
getParameterName(stepStartDate) +","+
getParameterName(stepDueDate) +","+
getParameterName(stepFinishDate)+","+
getParameterName(stepStatus) +","+
"null)";
if (log.IsDebugEnabled)
{
log.Debug("Executing SQL statement: " + sql);
}
IDbCommand stmt = createDbCommand(conn, sql);
long id = getNextStepSequence(conn);
stmt.Parameters.Add(createDataParameter(stepId,id));
stmt.Parameters.Add(createDataParameter(stepEntryId, entryId));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -