Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

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

375 views

Published on

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

Published in: Technology
  • Be the first to comment

  • Be the first to like this

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

  1. 1. World® ’16 Using Java to Access Your CA IDMS Databases and Applications David Ross, Sr. Principal Product Owner CA Technologies MFX74E MAINFRAME AND WORKLOAD AUTOMATION
  2. 2. 2 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Abstract Many users are focused on developing new applications in Java, but still have a large investment in CA IDMS databases and applications. This session shows how you can use JDBC and SQL to leverage your CA IDMS databases and business logic from your Java applications. It includes an overview of Java programming concepts and JDBC for those new to Java, as well as more advanced topics for more experienced users. David Ross CA Technologies Sr. Principal Product Owner, CA IDMS
  3. 3. 3 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Agenda OOPS CONCEPTS JAVA PROGRAMMING ELEMENTS JDBC OVERVIEW AND SAMPLE APPLICATION JAVA PERSISTENCE AND HIBERNATE WITH CA IDMS ADVANCED CA IDMS JDBC FEATURES 1 2 3 4 5
  4. 4. 4 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD OOPS Concepts
  5. 5. 5 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Object Oriented Programming § Objects § Messages § Classes § Inheritance
  6. 6. 6 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Object § Software bundle – Variables – Methods § State § Behavior Private Implementation Details Public API
  7. 7. 7 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Message § How objects interact § Components – Object address – Method name – Parameters Object A Object B Message
  8. 8. 8 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Class § Object “blueprint” § Members – Class – Instance Private Implementation Details Public API
  9. 9. 9 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Inheritance § Superclass – Common behavior – Reusable § Subclass – Specialized behavior – Override methods – Hide variables Subclasses Superclass
  10. 10. 10 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Java Programming Elements
  11. 11. 11 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Java § Object oriented programming language § Software platform – Java Virtual Machine – Java Application Programming Interface
  12. 12. 12 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Java Language Elements § class § interface § package § exception § import
  13. 13. 13 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Class § Basic programming unit § Members – Variables – Methods
  14. 14. 14 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Interface § More than a header § Named “protocol” – Defines abstract methods – Declares constants § Classes implement interfaces § Reference type
  15. 15. 15 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Package § Like a library § Related – Classes – Interfaces – Exceptions § #import into Java program
  16. 16. 16 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD JDBC Overview
  17. 17. 17 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD JDBC Concepts § “Java Data Base Connectivity” § Call Level Interface § Object Oriented § Interoperability § Any Java platform
  18. 18. 18 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD JDBC Architecture Java Application JDBC Driver Manager JDBC Driver URL Driver interface Network and DBMS JDBC Driver URL
  19. 19. 19 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD JDBC Objects § Packages – java.sql – Javax.sql § Interfaces § Classes § Exceptions
  20. 20. 20 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD JDBC Classes § DriverManager § DriverPropertyInfo § Types § Date § Time § Timestamp
  21. 21. 21 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Commonly Used JDBC Interfaces § Driver § DataSource § Connection § DatabaseMetaData § Statement § CallableStatement § PreparedStatment § ResultSet § ResultSetMetaData
  22. 22. 22 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD JDBC Exceptions § SQLException § SQLWarning § DataTruncation
  23. 23. 23 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD JDBC Object Relationships ResultSet Statement ResultSet Statement Connection Statement Connection DriverManager
  24. 24. 24 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Sample JDBC Application
  25. 25. 25 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD JDBC Query Application § Simplified version of IdmsExample – Included with CA IDMS Server – Can execute any SQL statement – Java version of “BCF” § Connect to a database § Execute a query § Retrieve results § Handle errors
  26. 26. 26 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Housekeeping import java.io.*; // standard output import java.sql.*; // basic JDBC classes class JdbcExample { public static void main (String[] args) { // register driver try { Class.forName("ca.idms.jdbc.IdmsJdbcDriver");
  27. 27. 27 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Get Connected // set connection information String url = "jdbc:idms://host:3709/dictname"; String uid = “userid"; String pwd = “password"; // get a connection to the database Connection conn = DriverManager.getConnection(url, uid, pwd);
  28. 28. 28 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Here’s the Meat // get a statement object to… Statement stmt = conn.createStatement(); // execute the query and get a result set ResultSet rs = stmt.executeQuery( "SELECT EMPFNAME, EMPLNAME FROM DEMO.EMPL"); // get and display the result set columns while (rs.next()) System.out.println( rs.getString(1) + " " + rs.getString(2));
  29. 29. 29 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD The Punting Game // disconnect conn.close(); } catch (ClassNotFoundException e) { System.out.println("No driver: " + e); } catch (SQLException e) { System.out.println("SQL Error: " + e); } } }
  30. 30. 30 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Java Persistence API and Hibernate
  31. 31. 31 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Object to Relational Mapping ••Need not be 1-1Class ••InstantiationObject ••Data memberAttribute ••ReferencesRelationship ••Need not be 1-1Table ••OccurrenceRow Column ••Foreign keys Referential constraint Object Relational (SQL)
  32. 32. 32 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Object to Relational Mapping Software Provider run time ••Generates SQL ••Reflection ••Mapping definitions Object definition tools ••Schema definition ••Reverse engineering Implementations ••Java Persistence Architecture (JPA) ••Hibernate
  33. 33. 33 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Schema Generation § Automatically generates DB schema from objects § Most useful for prototyping DB § Physical tuning always manual § Over-reliance on ORM can lead to poor DB design § DBA should do final design
  34. 34. 34 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Reverse Engineering § Create object definitions from database § Most application databases already exist § Not biased toward a single application § Most ORM frameworks provide reverse engineering tool § Uses database metadata API’s to discover – Entities – Attributes – Relationships
  35. 35. 35 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD JPA and Hibernate Architecture SQL DBMS JDBC Driver JPA/Hibernate Provider Application
  36. 36. 36 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD JPA Entities § Entity – Represents application object – May represent database table – POJO § EntityManager – Manages state and life cycle of entity § Persist § CreateEntityGraph § Remove § Find (uses primary key) § Query § Transaction
  37. 37. 37 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Reflection and annotations How JPA works § Reflection – Discover classes, fields, methods in code – Depends on coding conventions (get, set, etc.) § Annotations – Metadata in code about classes, fields, methods – Relate Java objects to database tables – Language feature introduced in J2SE 5 – @<name>(optional arguments) – Extensive use of defaults – Alternative to XML descriptor files
  38. 38. 38 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD JPA annotations § @Entity § @Table § @Column § @Id § @OneToMany § @ManyToMany § @Inheritance § Many more…
  39. 39. 39 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Using Hibernate with CA IDMS
  40. 40. 40 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD CA IDMS 19.0 SQL and Hibernate § Enhanced compatibility with CA IDMS 19.0 – Eliminates most customization of generated Java code § Reverse engineering – Virtual Foreign Keys § Schema generation – Standard Constraint DDL
  41. 41. 41 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Hibernate Reverse Engineering
  42. 42. 42 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Using Hibernate With CA IDMS EMPLOYEE 415 EMP-ID-0415 EMP-DEMO-REGION F 116 CALC DN COVERAGE 400 EMP-COVERAGE INS-DEMO-REGION F 16 VIA EMP-COVERAGE NPO MA FIRST ••EMPLOYEE ••COVERAGE Employee database ••Reverse Engineering ••Virtual Foreign Keys Techniques ••Employee ••Coverage Entity classes
  43. 43. 43 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Reverse Engineered Employee Class Primary key ROWID and set Coverage @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. 44. 44 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Reverse Engineered Employee Class Related to Coverage in a OneToMany 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. 45. 45 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Reverse Engineered Coverage Class Primary key ROWID and Reference to Owning Employee Object @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. 46. 46 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Reverse Engineered Coverage Class Related To employee in ManyToOne 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. 47. 47 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD § Customize Employee class – Add reference to member object Coverage – Use set specification instead of foreign key § Customize Coverage class – Add ROWID as primary key – Add reference to owner object § Populate set occurrence objects in business logic It’s More Work Without Virtual Foreign Keys
  48. 48. 48 © 2016 CA. ALL RIGHTS RESERVED.@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") Modified Employee Class
  49. 49. 49 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Populate Set Occurrence Objects EntityManagerFactory 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. 50. 50 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Object to Relational to Network Mapping Set Occurrence Exposed as Objects c.ROWID c.YEAR c.TYPE 08010202 2008 F 08010204 2009 F 08010210 2010 M 08010303 2011 F EMP 23 COV 2008 COV 2009 COV 2010 COV 2011 Database Set Occurrence SQL Query Result Set Java Objects Employee e = {23, Joe, …} List<Coverage> coverage = {e, 08010202, 2008, F, …} {e, 08010204, 2009, F, …} {e, 08010210, 2010, M, …} {e, 08010303, 2011, F, …}
  51. 51. 51 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Hibernate Schema Generation
  52. 52. 52 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD POJO: Plain Old Java Objects Employee Department
  53. 53. 53 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Plain Old Java Employee public 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. 54. 54 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Plain Old Java Department public 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. 55. 55 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Add Annotations to Employee @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. 56. 56 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Add Annotations to Department @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 = new HashSet<Employee>(0);
  57. 57. 57 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Persisting Object Session session = HibernateUtil.getSessionFactory().openSession(); Transaction transaction = transaction = session.beginTransaction(); //Create a Department Dept devDept = new Dept("Mainframe", 1); //Add Employees devDept.addEmployee("James", "Scrum Master", "111223333", 50000); ... //Save the department session.save(devDept); //flush the session transaction.commit(); //close the connection session.close();
  58. 58. 58 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD DDL to clean up alter table IUA.EMPLOYEE drop constraint FK75C8D6AEFF9D0229; drop table IUA.DEPT cascade; drop table IUA.EMPLOYEE cascade;
  59. 59. 59 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Create tables 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. 60. 60 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Add Constraint alter table IUA.EMPLOYEE add constraint FK75C8D6AEFF9D0229 foreign key (DEPT_ID) references IUA.DEPT
  61. 61. 61 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Database representation DEPT EMPLOYEE FK75C8D6AEFF9…
  62. 62. 62 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Create Department insert into IUA.DEPT (DEPT_NAME, DEPT_ID) values (?, ?) 10:14:42 DEBUG StringType:80 - binding 'Mainframe' to parameter: 1 10:14:43 DEBUG LongType:80 - binding '1' to parameter: 2
  63. 63. 63 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Create Employees insert into IUA.EMPLOYEE (NAME, TITLE, DEPT_ID, SALARY, SSN) values (?, ?, ?, ?, ?) 10:14:43 DEBUG StringType:80 - binding 'Mary' to parameter: 1 10:14:43 DEBUG StringType:80 - binding 'Product Owner' to parameter: 2 10:14:43 DEBUG LongType:80 - binding '1' to parameter: 3 10:14:43 DEBUG IntegerType:80 - binding '85000' to parameter: 4 10:14:43 DEBUG StringType:80 - binding '333445555' to parameter: 5
  64. 64. 64 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Add new Employee //Find Department based on ID Dept devDept= (Dept) session.get(Dept.class, 1); select dept0_.DEPT_ID as DEPT1_0_0_, dept0_.DEPT_NAME as DEPT2_0_0_ from IUA.DEPT dept0_ where dept0_.DEPT_ID=?
  65. 65. 65 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Add new Employee //Add new employee to the Department devDept.addEmployee("Joe", "Developer", "123456789", 199); select deptemploy0_.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_ from IUA.EMPLOYEE deptemploy0_ where deptemploy0_.DEPT_ID=? Returns all of the Employees in the department with ID=1.
  66. 66. 66 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Add new Employee //Save the department session.save(devDept); //close the transaction transaction.commit(); insert into IUA.EMPLOYEE (NAME, TITLE, DEPT_ID, SALARY, SSN) values (?, ?, ?, ?, ?)
  67. 67. 67 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Modify Employee //Find employee based on SSN Employee e1 = (Employee) session.get(Employee.class, "111223333"); select employee0_.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_ from IUA.EMPLOYEE employee0_ inner join IUA.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. 68. 68 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Modify Employee 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. 69. 69 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Modify Employee update IUA.EMPLOYEE set NAME=?,TITLE=?, DEPT_ID=?, SALARY=? where SSN=? int empSalary = e1.getEmployeeSalary(); e1.setEmployeeSalary(empSalary*2);//double salary //Save the new Employee session.save(e1);
  70. 70. 70 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Delete Employee //Find employee based on SSN Employee e1 = (Employee) session.get(Employee.class, "123456789"); //Delete employee session.delete(e1); //close the transaction transaction.commit(); delete from IUA.EMPLOYEE where SSN=? 11:54:43 DEBUG StringType:80 - binding '123456789' to parameter: 1
  71. 71. 71 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Advanced CA IDMS JDBC Features
  72. 72. 72 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Advanced CA IDMS JDBC Features § Type 4 JDBC Driver § Data Sources § Procedures and Returned Result Sets § Batch and Positioned Updates § Enhanced Result Sets
  73. 73. 73 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Type 4 JDBC Driver § Direct connection from JDBC Driver to CV – Uses TCP/IP line driver – CAICCI not needed § JDBC Server in CV – Generic listener task § Transparent to JDBC driver – Just identified by URL
  74. 74. 74 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Browser CA-IDMS JDBC Server SQL Client Any MF* Apache JSP JDBC Driver Any Java HTML Type 4 JDBC Driver
  75. 75. 75 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Data Sources § Encapsulate all connection information § Use with JNDI § Java Bean conventions – properties – get/set methods – Serializable
  76. 76. 76 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD IDMS DataSource Classes § IdmsDataSource § IdmsConnectionPoolDataSource § IdmsXADataSource § Often implemented by application server
  77. 77. 77 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Connection Pooling Application Server JDBC App JDBC Driver Datasource API ConnectionPoolDatasource logical Connection object physical PooledConnection object pool
  78. 78. 78 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD XA Transactions Application Server JDBC App JDBC Driver Datasource XADatasource logical Connection physical XAConnection pool A JDBC Driver pool B A A B B XA Tran Mgr A B XAResource
  79. 79. 79 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Called Procedures § IdmsCallableStatement class § Escape syntax – {call procedurename(?)} § DatabaseMetaData methods – getProcedures() – getProcedureColumns() § CallableStatement methods – Output parameters
  80. 80. 80 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Named Parameters § Bind to parameter markers using names instead of indexes: – Use with SQL CALL statement – Names as specified by CREATE PROCEDURE – Supports both input and output parameters § Simplifies use of procedures that have many parameters – Particularly when defaults are acceptable – Named parameters can be specified in any order – Unused parameters can be omitted
  81. 81. 81 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD JDBC Named Parameter Binding 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. 82. 82 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD CA IDMS Returned Result Sets in Procedure § Procedures can return result sets CREATE PROCEDURE RSPROC CHAR SOMEPARM, …) DYNAMIC RESULT SETS 5 § Cursors left open after procedure exits are RETURNED ALLOCATE CURSNAME CURSOR WITH RETURN
  83. 83. 83 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD CA IDMS Returned Result Sets in Calling Program § Calling program gets result sets § Allocate RECEIVED cursor for result sets CALL RSPROC(…) ALLOCATE RCURNAME FOR PROCEDURE SPECIFIC PROCEDURE RSPROC § Step through RETURNED result sets Loop until SQLSTATE = ‘0100D’ Loop until SQLSTATE = ‘02000’ FETCH RCURNAME CLOSE RCURNAME
  84. 84. 84 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD JDBC Multiple Result Sets § JDBC driver can have multiple RECEIVED cursors KEEP_CURRENT_RESULT, CLOSE_CURRENT_RESULT, CLOSE_ALL_RESULTS § Allocate cursor and step through result sets rc = statement.executeQuery(“CALL RSPROC”); while (rc != false) { resultSet = statement.getResultSet(); while (rc != false) { resultSet.fetch(); } rc = statement.getMoreResults(CLOSE_CURRENT_RESULT); }
  85. 85. 85 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Positioned Updates § Statement methods: – setCursorName(“CURSOR1”) – getCursorName() § SQL statements – SELECT … FOR UPDATE – UPDATE WHERE CURRENT OF CURSOR1 § Disables BULK FETCH
  86. 86. 86 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Batched Updates § Statement methods – addBatch() – executeBatch() – cancelBatch() § Required for J2EE compliance § Driver caches most SQL commands § Direct support for INSERT BULK
  87. 87. 87 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Enhanced Result Sets § Scrollable § Updateable § Typical ResultSet methods: – getRow() – updateRow() § Driver caches fetched rows § Uses “optimistic concurrency” for updating
  88. 88. 88 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD JDBC Result Sets § ResultSet type attribute – TYPE_FORWARD_ONLY – TYPE_SCROLL_INSENSITIVE – TYPE_SCROLL_SENSITIVE § ResultSet concurrency attribute – CONCUR_READ_ONLY – CONCUR_UPDATABLE § ResultSet methods – Position cursor – Update row
  89. 89. 89 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD CA IDMS Scrollable Result Sets § Caches rows as fetched from CA IDMS § ResutSet type attribute – TYPE_FORWARD_ONLY – TYPE_SCROLL_INSENSITIVE § ResultSet concurrency attribute – CONCUR_READ_ONLY § ResultSet methods – Position cursor
  90. 90. 90 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD JDBC Row Sets § Extend ResultSet interface § Reference Implementation – CachedRowSet – Included in JRE § Extends CA IDMS result set implementation – TYPE_SCROLL_SENSITIVE – CONCUR_UPDATABLE – Update methods
  91. 91. 91 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Examples Examples of a simple JDBC query application as well as Hibernate reverse engineering and schema generation with CA IDMS databases. Java Concepts Reviews of Object Oriented Programming and basic Java concepts. JDBC Overview Overview of JDBC and advanced features of the CA IDMS JDBC driver and SQL. Summary
  92. 92. @CAWORLD #CAWORLD © 2016 CA. All RIGHTS RESERVED.92 @CAWORLD #CAWORLD Mainframe and Workload Automation For more information on Mainframe and Workload Automation, please visit: http://cainc.to/9GQ2JI
  93. 93. 93 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Recommended Sessions SESSION # TITLE DATE/TIME MFX100S Strategy and Vision for CA IDMS 11/16/2016 at 12:45 pm MFX101S Legacy is not a Dirty Word 11/16/2016 at 1:45 pm MFX102S CA IDMS 19.0 Web Services for Modernization 11/16/2016 at 3:00 pm MFX103S CA IDMS 19.0 SQL Enhancements for Modernization 11/16/2016 at 3:30 pm MFX104S Java Access to CA-IDMS Data at BT (British Telecom) 11/16/2016 at 4:45 pm MFX105S Implementation and Use of Generic VTAM Resources with Parallel SYSPLEX Features (CA and CAXIA) 11/17/2016 at 12:45 pm MFX106S CA IDMS Buffer Tuning 11/17/2016 at 1:45 pm MFX107S M3A Services Monitor, Measure, Manage and Alert 11/17/2016 at 3:00 pm MFX108S Birds of a Feather/Stump the Techie! 11/17/2016 at 3:45 pm
  94. 94. 94 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Must See Demos Demo Name Product X Theater # location Demo Name Services Y Theater # location Demo Name Solution Y Theater # location Demo Name Product X Theater # location
  95. 95. 95 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Questions?
  96. 96. 96 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD Thank you. Stay connected at communities.ca.com
  97. 97. 97 © 2016 CA. ALL RIGHTS RESERVED.@CAWORLD #CAWORLD © 2016 CA. All rights reserved. All trademarks referenced herein belong to their respective companies. The content provided in this CA World 2016 presentation is intended for informational purposes only and does not form any type of warranty. The information provided by a CA partner and/or CA customer has not been reviewed for accuracy by CA. For Informational Purposes Only Terms of this Presentation

×