Source

osworkflow / docs / Queries.html

Full commit
<html><head><title>OSWorkflow Queries</title></head><body>
<ul class="star">
<li>Up to <a href="Documentation.html">Documentation</a></li>
<li>Back to <a href="Executing_actions.html">Executing actions</a></li>
</ul><p class="paragraph"></p>OSWorkflow 2.6 introduces a new <span class="nobr"></img><a href="http://www.opensymphony.com/osworkflow/api/com/opensymphony/workflow/query/WorkflowExpressionQuery.html">ExpressionQuery</a></span> API.<p class="paragraph"></p>Note that not all workflow stores support queries. Currently the Hibernate, JDBC, and Memory workflow stores do support queries. The hibernate store however does not support mixed-type queries (for example, a query that uses both the history and current step contexts). To execute a query, a WorkflowExpressionQuery object is constructed, and the <span class="nobr"></img><a href="http://www.opensymphony.com/osworkflow/api/com/opensymphony/workflow/Workflow.html#query(com.opensymphony.workflow.query.WorkflowExpressionQuery)">query</a></span> method is invoked on the Workflow object.<p class="paragraph"></p>Below are some query example:<p class="paragraph"></p><div class="wikicode"><pre>//Get all workflow etnry ID's <span class="java&#45;keyword">for</span> which the owner is 'testuser'
<span class="java&#45;keyword">new</span> WorkflowExpressionQuery(
  <span class="java&#45;keyword">new</span> FieldExpression(FieldExpression.OWNER, //Check the OWNER field
  FieldExpression.CURRENT_STEPS,  //Look in the current steps context
  FieldExpression.EQUALS, //check equality
  <span class="java&#45;quote">"testuser"</span>)); //the equality value is 'testuser'</pre></div><p class="paragraph"></p><div class="wikicode"><pre>//Get all workflow entry ID's that have the name 'myworkflow'
<span class="java&#45;keyword">new</span> WorkflowExpressionQuery(
  <span class="java&#45;keyword">new</span> FieldExpression(FieldExpression.NAME, //Check the NAME field
  FieldExpression.ENTRY,  //Look in the entries context
  FieldExpression.EQUALS,  //Check equality
  'myworkflow')) //equality value is 'myworkflow'</pre></div><p class="paragraph"></p>Below is an example of a nested query:<p class="paragraph"></p><div class="wikicode"><pre>// Get all finished workflow entries where the current owner is 'testuser'
Expression queryLeft = <span class="java&#45;keyword">new</span> FieldExpression(
  FieldExpression.OWNER, 
  FieldExpression.CURRENT_STEPS, 
  FieldExpression.EQUALS, 'testuser');
Expression queryRight = <span class="java&#45;keyword">new</span> FieldExpression(
  FieldExpression.STATUS, 
  FieldExpression.CURRENT_STEPS, 
  FieldExpression.EQUALS, 
  <span class="java&#45;quote">"Finished"</span>, 
  <span class="java&#45;keyword">true</span>);
WorkflowExpressionQuery query = <span class="java&#45;keyword">new</span> WorkflowExpressionQuery(
  <span class="java&#45;keyword">new</span> NestedExpression(<span class="java&#45;keyword">new</span> Expression&#91;&#93; &#123;queryLeft, queryRight&#125;,
  NestedExpression.AND));</pre></div><p class="paragraph"></p>Finally, here is an example of a mixed-context query. Note that this query is not supported by the Hibernate workflow store.<p class="paragraph"></p><div class="wikicode"><pre>//Get all workflow entries that were finished in the past
//or are currently marked finished
Expression queryLeft = <span class="java&#45;keyword">new</span> FieldExpression(
  FieldExpression.FINISH_DATE, 
  FieldExpression.HISTORY_STEPS, 
  FieldExpression.LT, <span class="java&#45;keyword">new</span> Date());
Expression queryRight = <span class="java&#45;keyword">new</span> FieldExpression(
  FieldExpression.STATUS, 
  FieldExpression.CURRENT_STEPS, 
  FieldExpression.EQUALS, <span class="java&#45;quote">"Finished"</span>);
WorkflowExpressionQuery query = <span class="java&#45;keyword">new</span> WorkflowExpressionQuery(
  <span class="java&#45;keyword">new</span> NestedExpression(<span class="java&#45;keyword">new</span> Expression&#91;&#93; &#123;queryLeft, queryRight&#125;,
  NestedExpression.OR));</pre></div></body></html>