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

|
F.1.3 Obtain Every Instance of Particular XML Documents
The search process performs the operations stated in F.1.1 Obtaining the Number of XML Documents that Match Search Conditions and F.1.2 Obtaining XML Documents that Match Search Conditions in a Specified Format to obtain all the data based on the filtering conditions.
The following example shows how the Java APIs are used. It shows how all the data of applicable hotels can be retrieved based on the hotel names obtained using the operations stated in F.1.2 Obtaining XML Documents that Match Search Conditions in a Specified Format.
Search Conditions
'I want to obtain detailed information about a number of the hotels in Sydney that have a vacancy on 2006/07/18.'Execute the search using the date (2006/07/18) and the location (Sydney) as search conditions. The record IDs that correspond to hotels are used to obtain detailed information.
An Example of Using the APIs
The following is a sample program using the Java APIs.
import com.fujitsu.shun.ShunConnection;
import com.fujitsu.shun.ShunPreparedRecordID;
import com.fujitsu.shun.ShunPreparedStatement;
import com.fujitsu.shun.ShunResultSet;
import com.fujitsu.shun.common.ShunException;
/*** Obtain all the record information applicable to the specified record ID ***/
public class JavaAPISample3 {
public static void main(String[] args) {
ShunConnection con = null;
ShunPreparedStatement pstmt = null;
ShunPreparedRecordID rid = null;
ShunResultSet rs = null;
try {
// Search conditional expression
String sQuery = "/document/base/city == 'Sydney' AND /document/information/date == '2006/07/18'";
// Return expression
String sReturn = "/document/base/name/text()";
// Record information
String sRecordID = "";
// Number of hits
int iHitNum = 0;
// Create ShunConnection object
con = new ShunConnection("DirSvr1", 33101);
// Specify search expression and create ShunPreparedStatement object
pstmt = con.prepareSearch(sQuery, sReturn);
//Specify number of items to return per request
pstmt.setRequest(1, 30);
// Execute search and create ShunResultSet object
rs = pstmt.executeSearch();
// Obtain number of hits
iHitNum = rs.getHitCount();
System.out.println("Number of hits = " + iHitNum);
// Create ShunPreparedRecordID object
rid = con.prepareSearchRecordID();
// Obtain one item of data that corresponds to search conditions
while (rs.next()) {
// Set record ID for Hotel 1 information
if (rs.getString().equals("Hotel 1")) {
rid.add(rs.getRecordID());
}
}
rs.close();
pstmt.close();
// View detailed information if acquisition of the corresponding record IDs is successful
if (0 < rid.getCount()) {
// Use specified record ID to create ShunResultSet object
rs = rid.searchByRecordID();
while (rs.next()) {
// Obtain data by specifying record ID
System.out.println("[Details] = " + rs.getString());
}
rs.close();
}
rid.close();
con.close();
}
catch (ShunException ex) {
int errorLevel = ex.getErrLevel();
switch( errorLevel ) {
case ShunException.SHUN_ERROR :
System.out.println("Error level :SHUN_ERROR");
break;
case ShunException.SHUN_ERROR_CONNECTION_TERMINATED :
System.out.println("Error level :SHUN_ERROR_CONNECTION_TERMINATED");
break;
}
System.out.println("Error message:" + ex.getMessage());
ex.printStackTrace();
}
catch (Exception ex) {
System.out.println("Error message:" + ex.getMessage());
ex.printStackTrace();
}
finally {
try {
if (rs != null)
rs.close();
}
catch (ShunException ex) {
int errorLevel = ex.getErrLevel();
switch( errorLevel ) {
case ShunException.SHUN_ERROR :
System.out.println("Error level :SHUN_ERROR");
break;
case ShunException.SHUN_ERROR_CONNECTION_TERMINATED :
System.out.println("Error level :SHUN_ERROR_CONNECTION_TERMINATED");
break;
}
System.out.println("Error message:" + ex.getMessage());
ex.printStackTrace();
}
try {
if (pstmt != null)
pstmt.close();
}
catch (ShunException ex) {
int errorLevel = ex.getErrLevel();
switch( errorLevel ) {
case ShunException.SHUN_ERROR :
System.out.println("Error level :SHUN_ERROR");
break;
case ShunException.SHUN_ERROR_CONNECTION_TERMINATED :
System.out.println("Error level :SHUN_ERROR_CONNECTION_TERMINATED");
break;
}
System.out.println("Error message:" + ex.getMessage());
ex.printStackTrace();
}
try {
if (rid != null)
rid.close();
}
catch (ShunException ex) {
int errorLevel = ex.getErrLevel();
switch( errorLevel ) {
case ShunException.SHUN_ERROR :
System.out.println("Error level :SHUN_ERROR");
break;
case ShunException.SHUN_ERROR_CONNECTION_TERMINATED :
System.out.println("Error level :SHUN_ERROR_CONNECTION_TERMINATED");
break;
}
System.out.println("Error message:" + ex.getMessage());
ex.printStackTrace();
}
try {
if (con != null)
con.close();
}
catch (ShunException ex) {
int errorLevel = ex.getErrLevel();
switch( errorLevel ) {
case ShunException.SHUN_ERROR :
System.out.println("Error level :SHUN_ERROR");
break;
case ShunException.SHUN_ERROR_CONNECTION_TERMINATED :
System.out.println("Error level :SHUN_ERROR_CONNECTION_TERMINATED");
break;
}
System.out.println("Error message:" + ex.getMessage());
ex.printStackTrace();
}
}
}
} |
Execution Results
Number of hits = 3
[Details] = <document>
<base>
<name>Hotel 1</name>
<city>Sydney</city>
<address>Bondi Beach</address>
<detail>http://xxxxx.com.au</detail>
<price>350</price>
</base>
<information>
<date>2006/07/18</date>
</information>
<note>En-suite bathroom and toilet, two minutes' walk to train station XX</note>
</document> |
All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006