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

Part 1 The Basic for Developing Application> Chapter 6 Direct Access Function> 6.7 Developing Application Using Direct Access Function

6.7.1 Using Direct Search to Delete or Update Data

This section explains the data deletion or update process by record ID using direct search.

First, issue the direct search API. Obtain the record ID of the data being deleted or updated and all the data.

Then, use the record ID information obtained from above to execute the deletion or the update.

mark1Process Flow

The following figure shows the flow of the direct search and the deletion or update of the record ID.

[Figure 6-16 The flow of the data deletion or data update using direct search]

mark1An Effect of the Data Manipulation

The following figure shows an effect of the data manipulation using direct search when comparing with the data manipulation by record ID.

[Figure 6-17 An effect of the data manipulation using direct search]

The access to the searchers is not necessary because the direct search is used instead of the search process, which is for obtaining record ID. Therefore, the process can be done faster.

The following sample codes shows the sample codes using Java API, .NET API and C API.

mark1For Java API

The sample code for deleting data using direct search

ShunConnection con = new ShunConnection();

ShunPreparedKey preSkey = con.prepareSearchKey("key1", "/");
preSkey.add("20061101,00000001");
ShunResultSet rs = preSkey.searchByKey();
ShunPreparedRecordID prid = con.prepareDeleteRecordID();
while (rs.next()) {
  prid.add(rs.getRecordID());
}
prid.deleteByRecordID();
prid.close();
rs.close();
preSkey.close();

con.close();

The sample code for updating data using direct search

ShunConnection con = new ShunConnection();
ShunPreparedKey preSkey = con.prepareSearchKey("key1", "/");
preSkey.add("20061101,00000001");
ShunResultSet rs = preSkey.searchByKey();
ShunPreparedRecordID prid = con.prepareUpdateRecordID();
while (rs.next()) {
  prid.add(rs.getRecordID(), updateData);
}
prid.updateByRecordID();
prid.close();
rs.close();
preSkey.close();

con.close();

mark1For .NET API

The sample code for deleting data using direct search

ShunService service = new ShunService();
service.Connect();

ShunRecord searchRecord = new ShunRecord();
searchRecord.Key = "20061101,00000001";

ShunKeyRequirement keyReq = new ShunKeyRequirement();
keyReq.KeyName = "key1";
keyReq.SearchType = ShunKeySearchType.CompleteMatch;
keyReq.Records.Add( searchRecord );

ShunResultSet rs = service.SearchByKey( keyReq, "/" );
ShunRecordCollection deleteRecords = new ShunRecordCollection();

foreach ( ShunRecord record in rs.Records ) {
  deleteRecords.Add( record );
}

service.Delete( deleteRecords );

service.Disconnect();

The sample code for updating data using direct search

ShunService service = new ShunService();
service.Connect();

ShunRecord searchRecord = new ShunRecord();
searchRecord.Key = "20061101,00000001";

ShunKeyRequirement keyReq = new ShunKeyRequirement();
keyReq.KeyName = "key1";
keyReq.SearchType = ShunKeySearchType.CompleteMatch;
keyReq.Records.Add( searchRecord );

ShunResultSet rs = service.SearchByKey( keyReq, "/" );
ShunRecordCollection updateRecords = new ShunRecordCollection();

foreach ( ShunRecord record in rs.Records ) {
  record.Data = updateData;
  updateRecords.Add( record );
}

service.Update( updateRecords );

service.Disconnect();

mark1For C API

The sample code for deleting data using direct search

/* This program assumes that the following variables have been declared           */
/* pKey       : Structure array for setting the direct access keys  */

SHUNHSTMT StmtH_Search;
SHUNHSTMT StmtH_Delete;

/* Allocate data manipulation handle */
ShunAllocHandle( ConH, &StmtH_Search );
ShunAllocHandle( ConH, &StmtH_Delete );

/* Use direct access key to perform search */
pKey[0].Key = "20061101,00000001";
pKey[0].Key_Len = strlen( pKey[0].Key );
ShunSearchKey( StmtH_Search, "key1", SHUN_KEY_COMPLETE_MATCH, 1, pKey, "/",
               &Return_Cnt, &Rec_Id_Out, &Data, &Key_Out );

/* Use record ID to perform delete */
if ( Return_Cnt > 0 ) {
  ShunDeleteRecId( StmtH_Delete, Return_Cnt, Rec_Id_Out);
}

/* Release data manipulation handle */
ShunFreeHandle( StmtH_Search );
ShunFreeHandle( StmtH_Delete );

The sample code for updating data using direct search

/* This program assumes that the following variables have been declared           */
/* pKey       :Structure array for setting the direct access keys */

SHUNHSTMT StmtH_Search;
SHUNHSTMT StmtH_Update;

/* Allocate data manipulation handle */
ShunAllocHandle( ConH, &StmtH_Search );
ShunAllocHandle( ConH, &StmtH_Update );

/* Use direct access key to perform search */
pKey[0].Key = "20061101,00000001";
pKey[0].Key_Len = strlen( pKey[0].Key );
ShunSearchKey( StmtH_Update, "key1", SHUN_KEY_COMPLETE_MATCH, 1, pKey, "/",
               &Return_Cnt, &Rec_Id_Out, &Data, &Key_Out);

/* Use record ID to perform update */
if ( Return_Cnt > 0 ) {
  ShunUpdateRecId( StmtH_Update, Return_Cnt, Rec_Id_Out, updateData );
}

/* Release data manipulation handle */
ShunFreeHandle( StmtH_Search );
ShunFreeHandle( StmtH_Update );

Contents Index PreviousNext

All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006