Application Development A Cocktail of Java and MCP MCP Guru Series Dan Meyer & Pramod Nair
Agenda Which of the following topics can be found in an Application Development cocktail? o Calling Java from COBOL-85 o Using Java7 NIO2 features o Accessing DMSII from Java o All of the above o Some of the above o None of the above 2013 Unisys Corporation. All rights reserved. 2
A Cocktail of Java and MCP Calling Java from COBOL85
Application Development Wouldn t It Be Nice by the Beach Boys Wouldn't it be nice if we were older Then we wouldn't have to wait so long Wouldn't it be nice to live together In the kind of world where we belong You know its gonna make it that much better When we can say goodnight and stay together Wouldn t it be nice if: Your favorite programming language could be used for everything? You could find libraries that could be easily called and not support? There were an endless supply of COBOL programmers? What a Wonderful World that would be 2013 Unisys Corporation. All rights reserved. 4
Mixing Languages Through Libraries We Invented It Application Program Interface (Wii API) A was well documented, in-house developed standard Specific application during definition Communication over TCPIP (Socket-to-Socket) Common Object Request Broker Architecture (CORBA) A well-defined Object Management Group (OMG) standard Vendor-independent architecture and structure Communication over the Internet Inter-Orb Protocol (IIOP) Java Native Interface (JNI) A well-defined Java standard Defined for C Java DLL 2013 Unisys Corporation. All rights reserved. 5
COBOL???? COBOL app needs to access an Oracle database COBOL app needs to be web services enabled COBOL app needs to create a PDF file COBOL app needs to decrypt messages encrypted with COBOL app needs to 2013 Unisys Corporation. All rights reserved. 6
Java Invocation Interface (Jii) COBOL-85 (via ALGOL) calling Java methods Can invoke standard Java packages Usually need minimal Java code Native program is in control Uses Java as a private library JVM ends when the native program ends 2013 Unisys Corporation. All rights reserved. 7
Java Invocation Interface (Jii) API developed to call Java methods Simplified with com.unisys.mcp.tools.jifgen Reads Java source or class and generates entrypoint INCLUDE file Does all the dirty work of calling JNI methods Based on C JNI method definition in a generated ALGOL library Calls for identifying methods by name Calls for identifying objects by name Chatty and error prone Application JNI Interfaces JNI Proxy Lib Java Worker Java Worker Java Class JVM JProcessor 2013 Unisys Corporation. All rights reserved. 8
Jii Development Process Demo Create or identify a Java class with public methods Demo COBOL program needing to accessing remote database using data from a DMSII database Java application needs 3 methods Connect to the remote database getconnection() Close database connection releaseconnection() Retrieve record using key passed from COBOL-85 and compare data compareequal (int id, String word) UniverseDemo.zip Application JNI Interfaces JNI Proxy Lib Java Worker Java Worker Java Class JVM JProcessor 2013 Unisys Corporation. All rights reserved. 9
Jii Development Process Demo package com.unisys.mcp.universe; import java.sql.*; public class Demo { static Connection con = null; static PreparedStatement pstmt = null; static String url = jdbc:unisys:dmsql:unisys.dmsii ; public static boolean releaseconnection() { try { if (pstmt <> null) pstmt.close(); if (con <> null) con.close(); return true; } catch (SQLException seq) { sqe.printstacktrace(); return false; } } 2013 Unisys Corporation. All rights reserved. 10
Jii Development Process Demo public static boolean getconnection() { boolean onmcp = System.getProperty("os.name").contains("MCP"); String hostname = onmcp? EVLANMCP : ECCSK ; try { Class.forName ("com.unisys.jdbc.dmsql.driver ) url = url + resource=universedb; + host= + hostname + ;port=1897 + user=java;password=java ); con = DriverManager.getConnection (url); if (con == null) return false; pstmt = con.preparestatement ("SELECT * FROM universedb.words + where word_id =?"); if (pstmt == null) return false; return true; } catch (SQLException sqe) { sqe.printstacktrace(); return false; } } 2013 Unisys Corporation. All rights reserved. 11
Jii Development Process Demo public static boolean compareequal (int id, String worda) { worda = worda.trim(); try { pstmt.setint(1, id); ResultSet rs = pstmt.executequery(); if (rs.next() { String a = rs.getstring( dmsii_word_a ); if (a.compareto(worda)!= 0) { System.err.println (id + ) + a + <> + worda); return false; } } else { System.err.println (id + ) not found [ + worda + ] ); return false; } return true; } catch (SQLException sqe) { sqe.printstacktrace(); return false; } } 2013 Unisys Corporation. All rights reserved. 12
Jii Development Process Demo } public static void main (String args[]) { String command = select * from dmsii_words ); try { if (getconnection()) { Statement stmt = con.createstatement(); ResultSet rs = stmt.executequery(command); while (rs.next()) { int id = rs.getint ( word_id ); String worda = rs.getstring ( dmsii_word_a ); System.out.println ( ( + id + ) + worda.trim() + : + compareequal (id, worda.getbytes()) ); } rs.close(); stmt.close(); releaseconnection(); } } catch (Exception e) { ; } } 2013 Unisys Corporation. All rights reserved. 13
Jii Development Process Demo Run JifGen to create files to be used on MCP RUN *DIR/JRE7/BIN/MCPTOOLS ("JifGen -verbose -cobol -d /-/JAVA/USERCODE/JAVA/UD -classpath /-/JAVA/DIR/JAVA/universedemo.jar -output DEMO com.unisys.mcp.universe.demo") [Creating file /-/JAVA/USERCODE/JAVA/UD/DEMOINCL.C85_M] [Creating file /-/JAVA/USERCODE/JAVA/UD/DEMO.ALG_M] Application JNI Interfaces JNI Proxy Lib Java Worker Java Worker Java Class JVM JProcessor 2013 Unisys Corporation. All rights reserved. 14
Jii Development Process Demo Modify existing application to use Java methods Include sections from *DIR/JRE7/JDK/INCLUDE/JNILIB/COBOL Include sections from "DEMOINCL.C85_M CALL JNI-CREATE-JAVA-VM USING GIVING RESULT. Do work using the following generated entry points ENTRY PROCEDURE INITIALIZE-DEMO ENTRY PROCEDURE DEMO-DEMO-GET-CONNECTION ENTRY PROCEDURE DEMO-DEMO-RELEASE-CONNECTION ENTRY PROCEDURE DEMO-DEMO-COMPARE-EQUAL CALL JNI-DESTROY-JAVA-VM USING GIVING RESULT. Create ALGOL library DEMO/LIBRARY COMPILE UD/"DEMO.ALG_M AS DEMO/LIBRARY SL DEMO = (JAVA)OBJECT/DEMO/LIBRARY 2013 Unisys Corporation. All rights reserved. 15
Jii Development Process Demo LOCAL-STORAGE SECTION. $$INCLUDE JNICOB="COBOL" ("JNI-PARAMETERS") $$INCLUDE DEMOCOB="""DEMOINCL.C85_M""" ("DEMO-PARAMETERS") PROGRAM-LIBRARY SECTION. $$INCLUDE JNICOB="COBOL" ("JNI-FUNCTIONS") $$INCLUDE DEMOCOB="""DEMOINCL.C85_M""" ("DEMO-FUNCTIONS") PROCEDURE DIVISION. 2013 Unisys Corporation. All rights reserved. 16
Jii Development Process Demo Initialize-JVM. STRING jvmoptions, jvmcp1, jvmcp2, jvmcp3, jvmcp4 DELIMITED BY SIZE INTO ARGUMENTS. ADD FUNCTION Length ( jvmoptions ), FUNCTION Length ( jvmcp1 ), FUNCTION Length ( jvmcp2 ), FUNCTION Length ( jvmcp3 ), FUNCTION Length ( jvmcp4 ) GIVING ArgLength. MOVE MCP-Options TO Arguments-2. MOVE FUNCTION Length ( MCP-Options ) to Arg2Length. CALL JNI-CREATE-JAVA-VM USING JNI-VM, JNI-ENV, Interface-Version, ARGUMENTS, ArgLength ARGUMENTS-2, Arg2Length GIVING RESULT. CALL INITIALIZE-DEMO USING JNI-ENV. CALL DEMO-DEMO-GET-CONNECTION USING JNI-ENV, bresult. 2013 Unisys Corporation. All rights reserved. 17
Jii Development Process Demo OPEN INQUIRY UNIVERSEDB ON EXCEPTION GO TO XIT. loop-it. FIND WORD VIA NEXT IDX-WORDS ON EXCEPTION GO TO XIT. MOVE DMSII-WORD-A TO DataWord. MOVE WORD-SZ TO WordSz. CALL DEMO-DEMO-COMPARE-EQUAL USING JNI-ENV, WORD-ID, DataWord, WordSz, bresult. IF NOT bresult THEN DISPLAY "COMPARE STRING ERROR=", bresult. GO loop-it. xit. CLOSE UNIVERSEDB ON EXCEPTION NEXT SENTENCE. 2013 Unisys Corporation. All rights reserved. 18
Jii Possibilities? Calling Bouncy Castle Crypto API Accessing JBoss through its Java Naming and Directory Interface (JNDI) Accessing third-party databases Creating thumbnails of images PDF Generation Creating JSON data files Using off-the-shelf components written in Java http://www.componentsource.com/features/java-components/index.html 2013 Unisys Corporation. All rights reserved. 19
Guidelines for Calling Java Calling Java from native code is complicated and tedious. Crossing between MCP and the Java environment is expensive. Try to write heavy functions. Pass everything as parameters rather than calling back for more information. Stay in Java if you can; calling native code is seldom faster. 2013 Unisys Corporation. All rights reserved. 20
Java Docs Main Page Virtual Machine for the Java 6.0 Platform on ClearPath MCP Programming Guide Installation and Administration Guide ClearPath Common Appliance Configuration Guide JVM for MCP API Specification Java Native Interface for MCP Readme, Errata and Other Notes Optimizing Java Socket Performance Example Java Programs 2013 Unisys Corporation. All rights reserved. 21
A Cocktail of Java and MCP Using Java NIO2 Interfaces
Java 7 Java SE 7 Available with MCPJAVA in 15.0 New I/O features: Asynchronous I/O Ability to extend and customize the I/O interface. For MCP this means: Ability to query and specify many file attributes. 2013 Unisys Corporation. All rights reserved. 23
Java 7 Example import java.nio.file.*; import com.unisys.mcp.file.*; import static com.unisys.mcp.file.initialfileattributes.*; Path file = FileSystems.getDefault().getPath( args[0] ); file.createfile( FileKind.COBOL85SYMBOL.asFileAttribute(), FileClass.RECORDORIENTED.asFileAttribute(), maximumrecordsize(80), note("this file was created by Java") ); 2013 Unisys Corporation. All rights reserved. 24
Java 7 Example file.copyto( destination, StandardCopyOption.ReplaceExisting, McpCopyOption.Recursive, McpCopyOption.SourceHost( ECCSK ), Copies a file identified by the file path at ECCSK to the local host as the file identified by the destination path. Uses MCP copy operation (BNA, FTP). Similar moveto will change the file name, if possible; otherwise copy and delete the original. 2013 Unisys Corporation. All rights reserved. 25
McpFileAttributes Class Provides most MCP attributes for a file. All the various time stamps. Title Note and many more 2013 Unisys Corporation. All rights reserved. 26
File Attributes arealength accesstimestamp fileclass areas altertimestamp filekind blocksize attributemodifytimestamp filename clearareas backuptimestamp filestructure compilerkind copydestinationtimestamp framesize ccsversion copysourcetimestamp hostname extmode creationtimestamp licensekey familyindex executetimestamp note familyname opentimestamp pathname sensitivedata readtimestamp product userinfo maximumrecordsize title 2013 Unisys Corporation. All rights reserved. 27
Open Options Specify any of these when opening a file. File Options Buffers BufferSize HostName IntName Record Options Fold IncludeSequenceNumbers NoCrLf StripSpaces Truncate Unfold 2013 Unisys Corporation. All rights reserved. 28
Initial File Attributes Specify any of these when creating a file. arealength blocksize familyindex hostname note userinfo areas clearareas framesize maximumrecordsize sensitivedata 2013 Unisys Corporation. All rights reserved. 29
Java Docs Main Page Virtual Machine for the Java 6.0 Platform on ClearPath MCP Programming Guide Installation and Administration Guide ClearPath Common Appliance Configuration Guide JVM for MCP API Specification Java Native Interface for MCP Readme, Errata and Other Notes Optimizing Java Socket Performance Example Java Programs 2013 Unisys Corporation. All rights reserved. 30
A Cocktail of Java and MCP Accessing DMSII From Java
Accessing DMSII From Java DMSII Databases D M S Q L 2013 Unisys Corporation. All rights reserved. 32
Accessing DMSII From Java COBOL & ALGOL access via Host Language constructs OPEN, FIND/LOCK, CREATE, STORE, BEGIN-TRANSACTION, END-TRANSACTION, Java access Java Host Language Interface (JHLI) and Java DMInterface (JDMI) Java EE Connector Architecture (JCA) components Resource Adapters MCP Transaction Resource Adapter (JRAC) Open Distributed Transaction Processing Resource Adapter (DTP-RA) Java Database Connectivity (JDBC) Resource adapters based on JCA Structured Query Language (SQL) based Hibernate 2013 Unisys Corporation. All rights reserved. 33
Querying DMSII using JDBC SQL Client Tools DMSII 2013 Unisys Corporation. All rights reserved. 34
JDBC Driver DMSII-JDBC @ GSA ClearPath JProcessor MCP Presentation Tier/ Business Tier JSF/RichFaces POJO SQL Query Processor for ClearPath MCP DMSII 2013 Unisys Corporation. All rights reserved. 35
Summary Invocation interface lets ALGOL or COBOL program call Java libraries. Java 7 will allow tighter file system integration. Consider the alternatives for accessing a DMSII database from Java 2013 Unisys Corporation. All rights reserved. 36
Questions? 2013 Unisys Corporation. All rights reserved. 37