2017-08-10 5 views
0

javaを使用してdocumentum内の特定のフォルダにファイルが存在するかどうかをチェックしたいと思います。 javaでdql検索クエリを実行するには?

は私のコード、

import com.documentum.com.DfClientX; 
import com.documentum.com.IDfClientX; 
import com.documentum.fc.client.DfQuery; 
import com.documentum.fc.client.IDfClient; 
import com.documentum.fc.client.IDfCollection; 
import com.documentum.fc.client.IDfFolder; 
import com.documentum.fc.client.IDfQuery; 
import com.documentum.fc.client.IDfSession; 
import com.documentum.fc.client.IDfSessionManager; 
import com.documentum.fc.common.DfException; 
import com.documentum.fc.common.DfId; 
import com.documentum.fc.common.IDfLoginInfo; 
import com.documentum.operations.IDfDeleteOperation; 

public class CountFiles { 

    // Documentum target repository where the files will be imported 
    private static final String REPO_NAME = "rep"; 



    public static void main(String[] args) throws Exception { 

     try { 
      String username = "user"; 
      String password = "pwd"; 

      System.out.println("Starting to connect ..."); 

      IDfSessionManager sessMgr = createSessionManager(); 
      addIdentity(sessMgr, username, password); 
      IDfSession sess = sessMgr.getSession(REPO_NAME); 
      System.out.println("Successfully connected to the server."); 
      queryDocumentum(sess); 


     } catch(Exception ex) { 
      System.out.println(ex); 
      ex.printStackTrace(); 
     } 
    } 


    private static void queryDocumentum(IDfSession sess) throws DfException { 
    IDfQuery query = new DfQuery(); 
String queryStr= "select count(*) from dm_document WHERE FOLDER ('/XXX/YYY',DESCEND) search document contains 'abc.pdf' "; 
    query.setDQL(queryStr); 
    IDfCollection coll = query.execute(sess,IDfQuery.DF_EXEC_QUERY); 
    while(coll.next()) 
    { 
     System.out.println("Result of method: " + coll.getValueAt(0)); 
    } 
    coll.close(); 
} 
/** 
    * Creates a new session manager instance. The session manager does not have 
    * any identities associated with it. 
    * 
    * @return a new session manager object. 
    * @throws DfException 
    */ 
    private static IDfSessionManager createSessionManager() 
      throws Exception { 
     IDfClientX clientX = new DfClientX(); 
     IDfClient localClient = clientX.getLocalClient(); 
     IDfSessionManager sessMgr = localClient.newSessionManager(); 

     System.out.println("Created session manager."); 

     return sessMgr; 
    } 

    /** 
    * Adds a new identity to the session manager. 
    * 
    */ 
    private static void addIdentity(final IDfSessionManager sm, 
      final String username, final String password) 
      throws Exception { 
     IDfClientX clientX = new DfClientX(); 

     IDfLoginInfo li = clientX.getLoginInfo(); 
     li.setUser(username); 
     li.setPassword(password); 

     // check if session manager already has an identity. 
     // if yes, remove it. 
     if(sm.hasIdentity(REPO_NAME)) { 
      sm.clearIdentity(REPO_NAME); 

      System.out.println("Cleared identity on :" + REPO_NAME); 
     } 

     sm.setIdentity(REPO_NAME, li); 

     System.out.println("Set up identity for the user."); 
    } 

} 

私は次の例外を取得していますです - [DM_QUERY_E_SYNTAX]エラー:dm_documentからSELECT COUNT(*) "パーサーエラー(構文エラー)の近くで発生しました" FOLDER( '/ XXX/YYY'、DESCEND)検索文書は、「 'abc.pdf' を含むWHEREクエリ/コード内の問題で何

答えて

0

まあ、明らかにあなたのDQLクエリが間違っている:。?

select count(*) from dm_document WHERE FOLDER ('/XXX/YYY',DESCEND) search document contains 'abc.pdf' 

if yoあなたは 'abc.pdf'という名前の文書がパス/ XXX/YYYとその下のすべてのフォルダ(キーワード 'descend')に存在するかどうかをチェックしたいだけですが、DQLはこれに近いはずです。フルテキスト検索機能は必要ありません

select count(*) from dm_document where folder('/XXX/YYY', DESCEND) and object_name = 'abc.pdf' 

あなたは、たとえば、 "LIKE" を使用することができ、正確なファイル名がわからない場合:そのため

select count(*) from dm_document where folder('/XXX/YYY', DESCEND) and object_name LIKE '%abc.pdf' 
+0

それは働きました。ありがとうKarolbe。 – Moizudddin

関連する問題