32
Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Embed Size (px)

Citation preview

Page 1: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Java Stored Procedures in DB2

for OS/390

Open, Portable Application Logic

Julian StuhlerDB2/CICS/IMS GUIDEMay 2000

Page 2: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Topics Introduction Java Stored Procedures – An

OverviewEnvironment Set-upDeveloping & Testing JSPsUsage ConsiderationsSummary

Page 3: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Introduction

Page 4: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

IntroductionDB2 consultant with Triton

Consulting, based in the UK14 years DB2 experience

Database Administration Systems Programming Application Development

IBM Gold ConsultantRedbook – DB2 Network

Computing Enhancements & Java Stored Procedures

Page 5: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

JSPs – An Overview

Page 6: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

What’s a Stored Procedure?

A program or routine executed by the database server in response to an SQL CALL statement issued by a client

Can receive and return parameters from / to calling client

Can enhance performance by replacing multiple SQL client calls

Can promote code re-use and consistency

Can improve security

Page 7: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Supported Languages

Can be written in a wide variety of languages Cobol C/C++ Assembler PL/1 REXX*

PSM*

Java*

* Needs additional APAR support for V5 and V6

Page 8: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Java Stored Procedures

Prerequisites OS/390 Unix System Services (USS) OS/390 Recoverable Resource Services

(RRS) and Workload Manager (WLM) DB2 For OS/390 V5 or V6 (with

necessary additional APARs) Enterprise Toolkit for OS/390 (part of

VisualAge for Java)Features

Open and fully portable code High Performance Java support JDBC (dynamic) and SQLJ (static)

support

Page 9: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

High Performance Java

HPJ compiler (part of ET/390) compiles Java into standard OS/390 machine code

Advantages Very high performance Retain code portability Allows WLM-managed stored procedures

address space to run Java SPs without JVM support

Disadvantages More complex program preparation

process

Page 10: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Java TerminologyClass

Equivalent to a module in traditional programming

Method Equivalent to an entry point in

traditional programmingPackage

A collection of related Java classes, “packaged” as a single unit

Not to be confused with a DB2 package!

Page 11: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Environment Overview

OS/390

USS

SourceCode

Links

SerialisedProfiles

WLM

ExecutingSP

DBRMLibrary

LoadLibrary

Page 12: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Runtime Environment

PROCEDURE RUNOPTS WLM_ENV ...

ADD_CUSTOMER ACMESOS/Add_customer.add_customer WLMJAVA

ProgramPreparation

Process

...CALL ADD_CUSTOMER (FIRSTNAME, ....)...

Client

SYSPROCEDURES (V5)

SYSROUTINES (V6)

JAVAENVDataset

1

2

USS Directory

ACMESOSPDSE Link

3

WLMJAVASP WLM Address Space

ADD_CUSTOMER5

via STEPLIB

via JAVAENV DD

ACMESOS4

HPJ load modulePDSE dataset

Via collection

bound in

client's plan

ACMESOS1 ACMESOS2 ACMESOS3 ACMESOS4

DB2 Packages

ACMESOS/Add_customer.sqlj

SQLJ Source

NAME SPECIFICNAME WLM_ENV ...

ADD_CUSTOMER ACMESOS/Add_customer.add_customer WLMJAVA

via CLASSPATH

via PDSE link 6

Page 13: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Environment Set-Up

Page 14: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Environment Set-UpComplex environmentPlenty of pre-requisites

OS/390 DB2

Allow plenty of time to install all pre-requisites and get sample applications working

Good communications needed between DB2 and USS systems support staff

Page 15: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Set-Up Tasks - 1Design library naming standards

USS High Performance Java (HPJ) libraries SQLJ/JDBC libraries Links directory Serialised profiles directory

OS/390 HPJ SQLJ load library Application stored procedure load library JAVAENV dataset DBRM library

Page 16: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Set-Up Tasks - 2Create .profile script

Probably subsystem-specificSet up new WLM environment for

JSPs Needs RRS enabled

Create HPJ versions of JDBC/SQLJ drivers

Create JAVAENV datasetTailor SQLJ properties and cursor

files, if necessary

Page 17: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Developing & Testing

Page 18: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

CodingMost standard Java constructs can

be usedSpecial code needed for null

handling E.g. to pass null input parameter from

JDBC client to a stored procedureSpecific code to handle SQLJ

iterators and result setsRefer to SC26-9018, Application

Programming Guide and Reference for Java

Page 19: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Program Prep - JDBC

Can run on any JDKplatform

Run on S/390 platform

prog.JAVA

Source

Java Compiler (JAVAC) prog.CLASS

JavaBytecode

JAR

Other CLASS files

.JAR file

Optional Step

DB2 Catalog

HPJ Compiler

JLL in PDSE

ExternalLink

1

3

2

4

CREATE PROCEDURE

orINSERT into

SYSPROCEDURES

Page 20: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Program Prep - SQLJ

SQLJ Translatorprog.SQLJ

SQLJSource

prog.JAVA

prog_SJProfile0.ser

ModfiedSource

Java Compiler (JAVAC) prog.CLASS

JavaBytecode

JAR

Other CLASS files

.JAR file

Optional Step

Profile Customiser

(DB2PROFC)

DB2 BIND PACKAGE

DB2 Catalog

HPJ Compiler

JLL in PDSE

ExternalLink

Can run on any JDKplatform

Run on S/390 platform

1

3

2

4

5

6

SerialisedProfile

prog_SJProfileKeys.class

DBRMDBRM

CREATE PROCEDURE

orINSERT into

SYSPROCEDURES

7

Page 21: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Error Handling & Debugging

Include provision for passing back results from SP in return parameters Consider passing back meaningful

message if problem encountered ( e.printStackTrace() )

As for other types of stored procedures, debugging can be a problem Output of Java println commands routed

to JSPDEBUG in WLM SP JCL Stored Procedure Builder and ET/390

Debugger tool provide additional facilities

Page 22: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Usage Guidelines

Page 23: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Naming IssuesSource files

One stored procedure (Java application class) per source file

Source file named after DB2 SP name Java package name

One to one relationship with HPJ load module

Use same name for PDS/E member name Group all related source files in single

USS directory named after packageMany others to be considered

Java class name, Java method, DB2 packages, JAR files, etc

Page 24: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

DB2 CollectionsEach SQLJ SP has 4 packages

associated with it (one for each isolation level)

Collection containing these SPs must appear in package list for client issuing SP CALL

Use one collection for each Java package, with same name as the package

For JDBC, collection named in client’s package list must contain 4 generic JDBC packages Collection name must match Java

package name

Page 25: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Case SensitivityUse upper case only for Java

package names on S/390 Ditto for other environments if

portability is important JDBC or SQLJ Java client calling a

stored procedure must code SP name in upper case

SQLJ stored procedure must refer to DB2 object names in upper case (else –204)

Page 26: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

PackagingCarefully consider number of SPs to

group in a single Java package Large number will result in large HPJ load

module for the package, which may need excessive WLM storage

Small number will result in many DB2 collections to manage

Rules of thumb Group together small, frequently used SPs Keep larger SPs in their own Java package Package remainder along application lines

Page 27: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

PortabilityNo code changes necessary to port

JSP source files from one platform to another (e.g. Windows NT to OS/390)

Some changes may be required when porting client code Class.forName (name of driver to be

loaded) Connection URL

Beware issues with ASCII/EBCDIC translation of Java curly brackets ({})

Page 28: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

PerformanceSignificant overhead on first use

of a given module Consider pre-staging critical

modules and keeping them in storage

Once in storage, performance on a par with other methods

Use different WLM application groups to correctly prioritise workload

Page 29: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Summary

Page 30: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Summary JSPs for DB2 for OS/390 provide

an open, scaleable, high-performance way of encoding an application’s business logic

Tread carefully in the short term; Complex environment set-up New application development skills DB2 code base still maturing

Page 31: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

Questions?

Page 32: Java Stored Procedures in DB2 for OS/390 Open, Portable Application Logic Julian Stuhler DB2/CICS/IMS GUIDE May 2000

For more information…

Triton ConsultingThe Royal

25 Bank PlainNorwich NR2 4SFUnited Kingdom

email:[email protected]://www.triton.co.uk

Tel: +44 (0) 870 2411550Fax: +44 (0) 870 2411549