Batch data retrieval in a IMS Universal DL/I driver application
Use the batchRetrieve method to retrieve multiple segments in a single call.
Instead of the client application making multiple GU and GN calls, IMS will perform all of the GU and GN processing and will deliver the results
back to the client in a single batch network operation. The fetch size property determines how much
data is sent back on each batch network operation.
Procedure
- Obtain an SSAList instance from the PCB instance that represents the database.
- Optionally, you can add qualification statements to the SSAList instance.
- Specify the segment fields to retrieve. Use the markFieldForRetrieval method to mark a single field, or use the markAllFieldsForRetrieval method to mark all the fields for a segment. Following the IMS default, all of the fields in the lowest-level segment specified by the SSAList instance are initially marked for retrieval.
-
Optionally, set the fetch size property.
The fetch size gives a hint to the IMS Universal DL/I driver as to the number of records to fetch from the database in a single batch operation. See
Improving query performance by setting fetch size
for more information. -
Call the batchRetrieve method with the SSAList instance
above as a parameter.
The batchRetrieve method returns a PathSet that contains a list of records that satisfy the criteria specified by the SSAList.
- Read the values of the retrieved fields out of the Path object after the retrieve call is made.
IMS Universal DL/I driver batch data retrieval example
The following code fragment illustrates how to use the batchRetrieve method to retrieve the hospital name (HOSPNAME), ward name (WARDNAME), patient count (PATCOUNT), nurse count (NURCOUNT), and doctor count (DOCCOUNT) fields from the Hospital database:
import com.ibm.ims.dli.*;
public class HospitalDLIReadClient {
public static void main(String[] args) {
PSB psb = null;
PCB pcb = null;
SSAList ssaList = null;
Path path = null;
PathSet pathSet = null;
try {
// establish a database connection
IMSConnectionSpec connSpec
= IMSConnectionSpecFactory.createIMSConnectionSpec();
connSpec.setDatastoreName("IMS1");
connSpec.setDatastoreServer("ecdev123.svl.ibm.com");
connSpec.setPortNumber(5555);
connSpec.setMetadataURL("class://BMP266.BMP266DatabaseView");
connSpec.setUser("usr");
connSpec.setPassword("password");
connSpec.setDriverType(IMSConnectionSpec.DRIVER_TYPE_4);
psb = PSBFactory.createPSB(connSpec);
System.out.println("**** Created a connection to the IMS database");
pcb = psb.getPCB("PCb01");
System.out.println("**** Created PCB object");
// specify the segment search arguments
ssaList = pcb.getSSAList("HOSPITAL", "WARD");
// add the initial qualification
ssaList.addInitialQualification("HOSPITAL", "HOSPCODE",
SSAList.GREATER_OR_EQUAL, 444);
// specify the fields to retrieve
ssaList.markFieldForRetrieval("HOSPITAL", "HOSPNAME", true);
ssaList.markAllFieldsForRetrieval("WARD", true);
ssaList.markFieldForRetrieval("WARD", "WARDNO", false);
System.out.println("**** Created SSAList object");
// issue the database call to perform a batch retrieve operation
pathSet = pcb.batchRetrieve(ssaList);
System.out.println("**** Batch Retrieve returned without exception");
System.out.println("**** Created PathSet object");
while(pathSet.hasNext()){
path = pathSet.next();
System.out.println("HOSPNAME: "+ path.getString("HOSPITAL", "HOSPNAME"));
System.out.println("WARDNAME: "+ path.getString("WARD", "WARDNAME"));
System.out.println("PATCOUNT: "+ path.getInt("WARD", "PATCOUNT"));
System.out.println("NURCOUNT: "+ path.getInt("WARD", "NURCOUNT"));
System.out.println("DOCCOUNT: "+ path.getShort("WARD", "DOCCOUNT"));
}
System.out.println("**** Fetched all rows from PathSet");
// close the database connection
psb.close();
System.out.println("**** Disconnected from IMS database");
} catch (DLIException e) {
System.out.println(e);
System.exit(0);
}
}
}