#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 {
// Create ShunService
service = new ShunService();
// Connect Shunsaku by specifying the host name and port number
service->Host = "DirSvr1";
service->Port = 33101;
service->Connect();
// Create ShunSearchRequirement
ShunSearchRequirement *req = new ShunSearchRequirement();
// Set each type of search conditions
req->QueryExpression = "/document/base/name == 'Hotel 1'";
req->ReturnExpression = "/document/base/name/text()";
req->ReplyNumber = 1;
req->RequestCount = 30;
// Specify the search condition and execute the search
ShunResultSet *rs = service->Search( req );
// Create ShunRecordCollection for updating data
ShunRecordCollection *updateRecords = new ShunRecordCollection();
// Obtain the records that correspond to the search conditions
ShunRecordEnumerator *enumerator = rs->Records->GetEnumerator();
while ( enumerator->MoveNext() ) {
ShunRecord *record = enumerator->Current;
if ( record->Data->Equals( "Hotel 1" ) ) {
// Set the record ID and data to update for Hotel 1 information
record->Data = String::Concat(
S"<document>",
S" <base>",
S" <name>Hotel 1</name>",
S" <city>Sydney</city>",
S" <address>Bondi Beach</address>",
S" <detail>http://xxxxx.com.au</detail>",
S" <price>300</price>",
S" </base>",
S" <information>",
S" <date>2006/07/18</date>",
S" </information>",
S" <note>En-suite bathroom and toilet, two minutes' walk to train station XX</note>",
S"</document>" );
updateRecords->Add( record );
}
}
// Update the data if the data was set successfully
if ( updateRecords->Count > 0 ) {
service->Update( updateRecords );
Console::WriteLine( "Update complete" );
}
// Close the connection to Shunsaku
service->Disconnect();
}
catch ( ShunContinuousException *e ) {
// Processing to perform if ShunContinuousException occurs
try {
if( service != 0 && service->State == ShunConnectionState::Open ) {
service->Disconnect();
}
}
catch ( ShunException *ex ) {
Console::WriteLine( "Error message : {0}", ex->Message );
}
Console::WriteLine( "Error message : {0}", e->Message );
}
catch ( ShunConnectionTerminatedException *e ) {
// Processing to perform if ShunConnectionTerminatedException occurs
Console::WriteLine( "Error message : {0}", e->Message );
}
}
};
int main() {
return SampleUpdate::Main( Environment::GetCommandLineArgs() );
} |