Interstage Shunsaku Data Manager アプリケーション開発ガイド - Microsoft(R) Windows(R) 2000/ Microsoft(R) Windows Server(TM) 2003 - - UNIX共通 -
目次 索引 前ページ次ページ

第1部 アプリケーション開発の基本> 第7章 Shunsaku File> 7.4 複数のShunsaku Fileを1つのトランザクションで扱う方法

7.4.2 .NET APIの記述例

1つのトランザクションを扱う.NET APIの場合の記述例について、以下に示します。

/*
 * 以下のように用意されていることを仮定しています。
 *  sPerson :追加したい従業員の情報
 *  sQuery :検索式を格納した文字列
 *  sReturn :リターン式を格納した文字列
 *  updateData :更新データを格納した文字列
 */
// ShunServiceオブジェクトを作成
// 接続先のホスト名:DirSvr1
// ポート番号:33101
// Shunsaku File名: fileA

ShunService service = new ShunService();
service.Host = "DirSvr1";
service.Port = 33101;
service.ShunsakuFile = "fileA";
service.Connect();

// 自動コミットを無効に設定
service.AutoCommit = false;

ShunRecordCollection insertRecords = new ShunRecordCollection();
ShunRecord personRecord = new ShunRecord( sPerson );
insertRecords.Add( personRecord );

// データ追加
service.Insert( insertRecords );

//接続先のShunsaku FileをfileDに切替え
service.ChangeShunsakuFile("fileD");

ShunSearchRequirement req = new ShunSearchRequirement();
req.QueryExpression = sQuery;
req.ReturnExpression = sReturn;
// 更新用のデータを検索
ShunResultSet rs = service.Search( req );
ShunRecord updateRecord = null;
foreach ( ShunRecord record in rs.Records ) {
  updateRecord = record;
}
updateRecord.Data = updateData;

ShunRecordCollection updateRecords = new ShunRecordCollection();
updateRecords.Add( updateRecord );

//データ更新
service.Update( updateRecords );

// ここまでの更新をコミット
service.Commit();

service.Disconnect();

目次 索引 前ページ次ページ

All Rights Reserved, Copyright(C) 富士通株式会社 2006