查询
在OSWorkflow 2.6中,引入了新的ExpressionQuery API。
注意:不是所有的workflow 的存储都支持查询。目前,Hibernate,JDBC和内存存储都支持查询。然而,hibernate存储不支持混合类型的查询(例如:一个历史和当前 步骤的查询信息的查询)。要执行查询,就要建立一个WorkflowExpressionQuery对象,然后在 WorkflowExpressionQuery对象中调用查询方法。
下面是一个查询的例子:
//Get all workflow entry ID's for which the owner is 'testuser'
new WorkflowExpressionQuery(
new FieldExpression(FieldExpression.OWNER, //Check the OWNER field
FieldExpression.CURRENT_STEPS, //Look in the current steps context
FieldExpression.EQUALS, //check equality
"testuser")); //the equality value is 'testuser'
//Get all workflow entry ID's that have the name 'myworkflow'
new WorkflowExpressionQuery(
new FieldExpression(FieldExpression.NAME, //Check the NAME field
FieldExpression.ENTRY, //Look in the entries context
FieldExpression.EQUALS, //Check equality
'myworkflow')) //equality value is 'myworkflow'
下面是一个嵌套查询的例子:
// Get all finished workflow entries where the current owner is 'testuser'
Expression queryLeft = new FieldExpression( FieldExpression.OWNER, FieldExpression.CURRENT_STEPS, FieldExpression.EQUALS, 'testuser');
Expression queryRight = new FieldExpression(FieldExpression.STATUS, FieldExpression.CURRENT_STEPS, FieldExpression.EQUALS, "Finished", true);
WorkflowExpressionQuery query = new WorkflowExpressionQuery( new NestedExpression(new Expression[] {queryLeft, queryRight},NestedExpression.AND));
Finally, here is an example of a mixed-context query. Note that this query is not supported by the Hibernate workflow store.
//Get all workflow entries that were finished in the past
//or are currently marked finished
Expression queryLeft = new FieldExpression(FieldExpression.FINISH_DATE, FieldExpression.HISTORY_STEPS, FieldExpression.LT, new Date());
Expression queryRight = new FieldExpression( FieldExpression.STATUS, FieldExpression.CURRENT_STEPS, FieldExpression.EQUALS, "Finished");
WorkflowExpressionQuery query = new WorkflowExpressionQuery(new NestedExpression(new Expression[] {queryLeft, queryRight},NestedExpression.OR));