#using <mscorlib.dll>
#using <system.dll>
#using <Fujitsu.Shunsaku.dll>
using namespace System;
using namespace Fujitsu::Shunsaku;
class SampleTransaction {
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->ShunsakuFile = "shunsakuFile1";
service->Connect();
// Set up a search condition for searching for the course where the number of participants is to be increased
ShunSearchRequirement *courseReq = new ShunSearchRequirement();
courseReq->QueryExpression = "/course/name == 'Business negotiation'";
courseReq->ReturnExpression = "/";
// Search the course information to be updated
ShunResultSet *courseRs = service->Search( courseReq );
// Obtain the record information from the search results
ShunRecord *updateCourseRecord = courseRs->Records->Item[0];
// The data of course information to be updated
updateCourseRecord->Data = String::Concat(
S"<course>",
S" <name>Business negotiation</name>",
S" <instructor>",
S" <first-name>Max</first-name>",
S" <last-name>cameron</last-name>",
S" </instructor>",
S" <capacity>40</capacity>",
S" <current-auditors>31</current-auditors>",
S"</course>" );
// Set up a search expression and a return expression for searching the students to be added to the attendance information
ShunSearchRequirement *studentReq = new ShunSearchRequirement();
studentReq->QueryExpression = "/student/e-mail == 'mary\\.tompson@def\\.com'";
studentReq->ReturnExpression = "/";
// Search student information to be updated
ShunResultSet *studentRs = service->Search( studentReq );
// Obtain the record information from the search results
ShunRecord *updateStudentRecord = studentRs->Records->Item[0];
// The data of students information to be updated
updateStudentRecord->Data = String::Concat(
S"<student>",
S" <first-name>Mary</first-name>",
S" <last-name>Tompson</last-name>",
S" <e-mail>mary.tompson@def.com</e-mail>",
S" <course>Chinese language</course>",
S" <course>Business negotiation</course>",
S"</student>" );
// Turn off auto-commit mode
service->AutoCommit = false;
try {
// Update course information
service->Update( updateCourseRecord );
Console::WriteLine( "Finished updating course information" );
// Update student information
service->Update( updateStudentRecord );
Console::WriteLine( "Finished updating student information" );
// Commit the updates made so far
service->Commit();
}
catch ( Exception *e ) {
if ( service->State == ShunConnectionState::Open ) {
service->Rollback();
}
throw;
}
// 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 SampleTransaction::Main( Environment::GetCommandLineArgs() );
} |