pre-con ed: using java to access your ca idms databases and applications

97
World ® ’1 6 Using Java to Access Your CA IDMS Databases and Applications David Ross, Sr. Principal Product Owner CA Technologies MFX74E MAINFRAME AND WORKLOAD AUTOMATION

Upload: ca-technologies

Post on 08-Feb-2017

152 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

World®’16

UsingJavatoAccessYourCAIDMSDatabasesandApplicationsDavidRoss,Sr.PrincipalProductOwnerCATechnologies

MFX74E

MAINFRAMEANDWORKLOADAUTOMATION

Page 2: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

2 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

Abstract

ManyusersarefocusedondevelopingnewapplicationsinJava,butstillhavealargeinvestmentinCAIDMSdatabasesandapplications.ThissessionshowshowyoucanuseJDBCandSQLtoleverageyourCAIDMSdatabasesandbusinesslogicfromyourJavaapplications.ItincludesanoverviewofJavaprogrammingconceptsandJDBCforthosenewtoJava,aswellasmoreadvancedtopicsformoreexperiencedusers.

DavidRoss

CATechnologiesSr.PrincipalProductOwner,CAIDMS

Page 3: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

3 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

Agenda

OOPSCONCEPTS

JAVAPROGRAMMINGELEMENTS

JDBCOVERVIEWANDSAMPLEAPPLICATION

JAVAPERSISTENCEANDHIBERNATEWITHCAIDMS

ADVANCEDCAIDMSJDBCFEATURES

1

2

3

4

5

Page 4: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

4 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

OOPSConcepts

Page 5: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

5 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

ObjectOrientedProgramming

§ Objects

§ Messages

§ Classes

§ Inheritance

Page 6: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

6 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

Object

§ Softwarebundle– Variables– Methods

§ State

§ Behavior

PrivateImplementationDetails

PublicAPI

Page 7: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

7 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

Message

§ Howobjectsinteract

§ Components– Objectaddress– Methodname– Parameters

ObjectA

ObjectB

Message

Page 8: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

8 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

Class

§ Object“blueprint”

§ Members– Class– Instance

PrivateImplementationDetails

PublicAPI

Page 9: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

9 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

Inheritance

§ Superclass– Commonbehavior– Reusable

§ Subclass– Specializedbehavior– Overridemethods– Hidevariables

Subclasses

Superclass

Page 10: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

10 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

JavaProgrammingElements

Page 11: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

11 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

Java

§ Objectorientedprogramminglanguage

§ Softwareplatform– JavaVirtualMachine– JavaApplicationProgrammingInterface

Page 12: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

12 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

JavaLanguageElements

§ class

§ interface

§ package

§ exception

§ import

Page 13: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

13 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

Class

§ Basicprogrammingunit

§ Members– Variables– Methods

Page 14: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

14 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

Interface

§ Morethanaheader

§ Named“protocol”– Definesabstractmethods– Declaresconstants

§ Classesimplementinterfaces

§ Referencetype

Page 15: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

15 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

Package

§ Likealibrary

§ Related– Classes– Interfaces– Exceptions

§ #importintoJavaprogram

Page 16: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

16 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

JDBCOverview

Page 17: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

17 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

JDBCConcepts

§ “JavaDataBaseConnectivity”

§ CallLevelInterface

§ ObjectOriented

§ Interoperability

§ AnyJavaplatform

Page 18: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

18 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

JDBCArchitecture

JavaApplication

JDBCDriverManager

JDBCDriver

URL

Driverinterface

NetworkandDBMS

JDBCDriver

URL

Page 19: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

19 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

JDBCObjects

§ Packages– java.sql– Javax.sql

§ Interfaces

§ Classes

§ Exceptions

Page 20: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

20 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

JDBCClasses

§ DriverManager

§ DriverPropertyInfo

§ Types

§ Date

§ Time

§ Timestamp

Page 21: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

21 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

CommonlyUsedJDBCInterfaces

§ Driver

§ DataSource

§ Connection

§ DatabaseMetaData

§ Statement

§ CallableStatement

§ PreparedStatment

§ ResultSet

§ ResultSetMetaData

Page 22: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

22 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

JDBCExceptions

§ SQLException

§ SQLWarning

§ DataTruncation

Page 23: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

23 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

JDBCObjectRelationships

ResultSet

Statement

ResultSet

Statement

Connection

Statement

Connection

DriverManager

Page 24: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

24 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

SampleJDBCApplication

Page 25: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

25 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

JDBCQueryApplication

§ SimplifiedversionofIdmsExample– IncludedwithCAIDMSServer– CanexecuteanySQLstatement– Javaversionof“BCF”

§ Connecttoadatabase

§ Executeaquery

§ Retrieveresults

§ Handleerrors

Page 26: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

26 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

Housekeeping

import java.io.*; // standard outputimport java.sql.*; // basic JDBC classes

class JdbcExample{

public static void main (String[] args) {

// register drivertry{Class.forName("ca.idms.jdbc.IdmsJdbcDriver");

Page 27: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

27 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

GetConnected

// set connection informationString url = "jdbc:idms://host:3709/dictname"; String uid = “userid"; String pwd = “password";

// get a connection to the databaseConnection conn = DriverManager.getConnection(url, uid, pwd);

Page 28: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

28 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

Here’stheMeat

// get a statement object to…Statement stmt = conn.createStatement();

// execute the query and get a result setResultSet rs = stmt.executeQuery("SELECT EMPFNAME, EMPLNAME FROM DEMO.EMPL");

// get and display the result set columnswhile (rs.next())System.out.println(

rs.getString(1) + " " + rs.getString(2));

Page 29: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

29 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

ThePuntingGame

// disconnectconn.close();

}catch (ClassNotFoundException e){System.out.println("No driver: " + e);

}catch (SQLException e){System.out.println("SQL Error: " + e);

}}

}

Page 30: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

30 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

JavaPersistenceAPIandHibernate

Page 31: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

31 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

ObjecttoRelationalMapping

••Neednotbe1-1Class

••InstantiationObject

••DatamemberAttribute

••ReferencesRelationship

••Neednotbe1-1Table

••OccurrenceRow

Column

••ForeignkeysReferentialconstraint

Object Relational(SQL)

Page 32: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

32 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

ObjecttoRelationalMappingSoftware

Providerruntime••GeneratesSQL••Reflection••Mappingdefinitions

Objectdefinitiontools••Schemadefinition••Reverseengineering

Implementations••JavaPersistenceArchitecture(JPA)••Hibernate

Page 33: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

33 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

SchemaGeneration

§ AutomaticallygeneratesDBschemafromobjects

§ MostusefulforprototypingDB

§ Physicaltuningalwaysmanual

§ Over-relianceonORMcanleadtopoorDBdesign

§ DBAshoulddofinaldesign

Page 34: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

34 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

ReverseEngineering

§ Createobjectdefinitionsfromdatabase

§ Mostapplicationdatabasesalreadyexist

§ Notbiasedtowardasingleapplication

§ MostORMframeworksprovidereverseengineeringtool

§ UsesdatabasemetadataAPI’stodiscover– Entities– Attributes– Relationships

Page 35: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

35 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

JPAandHibernateArchitecture

SQLDBMS

JDBCDriver

JPA/HibernateProvider

Application

Page 36: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

36 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

JPAEntities

§ Entity– Representsapplicationobject– Mayrepresentdatabasetable– POJO

§ EntityManager– Managesstateandlifecycleof

entity§ Persist§ CreateEntityGraph§ Remove§ Find(usesprimarykey)§ Query§ Transaction

Page 37: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

37 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

ReflectionandannotationsHowJPAworks

§ Reflection– Discoverclasses,fields,methodsincode– Dependsoncodingconventions(get,set,etc.)

§ Annotations– Metadataincodeaboutclasses,fields,methods– RelateJavaobjectstodatabasetables– LanguagefeatureintroducedinJ2SE5– @<name>(optionalarguments)– Extensiveuseofdefaults– AlternativetoXMLdescriptorfiles

Page 38: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

38 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

JPAannotations

§ @Entity

§ @Table

§ @Column

§ @Id

§ @OneToMany

§ @ManyToMany

§ @Inheritance

§ Manymore…

Page 39: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

39 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

UsingHibernatewithCAIDMS

Page 40: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

40 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

CAIDMS19.0SQLandHibernate

§ EnhancedcompatibilitywithCAIDMS19.0– EliminatesmostcustomizationofgeneratedJavacode

§ Reverseengineering– VirtualForeignKeys

§ Schemageneration– StandardConstraint DDL

Page 41: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

41 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

HibernateReverseEngineering

Page 42: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

42 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

UsingHibernateWithCAIDMS

EMPLOYEE

415

EMP-ID-0415

EMP-DEMO-REGION

F 116 CALC

DN

COVERAGE

400

EMP-COVERAGE

INS-DEMO-REGION

F 16 VIA

EMP-COVERAGENPOMAFIRST

••EMPLOYEE••COVERAGE

Employeedatabase

••ReverseEngineering

••VirtualForeignKeysTechniques

••Employee••Coverage

Entityclasses

Page 43: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

43 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

ReverseEngineeredEmployeeClassPrimarykeyROWIDandsetCoverage

@Entity@Table(name = "EMPLOYEE")public class Employee implements java.io.Serializable {

private byte[] rowid;private short empId;...private Set<Coverage> coverages = new HashSet<Coverage>(0);

// remaining private member variables for each column...public Employee() {}

@Id@Column(name = "ROWID")public byte[] getRowid() {

return this.rowid;}

Page 44: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

44 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

ReverseEngineeredEmployeeClassRelatedtoCoverageinaOneToMany relationship

@OneToMany(fetch = FetchType.LAZY,mappedBy = "employee")public Set<Coverage> getCoverages() {

return this.coverages;}public void setCoverages(Set<Coverage> coverages) {

this.coverages = coverages;}

// access methods for each member variable...}

Page 45: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

45 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

ReverseEngineeredCoverageClassPrimarykeyROWIDandReferencetoOwningEmployeeObject

@Entity@Table(name = "COVERAGE")public class Coverage implements java.io.Serializable {

private byte[] rowid;private Employee employee;...

public Coverage() {}@Id@Column(name = "ROWID")public byte[] getRowid() {

return this.rowid;}public void setRowid(byte[] rowid) {

this.rowid = rowid;}

Page 46: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

46 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

ReverseEngineeredCoverageClassRelatedToemployeeinManyToOne Relationship

@ManyToOne(fetch = FetchType.LAZY)@JoinColumn(name = "FKEY_EMP_COVERAGE")public Employee getEmployee() {

return this.employee;}public void setEmployee(Employee employee) {

this.employee = employee;}

// access methods for each member variable...}

Page 47: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

47 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

§ CustomizeEmployeeclass– AddreferencetomemberobjectCoverage– Usesetspecificationinsteadofforeignkey

§ CustomizeCoverageclass– AddROWIDasprimarykey– Addreferencetoownerobject

§ Populatesetoccurrenceobjectsinbusinesslogic

It’sMoreWorkWithoutVirtualForeignKeys

Page 48: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

48 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

@SqlResultSetMapping(name = "EmpCoverageResult", entities = {

@EntityResult(entityClass=Coverage.class)})

@NamedNativeQuery(name="GetEmpCoverage",query=

"SELECT c.ROWID, c.* FROM " +"EMPSCHM.EMPLOYEE e, EMPSCHM.COVERAGE c " +"WHERE EMP_ID_0415 = :empID " +"AND \"EMP-COVERAGE\"",

resultSetMapping="EmpCoverageResult")

ModifiedEmployeeClass

Page 49: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

49 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

PopulateSetOccurrenceObjectsEntityManagerFactory emf =

Persistence.createEntityManagerFactory("NonSqlJPA");EntityManager em = emf.createEntityManager();

Employee e = em.getReference(Employee.class, 23);

Query q = em.createNamedQuery("GetEmpCoverage");q = q.setParameter(1, 23);List<Coverage> l = List<Coverage>)q.getResultList();e.setCoverage(l);

Iterator<Coverage> ci = e.getCoverage().iterator();while (ci.hasNext()){

Coverage c = ci.next();c.setEmployee(e);

}

Page 50: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

50 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

ObjecttoRelationaltoNetworkMappingSetOccurrenceExposedasObjects

c.ROWID c.YEAR c.TYPE08010202 2008 F08010204 2009 F08010210 2010 M08010303 2011 F

EMP23

COV2008

COV2009

COV2010

COV2011

DatabaseSetOccurrence

SQLQueryResultSet

JavaObjects

Employee e = {23, Joe, …}List<Coverage> coverage = {e, 08010202, 2008, F, …}

{e, 08010204, 2009, F, …}{e, 08010210, 2010, M, …}{e, 08010303, 2011, F, …}

Page 51: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

51 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

HibernateSchemaGeneration

Page 52: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

52 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

POJO:PlainOldJavaObjects

Employee

Department

Page 53: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

53 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

PlainOldJavaEmployeepublic class Employee {

private String employeeSSN;private String employeeName;private String employeeTitle;private Dept employeeDept;private int employeeSalary;

public Employee(String employeeName, String employeeTitle, String employeeSSN, Dept employeeDept, int employeeSalary) {

this.employeeName = employeeName;this.employeeTitle = employeeTitle;this.employeeSSN = employeeSSN;this.employeeDept = employeeDept;this.employeeSalary = employeeSalary;

}

public int getEmployeeSalary() {return employeeSalary;

}

public void setEmployeeSalary(int employeeSalary) {this.employeeSalary = employeeSalary;

}//more getter/setters

Page 54: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

54 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

PlainOldJavaDepartmentpublic class Dept {

private long deptId;private String deptName;private Set<Employee> deptEmployeeNumbers = new HashSet<Employee>(0);

public Dept (String deptName, int deptId) {

this.deptName = deptName;this.deptEmployee = new HashSet<Employee>(0);this.deptId = deptId;

}

public long getDeptId() {return this.deptId;

}

public void setDeptId(long deptId) {this.deptId = deptId;

}}

Page 55: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

55 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

AddAnnotationstoEmployee@Entity@Table(name = "EMPLOYEE")public class Employee {

@Id@Column(name = "SSN", length=15)private String employeeSSN;

@Column(name = "NAME", length=10)private String employeeName;

@Column(name = "TITLE", length=15)private String employeeTitle;

@ManyToOne(optional = false) @JoinColumn(name = "DEPT_ID", nullable = false) private Dept employeeDept;

@Column(name = "SALARY", nullable = false, length=15)private int employeeSalary;

Page 56: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

56 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

AddAnnotationstoDepartment@Entity@Table(name = "DEPT")public class Dept {

@Id@Column(name = "DEPT_ID")private long deptId;

@Column(name = "DEPT_NAME", nullable = false, length = 100)private String deptName;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "employeeDept")private Set<Employee> deptEmployee = newHashSet<Employee>(0);

Page 57: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

57 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

PersistingObjectSession session = HibernateUtil.getSessionFactory().openSession();Transaction transaction = transaction = session.beginTransaction();

//Create a DepartmentDept devDept = new Dept("Mainframe", 1);

//Add EmployeesdevDept.addEmployee("James", "Scrum Master", "111223333", 50000);...

//Save the departmentsession.save(devDept);

//flush the sessiontransaction.commit();

//close the connectionsession.close();

Page 58: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

58 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

DDLtocleanupalter table IUA.EMPLOYEE

drop constraint FK75C8D6AEFF9D0229;

drop table IUA.DEPT cascade;

drop table IUA.EMPLOYEE cascade;

Page 59: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

59 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

Createtables

create table IUA.DEPT (DEPT_ID integer not null,DEPT_NAME varchar(100) not null,primary key (DEPT_ID)

);

create table IUA.EMPLOYEE (SSN varchar(15) not null,NAME varchar(20),TITLE varchar(255),SALARY integer not null,DEPT_ID integer not null,primary key (SSN)

);

Page 60: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

60 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

AddConstraint

alter table IUA.EMPLOYEE add constraint FK75C8D6AEFF9D0229 foreign key (DEPT_ID) references IUA.DEPT

Page 61: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

61 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

Databaserepresentation

DEPT

EMPLOYEE

FK75C8D6AEFF9…

Page 62: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

62 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

CreateDepartmentinsert

intoIUA.DEPT(DEPT_NAME, DEPT_ID)

values(?, ?)

10:14:42 DEBUG StringType:80 - binding 'Mainframe' to parameter: 110:14:43 DEBUG LongType:80 - binding '1' to parameter: 2

Page 63: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

63 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

CreateEmployeesinsert

intoIUA.EMPLOYEE(NAME, TITLE, DEPT_ID, SALARY, SSN)

values(?, ?, ?, ?, ?)

10:14:43 DEBUG StringType:80 - binding 'Mary' to parameter: 110:14:43 DEBUG StringType:80 - binding 'Product Owner' to parameter: 210:14:43 DEBUG LongType:80 - binding '1' to parameter: 310:14:43 DEBUG IntegerType:80 - binding '85000' to parameter: 410:14:43 DEBUG StringType:80 - binding '333445555' to parameter: 5

Page 64: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

64 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

AddnewEmployee//Find Department based on IDDept devDept= (Dept) session.get(Dept.class, 1);

selectdept0_.DEPT_ID as DEPT1_0_0_,dept0_.DEPT_NAME as DEPT2_0_0_

fromIUA.DEPT dept0_

wheredept0_.DEPT_ID=?

Page 65: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

65 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

AddnewEmployee//Add new employee to the DepartmentdevDept.addEmployee("Joe", "Developer", "123456789", 199);

selectdeptemploy0_.DEPT_ID as DEPT5_1_,deptemploy0_.SSN as SSN1_,deptemploy0_.SSN as SSN1_0_,deptemploy0_.NAME as NAME1_0_,deptemploy0_.TITLE as TITLE1_0_,deptemploy0_.DEPT_ID as DEPT5_1_0_,deptemploy0_.SALARY as SALARY1_0_

fromIUA.EMPLOYEE deptemploy0_

wheredeptemploy0_.DEPT_ID=?

Returns all of the Employees in the department with ID=1.

Page 66: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

66 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

AddnewEmployee

//Save the departmentsession.save(devDept);

//close the transactiontransaction.commit();

insertinto

IUA.EMPLOYEE(NAME, TITLE, DEPT_ID,

SALARY, SSN) values

(?, ?, ?, ?, ?)

Page 67: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

67 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

ModifyEmployee//Find employee based on SSNEmployee e1 = (Employee) session.get(Employee.class, "111223333");

selectemployee0_.SSN as SSN1_1_,employee0_.NAME as NAME1_1_,employee0_.TITLE as TITLE1_1_,employee0_.DEPT_ID as DEPT5_1_1_,employee0_.SALARY as SALARY1_1_,dept1_.DEPT_ID as DEPT1_0_0_,dept1_.DEPT_NAME as DEPT2_0_0_

fromIUA.EMPLOYEE employee0_

inner joinIUA.DEPT dept1_

on employee0_.DEPT_ID=dept1_.DEPT_ID where

employee0_.SSN=?

09:14:18,956 DEBUG StringType:80 - binding '111223333' to parameter: 1

Page 68: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

68 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

ModifyEmployee

09:14:19,039 DEBUG LongType:122 - returning '1' as column: DEPT1_0_0_09:14:19,042 DEBUG StringType:122 - returning 'Mainframe' as column: DEPT2_0_0_09:14:19,043 DEBUG StringType:122 - returning 'James' as column: NAME1_1_09:14:19,043 DEBUG StringType:122 - returning 'Scrum Master' as column: TITLE1_1_09:14:19,044 DEBUG LongType:122 - returning '1' as column: DEPT5_1_1_09:14:19,044 DEBUG IntegerType:122 - returning '100000' as column: SALARY1_1_

Page 69: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

69 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

ModifyEmployee

updateIUA.EMPLOYEE

setNAME=?,TITLE=?,DEPT_ID=?,SALARY=?

whereSSN=?

int empSalary = e1.getEmployeeSalary();e1.setEmployeeSalary(empSalary*2);//double salary

//Save the new Employeesession.save(e1);

Page 70: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

70 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

DeleteEmployee

//Find employee based on SSNEmployee e1 = (Employee) session.get(Employee.class, "123456789");

//Delete employeesession.delete(e1);

//close the transactiontransaction.commit();

deletefrom

IUA.EMPLOYEE where

SSN=?

11:54:43 DEBUG StringType:80 - binding '123456789' to parameter: 1

Page 71: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

71 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

AdvancedCAIDMSJDBCFeatures

Page 72: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

72 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

AdvancedCAIDMSJDBCFeatures

§ Type4JDBCDriver

§ DataSources

§ ProceduresandReturnedResultSets

§ BatchandPositionedUpdates

§ EnhancedResultSets

Page 73: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

73 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

Type4JDBCDriver

§ DirectconnectionfromJDBCDrivertoCV– UsesTCP/IPlinedriver– CAICCInotneeded

§ JDBCServerinCV– Genericlistenertask

§ TransparenttoJDBCdriver– JustidentifiedbyURL

Page 74: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

74 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

Browser

CA-IDMS

JDBC Server

SQL Client

Any MF*

Apache

JSP

JDBC Driver

Any Java

HTML

Type4JDBCDriver

Page 75: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

75 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

DataSources

§ Encapsulateallconnectioninformation

§ UsewithJNDI

§ JavaBeanconventions– properties– get/setmethods– Serializable

Page 76: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

76 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

IDMSDataSourceClasses

§ IdmsDataSource

§ IdmsConnectionPoolDataSource

§ IdmsXADataSource

§ Oftenimplementedbyapplicationserver

Page 77: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

77 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

ConnectionPooling

ApplicationServer

JDBCApp

JDBCDriver

DatasourceAPI

ConnectionPoolDatasource

logicalConnectionobject

physicalPooledConnectionobject

pool

Page 78: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

78 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

XATransactions

Application Server

JDBC App

JDBC Driver

Datasource

XADatasource

logicalConnection

physicalXAConnection

pool A

JDBC Driver

pool B

A

A

B

B

XATranMgr

A

B

XAResource

Page 79: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

79 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

CalledProcedures

§ IdmsCallableStatementclass

§ Escapesyntax– {callprocedurename(?)}

§ DatabaseMetaDatamethods– getProcedures()– getProcedureColumns()

§ CallableStatementmethods– Outputparameters

Page 80: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

80 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

NamedParameters

§ Bindtoparametermarkersusingnamesinsteadofindexes:– UsewithSQLCALLstatement– NamesasspecifiedbyCREATEPROCEDURE– Supportsbothinputandoutputparameters

§ Simplifiesuseofproceduresthathavemanyparameters– Particularlywhendefaultsareacceptable– Namedparameterscanbespecifiedinanyorder– Unusedparameterscanbeomitted

Page 81: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

81 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

JDBCNamedParameterBinding

CallableStatement cstmt =conn.prepareCall(“CALL GETEMPLOYEE(?,?,?)”);

cstmt.setString(“EmpID”, “B503-8907-15”);cstmt.registerOutParameter(“Name”, Types.VARCHAR);cstmt.registerOutParameter(“Age”, Types.INTEGER);

cstmt.execute();

System.out.println(“Employee: ” + cstmt.getString(“Name”)) + “ is ” + cstmt.getInt(“Age”) + “ old.”;

Page 82: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

82 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

CAIDMSReturnedResultSetsinProcedure

§ ProcedurescanreturnresultsetsCREATE PROCEDURE RSPROC

CHAR SOMEPARM, …)

DYNAMIC RESULT SETS 5

§ CursorsleftopenafterprocedureexitsareRETURNEDALLOCATE CURSNAME CURSOR WITH RETURN

Page 83: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

83 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

CAIDMSReturnedResultSetsinCallingProgram

§ Callingprogramgetsresultsets

§ AllocateRECEIVEDcursorforresultsetsCALL RSPROC(…)

ALLOCATE RCURNAME FOR PROCEDURE

SPECIFIC PROCEDURE RSPROC

§ StepthroughRETURNEDresultsetsLoop until SQLSTATE = ‘0100D’

Loop until SQLSTATE = ‘02000’

FETCH RCURNAME

CLOSE RCURNAME

Page 84: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

84 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

JDBCMultipleResultSets

§ JDBCdrivercanhavemultipleRECEIVEDcursorsKEEP_CURRENT_RESULT, CLOSE_CURRENT_RESULT, CLOSE_ALL_RESULTS

§ Allocatecursorandstepthroughresultsetsrc = statement.executeQuery(“CALL RSPROC”);

while (rc != false) {

resultSet = statement.getResultSet();

while (rc != false) {

resultSet.fetch();

}

rc = statement.getMoreResults(CLOSE_CURRENT_RESULT);

}

Page 85: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

85 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

PositionedUpdates

§ Statementmethods:– setCursorName(“CURSOR1”)– getCursorName()

§ SQLstatements– SELECT…FORUPDATE– UPDATEWHERECURRENTOFCURSOR1

§ DisablesBULKFETCH

Page 86: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

86 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

BatchedUpdates

§ Statementmethods– addBatch()– executeBatch()– cancelBatch()

§ RequiredforJ2EEcompliance

§ DrivercachesmostSQLcommands

§ DirectsupportforINSERTBULK

Page 87: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

87 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

EnhancedResultSets

§ Scrollable

§ Updateable

§ TypicalResultSetmethods:– getRow()– updateRow()

§ Drivercachesfetchedrows

§ Uses“optimisticconcurrency”forupdating

Page 88: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

88 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

JDBCResultSets

§ ResultSettypeattribute– TYPE_FORWARD_ONLY– TYPE_SCROLL_INSENSITIVE– TYPE_SCROLL_SENSITIVE

§ ResultSetconcurrencyattribute– CONCUR_READ_ONLY– CONCUR_UPDATABLE

§ ResultSetmethods– Positioncursor– Updaterow

Page 89: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

89 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

CAIDMSScrollableResultSets

§ CachesrowsasfetchedfromCAIDMS

§ ResutSettypeattribute– TYPE_FORWARD_ONLY– TYPE_SCROLL_INSENSITIVE

§ ResultSetconcurrencyattribute– CONCUR_READ_ONLY

§ ResultSetmethods– Positioncursor

Page 90: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

90 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

JDBCRowSets

§ ExtendResultSetinterface

§ ReferenceImplementation– CachedRowSet– IncludedinJRE

§ ExtendsCAIDMSresultsetimplementation– TYPE_SCROLL_SENSITIVE– CONCUR_UPDATABLE– Updatemethods

Page 91: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

91 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

ExamplesExamplesofasimpleJDBCqueryapplicationaswellasHibernatereverseengineeringandschemagenerationwithCAIDMSdatabases.

JavaConceptsReviewsofObjectOrientedProgrammingandbasicJavaconcepts.

JDBCOverviewOverviewofJDBCandadvancedfeaturesoftheCAIDMSJDBCdriverandSQL.

Summary

Page 92: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

@CAWORLD#CAWORLD ©2016CA.AllRIGHTSRESERVED.92 @CAWORLD#CAWORLD

MainframeandWorkloadAutomation

FormoreinformationonMainframeandWorkloadAutomation,pleasevisit:http://cainc.to/9GQ2JI

Page 93: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

93 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

RecommendedSessionsSESSION# TITLE DATE/TIME

MFX100S StrategyandVisionforCAIDMS 11/16/2016at12:45pm

MFX101S LegacyisnotaDirtyWord 11/16/2016at1:45pm

MFX102S CAIDMS19.0WebServicesforModernization 11/16/2016at3:00pm

MFX103S CAIDMS19.0SQLEnhancementsforModernization 11/16/2016at3:30pm

MFX104S JavaAccesstoCA-IDMSDataatBT(BritishTelecom) 11/16/2016at4:45pm

MFX105SImplementationandUseofGenericVTAMResourceswithParallelSYSPLEXFeatures(CA andCAXIA) 11/17/2016at12:45pm

MFX106S CAIDMSBufferTuning 11/17/2016at1:45pm

MFX107S M3AServicesMonitor,Measure,ManageandAlert 11/17/2016at3:00pm

MFX108S BirdsofaFeather/StumptheTechie! 11/17/2016at3:45pm

Page 94: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

94 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

MustSeeDemos

DemoNameProductXTheater#location

DemoNameServicesYTheater#location

DemoNameSolutionYTheater#location

DemoNameProductXTheater#location

Page 95: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

95 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

Questions?

Page 96: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

96 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

Thankyou.

Stayconnectedatcommunities.ca.com

Page 97: Pre-Con Ed: Using Java to Access Your CA IDMS Databases and Applications

97 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD

©2016CA.Allrightsreserved.Alltrademarksreferencedhereinbelongtotheirrespectivecompanies.

Thecontentprovidedinthis CAWorld2016presentationisintendedforinformationalpurposesonlyanddoesnotformanytypeofwarranty. The informationprovidedbyaCApartnerand/orCAcustomerhasnotbeenreviewedforaccuracybyCA.

ForInformationalPurposesOnlyTermsofthisPresentation