how to use shark library!
来源:互联网 发布:mac磁盘工具怎么用 编辑:程序博客网 时间:2024/04/27 18:39
在shark的安装路径doc/HowTo/how_to.html 下面文档
Client interface
How to use Shark library
Example 8. Using external transactions
Each method of Shark API invocation presents separate transaction: engine internally creates, uses, optionally commits, and eventually releases transaction. This means that even quite simple code utilizing Shark may unknowingly use many transactions.
Sometimes, it is required to do things a differently, therefore SharkTransaction is introduced. An application('s developer) may choose to use external transactions for number of reasons including usage of the same database to store application (non work-flow related) data, to avoid constantly creating/discarding transactions, ...
Of course, this approach comes with a price: you must obey the rules of usage. Transactions are created calling Shark.getInstance().createTransaction();, just before you release one, your application must call Shark.getInstance().unlockProcesses(st); notifying Shark to do it's internal bookkeeping. If anything goes awry, you must catch a Throwable and call Shark.getInstance().emptyCaches(st);. Yes, you've read it right even Error's must be caught, otherwise you'll leave the engine in undefined state.
Here is the variable setting example modified to use a single transaction.
/**//*
SharkConnection sConn;
String activityId;
String vName;
String vValue;
*/
SharkTransaction st = Shark.getInstance().createTransaction();
try ...{
WfAssignment a = null;
WfAssignment[] ar = sConn.getResourceObject(st)
.get_sequence_work_item(st, 0);
for (int i = 0; i < ar.length; ++i) ...{
if (activityId.equals(ar[i].activity(st).key(st))) ...{
a = ar[i];
break;
}
}
if (null == a) throw new BaseException("Activity:"
+ activityId
+ " not found in "
+ sConn.getResourceObject(st)
.resource_key(st)
+ "'s worklist");
if (!a.get_accepted_status(st)) throw new BaseException("I don't own activity "
+ activityId);
Map _m = new HashMap();
WfActivity activity = a.activity(st);
Object c = activity.process_context(st).get(vName);
if (c instanceof Long) ...{
c = new Long(vValue);
} else ...{
c = vValue;
}
_m.put(vName, c);
activity.set_result(st, _m);
activity.complete(st);
st.commit();
} catch (Throwable t) ...{
Shark.getInstance().emptyCaches(st);
st.rollback();
if (t instanceof RootException)
throw (RootException) t;
else
throw new RootException(t);
} finally ...{
try ...{
Shark.getInstance().unlockProcesses(st);
} catch (Exception _) ...{}
st.release();
}
SharkConnection sConn;
String activityId;
String vName;
String vValue;
*/
SharkTransaction st = Shark.getInstance().createTransaction();
try ...{
WfAssignment a = null;
WfAssignment[] ar = sConn.getResourceObject(st)
.get_sequence_work_item(st, 0);
for (int i = 0; i < ar.length; ++i) ...{
if (activityId.equals(ar[i].activity(st).key(st))) ...{
a = ar[i];
break;
}
}
if (null == a) throw new BaseException("Activity:"
+ activityId
+ " not found in "
+ sConn.getResourceObject(st)
.resource_key(st)
+ "'s worklist");
if (!a.get_accepted_status(st)) throw new BaseException("I don't own activity "
+ activityId);
Map _m = new HashMap();
WfActivity activity = a.activity(st);
Object c = activity.process_context(st).get(vName);
if (c instanceof Long) ...{
c = new Long(vValue);
} else ...{
c = vValue;
}
_m.put(vName, c);
activity.set_result(st, _m);
activity.complete(st);
st.commit();
} catch (Throwable t) ...{
Shark.getInstance().emptyCaches(st);
st.rollback();
if (t instanceof RootException)
throw (RootException) t;
else
throw new RootException(t);
} finally ...{
try ...{
Shark.getInstance().unlockProcesses(st);
} catch (Exception _) ...{}
st.release();
}
每个Shark的API的方法都会应用单独的transcation:引擎内部生成,使用,随意commit ,最终releases transcation。这意味着及时简单地使用shark代码也无意识地使用了transcation。
有时,明确地要求transcation来完成一个任务,因此引进SharkTransaction。一个应用可能因下列原因选用外部transcation:使用相同地数据库来存储应用数据(非工作流相关的),这样可以避免重复的creating/discarding transactions!
当然,这种方法也带来了一些代价:你必需遵循使用规则。通过调用Shark.getInstance().createTransaction()生成Transactions;在release transactions之前,你必须调用Shark.getInstance().unlockProcesses(st),通知Shark 完成内部的薄记(do it's internal bookkeeping)!如果出错,必须在接受一个Throwable,并调用Shark.getInstance().emptyCaches(st);当然即使接住错误,你也要正确的读出Throwable。否则引擎就处于无定义的状态!
下面就是一个采用单个transaction 来设置一个变量设定的例子!
(2) 分析如何使用transaction,以及transaction起到了何作用?
Shark.createTransaction();返回生成了一个SharkDODSTransaction
具体还没有弄明白???
(3)把任务和角色重新建立连接!
WfAssignment. set_assignee(WfResource new_value)方法的作用,
A WfAssignment is associated with one WfResource. The association is established when the assignment is created as part of the resource selection process for the activity; the assignment can be reassigned to another resource at a later point in time. The following operation support changing the assignee relationship. An InvalidResource exception is raised by an attempt to assign an invalid resource to the assignment.
以上是此方法的注释!
org.enhydra.shark.swingclient.workflowadmin.worklist 包中Reassignment类有具体如何出来重新分配WfResource
- how to use shark library!
- how to use the boost library
- How To Use Google Logging Library (glog)
- How To Use Google Logging Library (glog)
- How To Use Google Logging Library (glog)
- How to: Create and Use a Data Connection Library
- How to use document library in Sharepoint 2010
- How to register and use the native Kentico jQuery library
- How to use Chrome/Chromium “base” library in private products ?
- How-to use a shared library in native-activity
- How to use gcov to get code coverage from static library in iphone?
- How to use libusb1.0 library to develop the application on Mac OS X
- How To Use DataGird
- how to use typedef
- how to use gz
- How to use chkconfig
- How to use ,,,,
- how to use dialog
- 一位IT老工程师的忠告
- 一次编辑 GridView 的所有行
- null
- 想念的天空
- blog的访问恢复正常
- how to use shark library!
- .NET三层经典架构PetShop3.0分析之数据访问层
- C++.net常见问题之二(字符串)
- 如何使用Bochs,一个x86硬件平台模拟器
- 墨子红包
- 因为一些原因,决定搬到这里.
- JSP学习经验总结(转)
- .NET三层经典架构PetShop3.0分析之表现层
- delphi下应用GIF动画的一些测试