首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用DFC删除documentum应用程序中的文档

无法使用DFC删除documentum应用程序中的文档
EN

Stack Overflow用户
提问于 2019-03-13 21:50:54
回答 3查看 1.3K关注 0票数 1

我按照《EMC DFC 7.2开发指南》中给出的方法编写了以下代码。使用这段代码,即使有更多的记录,我也只能删除50个文档。在删除之前,我将获取对象id的转储。我不确定IDfDeleteOperation是否有任何限制。因为这只删除了50个文档,所以我尝试使用DQL delete命令,即使在那里它也被限制为50个文档。我尝试使用文档中的destory()和destroyAllVersions()方法,即使这样对我也不起作用。我已经在main方法中编写了所有内容。

代码语言:javascript
复制
import com.documentum.com.DfClientX;
import com.documentum.com.IDfClientX;
import com.documentum.fc.client.*;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.DfId;
import com.documentum.fc.common.IDfLoginInfo;
import com.documentum.operations.IDfCancelCheckoutNode;
import com.documentum.operations.IDfCancelCheckoutOperation;
import com.documentum.operations.IDfDeleteNode;
import com.documentum.operations.IDfDeleteOperation;

import java.io.BufferedWriter;
import java.io.FileWriter;

public class DeleteDoCAll {

    public static void main(String[] args) throws DfException {
       System.out.println("Started...");

        IDfClientX clientX  = new DfClientX();
        IDfClient dfClient = clientX.getLocalClient();
        IDfSessionManager sessionManager = dfClient.newSessionManager();
        IDfLoginInfo loginInfo = clientX.getLoginInfo();
        loginInfo.setUser("username");
        loginInfo.setPassword("password");
        sessionManager.setIdentity("repo", loginInfo);

        IDfSession dfSession = sessionManager.getSession("repo");
        System.out.println(dfSession);

        IDfDeleteOperation delo = clientX.getDeleteOperation();
        IDfCancelCheckoutOperation cco = clientX.getCancelCheckoutOperation();

       try {
           String dql = "select r_object_id from my_report where folder('/Home', descend);
           IDfQuery idfquery = new DfQuery();
           IDfCollection collection1 = null;

           try {
               idfquery.setDQL(dql);
               collection1 = idfquery.execute(dfSession, IDfQuery.DF_READ_QUERY);
               int i = 1;
               while(collection1 != null && collection1.next()) {
                   String r_object_id = collection1.getString("r_object_id");

                   StringBuilder attributes = new StringBuilder();

                   IDfDocument iDfDocument = (IDfDocument)dfSession.getObject(new DfId(r_object_id));
                   attributes.append(iDfDocument.dump());

                   BufferedWriter writer = new BufferedWriter(new FileWriter("path to file", true));
                   writer.write(attributes.toString());
                   writer.close();

                   cco.setKeepLocalFile(true);
                   IDfCancelCheckoutNode cnode;


                   if(iDfDocument.isCheckedOut()) {
                       if(iDfDocument.isVirtualDocument()) {
                           IDfVirtualDocument vdoc = iDfDocument.asVirtualDocument("CURRENT", false);
                           cnode = (IDfCancelCheckoutNode)cco.add(iDfDocument);
                       } else {
                           cnode = (IDfCancelCheckoutNode)cco.add(iDfDocument);
                       }

                       if(cnode == null) {
                           System.out.println("Node is null");
                       }
                       if(!cco.execute()) {
                           System.out.println("Cancel check out operation failed");
                       } else {
                           System.out.println("Cancelled check out for " + r_object_id);
                       }
                   }

                   delo.setVersionDeletionPolicy(IDfDeleteOperation.ALL_VERSIONS);
                   IDfDeleteNode node = (IDfDeleteNode)delo.add(iDfDocument);
                   if(node == null) {
                       System.out.println("Node is null");
                       System.out.println(i);
                       i += 1;
                   }
                   if(delo.execute()) {
                       System.out.println("Delete operation done");
                       System.out.println(i);
                       i += 1;
                   } else {
                       System.out.println("Delete operation failed");
                       System.out.println(i);
                       i += 1;
                   }
               }
           } finally {
               if(collection1 != null) {
                   collection1.close();
               }
           }

       } catch(Exception e) {
           e.printStackTrace();
       } finally {
           sessionManager.release(dfSession);
       }
   }
}

我不知道我在哪里犯了错,每次我尝试的时候,程序都会在50次迭代时停止。你能帮我删除所有的文件吗?非常感谢!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-03-13 23:41:14

例如,首先将所有文档ID选择到List<IDfId>中,然后关闭集合。不要在打开的集合中执行另一个昂贵的操作,因为这样会不必要地阻塞它。

这就是为什么它只做了50个文档的原因。因为您有一个打开的主集合,而每次执行delete操作都会打开另一个集合,它可能会达到一定的限制。因此,正如我所说的,最好先使用集合,然后再进一步处理这些数据:

代码语言:javascript
复制
    List<IDfId> ids = new ArrayList<>();
    try {
        query.setDQL("SELECT r_object_id FROM my_report WHERE FOLDER('/Home', DESCEND)");
        collection = query.execute(session, IDfQuery.DF_READ_QUERY);
        while (collection.next()) {
            ids.add(collection.getId("r_object_id"));
        }
    } finally {
        if (collection != null) {
            collection.close();
        }
    }

之后,您可以遍历列表并对所需的文档执行所有操作。但是不要在每次迭代中执行删除操作-这是无效的。而不是将所有文档添加到一个操作中,并在最后执行一次。

代码语言:javascript
复制
    IDfDeleteOperation deleteOperation = clientX.getDeleteOperation();
    deleteOperation.setVersionDeletionPolicy(IDfDeleteOperation.ALL_VERSIONS);
    for (IDfId id : ids) {
        IDfDocument document = (IDfDocument) session.getObject(id);
        ...
        deleteOperation.add(document);
    }
    deleteOperation.execute();

IDfCancelCheckoutOperation也是如此。

还有一件事--当你使用FileWriter时,在finally块中使用close(),或者像这样使用try-with-resources:

代码语言:javascript
复制
    try (BufferedWriter writer = new BufferedWriter(new FileWriter("file.path", true))) {
        writer.write(document.dump());
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }

使用StringBuilder是个好主意,但只在开始时创建一次,在每次迭代中附加所有属性,然后在结束时而不是每次迭代期间将StringBuilder的内容写入文件-这很慢。

票数 1
EN

Stack Overflow用户

发布于 2019-03-13 22:57:08

你可以直接从你的代码内部来做:

删除文件夹所在的主目录对象(‘/ my_report’,descend)

无需再次获取您要丢弃的信息;-)

票数 0
EN

Stack Overflow用户

发布于 2019-03-13 23:43:26

您可能面临DFC客户端的结果集限制。尝试添加到dfc.properties这些行,并重新运行您的代码,看看是否可以删除超过50行,然后根据您的需要进行调整。

代码语言:javascript
复制
dfc.search.max_results = 100
dfc.search.max_results_per_source = 100
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55143517

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档