Understanding the Java Template

You can use the Java template as a starting point for your Java program. This section contains a skeleton of the generated Java template for a component interface named SDK_BUS_EXP, which is part of the component interface SDK. The template has been edited for length.

Import all the required classes.

import java.io.*;
import psft.pt8.joa.*;
import PeopleSoft.Generated.CompIntfc.*;
public class SDK_BUS_EXP {
   public static ISession oSession;
   .....
   public static void main (String args[]) {
   try {
      //***** Set Connect Parameters *****
      String strServerName, strServerPort, strAppServerPath;
      String strUserID, strPassword;
      .....
      //Build Application Server Path
      strAppServerPath = strServerName + ":" + strServerPort;

Note: To enable Jolt failover and load balancing in the PeopleSoft Pure Internet Architecture, you can supply multiple application server domains for the strAppServerPath variable. Separate the domain names with a comma, and make sure that no spaces are included, for example, strAppServerPath = //APPSRVR1:8000,//APPSRVR2:9000

Create the PeopleSoft Session object to enable access to the PeopleSoft system.

The Session object controls the environment and enables you to do error handling for all APIs from a central location.

      //***** Create PeopleSoft Session Object *****
      oSession = API.createSession();

Connect to the application server by using the connect method of the Session object.

//***** Connect to the App Server *****
//if the Jolt Password is to be provided, switch to the the second 
//version of the statement below
if (!oSession.connect(1, strAppServerPath, strUserID, 
strPassword, null)) {
//if (!oSession.connectS(1, strAppServerPath, strUserID,
//strPassword, null, strJoltPwd)){
System.out.println("\nUnable to Connect to the Application Server. 
Please verify it is running");
ErrorHandler();
return;
}

You define the domain connection password using the DomainConnectionPwd field in the Security section of the application server configuration file, configuration.properties. Security OptionsConfiguring Domain Connection Password

Beginning in PeopleTools 8.53, using a domain connection password to connect to the application server is optional. However, if a domain connection password is specified, then the methods in the component interface APIs have to specify a value for it.

If the application server is configured to use a domain connection password other than the default value, use the connectS method, currently shown commented out in the previous Java template example, instead of the Connect method. The connectS method takes in all the same parameters as the Connect method, plus a domain Connection password as an additional parameter:

connectS(1, strAppServerPath, strUserID, strPassword, null, strJoltPwd);

Get a reference to the component interface providing its name. (A runtime error occurs if the component interface does not exist.)

  ISdkBusExp oSdkBusExp;
      String ciName;
      ciName = "SDK_BUS_EXP";
      oSdkBusExp = (ISdkBusExp) oSession.getCompIntfc(ciName);
      if (oSdkBusExp == null) {
         System.out.println("\nUnable to Get Component Interface " + 
            ciName);
         ErrorHandler();
         return;
      }
 
      //***** Set the Component Interface Mode *****
      oSdkBusExp.setInteractiveMode(false);
      oSdkBusExp.setGetHistoryItems(true);
      oSdkBusExp.setEditHistoryItems(false);

Set the keys for the component interface. In this example, SDK_EMPLID is the Get key.

//***** Set Component Interface Get/Create Keys *****
      String strSdkEmplid;
      System.out.print("\nEnter SdkEmplid: ");
      strSdkEmplid = inData.readLine();
      oSdkBusExp.setSdkEmplid(strSdkEmplid);

The get() method retrieves data from the database, associated with the key values.

//***** Execute Get *****
      if (!oSdkBusExp.get()) {
         System.out.println("\nNo rows exist for the specified keys.
          \nFailed to get the Component Interface.");
         ErrorHandler();
         return;
      }
      .....

Get and print properties at level 0.

      System.out.println("oSdkBusExp.SdkName: " + 
         oSdkBusExp.getSdkName());
      .....

Similar code is generated for the properties SDK_BIRTHDATE and SDK_DEPTID.

Get collection at level 1 (SDK_BUS_EXP_PER).

      ISdkBusExpSdkBusExpPerCollection oSdkBusExpPerCollection;
      ISdkBusExpSdkBusExpPer oSdkBusExpPer;
      oSdkBusExpPerCollection = oSdkBusExp.getSdkBusExpPer();

Get and print properties at level 1.

for (int i17 = 0; 
         i17 < oSdkBusExpPerCollection.getCount(); i17++) {
         oSdkBusExpPer = oSdkBusExpPerCollection.item(i17);

         System.out.println("oSdkBusExpPer.SdkExpPerDt: " + 
         oSdkBusExpPer.getSdkExpPerDt());
         .....

Similar code is generated for the properties SDK_EMPLID and SDK_BUS_EXP_SUM in the SDK_BUS_EXP_PER collection.

Get collection at level 2 (SDK_BUS_EXP_DTL).

         ISdkBusExpSdkBusExpPerSdkBusExpDtlCollection 
            oSdkBusExpDtlCollection;
         ISdkBusExpSdkBusExpPerSdkBusExpDtl oSdkBusExpDtl;
         oSdkBusExpDtlCollection = oSdkBusExpPer.getSdkBusExpDtl();

Get and print properties at level 2.

         for (int i211 = 0; 
            i211 < oSdkBusExpDtlCollection.getCount(); i211++) {
            oSdkBusExpDtl = oSdkBusExpDtlCollection.item(i211);
 
            System.out.println("oSdkBusExpDtl.SdkChargeDt: " + 
               oSdkBusExpDtl.getSdkChargeDt());
            .....

Similar code is generated for the properties SDK_EMPID, SDK_EXP_PER_DT, SDK_EXPENSE_CD, SDK_EXPENSE_AMT, SDK_CURRENCY_CD, SDK_BUS_PURPOSE, and SDK_DEPTID.

         }
      }

Disconnect from the Application server by using the disconnect method of the Session object. This method clears the buffers and releases the memory.

 //***** Disconnect from the App Server *****
      oSession.disconnect();
      return;
   }
   catch (Exception e) {
      e.printStackTrace();
      System.out.println("An error occurred: ");
      ErrorHandler();
   }
   }
}