The following source file contains an example of a PL/I module
calling Java™ through the JNI
to invoke the batch container commit method using the steps as described
above. One may als0 think of this as simple proxy for any PL/I “main”
routine launched from the z/OS® Batch
Runtime and invoking simple Java methods.
Figure 1. PL/I Sample to
Commit Transaction Using JNI*Process Limits( Extname( 100 ) );
*Process Margins( 1, 100 );
*Process Display(STD) Rent;
*Process Default( ASCII ) Or('|');
*Process Options InSource Source Nest Macro Storage;
*Process Aggregate Offset;
*Process List Flag(I) MarginI('|');
*Process Opt(2) Attributes(Full) Xref(Short);
/* PL/I calling batch container commit using JNI */
PLICOMIT: Procedure Options( Fetchable
Assembler );
/********************************************************************/
/* */
/* This sample invokes the z/OS batch runtime to commit a */
/* transaction. */
/* */
/* The batch runtime transaction helper class is loaded and the */
/* commit method is located and invoked. */
/* */
/********************************************************************/
/************/
/* Includes */
/************/
%INCLUDE ibmzjni;
/*************/
/* Constants */
/*************/
Dcl NULLPTR Pointer Static Init(PtrValue(0));
Dcl TRANSACTION_HELPER_CLASS_NAME Char(60) VaryingZ Static
Init("com/ibm/batch/spi/UserControlledTransactionHelper");
/*******************/
/* Local variables */
/*******************/
Dcl myRC Fixed Bin(31);
Dcl myClass Type jclass;
Dcl myMethodID Type jmethodID;
Dcl myjstring Type jstring;
Dcl javaNumVMs Type jsize;
Dcl myNull Pointer;
Put skip list("Starting PLICOMIT ...");
/*****************/
/* Query the JVM */
/*****************/
myRC = JNI_GetCreatedJavaVMs( addr(JavaVM),
1,
addr(javaNumVMs) );
If myRC = JNI_OK then
Do;
If javaNumVMs = 1 then
Do;
/*******************************/
/* Get env pointer for our JVM */
/*******************************/
myRC = JGetEnv( JavaVM,
addr(JNIEnv),
JNI_VERSION_1_4 );
If myRC ^= JNI_OK then
Do;
Put skip list("JGetEnv failed rc=",myRC);
Stop;
End;
Else;
End;
Else
Do;
Put skip list("javaNumVMs not 1",javanumVMs);
Stop;
End;
End;
Else
Do;
Put skip list("getCreatedJavaVMs failed",myRC);
Stop;
End;
/******************************/
/* Get the Java class to call */
/******************************/
myClass = FindClass( JNIEnv,
TRANSACTION_HELPER_CLASS_NAME );
If myClass = NULLPTR then
Do;
Put skip list("myClass is null");
Stop;
End;
Else;
/***********************************/
/* Get method id for commit method */
/***********************************/
myMethodID = GetStaticMethodID( JNIEnv,
myClass,
"commit",
"()V" );
If myMethodID = NULLPTR then
Do;
Put skip list("myMethodID is null");
Stop;
End;
Else;
Put skip list("Calling commit method ...");
myNull = CallStaticVoidMethod( JNIEnv,
myClass,
myMethodID );
Call PLIRETC(0); /* Set rc=0 */
Put skip list("PLICOMIT ended.");
End PLICOMIT;