10.5 Solution of the Model Problem


This section describes our experience with the setup and development of the model solution.

Design of the Model Solution

To implement the model solution, we first must identify the sequence of steps to be followed. In particular, the model solution must

  1. Start a transaction, using the JTS from a Micro Focus COBOL program

  2. Write to the Oracle 8i database, using JDBC and SQL

  3. Invoke an EJB method that also writes to the same Oracle 8i database as part of the same transaction

  4. Return control to the COBOL program

  5. Either roll back or commit the database changes made by both the COBOL and EJB programs

For purposes of evaluation, it is often convenient to start with an existing prototype. Sample programs shipped with development tools are often ideally suited for this purpose. In our case, the model solution is based on a sample banking program that manages client accounts by using EJBs. The EJB application consists of a database, a Java client, and two EJBs: an account bean and a transfer bean. As Figure 10-5 illustrates, the account bean is an entity bean that persists in a relational table, and the transfer bean is a session bean that withdraws funds from one account and deposits that amount in another account in the context of a single transaction. The Java client is a simple program that accepts a request from the user and invokes the beans to perform account creations or transfers. The client uses the Java Naming Directory Interface (JNDI) to get references to various resources and the Java Transaction API (JTA) to start, commit, and roll back transactions. We used a Java client program to verify the operation of the banking application: EJBs, transaction logic, and interaction with the Oracle 8i database.

Figure 10-5. Initial architecture

This client program was later used as a basis to construct a test adapter, as shown in Figure 10-6. The Java client was replaced with a combination of Micro Focus COBOL and Java code developed using Net Express Micro Focus COBOL.

Figure 10-6. Model-solution architecture

Building the Test Adapter

As stated earlier, the test adapter required mixed-language programming using COBOL and Java. Therefore, our first step was to understand how Micro Focus COBOL interfaces with Java.

We obtained an evaluation version of Micro Focus Net Express IDE v3.1 and began working with the product to determine how to invoke Java methods from a COBOL program. The Java demonstration programs provided as part of the IDE software package contained helpful information on how to call Java from COBOL and vice versa. These examples were interesting because none of them showed how to call Java from a COBOL executable or how to pass strings from COBOL to Java. Examples typically consisted of a Java program calling a COBOL procedure linked into a dynamic link library (DLL). Then, while executing the COBOL code inside the DLL, the COBOL program would invoke a Java method.

Because we could not find an example that met our needs, we developed a simple test program that passed an integer from COBOL to Java. Figure 10-7 and Figure 10-8 show the respective Java and COBOL sections of the program.

Figure 10-7 Figure Java integer code
 public class TestJava { public void PassInt(int IntFromCOBOL){    System.out.println("int from COBOL: "+IntFromCOBOL);  } } 
Figure 10-8 Figure COBOL integer code
 $set ooctrl(+p-f) program-id. COBOLCallingJava. class-control.  TestJava is class "$java$TestJava"  . working-storage section. copy javatypes. 01 IntForJava        jint.  01 JavaClassRef      object reference. procedure division.  display "Load Java Class"  invoke TestJava "new" returning JavaClassRef  display "Java Class Load Complete"  set IntForJava to 123456  invoke JavaClassRef "PassInt" using IntForJava  invoke JavaClassRef "finalize" returning JavaClassRef  stop run  . 

Next, we expanded our test program to include passing a string, having a return value, and catching Java exceptions in the COBOL portion of the program. Our updated COBOL and Java programs are shown in Figures 10-9 and 10-10, respectively. We tested our new mixed-language application and everything seemed to work correctly.

Figure 10-9 Figure Expanded integer Java code
 public class TestJava {  public String PassInt(String StringFromCOBOL, int IntFromCOBOL) throws Exception {   System.out.println(StringFromCOBOL+IntFromCOBOL);   if (IntFromCOBOL==1234){      Exception e = new Exception ("Test Exception for COBOL" );      throw e;     }   return("Hello from Java");  } } 
Figure 10-10 Figure Expanded integer COBOL code
 $set ooctrl(+p-f) program-id. COBOLCallingJava. class-control.  ExceptionManager         is class "exptnmgr"  EntryCallback            is class "entrycll"  JavaExceptionManager     is class "javaexpt"  TestJava                 is class "$java$TestJava" . working-storage section.  copy javatypes.  01 JavaClassRef      object reference.  01 wsCallBack        object reference.  01 wsIterator        object reference.  01 IntForJava        jint.  01 StringFromJava    pic x(100) . linkage section.  01 lnkErrorNumber            pic x(4) comp-5.  01 lnkErrorObject            object reference.  01 lnkErrorTextCollection    object reference.  01 lnkException              object reference.  01 anElement                 object reference. procedure division.  invoke EntryCallback "new" using z"JException" returning wsCallback  invoke ExceptionManager "register" using javaexceptionmanager wsCallback  *>Register a CallBack to use as an Iterator (For Errors)  invoke EntryCallback "new" using z"DispError" returning  wsIterator  display "Load Java Class"  invoke TestJava "new" returning JavaClassRef  display "Test Java Load Complete"  display "Enter a integer to pass"  Accept IntForJava.  invoke JavaClassRef "PassInt" using z"Int From COBOL :"     IntForJava         returning StringFromJava  display "String Returned from Java = " StringFromJava  invoke JavaClassRef "finalize" returning JavaClassRef  stop run  . 

Once we had determined how to pass data successfully from a COBOL program to a Java program and to handle Java exceptions from within COBOL, we began building a test adapter. The test adapter was constructed from the Java client described previously. Similar to the Java client, this adapter uses the account bean, transfer bean, JNDI, and JTA but is controlled and instantiated via the COBOL portion of the program.

We determined through our test adapter that COBOL strings must be NULL terminated before being passed in a Java invocation and that Java methods receiving strings from a COBOL program must strip off any trailing spaces. Additionally, we noticed that any COBOL string used as a return value for a Java method invocation must be cleared before invoking the Java method. We did not notice this issue with our simple test program, because we were passing only one string, were not performing string comparisons, and invoked the Java method only once instead of repeatedly.

After making these modifications to the COBOL and Java portions of the program, the adapter executed correctly. At this point, it is tempting to expand the model solution further, for example, by measuring the performance of setter and getter methods in the enterprise bean to determine whether there are any start-up timing or reentrance problems. However, this effort may be wasted if performance is not a major risk or if this approach is eliminated because it fails to address another major risk. Therefore, this work should be attempted in an additional model problem intended to address a critical risk.



Modernizing Legacy Systems
Modernizing Legacy Systems: Software Technologies, Engineering Processes, and Business Practices
ISBN: 0321118847
EAN: 2147483647
Year: 2003
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net