#using <mscorlib.dll>
#using <system.dll>
#using <Fujitsu.Shunsaku.dll>
using namespace System;
using namespace Fujitsu::Shunsaku;
class SampleUpdate {
public:
static void Main( String *args __gc[] ) {
ShunService *service = 0;
try {
// ShunService の作成
service = new ShunService();
// ホスト名 ポート番号を指定して Shunsaku に接続
service->Host = "DirSvr1";
service->Port = 33101;
service->Connect();
// ShunSearchRequirement の作成
ShunSearchRequirement *req = new ShunSearchRequirement();
// 各種検索条件の設定
req->QueryExpression = "/document/base/name == 'ホテル1'";
req->ReturnExpression = "/document/base/name/text()";
req->ReplyNumber = 1;
req->RequestCount = 30;
// 検索条件を指定して検索を実行
ShunResultSet *rs = service->Search( req );
// 更新用 ShunRecordCollection を作成
ShunRecordCollection *updateRecords = new ShunRecordCollection();
// 検索条件に該当するレコードを取得
ShunRecordEnumerator *enumerator = rs->Records->GetEnumerator();
while ( enumerator->MoveNext() ) {
ShunRecord *record = enumerator->Current;
if ( record->Data->Equals( "ホテル1" ) ) {
// ホテル1の情報について、レコードID、更新データを設定
record->Data = String::Concat(
S"<document>",
S" <base>",
S" <name>ホテル1</name>",
S" <prefecture>大阪</prefecture>",
S" <address>大阪府大阪市中央区</address>",
S" <detail>http://xxxxx.co.jp</detail>",
S" <price>8000</price>",
S" </base>",
S" <information>",
S" <date>2006年07月18日</date>",
S" </information>",
S" <note>バス付 トイレ付 地下鉄 **駅徒歩02分</note>",
S"</document>" );
updateRecords->Add( record );
}
}
// データ設定に成功している場合、データを更新
if ( updateRecords->Count > 0 ) {
service->Update( updateRecords );
Console::WriteLine( "更新終了" );
}
// Shunsaku から切断
service->Disconnect();
}
catch ( ShunContinuousException *e ) {
// ShunContinuousExceptionが発生した場合の処理を記述
try {
if( service != 0 && service->State == ShunConnectionState::Open ) {
service->Disconnect();
}
}
catch ( ShunException *ex ) {
Console::WriteLine( "エラーメッセージ : {0}", ex->Message );
}
Console::WriteLine( "エラーメッセージ : {0}", e->Message );
}
catch ( ShunConnectionTerminatedException *e ) {
// ShunConnectionTerminatedExceptionが発生した場合の処理を記述
Console::WriteLine( "エラーメッセージ : {0}", e->Message );
}
}
};
int main() {
return SampleUpdate::Main( Environment::GetCommandLineArgs() );
} |