using System;
using Fujitsu.Shunsaku;
class SampleTransaction {
static public void Main( string[] args ) {
ShunService service = null;
try {
// Create ShunService
service = new ShunService();
// Connect Shunsaku by specifying the host name and port number
service.Host = "DirSrv1";
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[0];
// The data of course information to be updated
updateCourseRecord.Data = String.Concat(
"<course>",
" <name>Business negotiation</name>",
" <instructor>",
" <first-name>Max</first-name>",
" <last-name>cameron</last-name>",
" </instructor>",
" <capacity>40</capacity>",
" <current-auditors>31</current-auditors>",
"</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[0];
// The data of students information to be updated
updateStudentRecord.Data = String.Concat(
"<student>",
" <first-name>Mary</first-name>",
" <last-name>Tompson</last-name>",
" <e-mail>mary.tompson@def.com</e-mail>",
" <course>Chinese language</course>",
" <course>Business negotiation</course>",
"</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 {
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 != null && 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 );
}
}
} |