Source

osworkflow / docs / 1.4 Persistence Options.html

Full commit
<html>
    <head>
        <title>1.4 Persistence Options</title>
	    <link rel="stylesheet" href="styles/site.css" type="text/css" />
    </head>

    <body>
	    <table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff">
		    <tr>
			    <td valign="top" class="pagebody">

				    <ul class="star">
<li> Back to <a href="1.3 Running the Example App.html">1.3 Running the Example App</a></li>
<li> Forward to <a href="1.5 Loading Workflow Definitions.html">1.5 Loading Workflow Definitions</a></li>
</ul><br/>
OSWorkflow provides a pluggable persistence mechanism that can be used to allow for many choices of ways for workflow content to be stored. Included with OSWorkflow are the following WorkflowStore implementations: <b class="strong">MemoryStore (default), SerializableStore, JDBCStore, OfbizStore, and EJBStore</b>. If one of these does not fit your requirements, you can implement your own workflow store by implementing the interface <span class="nobr"><a href="http://www.opensymphony.com/osworkflow/api/com/opensymphony/workflow/spi/WorkflowStore.html">com.opensymphony.workflow.spi.WorkflowStore<sup><img src="./icons/linkext7.gif" height="7" width="7" align="absmiddle" alt="&gt;&gt;" border="0"/></sup></a></span>. See the javadocs for more information. <p class="paragraph">Also, please note that each workflow store implementation may have required or optional properties that must or can be set. It is recommend that you read the javadocs for the workflow store that you plan to use so that you can configure it correctly. A sample JDBC configuration for the JDBCStore is given below:</p>(from osworkflow.xml)
<div class="code"><pre>&lt;persistence class=&quot;com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore&quot;&gt;&#10;	&lt;&#33;&#45;&#45; For jdbc persistence, all are required. &#45;&#45;&gt;&#10;	&lt;property key=&quot;datasource&quot; value=&quot;jdbc/DefaultDS&quot;/&gt;&#10;	&lt;property key=&quot;entry.sequence&quot; &#10;                      value=&quot;SELECT nextVal(&#039;seq&#95;os&#95;wfentry&#039;)&quot;/&gt;&#10;	&lt;property key=&quot;entry.table&quot; value=&quot;OS&#95;WFENTRY&quot;/&gt;&#10;	&lt;property key=&quot;entry.id&quot; value=&quot;ID&quot;/&gt;&#10;	&lt;property key=&quot;entry.name&quot; value=&quot;NAME&quot;/&gt;&#10;	&lt;property key=&quot;entry.state&quot; value=&quot;STATE&quot;/&gt;&#10;	&lt;property key=&quot;step.sequence&quot; &#10;                       value=&quot;SELECT nextVal(&#039;seq&#95;os&#95;currentsteps&#039;)&quot;/&gt;&#10;	&lt;property key=&quot;history.table&quot; value=&quot;OS&#95;HISTORYSTEP&quot;/&gt;&#10;	&lt;property key=&quot;current.table&quot; value=&quot;OS&#95;CURRENTSTEP&quot;/&gt;&#10;	&lt;property key=&quot;historyPrev.table&quot; value=&quot;OS&#95;HISTORYSTEP&#95;PREV&quot;/&gt;&#10;	&lt;property key=&quot;currentPrev.table&quot; value=&quot;OS&#95;CURRENTSTEP&#95;PREV&quot;/&gt;&#10;	&lt;property key=&quot;step.id&quot; value=&quot;ID&quot;/&gt;&#10;	&lt;property key=&quot;step.entryId&quot; value=&quot;ENTRY&#95;ID&quot;/&gt;&#10;	&lt;property key=&quot;step.stepId&quot; value=&quot;STEP&#95;ID&quot;/&gt;&#10;	&lt;property key=&quot;step.actionId&quot; value=&quot;ACTION&#95;ID&quot;/&gt;&#10;	&lt;property key=&quot;step.owner&quot; value=&quot;OWNER&quot;/&gt;&#10;	&lt;property key=&quot;step.caller&quot; value=&quot;CALLER&quot;/&gt;&#10;	&lt;property key=&quot;step.startDate&quot; value=&quot;START&#95;DATE&quot;/&gt;&#10;	&lt;property key=&quot;step.finishDate&quot; value=&quot;FINISH&#95;DATE&quot;/&gt;&#10;	&lt;property key=&quot;step.dueDate&quot; value=&quot;DUE&#95;DATE&quot;/&gt;&#10;	&lt;property key=&quot;step.status&quot; value=&quot;STATUS&quot;/&gt;&#10;	&lt;property key=&quot;step.previousId&quot; value=&quot;PREVIOUS&#95;ID&quot;/&gt;&#10;&lt;/persistence&gt;</pre></div><p class="paragraph">If you are using tomcat as the servlet container, you should config <b class="strong">$TOMCAT_HOME/conf/server.xml</b> for data source, by default, the data source name is <b class="strong">jdbc/DefaultDS</b>.</p>You should also config the propertyset to use jdbc by adding  <em class="emphasis">WEB-INF/classes/propertyset.xml</em>, please note that the datasource setting should match the name defined in tomcat.
<div class="code"><pre>&lt;propertysets&gt;&#10;    &lt;propertyset name=&quot;jdbc&quot; &#10;      class=&quot;com.opensymphony.module.propertyset.database.JDBCPropertySet&quot;&gt;&#10;        &lt;arg name=&quot;datasource&quot; value=&quot;jdbc/DefaultDS&quot;/&gt;&#10;        &lt;arg name=&quot;table.name&quot; value=&quot;OS&#95;PROPERTYENTRY&quot;/&gt;&#10;        &lt;arg name=&quot;col.globalKey&quot; value=&quot;GLOBAL&#95;KEY&quot;/&gt;&#10;        &lt;arg name=&quot;col.itemKey&quot; value=&quot;ITEM&#95;KEY&quot;/&gt;&#10;        &lt;arg name=&quot;col.itemType&quot; value=&quot;ITEM&#95;TYPE&quot;/&gt;&#10;        &lt;arg name=&quot;col.string&quot; value=&quot;STRING&#95;VALUE&quot;/&gt;&#10;        &lt;arg name=&quot;col.date&quot; value=&quot;DATE&#95;VALUE&quot;/&gt;&#10;        &lt;arg name=&quot;col.data&quot; value=&quot;DATA&#95;VALUE&quot;/&gt;&#10;        &lt;arg name=&quot;col.<span class="java&#45;object">float</span>&quot; value=&quot;FLOAT&#95;VALUE&quot;/&gt;&#10;        &lt;arg name=&quot;col.number&quot; value=&quot;NUMBER&#95;VALUE&quot;/&gt;&#10;    &lt;/propertyset&gt;&#10;&lt;/propertysets&gt;</pre></div><p class="paragraph">A number of sample sql scripts to create the required tables are included in the OSWorkflow distribution in in the src/etc/deployment/jdbc directory.</p>If HypersonicSQL is used as the datasource, you can follow these steps:
<ol>
<li> Assume your hsql db is named <b class="strong">oswf</b> and created in directory <b class="strong">/db</b></li>
<li> Use the hsql.sql script to create the tables, you can use <b class="strong">java -cp hsqldb.jar org.hsqldb.util.DatabaseManager</b> to startup the tool to execute the sript.</li>
<li> Add the context config to <b class="strong">$TOMCAT_HOME/conf/server.xml</b></li>
</ol>
<div class="code"><pre>&lt;Context path=&quot;/osworkflow&quot; &#10;         docBase=&quot;/jakarta&#45;tomcat&#45;4.1.27/webapps/osworkflow&#45;2.7.0&#45;example&quot;&gt;&#10;          &lt;Resource name=&quot;jdbc/oswf&quot; type=&quot;javax.sql.DataSource&quot;/&gt;&#10;          &lt;ResourceParams name=&quot;jdbc/DefaultDS&quot;&gt;&#10;            &lt;parameter&gt;&lt;name&gt;username&lt;/name&gt;&lt;value&gt;sa&lt;/value&gt;&lt;/parameter&gt;&#10;            &lt;parameter&gt;&lt;name&gt;password&lt;/name&gt;&lt;value&gt;&lt;/value&gt;&lt;/parameter&gt;&#10;            &lt;parameter&gt;&lt;name&gt;driverClassName&lt;/name&gt;&#10;              &lt;value&gt;org.hsqldb.jdbcDriver&lt;/value&gt;&lt;/parameter&gt;&#10;            &lt;parameter&gt;&lt;name&gt;url&lt;/name&gt;&#10;              &lt;value&gt;jdbc&#58;hsqldb&#58;/db/oswf&lt;/value&gt;&lt;/parameter&gt;&#10;          &lt;/ResourceParams&gt;&#10;&lt;/Context&gt;</pre></div><p class="paragraph">4. Add <b class="strong">WEB-INF/classes/propertyset.xml</b> as described above</p>5. Change the persistent setting of <em class="emphasis">WEB-INF/classes/osworkflow.xml</em>. This example below should be used for any database that does not support sequences (eg, HSQL)

<div class="code"><pre>&lt;persistence class=&quot;com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore&quot;&gt;&#10;	&lt;&#33;&#45; For jdbc persistence, all are required. &#45;&#45;&gt;&#10;	&lt;property key=&quot;datasource&quot; value=&quot;jdbc/DefaultDS&quot;/&gt;&#10;	&lt;property key=&quot;entry.sequence&quot; &#10;                       value=&quot;select count(&#42;) &#43; 1 from os&#95;wfentry&quot;/&gt;&#10;	&lt;property key=&quot;entry.table&quot; value=&quot;OS&#95;WFENTRY&quot;/&gt;&#10;	&lt;property key=&quot;entry.id&quot; value=&quot;ID&quot;/&gt;&#10;	&lt;property key=&quot;entry.name&quot; value=&quot;NAME&quot;/&gt;&#10;	&lt;property key=&quot;entry.state&quot; value=&quot;STATE&quot;/&gt;&#10;	&lt;property key=&quot;step.sequence&quot; value=&quot;select sum(c1) from &#10;(select 1 tb, count(&#42;) c1 from os&#95;currentstep &#10;union select 2 tb, count(&#42;) c1 from os&#95;historystep)&quot;/&gt;&#10;	&lt;property key=&quot;history.table&quot; value=&quot;OS&#95;HISTORYSTEP&quot;/&gt;&#10;	&lt;property key=&quot;current.table&quot; value=&quot;OS&#95;CURRENTSTEP&quot;/&gt;&#10;	&lt;property key=&quot;historyPrev.table&quot; value=&quot;OS&#95;HISTORYSTEP&#95;PREV&quot;/&gt;&#10;	&lt;property key=&quot;currentPrev.table&quot; value=&quot;OS&#95;CURRENTSTEP&#95;PREV&quot;/&gt;&#10;	&lt;property key=&quot;step.id&quot; value=&quot;ID&quot;/&gt;&#10;	&lt;property key=&quot;step.entryId&quot; value=&quot;ENTRY&#95;ID&quot;/&gt;&#10;	&lt;property key=&quot;step.stepId&quot; value=&quot;STEP&#95;ID&quot;/&gt;&#10;	&lt;property key=&quot;step.actionId&quot; value=&quot;ACTION&#95;ID&quot;/&gt;&#10;	&lt;property key=&quot;step.owner&quot; value=&quot;OWNER&quot;/&gt;&#10;	&lt;property key=&quot;step.caller&quot; value=&quot;CALLER&quot;/&gt;&#10;	&lt;property key=&quot;step.startDate&quot; value=&quot;START&#95;DATE&quot;/&gt;&#10;	&lt;property key=&quot;step.finishDate&quot; value=&quot;FINISH&#95;DATE&quot;/&gt;&#10;	&lt;property key=&quot;step.dueDate&quot; value=&quot;DUE&#95;DATE&quot;/&gt;&#10;	&lt;property key=&quot;step.status&quot; value=&quot;STATUS&quot;/&gt;&#10;	&lt;property key=&quot;step.previousId&quot; value=&quot;PREVIOUS&#95;ID&quot;/&gt;&#10;&lt;/persistence&gt;</pre></div><p class="paragraph">Note that the exact query for step.sequence and entry.sequence might vary in order to use an appropriate sequencing native DB mechanism.</p>For example, in MSSQL the correct step.sequence value would be (assuming you&#039;re not using a database sequence):

<div class="code"><pre>&lt;property key=&quot;step.sequence&quot; value=&quot;select sum(c1) &#43; 1 from (select 1 as&#10;tb, count(&#42;) as c1 from os&#95;currentstep union select 2 as tb, count(&#42;) as c1&#10;from os&#95;historystep) as TabelaFinal&quot; /&gt;</pre></div><p class="paragraph">For MYSQL, OSWorkflow provides a custom store that can be used. This schema uses a separate table to store ID values (the schema is listed in the mysql.sql file).</p>In addition to this, two other changes from a standard deployment must be specified. The first are the calls to access the ID sequences. There are specified in the store properties in osworkflow.xml. The elements to be added are:
<div class="code"><pre>&lt;property key=&quot;step.sequence.increment&quot; &#10;    value=&quot;INSERT INTO OS&#95;STEPIDS (ID) values (null)&quot;/&gt;&#10;  &lt;property key=&quot;step.sequence.retrieve&quot; &#10;    value=&quot;SELECT max(ID) FROM OS&#95;STEPIDS&quot;/&gt;</pre></div><p class="paragraph">In the same file, the store factory specified should be <b class="strong">com.opensymphony.workflow.spi.jdbc.MySQLWorkflowStore</b>
<ul class="star">
<li> Back to <a href="1.3 Running the Example App.html">1.3 Running the Example App</a></li>
<li> Forward to <a href="1.5 Loading Workflow Definitions.html">1.5 Loading Workflow Definitions</a></li>
</ul></p>

				    
			    </td>
		    </tr>
	    </table>
    </body>
</html>