1第5章OracleWorkflowforJava5.2创建Oracle工作流的定义和组件5.2.4创建、修改和删除Oracle工作流的组件在修改API之前,编写并执行一个自定义的升级脚本,来为任何引用API的激活的工作项创建和移植新项属性。下面实例显示一种结构化一个升级脚本的方法。foreachactiveworkitembeginwf_engine.AddItemAttr(itemtype,itemkey,’new_attribute_name’);wf_engine.SetItemAttrText(itemtype,itemkey,’new_attribute_name’,’Newattributevalue’);end;endloop;下面的实例显示一种结构化如下的一个意外处理器的方法。procedureprocedure_name(itemtypeinvarchar2,itemkeyinvarchar2,actidinnumber,funcmodeinvarchar2,resultinoutvarchar2)isbegin––––RUNmode–normalprocessexecution––if(funcmode=’RUN’)then––yourruncodegoesherenull;wf_engine.SetItemAttrText(itemtype,itemkey,’existing_attribute_name’,2’Existingattributevalue’);beginwf_engine.SetItemAttrText(itemtype,itemkey,’new_attribute_name’,’Newattributevalue’);exceptionwhenothersthenif(wf_core.error_name=’WFENG_ITEM_ATTR’)thenwf_engine.AddItemAttr(itemtype,itemkey,’new_attribute_name’);wf_engine.setitemattrtext(itemtype,itemkey,’new_attribute_name’,’Newattributevalue’);elseraise;endif;end;––examplecompletionresult:=’COMPLETE:’;return;endif;––––CANCELmode–activity’compensation’––––Thisisintheeventthattheactivitymustbeundone,––forexamplewhenaprocessisresettoanearlierpoint––duetoaloopback.––if(funcmode=’CANCEL’)then––yourcancelcodegoesherenull;––noresultneededresult:=’COMPLETE’;return;endif;––––Otherexecutionmodesmaybecreatedinthefuture.Your––activitywillindicatethatitdoesnotimplementamode––byreturningnull––result:=’’;3return;exceptionwhenothersthen––Thelinebelowrecordsthisfunctioncallintheerror––systeminthecaseofanexception.wf_core.context(’package_name’,’procedure_name’,itemtype,itemkey,to_char(actid),funcmode);raise;endprocedure_name;5.3创建Oracle工作流的图形化表示5.3.3Oracle工作流的角色与编码3.Oracle工作流的编码(8)循环结构下面给出API代码实例,解决如何应付各种可能的节点。If(funcmode=‘CANCEL’)then…docancelmodeprocessing…elseif(funcmode=‘RUN’)then…doregularruntimeprocessing…elseif(funcmode=‘TIMEOUT’)then…onlyvalidforvotefunctions…else--thereshouldn’tbeanyothermodesnull;endif;(10)雇主/零售商流下面给出独立创建和启动每个零售商行的实例。--setupandstarttheparentflowWF_ENGINE.CreateProcess(order_header,header_id,process_name);WF_ENGINE.StartProcess(order_header,header_id);--setupchildflowsForeachdetail_lineloopWF_ENGINE.CreateProcess(order_lines,detail_line.line_id);4WF_ITEM.SetItemParent(order_lines,detail_line.line_id,order_header,header_id);WF_ENGINE.StartProcess(order_lines,detail_line.line_id));Endloop下面再给出首先创建所有的零售商行,然后启动孩子的实例。--setupandstarttheparentflowWF_ENGINE.CreateProcess(order_header,header_id,process_name);WF_ENGINE.StartProcess(order_header,header_id);--setupchildflowsForeachdetail_lineloopWF_ENGINE.CreateProcess(order_lines,detail_line.line_id);WF_ITEM.SetItemParent(order_lines,detail_line.line_id,order_header,header_id);Endloop--nowtherelationshipisestablished,startthechildrenForeachdetail_lineloopWF_ENGINE.StartProcess(order_lines,detail_line.line_id));Endloop(12)通知下面给出区分FYI通知的实例代码的选段。selectnotification_id,message_name,message_typefromwf_notificationsnwherenotexists(select‘respondattributesexist’fromwf_message_attributeswheremessage_name=n.message_nameandmessage_type=n.message_typeandsubtype='RESPOND')下面再给出实例代码,显示如何写PL/SQLCLOB文档。procedureExample_package(document_idinvarchar2,display_typeinvarchar2,documentinoutclob,document_typeinoutvarchar2)isbuild_stringvarchar2(4000);open_tdvarchar2(5):=’TD’;close_tdvarchar2(5):=’/TD’;open_rwvarchar2(5):=’TR’;close_rwvarchar2(5):=’/TR’;cursordata_stream(ordernumbernumber)is5selectc.catalog_number,c.catalog_descriptionfromparts_catalogc,customer_order_linecowhereco.catalog_number=c.catalog_numberandco.order_number=ordernumber;beginbuild_string:=’PTABLE’;fordata_rec(to_number(document_id))indata_streamloopbuild_string:=build_string||open_tr||open_td||to_char(data_rec.catalog_number)||close_td||open_td||data_rec.catalog_description||close_td||close_tr;WF_NOTIFICATIONS.WriteToClob(document,build_string);build_string:=null;endloop;--ifstringisnull,thenitmusthavebeenwrittento--document,sowemustaddtheclosetabletag.ifbuild_stringisnullthenWF_NOTIFICATIONS.WriteToClob(document,’/TABLE’);endif;end;(14)查找下面给出查找的实例代码。--Getattributenamestoredinactivityattribute--withinternalname‘ATTR’aname:=wf_engine.GetActivityAttrText(itemtype,itemkey,actid,'ATTR');wf_engine.GetItemAttrInfo(itemtype,aname,atype,asubtype,aformat);--NUMBERvalueif(atype='NUMBER')thenwf_engine.SetItemAttrNumber(itemtype,itemkey,aname,wf_engine.GetActivityAttrNumber(itemtype,itemkey,actid,'NUMBER_VALUE'));--DATEvalueelsif(atype='DATE')thenwf_engine.SetItemAttrDate(itemtype,itemkey,aname,wf_engine.GetActivityAttrDate(itemtype,itemkey,actid,'DATE_VALUE'));--TEXTvalue(VARCHAR2,LOOKUP,FORM,URL,DOCUMENT,etc.)elsewf_engine.SetItemAttrText(itemtype,itemkey,aname,6wf_engine.GetActivityAttrText(itemtype,itemkey,actid,'TEXT_VALUE'));endif;(15)背景引擎下面给出背景引擎的实例代码。procedureBackground(itemtypeinvarchar2default’’,minthresholdinnumberdefaultnull,maxthresholdinnumberdefaultnull,process_deferredinbooleandefaultTRUE,process_timeoutinbooleandefaultTRUE)process_stuckinbooleandefaultFALSE);(16)提