Interstage Shunsaku Data Manager Application Development Guide - Microsoft(R) Windows(R) 2000/ Microsoft(R) Windows Server(TM) 2003 - - UNIX -
Contents Index PreviousNext

Appendix I Sample C++ .NET Programs> I.3 Advanced Applications

I.3.4 Update Data Using Direct Access Key

The following is a sample program to update data with the direct access key using the C++ .NET.

mark1Data to be Updated

<course>
  <id>0001</id>
  <name>Business negotiation</name>
  <instructor>
    <first-name>Max</first-name>
    <last-name>cameron</last-name>
  </instructor>
  <capacity>40</capacity>
  <current-auditors>30</current-auditors>
</course>

mark1Defined Direct Access Key

key /course/id/text()

mark1An Example of Using the APIs

The following is a sample program using the C++ .NET.

#using <mscorlib.dll>
#using <system.dll>
#using <Fujitsu.Shunsaku.dll>

using namespace System;
using namespace Fujitsu::Shunsaku;

class SampleDirectAccessUpdate {
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();

      // Create ShunKeyRequirement object for updating data
      ShunKeyRequirement *keyReq = new ShunKeyRequirement();
      keyReq->KeyName = "key";

      // Add the key to be updated
      keyReq->Records->Add( new ShunRecord() );
      keyReq->Records->get_Item( 0 )->Key = "0001";

      // Set update data
      keyReq->Records->get_Item( 0 )->Data = String::Concat(
        S"<course>",
        S"  <id>0001</id>",
        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>" );

      //Update course information
      service->UpdateByKey( keyReq );
      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 
SampleDirectAccessUpdate::Main( Environment::GetCommandLineArgs() );
}

mark1Execution Results

Update complete

Contents Index PreviousNext

All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006