JMP programming models
JMP applications can retrieve input messages from the IMS message queue, access IMS and Db2 for z/OS® databases, commit or roll back transactions, and send output messages.
Creating the main
method for a JMP application
The
main
method (public static void main(String[] args)
) is the
program entry point for all JMP and JBP applications.
A JMP application starts when IMS receives a message with a transaction code for the JMP application and schedules the message. A JMP application typically ends when there are no more messages with that transaction code to process.
JMP application main
method code sample
The following code sample shows how to implement a JMP application to access the hospital database and send messages:
package hospital.ims;
import java.sql.*;
import com.ibm.ims.dli.tm.*;
import com.ibm.ims.dli.DLIException;
public static void main(String args[]) {
try {
Application app = null;
MessageQueue messageQueue = null;
IOMessage inputMessage = null;
IOMessage outputMessage = null;
Transaction tran = null;
app = ApplicationFactory.createApplication();
inputMessage = app.getIOMessage("class://hospital.ims.InMessage");
outputMessage = app.getIOMessage("class://hospital.ims.OutMessage");
messageQueue = app.getMessageQueue();
tran = app.getTransaction();
IMSDataSource dataSource = new IMSDataSource();
dataSource.setMetadataURL("class://hospital.ims.HospitalDBView");
dataSource.setDriverType(IMSDataSource.DRIVER_TYPE_2);
dataSource.setDatastoreName("IMS1");
Connection conn = dataSource.getConnection();
conn.SetAutoCommit(false);
Statement st = conn.createStatement();
String in = new String("");
// Returns true if a message is read from the queue
while (messageQueue.getUnique(inputMessage)) {
in = inputMessage.getString("Message").trim();
if (!in.equals("")) {
// Query the database for all hospital names
ResultSet rs
= st.executeQuery("SELECT HOSPNAME FROM PCB01.HOSpital");
while (rs.next()) {
// Return hospital name in output message
outputMessage.setString("Message", rs.getString("HOSPNAME"));
messageQueue.insert(outputMessage,
MessageQueue.DEFAULT_DESTINATION);
// Commit this transaction
tran.commit();
}
conn.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Accessing Db2 for z/OS data from a JMP application
When a JMP application accesses only IMS data, it must open a database connection only once to process multiple transactions. However, a JMP application that accesses Db2 for z/OS data must open and close a database connection for each message that is processed.