windchill 中根据持久化对象获取相关联的流程_不包含子流程版
程序员文章站
2022-03-31 21:45:43
...
public static WfProcess getRelatedProcess(Persistable obj)
throws RemoteException, InvocationTargetException, WTException {
if (!RemoteMethodServer.ServerFlag) {
String method = "getRelatedProcess";
Class[] types = { Persistable.class };
Object[] vals = { obj };
return (WfProcess) RemoteMethodServer.getDefault().invoke(method, CLASSNAME, null, types, vals);
}
WfProcess process = null;
QueryResult qrProcs = null;
qrProcs = WfEngineHelper.service.getAssociatedProcesses(obj, null, null);
// 按时间排序,取最新一个流程实例
CollationKeyFactory timeKeyFact = new CollationKeyFactory() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
public String getCollationString(Object o) {
if (!(o instanceof Persistable) || !PersistenceHelper.isPersistent(o))
return "";
return sdf.format(PersistenceHelper.getModifyStamp((Persistable) o));
}
};
Enumeration enProcs = new SortedEnumeration(qrProcs, timeKeyFact, SortedEnumeration.DESCENDING);
while (enProcs.hasMoreElements()) {
process = (WfProcess) enProcs.nextElement();
// 最新的非子进程(子进程的名称带有$符号
if (process.getName().indexOf("$") == -1) {
logger.debug(" getRelatedProcess process=" + process.getName() + " oid=" + process);
break;
}
}
return process;
}
//这里顺便提一下QueryResult
//推荐用法:
QueryResult qr = PersistenceHelper.manager.find((StatementSpec) qs);
//过时API:
QueryResult qr = PersistenceHelper.manager.find(qs);
//区别:自行研究,哈哈