IBM FileNet P8, バージョン 5.2.1            

バッチの操作

バッチでの更新

オブジェクト・ストアに永続化されているオブジェクトをバッチ操作で更新できます。オブジェクトに対してアクション (チェックインや削除など) を実行した後で、そのオブジェクトを UpdatingBatch インスタンスに追加します。これは、オブジェクトを保存して保留中の更新をオブジェクトに対して実行する、オブジェクトに対する個別の (非バッチの) 操作とは対照的です。更新対象のすべてのオブジェクトを UpdatingBatch インスタンスに追加した後に、updateBatch メソッドをそのインスタンスに対して呼び出して保留中のバッチ更新を実行します。

この操作は、トランザクション操作です。バッチ内のすべての呼び出しは、全体が成功または失敗します。失敗した場合は、トランザクションがロールバックされ、例外がスローされます。

バッチ更新操作に関する一般的なシーケンスは次のとおりです。

Java™ の例

// UpdatingBatch クラスのインスタンスを取得
Domain myDomain = os.get_Domain();

// RefreshMode パラメーターが REFRESH に設定され、
// このインスタンスのプロパティー・キャッシュが更新済みデータでリフレッシュされる
UpdatingBatch ub = UpdatingBatch.createUpdatingBatchInstance(myDomain, RefreshMode.REFRESH);

// オブジェクトの更新をバッチに追加
// この場合、これらのドキュメントがチェックアウト済みであることを前提とする
// 使用されるプロパティー・フィルターはなし (フィルター・パラメーターは null)
Document doc1 = Factory.Document.fetchInstance(os, new Id("{F905DBD6-5A69-4252-9985-2D3DD28D7FBA}"), null);
Document doc2 = Factory.Document.fetchInstance(os, new Id("{35026B90-B443-40CA-B5C3-66BEAD13E2B7}"), null);

// バッチに組み込まれる第 1 更新
doc1 = (Document) doc1.get_Reservation();
doc1.checkin(null, CheckinType.MAJOR_VERSION);

// バッチに組み込まれる第 2 更新
doc2 = (Document) doc2.get_Reservation();
doc2.checkin(null, CheckinType.MAJOR_VERSION); 

// Third update to be included in batch. Sets the document title and assigns the 
// specified property values (Properties.putValue) to the retrieved properties for the 
// doc (the inherited EngineObject.getProperties). 
doc1.getProperties().putValue("DocumentTitle", "doc1"); 

// バッチに組み込まれる第 4 更新
doc2.getProperties().putValue("DocumentTitle", "doc2"); 

// Adds all four updates (to the two Document objects) to the UpdatingBatch instance. 
ub.add(doc1, null);  
ub.add(doc2, null);  

// バッチの更新処理を実行
ub.updateBatch();
 

C# の例

// UpdatingBatch クラスのインスタンスを取得
IDomain myDomain = os.Domain;

// RefreshMode パラメーターが REFRESH に設定され、
// このインスタンスのプロパティー・キャッシュが更新済みデータでリフレッシュされる
UpdatingBatch ub = UpdatingBatch.CreateUpdatingBatchInstance(myDomain, FileNet.Api.Constants.RefreshMode.REFRESH);

// オブジェクトの更新をバッチに追加
// この場合、これらのドキュメントがチェックアウト済みであることを前提とする
// 使用されるプロパティー・フィルターはなし (フィルター・パラメーターは null)
IDocument doc1 = Factory.Document.FetchInstance(os, new Id("{CF0BE923-DCFD-4832-8CE0-001E4A111E25}"), null);
IDocument doc2 = Factory.Document.FetchInstance(os, new Id("{A25A8FB0-D4EF-4690-83BB-41F7EB98D631}"), null);

// バッチに組み込まれる第 1 更新
doc1 = (IDocument) doc1.Reservation;
doc1.Checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);

// バッチに組み込まれる第 2 更新
doc2 = (IDocument) doc2.Reservation;
doc2.Checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);

// Third update to be included in batch. Sets the document title and assigns the 
// specified property values (Properties.putValue) to the retrieved properties for the 
// doc (the inherited EngineObject.getProperties).     
doc1.Properties.GetProperty("DocumentTitle").SetObjectValue("doc1");

// バッチに組み込まれる第 4 更新
doc2.Properties.GetProperty("DocumentTitle").SetObjectValue("doc2");

// Adds all four updates (to the two Document objects) to the UpdatingBatch instance. 
ub.Add(doc1, null);
ub.Add(doc2, null);

// バッチの更新処理を実行
ub.UpdateBatch();
 

例: オブジェクトを削除するバッチ更新

オブジェクトを削除するバッチ更新操作を、次の例に示します。

Java の例

public static void updatePendingDeletion(Domain myDomain) throws Exception
{
    PropertyFilter myOSFilter = null;
    String myOS = "LaurelTree";
    ObjectStore os = Factory.ObjectStore.fetchInstance(myDomain, myOS, myOSFilter);
    
    // RefreshMode パラメーターは、このインスタンスのプロパティー・キャッシュが
    // 更新済みデータでリフレッシュされることを示す
    UpdatingBatch ub = UpdatingBatch.createUpdatingBatchInstance(myDomain, RefreshMode.NO_REFRESH);
    
    // Get the documents. 下記の documents.Calls findDocs ルーチンを取得し、最大 3 つのドキュメントを
    // DocumentTitle が "Batch Deleting Example" の指定したオブジェクト・ストアから取得// これらのドキュメントが現在チェックアウト済みかどうかは問わない
    Document[] docArr = findDocs(os, "Batch Deleting Example", false, 3);
    Document doc1 = docArr[0];
    Document doc2 = docArr[1];
    Document doc3 = docArr[2];
                        
    // 更新シーケンス番号のチェックを上書き
    doc1.setUpdateSequenceNumber(null);
    doc2.setUpdateSequenceNumber(null);
    doc3.setUpdateSequenceNumber(null);
    
    // 継承された IndependentlyPersistedObject.delete メソッドがこの保留中のアクションを追加
    doc1.delete(); 
    doc2.delete(); 
    doc3.delete(); 
    
    // 削除が保留中の Document オブジェクトを UpdatingBatch インスタンスに追加
    ub.add(doc1, null);  
    ub.add(doc2, null);  
    ub.add(doc3, null);  
    ub.updateBatch();
        
}
        
// SearchSQL と SearchScope を使用して、指定したタイトルのドキュメントを検索し、これらの Document オブジェクトをフェッチ
// onlyReservation パラメーターは、現在チェックアウト済みのドキュメントのみを
// 必要とするかどうかを示す
static Document[] findDocs(
    ObjectStore os, 
    String docTitle, 
    boolean onlyReservation, 
    int findCount) throws Exception
{
    // Declare document array.
    Document[] docArr = new Document[findCount];
        
    // Build the SQL statement.
    String sql = "select d.this from Document d " + 
        "where DocumentTitle = '" + docTitle + "'";
    SearchSQL searchSQL = new SearchSQL();
    searchSQL.setQueryString(sql);
        
    SearchScope searchScope = new SearchScope(os);
    IndependentObjectSet objectSet = searchScope.fetchObjects(searchSQL, null, null, null);
        
    int count = 0;
    Iterator iter = objectSet.iterator();
    while (iter.hasNext() == true && count < findCount)
    {
        Document doc = (Document) iter.next();
        doc.refresh();
        boolean statusReservation = false;
        if (doc.get_VersionStatus() == VersionStatus.RESERVATION)
        {
            statusReservation = true;
        }
            
        if (onlyReservation == false || statusReservation == true)
        {
            System.out.println("Document: " + doc.get_Id().toString());
            docArr[count] = doc;
            count++;                           
        }
    }
        
    // ドキュメントを検出できない場合は例外をスロー
    if (count < findCount)
    {
        String message = "Unable to find " + findCount + " ";
        if (onlyReservation == true)
        {
            message = message + "reserved ";
        }
        message = message + " documents with title '" + docTitle + "'"; 
        throw new Exception(message);
    }
        
    // Return document array.
    return docArr;
}
 

C# の例

public static void UpdatePendingDeletion(IDomain myDomain)
{
    PropertyFilter myOSFilter = null;
    string myOS = "LaurelTree";
    IObjectStore os = Factory.ObjectStore.FetchInstance(myDomain, myOS, myOSFilter);

    UpdatingBatch ub = UpdatingBatch.CreateUpdatingBatchInstance(myDomain, RefreshMode.NO_REFRESH);
            
    IDocument[] docArr = findDocs(os, "Batch Deleting Example", false, 3);
    IDocument doc1 = docArr[0];
    IDocument doc2 = docArr[1];
    IDocument doc3 = docArr[2];

    doc1.SetUpdateSequenceNumber(null);
    doc2.SetUpdateSequenceNumber(null);
    doc3.SetUpdateSequenceNumber(null);

    doc1.Delete();
    doc2.Delete();
    doc3.Delete();

    ub.Add(doc1, null);
    ub.Add(doc2, null);
    ub.Add(doc3, null);

    ub.UpdateBatch();
}

static IDocument[] findDocs(IObjectStore os, string docTitle, bool onlyReservation, int findCount)
{
    IDocument[] docArr = new IDocument[findCount];
    string sql = "select d.this from Document d " +
                        "where DocumentTitle = '" + docTitle + "'";
    SearchSQL searchSQL = new SearchSQL();
    searchSQL.SetQueryString(sql);
    SearchScope searchScope = new SearchScope(os);
    IIndependentObjectSet objectSet = searchScope.FetchObjects(searchSQL, null, null, null);

    int count = 0;
    foreach (IDocument doc in objectSet)
    {
        if (count < findCount)
        {
            doc.Refresh();
            bool statusReservation = false;
            if (doc.VersionStatus == VersionStatus.RESERVATION)
            {
                statusReservation = true;
            }
            if (onlyReservation == false || statusReservation == true)
            {
                System.Console.WriteLine("Document: " + doc.Id.ToString());
                docArr[count] = doc;
                count++;
            }
        }
    }

    if (count < findCount)
    {
        string message = "Unable to find " + findCount + " ";
        if (onlyReservation == true)
        {
            message = message + "reserved ";
        }
        message = message + " documents with title '" + docTitle + "'";
        throw new System.Exception(message);
    }
    return docArr;
}
 

保留中のバッチ更新

UpdatingBatch.hasPendingExecute メソッドを呼び出すことにより、バッチ操作が実行済みかどうか (updateBatch メソッドが呼び出されたかどうか) を調べることができます。

バッチでの取得

バッチ取得操作を使用して、IndependentObject オブジェクトからサブクラス化される、Content Engine の任意のオブジェクトを取得できます。バッチでの更新とは異なり、この操作はトランザクション操作ではありません。それぞれのオブジェクトの取得は、個別に成功または失敗します。

取得したオブジェクトに対するバッチ内での以降の変更は、その場で実行されます (バッチ内のオブジェクトへの参照のみが取得されます)。

バッチ取得操作の一般的なシーケンスは次のとおりです。

Java の例

// RetrievingBatch クラスのインスタンスを取得
Domain myDomain = os.get_Domain();
RetrievingBatch rb = RetrievingBatch.createRetrievingBatchInstance(myDomain);

// オブジェクトをバッチに追加 (この目的のため、新しいオブジェクトを使用)
Document doc1 = Factory.Document.createInstance(os, null);
doc1.checkin(null, null);
doc1.save(RefreshMode.NO_REFRESH);

Document doc2 = Factory.Document.createInstance(os, null);
doc2.checkin(null, null);
doc2.save(RefreshMode.NO_REFRESH);

// 使用されるフィルタリングはなし
rb.add(doc1, null);  
rb.add(doc2, null);  

// バッチの取得処理を実行
rb.RetrieveBatch();

C# の例

// RetrievingBatch クラスのインスタンスを取得
IDomain myDomain= os.Domain;
RetrievingBatch rb = RetrievingBatch.CreateRetrievingBatchInstance(myDomain);

// オブジェクトをバッチに追加 (この目的のため、新しいオブジェクトを使用)
IDocument doc1 = Factory.Document.CreateInstance(os, null);
doc1.Checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
doc1.Save(RefreshMode.NO_REFRESH);

IDocument doc2 = Factory.Document.CreateInstance(os, null);
doc2.Checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
doc2.Save(RefreshMode.NO_REFRESH);

// 使用されるフィルタリングはなし
rb.Add(doc1, null);
rb.Add(doc2, null);

rb.RetrieveBatch();

取得での例外の確認

バッチでの取得操作の実行後に、hasExceptions メソッドを呼び出してブール値を返すことにより、オブジェクト取得によって例外が発生したかどうかを調べることができます。しかし、特定のオブジェクト取得で例外がスローされたかどうかに基づいて何らかの処理を行えるようにする場合は、BatchItemHandle インスタンスのコレクションを取得し、これを反復処理して、例外がスローされたオブジェクト取得を調べる必要があります。 次に例を示します。

Java の例

Iterator iterator1 = rb.getBatchItemHandles(null).iterator();
while (iterator1.hasNext()) {
    BatchItemHandle obj = (BatchItemHandle) iterator1.next();
    if (obj.hasException()) 
    {
        // ここでは簡潔にするため、例外を表示
        EngineRuntimeException thrown = obj.getException();
        System.out.println("Exception: " + thrown.getMessage());
    }
}                       

C# の例

foreach (IBatchItemHandle obj in rb.GetBatchItemHandles(null))
{
    if (obj.HasException())
    {
        FileNet.Api.Exception.EngineRuntimeException thrown = obj.GetException();
        System.Console.WriteLine("Exception: " + thrown.Message);
    }
}


最終更新日: 2015 年 10 月
batch_procedures.htm

© Copyright IBM Corp. 2015.