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

Appendix H Sample VB .NET Programs> H.3 Advanced Applications

H.3.1 Sample Applications Using Transactions and Shunsaku File

The following is a sample program using the VB .NET with the transaction function and Shunsaku File.

Usage examples are provided for VB .NET, using the university course registration example explained in Overview of Transactions in 5.1 Overview of Transactions.

mark1An Example of Using the APIs

The following is a sample program using the VB .NET.

Imports System
Imports Fujitsu.Shunsaku
Imports System.ComponentModel

Class SampleDelete

  Shared Public Function Main( ByVal args() As String ) As Integer
    Dim service As ShunService = Nothing

    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
      Dim courseReq As ShunSearchRequirement = new ShunSearchRequirement()
      courseReq.QueryExpression = "/course/name == 'Business negotiation'"
      courseReq.ReturnExpression = "/"

      '' Search the course information to be updated
      Dim courseRs As ShunResultSet = service.Search( courseReq )

      '' Obtain the record information from the search results
      Dim updateCourseRecord As ShunRecord = 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
      Dim studentReq As ShunSearchRequirement = new ShunSearchRequirement()
      studentReq.QueryExpression = "/student/e-mail == 'mary\.tompson@def\.com'"
      studentReq.ReturnExpression = "/"

      '' Search student information to be updated
      Dim studentRs As ShunResultSet = service.Search( studentReq )

      '' Obtain the record information from the search results
      Dim updateStudentRecord As ShunRecord = 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" )
        
        '' Turn off auto-commit mode
        service.Commit()

      Catch
        If service.State = ShunConnectionState.Open
          service.Rollback()
        End If
        Throw
      End Try
      

      '' Close the connection to Shunsaku
      service.Disconnect()
    
    Catch e As ShunContinuousException
      '' Processing to perform if ShunContinuousException occurs
      Try
        If Not service Is Nothing And service.State = ShunConnectionState.Open Then
          service.Disconnect()
        End If
      Catch ex As ShunException
        Console.WriteLine( "Error message : {0}", ex.Message )
      End Try
      Console.WriteLine( "Error message : {0}", e.Message )
    
    Catch e As ShunConnectionTerminatedException
      '' Processing to perform if ShunConnectionTerminatedException occurs
      Console.WriteLine( "Error message : {0}", e.Message )

    End Try
  End Function
End Class

mark1Execution Results

Finished updating course information
Finished updating student information

Contents Index PreviousNext

All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006