Transcript IMS Java
E32
JDBC Access to IMS DB from DB2,
CICS, and Websphere
Christopher Holtz, Kyle Charlet
Las Vegas, NV
September 15 – September 18, 2003
IBM Corporation 2003
Overview
• IMS Java
– What Is IMS Java
– Why Use IMS Java
– IMS Java Class Library Architecture
• JDBC and J2EE
• Dealership Sample Application
– Front-end/Back-end split
• Environments
– Non-Managed
• IMS
• CICS
• DB2
– Managed
• WebSphere
IBM Corporation 2003
IMS Technical Conference
What is IMS Java?
• A new feature in IMS v7
• A set of classes that...
– Offers Java support to access IMS Databases from various
environments (IMS, CICS, DB2, WebSphere)
– Enables SQL access through the JDBC interface
• Java Virtual Machine (JVM) support in dependent regions
–
–
–
–
JDK 1.3 support
JDBC 2.1 support
Just-In-Time (JIT) compilation
Resetable JVM
IBM Corporation 2003
IMS Technical Conference
Why IMS Java?
•
Rapid Application Development
– Reduce the Total Cost of Ownership (TCO) for IT and Data Management
needs and Total Time to Value (TTV)
•
Extend the life and scope of IMS applications
– Minimum amount of impact on core applications and effort for
developers, system programmers, and DBAs
•
Leverage existing marketplace, industry-sanctioned standards they are the slowest changing and most persistent
– JDBC and J2EE are standards – help to minimize specific back end
knowledge of IMS
•
Leverage new and abundant skills in the marketplace and
mitigate the loss of 390 skills for customers
•
Integrate with other products
Our response is IMS Java, Web Services, WebSphere support, CICS
support, DB2 SP support
IBM Corporation 2003
IMS Technical Conference
Java Class Library
IMS DB Metadata
Business Logic
IMS Dep. Region
Transaction and
Message
Processing
A
p
p
Mapping
to DL/I
APIs
DLI
Database
View
IMS Java
App
Customer Code
JDBC / SQL
IMS Java Class Library
DB
Base
JNI
C Layer Interface to IMS
CEETDLI Interface
JDBC, JCA
interface
Java to C
interface
IBM Corporation 2003
IMS Technical Conference
IMS Java – The Big Picture
DLI
Database
View
IMS Java
DLI
Database
View
IMS Java
App
JCICS
A
p
p
Stored
Procedure
DLI
Database
View
IMS Java
App
JDBC / SQL
DB
Base
JNI
Java Virtual Machine
JDBC / SQL
DLI
Database
View
IMS Java
App
A
p
p
JDBC / SQL
DB
Base
DB
Base
JNI
JNI
CEETDLI Interface
CEETDLI Interface
JMP
ODBA
JBP
DRA
Java Virtual Machine
IMS DB
DLI
Database
View
IMS Java
App
A
p
p
EJB
A
p
p
Java Virtual Machine
Java Virtual Machine
I
F
P
DLI
Database
View
IMS Java
App
JNI
DB
JNI
B
M
P
DB
Base
CEETDLI Interface
CEETDLI Interface
Base
M
P
P
JDBC / SQL
JDBC / SQL
CEETDLI Interface
A
p
p
App
A
p
p
JDBC / SQL
DBDs
DB
Base
JNI
PSBs
COPYLIB
CEETDLI Interface
IBM Corporation 2003
IMS Technical Conference
Overview
• IMS Java
– What Is IMS Java
– Why Use IMS Java
– IMS Java Class Library Architecture
• JDBC and J2EE
• Dealership Sample Application
– Front-end/Back-end split
• Environments
– Non-Managed
• IMS
• CICS
• DB2
– Managed
• WebSphere
IBM Corporation 2003
IMS Technical Conference
JDBC and J2EE Standards Evolution
• Standard way to Query Database (relational)
– Structured Query Language (SQL)
• Communicating Query to Database
– Open Database Connectivity (ODBC) – C based
• Standard API to Query Database
– “Java Database Connectivity” (JDBC) – Platform/DB
Independent
• Standard API to Establish Connection
– J2EE Connection Architecture (JCA, J2C)
• Standard API to Build Enterprise Applications
– Java 2 Enterprise Edition (J2EE)
IBM Corporation 2003
IMS Technical Conference
J2EE Architecture
Applet
Container
Web Container
HTTP
SSL
Applet
JSP
EJB
Servlet
JAF
J2SE
JDBC
Java
Mail
RMI/IIOP
JTA
J2SE
JNDI
JMS
JAF
JDBC
Java
Mail
RMI/IIOP
JTA
Application
Client Container
JNDI
HTTP
SSL
JMS
J2SE
EJB Container
Database
Application
Client
JDBC
RMI/IIOP
JNDI
JMS
J2SE
IBM Corporation 2003
IMS Technical Conference
J2EE Connection Architecture
• Proposed Java standard architecture for deploying a
resource adapter in a J2EE compliant application server
• Defines contracts between...
– resource adapter and the application component
– resource adapter and the application server
IBM Corporation 2003
IMS Technical Conference
J2EE Connection Architecture
ContainerComponent
Contract
Application
Component
JDBC
Application
Server
System
Contracts
WebSphere
Resource Adapter
IMS Java
EIS specific interface
Enterprise
Information
System
IMS
IBM Corporation 2003
IMS Technical Conference
DataSource
• Factory for connections to a physical data source
• Replacement to the DriverManager facility
– Required when running in a managed environment
(WebSphere)
• Typically registered with a naming service based on the
Java™ Naming and Directory (JNDI) API.
– Names are associated with objects and objects are found based
on their names.
• DataSource objects have properties that can be modified
when necessary
– Code accessing the data source does not need to be changed
– (Properties include: DRA Name, DLIDatabaseView)
IBM Corporation 2003
IMS Technical Conference
DataSource Deployment
DataSource
AbcdefDB
DRA:
DBView:
EmployeeDB
DRA:
DBView:
SYS3
TestAppDatabaseView
DataSource
SYS1
TestApp2DatabaseView
JNDI
DataSource
Admin Tool
DRA: SYS1
DBView: AUTPSB11DatabaseView
IBM Corporation 2003
IMS Technical Conference
DataSource Deployment
DataSource
AbcdefDB
DRA:
DBView:
EmployeeDB
DRA:
DBView:
SYS3
TestAppDatabaseView
DataSource
DealershipDB
SYS1
TestApp2DatabaseView
DataSource
DRA:
DBView:
SYS1
AUTPSB11DatabaseView
JNDI
DataSource
Admin Tool
DRA: SYS1
DBView: AUTPSB11DatabaseView
IBM Corporation 2003
IMS Technical Conference
DataSource Retrieval
DataSource
AbcdefDB
DRA:
DBView:
DealershipDB
DRA:
DBView:
EmployeeDB
DRA:
DBView:
SYS3
TestAppDatabaseView
DataSource
SYS1
AUTPSB11DatabaseView
DataSource
SYS1
TestApp2DatabaseView
JNDI
DataSource
DRA: SYS1
DBView: AUTPSB11DatabaseView
EJB 1
DataSource
EJB 2
DRA: SYS1
DBView: AUTPSB11DatabaseView
IBM Corporation 2003
IMS Technical Conference
Overview
• IMS Java
– What Is IMS Java
– Why Use IMS Java
– IMS Java Class Library Architecture
• JDBC and J2EE
• Dealership Sample Application
– Front-end/Back-end split
• Environments
– Non-Managed
• IMS
• CICS
• DB2
– Managed
• WebSphere
IBM Corporation 2003
IMS Technical Conference
Dealership Sample Database
DEALER
MODEL
ORDER
SALES
SALESPER
STOCK
IBM Corporation 2003
SALESINF
IMS Technical Conference
Dealership Sample Application
• Performs specific queries to the database
– List all models
– List details of a particular model
• Split into a front-end and a back-end
• Front-End (Environment Specific)
–
–
–
–
Process message queue (IMS)
Invoke stored procedure (DB2)
JCICS application (CICS)
Enterprise Java Bean (WebSphere)
• Back-End (Environment Independent)
– Performs all query processing
– Sends data back to the caller (front-end)
IBM Corporation 2003
IMS Technical Conference
Dealership Sample (Back-End)
public class AutoDealership {
/** The database connection is created by each front-end and given
to the single back-end **/
public AutoDealership(Connection connection) {
this.connection = connection;
}
public Vector listModels() throws SQLException {
SQL processing logic here...
}
public Vector findCar(FindCarInput input) throws
SQLException {
SQL processing logic here...
}
}
IBM Corporation 2003
IMS Technical Conference
Dealership Sample (Back-End)
public Vector listModels() throws SQLException {
// Create the SQL statement - no inputs needed
String query = "SELECT * FROM Order.ModelSegment";
// Execute the query
Statement statement = connection.createStatement();
ResultSet results = statement.executeQuery(query);
process results...
}
IBM Corporation 2003
IMS Technical Conference
Dealership Sample (Back-End)
public Vector listModels() throws SQLException {
create statement and execute query...
Vector models = new Vector();
ListModelOutput output = null;
while (results.next()) {
output = new ListModelOutput();
output.setModelType(results.getString("ModelType"));
output.setMake(results.getString("Make"));
output.setModel(results.getString("Model"));
output.setYear(results.getString("Year"));
models.addElement(output);
}
return models;
}
IBM Corporation 2003
IMS Technical Conference
Overview
• IMS Java
– What Is IMS Java
– Why Use IMS Java
– IMS Java Class Library Architecture
• JDBC and J2EE
• Dealership Sample Application
– Front-end/Back-end split
• Environments
– Non-Managed
• IMS
• CICS
• DB2
– Managed
• WebSphere
IBM Corporation 2003
IMS Technical Conference
Running Environments
•
Non-Managed Environments
–
–
–
–
•
Managed Environments
– WebSphere 4.01 (JVM)
IMS TM 7.1 ( Resetable JVM)
IMS TM 8.1 (Resetable JVM)
CICS 2.1 (Resetable JVM)
DB2 V7 (Resetable JVM)
DLI
Database
View
IMS Java
App
JCICS
A
p
p
Stored
Procedure
DLI
Database
View
IMS Java
App
A
p
p
JDBC / SQL
DB
JNI
JDBC / SQL
Base
JNI
Java Virtual Machine
Java Virtual Machine
DLI
Database
View
IMS Java
App
I
F
P
DB
Java Virtual Machine
JNI
B
M
P
JDBC / SQL
CEETDLI Interface
CEETDLI Interface
M
P
P
EJB
A
p
p
DB
Base
A
p
p
DLI
Database
View
IMS Java
App
Base
CEETDLI Interface
JDBC / SQL
DLI
Database
View
IMS Java
App
A
p
p
JDBC / SQL
DB
Base
DB
Base
JNI
JNI
CEETDLI Interface
CEETDLI Interface
JMP
ODBA
JBP
DRA
Java Virtual Machine
IMS DB
IBM Corporation 2003
IMS Technical Conference
Non-Managed Connection Establishment
• Non-Managed Environment (IMS, DB2, CICS)
– An application can construct a DataSource prior to its use
• Alternatively, a DataSource can be bound to the namespace
– Application acquires a Connection from the DataSource
IMSJdbcManagedConnectionFactory mcf = new IMSJdbcManagedConnectionFactory();
mcf.setDRAName("SYS1");
mcf.setDatabaseViewName("samples.dealership.AUTPSB11DatabaseView");
DataSource dataSource = (DataSource)mcf.createConnectionFactory();
Connection connection = dataSource.getConnection();
IBM Corporation 2003
IMS Technical Conference
IMS TM Java Access to IMS Data
• Run in JVM
– IMS 7.1 or later
– JDK 1.3
– JDBC 2.1
• Can only connect to one PSB
• Synchpoints done by calls to application package
IBM Corporation 2003
IMS Technical Conference
IMS TM Java Access to IMS Data
// Import the IMS Java packages
import com.ibm.ims.db.*;
import com.ibm.ims.application.*;
public class IMSAuto {
/* Entry point of the application. */
public static void main(String args[]) {
// setup message queue access.
IMSMessageQueue messageQueue = new IMSMessageQueue();
InputMessage inputMessage = new InputMessage();
while (messageQueue.getUniqueMessage(inputMessage)) {
create connection…
call back-end…
reply to message queue…
commit…
}
}
}
IBM Corporation 2003
IMS Technical Conference
IMS TM Java Access to IMS Data
/* Entry point of the application. */
public static void main(String args[]) {
access message queue and get message...
// Get connection
IMSJdbcManagedConnectionFactory mcf = new IMSJdbcManagedConnectionFactory();
mcf.setDatabaseViewName("samples.dealership.AUTPSB11DatabaseView");
DataSource dataSource = (DataSource)mcf.createConnectionFactory();
Connection connection = dataSource.getConnection();
// Pass connection to back-end
AutoDealership autoDealership = new AutoDealership(connection);
// Call listModels method and get results in 'output' Object
Vector output = autoDealership.listModels();
reply to message queue...
commit...
}
IBM Corporation 2003
IMS Technical Conference
IMS TM Java Access to IMS Data
/* Entry point of the application. */
public static void main(String args[]) {
access message queue and get message...
create connection...
call back-end...
// Format and insert output message
OutputMessage outputMessage = new OutputMessage(output);
messageQueue.insertMessage(outputMessage);
// Close connection and commit database before we get next Message.
connection.close();
IMSTransaction.getTransaction().commit();
}
}
IBM Corporation 2003
IMS Technical Conference
CICS Java Access to IMS Data
• Run in JVM
– CICS TS 2.1
– JCICS API
• Java version of the CICS API
– JDK 1.3
– JDBC 2.1
• Can only connect to (allocate) one PSB at a time
– Only one Connection active at a time in an application
• Synchpoint done at deallocate PSB
IBM Corporation 2003
IMS Technical Conference
CICS Java Access to IMS Data
// Import the JCICS package
import com.ibm.cics.server.*;
public class CICSAuto {
private static Task task = Task.getTask();
/* Invoked when the CICS transaction corresponding to this class
is executed. */
public static void main(CommAreaHolder cah) {
CICSAuto application = new CICSAuto();
application.listModels();
}
/* The listModels method provides a collection of all automobile
models in the database */
public void listModels() {
method logic here...
}
}
IBM Corporation 2003
IMS Technical Conference
CICS Java Access to IMS Data
/* The listModels method provides a collection of all automobile
models in the database */
public void listModels() {
// Get connection
IMSJdbcManagedConnectionFactory mcf = new IMSJdbcManagedConnectionFactory();
mcf.setDatabaseViewName("samples.dealership.AUTPSB11DatabaseView");
DataSource dataSource = (DataSource)mcf.createConnectionFactory();
Connection connection = dataSource.getConnection();
// Pass connection to back-end
AutoDealership autoDealership = new AutoDealership(connection);
// Call listModels method and get results in 'output' Object
Vector output = autoDealership.listModels();
display results...
}
IBM Corporation 2003
IMS Technical Conference
DB2 Stored Procedure Support
• Run in JVM
– DB2 Version 7
– APAR PQ46673 (resetable JVM)
• Stored Procedures that access IMS Databases
– User-written structured query language (SQL) programs that are
stored at the DB2 server and can be invoked by a client
application
• DB2 handles synchpoint (not stored procedure)
• DRA table and name required
IBM Corporation 2003
IMS Technical Conference
DB2 Stored Procedure Support
public class DB2Auto() {
public static void listModels(String[] make, String[] model) {
// Get connection
IMSJdbcManagedConnectionFactory mcf = new IMSJdbcManagedConnectionFactory();
mcf.setDRAName("SYS1");
mcf.setDatabaseViewName("samples.dealership.AUTPSB11DatabaseView");
DataSource dataSource = (DataSource)mcf.createConnectionFactory();
Connection connection = dataSource.getConnection();
// Pass connection to back-end
AutoDealership autoDealership = new AutoDealership(connection);
Vector output = autoDealership.listModels();
// Return data to client
make[0] = ((ListModelOutput)output.elementAt(0)).getMake();
model[0] = ((ListModelOutput)output.elementAt(0)).getModel();
}
}
IBM Corporation 2003
IMS Technical Conference
Managed Connection Establishment
• Managed Environment (WebSphere)
– DataSource deployed in JNDI namespace using:
• WebSphere Application Server for z/OS and OS/390
Administration tool (4.01)
• Web UI tool (5.0)
– Application (EJB) makes a request for the DataSource and
acquires a Connection from it
Context ctx = new InitialContext();
DataSource dataSource = (DataSource)ctx.lookup("DealershipDB");
Connection con = dataSource.getConnection();
IBM Corporation 2003
IMS Technical Conference
WebSphere 4.01, 5.0 Support
• Runs in JVM
– JDK 1.3
– JDBC 2.1
• Applications run as Enterprise Java Beans (EJBs)
• Access IMS databases through ODBA/DRA
• J2EE Connection Architecture
– Managed Environment
• Connections are managed by application server
IBM Corporation 2003
IMS Technical Conference
Enterprise Archive (EJB)
public Vector listModels() throws javax.ejb.EJBException {
InitialContext initialContext = new InitialContext();
// perform JNDI lookup to obtain the DataSource and get the Connection
DataSource dataSource = (DataSource)initialContext.lookup("DealershipDB");
Connection connection = dataSource.getConnection();
AutoDealership dealer = new AutoDealership(connection);
Vector output = dealer.listModels();
return output;
}
IBM Corporation 2003
IMS Technical Conference
Overview of Application Development Steps
• Obtain Resource Adapter Archive (.rar)
– Deploy Resource Adapter Archive (install into server)
• Deploy DataSource (represents connection to a database)
– Deploy Resource Adapter Instance
• Build and Deploy Enterprise Archive (.ear)
– Two main development components
• Servlet
– Accesses EJB and invokes methods on the EJB
• EJB
– Accesses deployed DataSource (resource adapter
instance)
– Uses DataSource to connect to database and performs
business logic
IBM Corporation 2003
IMS Technical Conference
ra.xml
Deploy IMS Java Resource Adapter
A
p
p
JDBC / SQL
DB
• We provide a J2EE Resource Adapter Archive
(RAR) file containing:
Base
JNI
CEETDLI Interface
– Deployment descriptor (ra.xml)
– IMS Custom Service (IMSJdbcCustomService.xml)
• Handles initialization and termination of IMS
– Latest information associated with installing the IMS JDBC
resource adapter (howto.html)
• WebSphere will provide tooling to deploy RAR file into
server
– Add IMS Custom Service
– Set CLASSPATH and LIBPATH
– Understand how to deploy an instance of an IMS Java Resource
Adapter (via ra.xml)
IBM Corporation 2003
IMS Technical Conference
DataSource Deployment
• Use WebSphere Application Server for z/OS and OS/390
Administration tool
– Shipped with WebSphere on OS/390
• Create J2EE Resource Instance
– Specify IMSJdbcDataSource as the J2EE Resource Type
• Configure
– DRA Startup Table
– Generated DLIDatabaseView
JNDI
• Deploy
Admin Tool
DataSource
DRA: SYS1
DBView: AUTPSB11DatabaseView
IBM Corporation 2003
IMS Technical Conference
Build and Deploy Enterprise Archive (ear)
Enterprise Archive (.ear)
•
J2EE Enterprise Application Archive
application.xml
– Complete J2EE application
Web Archive (.war)
•
web.xml
Must contain
– One or more J2EE modules
HTML Servlet
(Java Archive)
JSP
– Deployment descriptor (application.xml)
• Represents a top level view of a J2EE
application's contents
•
Java Archive (.jar)
ejb-jar.xml
Home Remote
EJB
May contain
– One or more Web modules (Web Archive)
– Libraries referenced by J2EE modules
IBM Corporation 2003
IMS Technical Conference
Enterprise Archive (Servlet)
Web Archive (.war)
web.xml
HTML
• Looks up the EJB home interface in JNDI
Servlet
JSP
• Using the home interface, creates the EJB remote
interface
• Invokes methods on the remote interface
– Remote interface uses IIOP to communiate to EJB
• Pass-through interface
• Passes results of method to a Java Server Page (JSP) for
displaying on a web browser
IBM Corporation 2003
IMS Technical Conference
Enterprise Archive (EJB)
Java Archive (.jar)
ejb-jar.xml
Home
• Receives requests from the servlet
Remote
EJB
• Obtains a connection
– Looks up the deployed DataSource instance and requests a
connection from it
• Accesses the database(s) and performs business logic
• Sends the results back to the servlet to display
IBM Corporation 2003
IMS Technical Conference
WebSphere Runtime
JNDI
Home
Websphere z/OS
A
p
p
Enterprise Archive (.ear)
JDBC / SQL
DB
Base
JNI
CEETDLI Interface
application.xml
Web Archive (.war)
Java Archive (.jar)
ejb-jar.xml
web.xml
HTML
Servlet
Home
Remote
EJB
JSP
IBM Corporation 2003
IMS Technical Conference
WebSphere Runtime
JNDI
Home
Websphere z/OS
Servlet
EJB
HTML
A
p
p
JSP
JDBC / SQL
DB
Base
JNI
CEETDLI Interface
application.xml
Web Archive (.war)
Java Archive (.jar)
ejb-jar.xml
web.xml
HTML
Servlet
Home
Remote
EJB
JSP
IBM Corporation 2003
IMS Technical Conference
WebSphere Runtime
DataSource
JNDI
Home
DRA:
SYS1
DBView: AUTPSB11DatabaseView
Websphere z/OS
DataSource
DRA:
SYS1
DBView: AUTPSB11DatabaseView
Servlet
Home
EJB
HTML
Remote
JSP
A
p
p
JDBC / SQL
Connection
DB
Base
JNI
CEETDLI Interface
HTTP
IBM Corporation 2003
IMS Technical Conference
Remote Database Services
• Available IMS Version 9
• Ability to access IMS DL/I data from a distributed J2EE server
• Complete client application deployed on distributed server
– Distributed functionality is transparent to client application
– Websphere Application Server 5.0 for z/OS
still required (server-side)
• All client-server communication is handled by new IMS Java
components
– IMS JDBC distributed Resource Adapter (client-side RAR)
– Container Managed EJB (server-side EAR)
– Bean Managed EJB (server-side EAR)
IBM Corporation 2003
IMS Technical Conference
WebSphere Runtime
JNDI
Home
Websphere z/OS
Websphere z/OS, distributed
BM EJB
EJB
Servlet
JDBC
JSP
CM EJB
JCA RA
HTML
Enterprise Archive (.ear)
A
p
p
JDBC / SQL
DB
Base
JNI
CEETDLI Interface
application.xml
Web Archive (.war)
Java Archive (.jar)
ejb-jar.xml
web.xml
HTML
Servlet
Home
Remote
EJB
JSP
IBM Corporation 2003
IMS Technical Conference
WebSphere Runtime
Home
JNDI
Home
DataSource
DataSource
Websphere z/OS
Websphere z/OS, distributed
Remote
BM EJB
EJB
Connection
Servlet
IIOP
JDBC
CM EJB
JCA RA
JSP
HTML
ORB
Connection
A
p
p
JDBC / SQL
DB
Base
JNI
CEETDLI Interface
HTTP
IBM Corporation 2003
IMS Technical Conference
Conclusion
Managed
Non-Managed
J2EE Application
HTML
IMS JMP/JBP
JCICS
Client
Servlet
JSP
DB2 Stored Proc
EJB
Application
Application
Common
Common
Common
Stored
Procedure
Common
Application
(Query
Processing)
DLI
Database
View
Common
A
p
p
JDBC / SQL
DB
Base
ODBA
JNI
DRA
CEETDLI Interface
IMS DB
IBM Corporation 2003
IMS Technical Conference