Interstage Shunsaku Data Manager Application Development Guide - Microsoft(R) Windows(R) 2000/ Microsoft(R) Windows Server(TM) 2003 - - UNIX - |
Contents
Index
![]() ![]() |
Part 2 Developing Applications by APIs | > Chapter 9 Developing Java Applications | > 9.3 How to Use Java APIs | > 9.3.2 Data Searches |
In general, Web applications do not display all the search results on a single page, but limit the number of items shown on each page.
Specify the reply start number (position) and the number of items to return per request (requestCount) in the setRequest method to control the number of items of data to be obtained.
The following diagram shows the process for obtaining search results according to the number of data items.
ShunConnection con = new ShunConnection(); String queryExpression = "/document/base/prefecture == 'Sydney'"; String returnExpression = "/document/base/name, /document/base/price"; ShunPreparedStatement pstmt = con.prepareSearch(queryExpression, returnExpression); (1) pstmt.setRequest(11,5); (2) ShunResultSet rs = pstmt.executeSearch(); (3) System.out.println("Number) = " + rs.getHitCount()); (3) while(rs.next()) { (4) System.out.println("[Search results] = " + rs.getString()); (4) } rs.close(); (5) pstmt.close(); (5) con.close(); |
Create a ShunPreparedStatement object by specifying a search expression and a return expression as parameters of the prepareSearch method.
Refer to Appendix B Format of Search, Return and Sort Expressions for more information on search expressions and return expressions.
Specify the reply start number and the number of items to return per request in the setRequest method. If the setRequest method is omitted, the number of items to return per request will be set to the value specified in the AnsMax parameter in the conductor or director environment file.
For the number of items to return per request, specify the number of data items to display on each page.
Execute the search using the executeSearch method. A ShunResultSet object will be created to hold the results of the search.
The number of hits (XML documents that match the search conditions) can be obtained using the getHitCount method. This value can be used to find such things as the number of pages of the search results.
Always invoke the next method before extracting the results of the search. The next method returns true if there is still more data that can be extracted and false otherwise.
Different methods can be used to extract XML documents for different objectives. The following table shows the methods that can be used.
Method |
Function |
---|---|
getString |
Extracts XML documents as String objects. |
getStringArray |
Extracts XML documents as a two-dimensional array of String objects. |
getStream |
Extracts XML documents as InputStream objects. |
Note: The getStringArray method is an effective way to extract search results in text format.
The getrecordID method can be used to obtain record IDs (which uniquely identify each data item) in addition to the results of the search. Record IDs are used to extract, delete, and update the corresponding XML documents.
Use the close methods of the ShunResultSet object and the ShunPreparedStatement object to release these objects when they are no longer required.
The following is sample code for a business class that uses a Shunsaku access class created with the Studio interactive wizard, and a prototype Shunsaku access class that is used by the business class.
ShunConnection con = new ShunConnection(); ShunsakuAccessController controller = new ShunsakuAccessController(con); controller.search(key); Object[] resultData = controller.getResultData(ShunsakuAccessController.SORT_NONE, 11, 5); controller.close(); con.close(); |
public class ShunsakuAccessController { : private ShunPreparedStatement pstmt; : } |
public void search(String keys) throws ShunException { : queryString = "/document/base/prefecture == ' " + keys + "'"; (a) returnString = "/"; (b) : getPreparedStatement(queryString, returnString); : } private void getPreparedStatement(String queryString, String returnString) { : pstmt = con.preparedSearch(queryString, returnString); (1) : } |
public Object[] getResultData(String sortString, int position, int requestCount) throws ShunException { : ShunResultSet resultSet = getResultSet(sortString, position, requestCount); : Object[] resultData = parseResultSet(resultSet); (4) : resultSet.close(); (5) : } public ShunResultSet getResultSet(String sortString, int position, int requestCount) throws ShunException { if(!sortString.equals(SORT_NONE)) { pstmt.setSort(sortString); } pstmt.setRequest(position, requestCount); (2) return pstmt.executeSearch(); (3) } |
public void close() throws ShunException { : pstmt.close(); (5) : } |
Contents
Index
![]() ![]() |