pre-con ed: using java to access your ca idms databases and applications
TRANSCRIPT
World®’16
UsingJavatoAccessYourCAIDMSDatabasesandApplicationsDavidRoss,Sr.PrincipalProductOwnerCATechnologies
MFX74E
MAINFRAMEANDWORKLOADAUTOMATION
2 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
Abstract
ManyusersarefocusedondevelopingnewapplicationsinJava,butstillhavealargeinvestmentinCAIDMSdatabasesandapplications.ThissessionshowshowyoucanuseJDBCandSQLtoleverageyourCAIDMSdatabasesandbusinesslogicfromyourJavaapplications.ItincludesanoverviewofJavaprogrammingconceptsandJDBCforthosenewtoJava,aswellasmoreadvancedtopicsformoreexperiencedusers.
DavidRoss
CATechnologiesSr.PrincipalProductOwner,CAIDMS
3 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
Agenda
OOPSCONCEPTS
JAVAPROGRAMMINGELEMENTS
JDBCOVERVIEWANDSAMPLEAPPLICATION
JAVAPERSISTENCEANDHIBERNATEWITHCAIDMS
ADVANCEDCAIDMSJDBCFEATURES
1
2
3
4
5
4 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
OOPSConcepts
5 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
ObjectOrientedProgramming
§ Objects
§ Messages
§ Classes
§ Inheritance
6 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
Object
§ Softwarebundle– Variables– Methods
§ State
§ Behavior
PrivateImplementationDetails
PublicAPI
7 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
Message
§ Howobjectsinteract
§ Components– Objectaddress– Methodname– Parameters
ObjectA
ObjectB
Message
8 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
Class
§ Object“blueprint”
§ Members– Class– Instance
PrivateImplementationDetails
PublicAPI
9 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
Inheritance
§ Superclass– Commonbehavior– Reusable
§ Subclass– Specializedbehavior– Overridemethods– Hidevariables
Subclasses
Superclass
10 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
JavaProgrammingElements
11 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
Java
§ Objectorientedprogramminglanguage
§ Softwareplatform– JavaVirtualMachine– JavaApplicationProgrammingInterface
12 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
JavaLanguageElements
§ class
§ interface
§ package
§ exception
§ import
13 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
Class
§ Basicprogrammingunit
§ Members– Variables– Methods
14 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
Interface
§ Morethanaheader
§ Named“protocol”– Definesabstractmethods– Declaresconstants
§ Classesimplementinterfaces
§ Referencetype
15 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
Package
§ Likealibrary
§ Related– Classes– Interfaces– Exceptions
§ #importintoJavaprogram
16 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
JDBCOverview
17 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
JDBCConcepts
§ “JavaDataBaseConnectivity”
§ CallLevelInterface
§ ObjectOriented
§ Interoperability
§ AnyJavaplatform
18 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
JDBCArchitecture
JavaApplication
JDBCDriverManager
JDBCDriver
URL
Driverinterface
NetworkandDBMS
JDBCDriver
URL
19 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
JDBCObjects
§ Packages– java.sql– Javax.sql
§ Interfaces
§ Classes
§ Exceptions
20 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
JDBCClasses
§ DriverManager
§ DriverPropertyInfo
§ Types
§ Date
§ Time
§ Timestamp
21 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
CommonlyUsedJDBCInterfaces
§ Driver
§ DataSource
§ Connection
§ DatabaseMetaData
§ Statement
§ CallableStatement
§ PreparedStatment
§ ResultSet
§ ResultSetMetaData
22 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
JDBCExceptions
§ SQLException
§ SQLWarning
§ DataTruncation
23 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
JDBCObjectRelationships
ResultSet
Statement
ResultSet
Statement
Connection
Statement
Connection
DriverManager
24 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
SampleJDBCApplication
25 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
JDBCQueryApplication
§ SimplifiedversionofIdmsExample– IncludedwithCAIDMSServer– CanexecuteanySQLstatement– Javaversionof“BCF”
§ Connecttoadatabase
§ Executeaquery
§ Retrieveresults
§ Handleerrors
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");
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);
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));
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);
}}
}
30 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
JavaPersistenceAPIandHibernate
31 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
ObjecttoRelationalMapping
••Neednotbe1-1Class
••InstantiationObject
••DatamemberAttribute
••ReferencesRelationship
••Neednotbe1-1Table
••OccurrenceRow
Column
••ForeignkeysReferentialconstraint
Object Relational(SQL)
32 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
ObjecttoRelationalMappingSoftware
Providerruntime••GeneratesSQL••Reflection••Mappingdefinitions
Objectdefinitiontools••Schemadefinition••Reverseengineering
Implementations••JavaPersistenceArchitecture(JPA)••Hibernate
33 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
SchemaGeneration
§ AutomaticallygeneratesDBschemafromobjects
§ MostusefulforprototypingDB
§ Physicaltuningalwaysmanual
§ Over-relianceonORMcanleadtopoorDBdesign
§ DBAshoulddofinaldesign
34 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
ReverseEngineering
§ Createobjectdefinitionsfromdatabase
§ Mostapplicationdatabasesalreadyexist
§ Notbiasedtowardasingleapplication
§ MostORMframeworksprovidereverseengineeringtool
§ UsesdatabasemetadataAPI’stodiscover– Entities– Attributes– Relationships
35 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
JPAandHibernateArchitecture
SQLDBMS
JDBCDriver
JPA/HibernateProvider
Application
36 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
JPAEntities
§ Entity– Representsapplicationobject– Mayrepresentdatabasetable– POJO
§ EntityManager– Managesstateandlifecycleof
entity§ Persist§ CreateEntityGraph§ Remove§ Find(usesprimarykey)§ Query§ Transaction
37 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
ReflectionandannotationsHowJPAworks
§ Reflection– Discoverclasses,fields,methodsincode– Dependsoncodingconventions(get,set,etc.)
§ Annotations– Metadataincodeaboutclasses,fields,methods– RelateJavaobjectstodatabasetables– LanguagefeatureintroducedinJ2SE5– @<name>(optionalarguments)– Extensiveuseofdefaults– AlternativetoXMLdescriptorfiles
38 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
JPAannotations
§ @Entity
§ @Table
§ @Column
§ @Id
§ @OneToMany
§ @ManyToMany
§ @Inheritance
§ Manymore…
39 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
UsingHibernatewithCAIDMS
40 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
CAIDMS19.0SQLandHibernate
§ EnhancedcompatibilitywithCAIDMS19.0– EliminatesmostcustomizationofgeneratedJavacode
§ Reverseengineering– VirtualForeignKeys
§ Schemageneration– StandardConstraint DDL
41 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
HibernateReverseEngineering
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
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;}
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...}
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;}
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...}
47 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
§ CustomizeEmployeeclass– AddreferencetomemberobjectCoverage– Usesetspecificationinsteadofforeignkey
§ CustomizeCoverageclass– AddROWIDasprimarykey– Addreferencetoownerobject
§ Populatesetoccurrenceobjectsinbusinesslogic
It’sMoreWorkWithoutVirtualForeignKeys
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
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);
}
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, …}
51 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
HibernateSchemaGeneration
52 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
POJO:PlainOldJavaObjects
Employee
Department
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
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;
}}
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;
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);
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();
58 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
DDLtocleanupalter table IUA.EMPLOYEE
drop constraint FK75C8D6AEFF9D0229;
drop table IUA.DEPT cascade;
drop table IUA.EMPLOYEE cascade;
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)
);
60 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
AddConstraint
alter table IUA.EMPLOYEE add constraint FK75C8D6AEFF9D0229 foreign key (DEPT_ID) references IUA.DEPT
61 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
Databaserepresentation
DEPT
EMPLOYEE
FK75C8D6AEFF9…
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
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
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=?
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.
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
(?, ?, ?, ?, ?)
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
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_
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);
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
71 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
AdvancedCAIDMSJDBCFeatures
72 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
AdvancedCAIDMSJDBCFeatures
§ Type4JDBCDriver
§ DataSources
§ ProceduresandReturnedResultSets
§ BatchandPositionedUpdates
§ EnhancedResultSets
73 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
Type4JDBCDriver
§ DirectconnectionfromJDBCDrivertoCV– UsesTCP/IPlinedriver– CAICCInotneeded
§ JDBCServerinCV– Genericlistenertask
§ TransparenttoJDBCdriver– JustidentifiedbyURL
74 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
Browser
CA-IDMS
JDBC Server
SQL Client
Any MF*
Apache
JSP
JDBC Driver
Any Java
HTML
Type4JDBCDriver
75 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
DataSources
§ Encapsulateallconnectioninformation
§ UsewithJNDI
§ JavaBeanconventions– properties– get/setmethods– Serializable
76 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
IDMSDataSourceClasses
§ IdmsDataSource
§ IdmsConnectionPoolDataSource
§ IdmsXADataSource
§ Oftenimplementedbyapplicationserver
77 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
ConnectionPooling
ApplicationServer
JDBCApp
JDBCDriver
DatasourceAPI
ConnectionPoolDatasource
logicalConnectionobject
physicalPooledConnectionobject
pool
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
79 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
CalledProcedures
§ IdmsCallableStatementclass
§ Escapesyntax– {callprocedurename(?)}
§ DatabaseMetaDatamethods– getProcedures()– getProcedureColumns()
§ CallableStatementmethods– Outputparameters
80 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
NamedParameters
§ Bindtoparametermarkersusingnamesinsteadofindexes:– UsewithSQLCALLstatement– NamesasspecifiedbyCREATEPROCEDURE– Supportsbothinputandoutputparameters
§ Simplifiesuseofproceduresthathavemanyparameters– Particularlywhendefaultsareacceptable– Namedparameterscanbespecifiedinanyorder– Unusedparameterscanbeomitted
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.”;
82 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
CAIDMSReturnedResultSetsinProcedure
§ ProcedurescanreturnresultsetsCREATE PROCEDURE RSPROC
CHAR SOMEPARM, …)
DYNAMIC RESULT SETS 5
§ CursorsleftopenafterprocedureexitsareRETURNEDALLOCATE CURSNAME CURSOR WITH RETURN
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
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);
}
85 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
PositionedUpdates
§ Statementmethods:– setCursorName(“CURSOR1”)– getCursorName()
§ SQLstatements– SELECT…FORUPDATE– UPDATEWHERECURRENTOFCURSOR1
§ DisablesBULKFETCH
86 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
BatchedUpdates
§ Statementmethods– addBatch()– executeBatch()– cancelBatch()
§ RequiredforJ2EEcompliance
§ DrivercachesmostSQLcommands
§ DirectsupportforINSERTBULK
87 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
EnhancedResultSets
§ Scrollable
§ Updateable
§ TypicalResultSetmethods:– getRow()– updateRow()
§ Drivercachesfetchedrows
§ Uses“optimisticconcurrency”forupdating
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
89 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
CAIDMSScrollableResultSets
§ CachesrowsasfetchedfromCAIDMS
§ ResutSettypeattribute– TYPE_FORWARD_ONLY– TYPE_SCROLL_INSENSITIVE
§ ResultSetconcurrencyattribute– CONCUR_READ_ONLY
§ ResultSetmethods– Positioncursor
90 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
JDBCRowSets
§ ExtendResultSetinterface
§ ReferenceImplementation– CachedRowSet– IncludedinJRE
§ ExtendsCAIDMSresultsetimplementation– TYPE_SCROLL_SENSITIVE– CONCUR_UPDATABLE– Updatemethods
91 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
ExamplesExamplesofasimpleJDBCqueryapplicationaswellasHibernatereverseengineeringandschemagenerationwithCAIDMSdatabases.
JavaConceptsReviewsofObjectOrientedProgrammingandbasicJavaconcepts.
JDBCOverviewOverviewofJDBCandadvancedfeaturesoftheCAIDMSJDBCdriverandSQL.
Summary
@CAWORLD#CAWORLD ©2016CA.AllRIGHTSRESERVED.92 @CAWORLD#CAWORLD
MainframeandWorkloadAutomation
FormoreinformationonMainframeandWorkloadAutomation,pleasevisit:http://cainc.to/9GQ2JI
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
94 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
MustSeeDemos
DemoNameProductXTheater#location
DemoNameServicesYTheater#location
DemoNameSolutionYTheater#location
DemoNameProductXTheater#location
95 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
Questions?
96 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
Thankyou.
Stayconnectedatcommunities.ca.com
97 ©2016CA.ALLRIGHTSRESERVED.@CAWORLD#CAWORLD
©2016CA.Allrightsreserved.Alltrademarksreferencedhereinbelongtotheirrespectivecompanies.
Thecontentprovidedinthis CAWorld2016presentationisintendedforinformationalpurposesonlyanddoesnotformanytypeofwarranty. The informationprovidedbyaCApartnerand/orCAcustomerhasnotbeenreviewedforaccuracybyCA.
ForInformationalPurposesOnlyTermsofthisPresentation