Commit 524c07dd authored by shyWang's avatar shyWang

PDM前端改造

添加删除对象公共方法
parent 780369c0
......@@ -34,6 +34,7 @@ import wt.org.WTUser;
import wt.part.WTPart;
import wt.part.WTPartMaster;
import wt.part.WTPartMasterIdentity;
import wt.pom.Transaction;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.query.WhereExpression;
......@@ -46,10 +47,10 @@ import wt.util.WTContext;
import wt.util.WTException;
import wt.util.WTProperties;
import wt.util.WTRuntimeException;
import wt.vc.Iterated;
import wt.vc.OneOffVersioned;
import wt.vc.VersionControlHelper;
import wt.vc.Versioned;
import wt.vc.*;
import wt.vc.struct.IteratedDescribeLink;
import wt.vc.struct.IteratedReferenceLink;
import wt.vc.struct.IteratedUsageLink;
import wt.vc.wip.CheckoutLink;
import wt.vc.wip.WorkInProgressException;
import wt.vc.wip.WorkInProgressHelper;
......@@ -61,9 +62,7 @@ import java.lang.reflect.Method;
import java.rmi.RemoteException;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.TimeZone;
import java.util.*;
public class CommonUtil implements RemoteAccess {
private static final Logger log = LogR.getLogger(CommonUtil.class.getName());
......@@ -629,6 +628,64 @@ public class CommonUtil implements RemoteAccess {
return result;
}
private static void deleteBizObj(RevisionControlled obj, boolean deleteAllVersion) throws Exception
{
Transaction tx = new Transaction();
tx.start();
try
{
// 先删除与指定对象每个Iteration的关联关系: IteratedDescribeLink
List<Persistable> objList = new ArrayList<Persistable>();
Set linkSet = new HashSet();
QueryResult qrIter;
if (deleteAllVersion)
qrIter = VersionControlHelper.service.allIterationsOf(obj.getMaster());
else
qrIter = VersionControlHelper.service.iterationsOf(obj);
while (qrIter.hasMoreElements())
{
Iterated iterated = (Iterated) qrIter.nextElement();
objList.add(iterated);
linkSet.addAll((PersistenceServerHelper.manager.expand(iterated, IteratedDescribeLink.DESCRIBES_ROLE, IteratedDescribeLink.class, false)).getObjectVectorIfc().getVector());
}
// 如果只有一个版本,则Master也将被自动删除,需要准备将Master的关联删除
// IteratedUsageLink, IteratedReferenceLink
if (deleteAllVersion || VersionControlHelper.service.allVersionsOf(obj).size() == 1)
{
linkSet.addAll((PersistenceServerHelper.manager.expand(obj.getMaster(), IteratedUsageLink.USED_BY_ROLE, IteratedUsageLink.class, false)).getObjectVectorIfc().getVector());
linkSet.addAll((PersistenceServerHelper.manager.expand(obj.getMaster(), IteratedReferenceLink.REFERENCED_BY_ROLE, IteratedReferenceLink.class, false)).getObjectVectorIfc().getVector());
}
// 删除关联Link
for (Iterator it = linkSet.iterator(); it.hasNext();)
{
BinaryLink link = (BinaryLink) it.next();
PersistenceServerHelper.manager.remove(link);
}
// 删除对象本身
for (Iterator it = objList.iterator(); it.hasNext();)
{
Iterated iterated = (Iterated) it.next();
// 如果一个版本有多个小版本的话,需要将状态设置为非控制状态,才可删除
iterated.getIterationInfo().setState(IterationState.toIterationState("unctrld"));
PersistenceHelper.manager.delete(iterated);
}
tx.commit();
tx = null;
// 删除对象本身
// removeObjectsBackground(objSet);
} catch (Exception e)
{
if (tx != null)
tx.rollback();
throw e;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment