Accessing GSAM data from a JBP application
GSAM data are frequently referred to as z/OS® data sets or as flat files. This kind of data is non-hierarchical in structure. You can access data from GSAM databases from a JBP application.
The JMP application connects to a GSAM database, performs database processing, periodically commits, and disconnects from the database at the end of the application. To access the GSAM data, you will need to supply your JBP application with the Java™ database metadata class for that database.
If your IMS system includes an activate IMS catalog database, you can connect to the catalog instead of using a database metadata class file.
Sample metadata class for a car dealership database
The following Java code sample provides an example of the Java database metadata class.
package samples.dealership.gsam;
import com.ibm.ims.db.*;
import com.ibm.ims.base.*;
public class AUTOGSAMDatabaseView extends DLIDatabaseView {
// This class describes the data view of PSB: AUTOGSAM
// PSB AUTOGSAM has database PCBs with 8-char PCBNAME or label:
// AUTOLPCB
// PCBGSAMG
// PCBGSAML
// The following describes Segment:
// DEALER ("DEALER") in PCB: AUTOLPCB ("AUTOLPCB")
static DLITypeInfo[] AUTOLPCBDEALERArray= {
new DLITypeInfo("DLRNO", DLITypeInfo.CHAR, 1, 4,
"DLRNO", DLITypeInfo.UNIQUE_KEY),
new DLITypeInfo("DLRNAME", DLITypeInfo.CHAR,
5, 30, "DLRNAME"),
new DLITypeInfo("CITY", DLITypeInfo.CHAR,
35, 10, "CITY"),
new DLITypeInfo("ZIP", DLITypeInfo.CHAR,
45, 10, "ZIP"),
new DLITypeInfo("PHONE", DLITypeInfo.CHAR,
55, 7, "PHONE")
};
static DLISegment AUTOLPCBDEALERSegment= new DLISegment
("DEALER","DEALER",AUTOLPCBDEALERArray,61);
// The following describes Segment: MODEL ("MODEL")
// in PCB: AUTOLPCB ("AUTOLPCB")
static DLITypeInfo[] AUTOLPCBMODELArray= {
new DLITypeInfo("MODKEY", DLITypeInfo.CHAR, 3, 24,
"MODKEY", DLITypeInfo.UNIQUE_KEY),
new DLITypeInfo("MODTYPE", DLITypeInfo.CHAR, 1, 2, "MODTYPE"),
new DLITypeInfo("MAKE", DLITypeInfo.CHAR, 3, 10, "MAKE"),
new DLITypeInfo("MODEL", DLITypeInfo.CHAR, 13, 10, "MODEL"),
new DLITypeInfo("YEAR", DLITypeInfo.CHAR, 23, 4, "YEAR"),
new DLITypeInfo("MSRP", DLITypeInfo.CHAR, 27, 5, "MSRP"),
new DLITypeInfo("COUNT1", DLITypeInfo.CHAR, 32, 2, "COUNT")
};
static DLISegment AUTOLPCBMODELSegment= new DLISegment
("MODEL","MODEL",AUTOLPCBMODELArray,37);
// An array of DLISegmentInfo objects follows
// to describe the view for PCB: AUTOLPCB ("AUTOLPCB")
static DLISegmentInfo[] AUTOLPCBarray = {
new DLISegmentInfo(AUTOLPCBDEALERSegment,DLIDatabaseView.ROOT),
new DLISegmentInfo(AUTOLPCBMODELSegment,0),
};
// Warning: PCB: PCBGSAMG has no SENSEGS
// The following describes GSAM Record:
// JAVGSAM1 ("JAVGSAM1") in PCB: PCBGSAMG ("GSAMRead")
static DLITypeInfo[] PCBGSAMGJAVGSAM1Array= {
new DLITypeInfo("DealerNo", DLITypeInfo.INTEGER, 1, 4),
new DLITypeInfo("DealerName", DLITypeInfo.CHAR, 5, 30),
new DLITypeInfo("ModelType", DLITypeInfo.CHAR, 35, 2),
new DLITypeInfo("ModelKey", DLITypeInfo.CHAR, 37, 24),
new DLITypeInfo("Make", DLITypeInfo.CHAR, 37, 10),
new DLITypeInfo("Model", DLITypeInfo.CHAR, 47, 10),
new DLITypeInfo("Year", "yyyy", DLITypeInfo.DATE, 57, 4),
new DLITypeInfo("MSRP", "S999999V99", DLITypeInfo.PACKEDDECIMAL, 61, 5),
new DLITypeInfo("Counter", DLITypeInfo.SMALLINT, 66, 2)
};
static GSAMRecord PCBGSAMGRecord= new GSAMRecord
("PCBGSAMGRecord",PCBGSAMGJAVGSAM1Array,80);
// An array of DLISegmentInfo objects follows
// to describe the view for PCB: PCBGSAMG ("GSAMRead")
static DLISegmentInfo[] PCBGSAMGarray = {
new DLISegmentInfo(PCBGSAMGRecord, DLIDatabaseView.ROOT)
};
// Warning: PCB: PCBGSAML has no SENSEGS
// The following describes GSAM Record:
// JAVGSAM1 ("JAVGSAM1") in PCB: PCBGSAML ("GSAMLoad")
static DLITypeInfo[] PCBGSAMLJAVGSAM1Array= {
new DLITypeInfo("DealerNo", DLITypeInfo.INTEGER, 1, 4),
new DLITypeInfo("DealerName", DLITypeInfo.CHAR, 5, 30),
new DLITypeInfo("ModelType", DLITypeInfo.CHAR, 35, 2),
new DLITypeInfo("ModelKey", DLITypeInfo.CHAR, 37, 24),
new DLITypeInfo("Make", DLITypeInfo.CHAR, 37, 10),
new DLITypeInfo("Model", DLITypeInfo.CHAR, 47, 10),
new DLITypeInfo("Year", "yyyy", DLITypeInfo.DATE, 57, 4),
new DLITypeInfo("MSRP", "S999999V99",
DLITypeInfo.PACKEDDECIMAL, 61, 5),
new DLITypeInfo("Counter", DLITypeInfo.SMALLINT, 66, 2)
};
static GSAMRecord PCBGSAMLRecord= new GSAMRecord
("PCBGSAMLRecord",PCBGSAMLJAVGSAM1Array,80);
// An array of DLISegmentInfo objects follows
// to describe the view for PCB: PCBGSAML ("GSAMLoad")
static DLISegmentInfo[] PCBGSAMLarray = {
new DLISegmentInfo(PCBGSAMLRecord, DLIDatabaseView.ROOT)
};
// Constructor
public AUTOGSAMDatabaseView() {
super("2.0","AUTOGSAM", "AUTOLPCB", "AUTOLPCB",
AUTOLPCBarray);
addDatabase("GSAMRead", "PCBGSAMG", PCBGSAMGarray);
addDatabase("GSAMLoad", "PCBGSAML", PCBGSAMLarray);
} // end AUTOGSAMDatabaseView constructor
} // end AUTOGSAMDatabaseView class definition
Sample JBP application for accessing a GSAM database
The following code example is a JBP application that relies on the previous code sample to access GSAM data.
package samples.dealership.gsam;
import java.io.*;
import java.util.Properties;
import java.math.BigDecimal;
import com.ibm.ims.dli.*;
import com.ibm.ims.dli.tm.*;
/**
* This is an auto dealership sample application
* demonstrating the use of the
* GSAM database functionality support in
* the IMS Java dependent region resource adapter.
*
*/
public class GSAMAuto {
private final String readOnlyGSAMPCB
= new String("GSAMRead");
private final String writeOnlyGSAMPCB
= new String("GSAMLoad");
private PSB psb;
/**
* The entry point of the application
*/
public static void main(String[] args) {
GSAMAuto gsamLoadSample = new GSAMAuto();
if (System.getProperty("com.ibm.ims.jdbcenvironment")
== null) {
Properties properties = System.getProperties();
properties.put("com.ibm.ims.jdbcenvironment", "IMS");
}
try {
gsamLoadSample.setup();
} catch (Exception e) {
e.printStackTrace();
}
try {
gsamLoadSample.runSample();
gsamLoadSample.closeDown();
} catch (Throwable e) {
e.printStackTrace();
}
}
/**
* This method does the set up for the application:
* 1. Enable trace
* 2. Creates dbConnection
* 3. Creates GSAMConnection object
* @throws IOException
* @throws SecurityException
* @throws DLIException
*/
void setup() throws SecurityException,
IOException, DLIException {
IMSConnectionSpec cSpec
= IMSConnectionSpecFactory.createIMSConnectionSpec();
cSpec.setDatastoreName("IMS1");
cSpec.setDriverType(IMSConnectionSpec.DRIVER_TYPE_2);
cSpec.setMetadataURL("class://samples.dealership.gsam.AUTOGSAMDatabaseView");
psb = PSBFactory.createPSB(cSpec);
}
/**
* This method does the clean up before application exit.
* 1. Commits the database work done. IMS Java dependent
* regions require all applications to commit before exiting.
* @throws DLIException
*
* @exception Exception
*/
void closeDown() throws DLIException {
try {
Application app = ApplicationFactory.createApplication();
Transaction transaction = app.getTransaction();
// Always commit any work before exiting
transaction.commit();
} catch (DLIException e) {
System.out.println("IMS commit failed. Reason: "
+ e.toString());
throw e;
}
}
/**
* Demonstrates how to write to and read from a
* GSAM database. Also shows different data types
* being stored into the GSAM database using the
* internal data conversion methods.
*/
void runSample() {
final int dealerNo = 1171;
final String dealerName = "ABC Autos";
final String modelType = "LX";
final String make = "Santro";
final String model = "Zen";
final java.sql.Date year
= java.sql.Date.valueOf("2011-05-18");
final BigDecimal msrp = new BigDecimal(17750.00);
final short count = (short) 8;
try {
GSAMPCB pcb1 = psb.getGSAMPCB(this.writeOnlyGSAMPCB);
Path myGSAMRecord = pcb1.getPathForInsert();
// Set values to individual fields in a GSAM record
myGSAMRecord.setInt("DealerNo", dealerNo);
myGSAMRecord.setString("DealerName", dealerName);
myGSAMRecord.setString("ModelType", modelType);
myGSAMRecord.setString("Make", make);
myGSAMRecord.setString("Model", model);
myGSAMRecord.setDate("Year", year);
myGSAMRecord.setBigDecimal("MSRP", msrp);
myGSAMRecord.setShort("Counter", count);
// Insert the GSAM record data
// and save the RSA of the record
RSA rsa = pcb1.insert(myGSAMRecord);
// Close the GSAM database explicitly
// for writing/loading data
pcb1.close();
// Open a GSAM Connection to write the GSAM dataset
GSAMPCB pcb2 = psb.getGSAMPCB(this.readOnlyGSAMPCB);
// Read the GSAM record data using
// the RSA stored earlier
Path gsamRecord = pcb2.getUnique(rsa);
// Print the GSAM data
if (gsamRecord != null) {
System.out.println("Dealer Number: "
+ gsamRecord.getInt("DealerNo"));
System.out.println("Dealer Name: "
+ gsamRecord.getString("DealerName"));
System.out.println("Model Type: "
+ gsamRecord.getString("ModelType"));
System.out.println("Make: "
+ gsamRecord.getString("Make"));
System.out.println("Model: "
+ gsamRecord.getString("Model"));
System.out.println("Year: "
+ gsamRecord.getDate("Year"));
System.out.println("MSRP: "
+ gsamRecord.getBigDecimal("MSRP"));
System.out.println("Counter: "
+ gsamRecord.getShort("Counter"));
System.out.println
("\nSuccessful completion of GSAM sample application");
} else {
System.out.println("GSAM DB is empty");
}
} catch (DLIException e) {
System.out.println
("GSAM sample failed. Reason: " + e.toString());
}
}
}