Java and/in DB2. Java and/in DB2. GSE NL DB2 working group. Bussum - 28/10/2010. Gie Indesteege - ABIS Training & Consulting

Similar documents
Performance Evaluation of Java Object Relational Mapping Tools

CACHÉ: FLEXIBLE, HIGH-PERFORMANCE PERSISTENCE FOR JAVA APPLICATIONS

Java EE 7: Back-End Server Application Development

PERFORMANCE EVALUATION OF JAVA OBJECT-RELATIONAL MAPPING TOOLS HASEEB YOUSAF. (Under the Direction of John A. Miller)

Enterprise Application Development In Java with AJAX and ORM

The JAVA Way: JDBC and SQLJ

Building Web Applications, Servlets, JSP and JDBC

Self-test Database application programming with JDBC

CS 377 Database Systems SQL Programming. Li Xiong Department of Mathematics and Computer Science Emory University

Chapter 13. Introduction to SQL Programming Techniques. Database Programming: Techniques and Issues. SQL Programming. Database applications

MAKING ORACLE AND SQLJ WORK FOR YOU John Jay King, King Training Resources

<Insert Picture Here> Java EE 7. Linda DeMichiel Java EE Platform Lead

1 File Processing Systems

Announcements. Comments on project proposals will go out by in next couple of days...

The Different Types of Search and Execution Systems

CA IDMS Server r17. Product Overview. Business Value. Delivery Approach

Core Java+ J2EE+Struts+Hibernate+Spring

Chapter 9 Java and SQL. Wang Yang wyang@njnet.edu.cn

Complex Data and Object-Oriented. Databases

White Paper: 1) Architecture Objectives: The primary objective of this architecture is to meet the. 2) Architecture Explanation

Oracle WebLogic Foundation of Oracle Fusion Middleware. Lawrence Manickam Toyork Systems Inc

CS346: Database Programming.

CS/CE 2336 Computer Science II

Using the DataDirect Connect for JDBC Drivers with the Sun Java System Application Server

WEB APPLICATION DEVELOPMENT. UNIT I J2EE Platform 9

Java Application Performance

Converting Java EE Applications into OSGi Applications

By Wick Gankanda Updated: August 8, 2012

Developing an EJB3 Application. on WebSphere 6.1. using RAD 7.5

Client-Server Architecture & J2EE Platform Technologies Overview Ahmed K. Ezzat

Weaving Stored Procedures into Java at Zalando

What is ODBC? Database Connectivity ODBC, JDBC and SQLJ. ODBC Architecture. More on ODBC. JDBC vs ODBC. What is JDBC?

This training is targeted at System Administrators and developers wanting to understand more about administering a WebLogic instance.

JBS-102: Jboss Application Server Administration. Course Length: 4 days

JAVA ENTERPRISE IN A NUTSHELL. Jim Farley and William Crawford. O'REILLY 4 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo.

Database System Architecture & System Catalog Instructor: Mourad Benchikh Text Books: Elmasri & Navathe Chap. 17 Silberschatz & Korth Chap.

Java DB Performance. Olav Sandstå Sun Microsystems, Trondheim, Norway Submission ID: 860

Database Programming. Week *Some of the slides in this lecture are created by Prof. Ian Horrocks from University of Oxford

Object Oriented Design with UML and Java. PART XVIII: Database Technology

Java SE 7 Programming

OpenShift is FanPaaStic For Java EE. By Shekhar Gulati Promo Code JUDCON.IN

Java Platform, Enterprise Edition (Java EE) From Yes-M Systems LLC Length: Approx 3 weeks/30 hours Audience: Students with experience in Java SE

Internet Engineering: Web Application Architecture. Ali Kamandi Sharif University of Technology Fall 2007

Case Studies of Running the Platform. NetBeans UML Servlet JSP GlassFish EJB

DB2 Application Development and Migration Tools

Framework Adoption for Java Enterprise Application Development

Oracle8/ SQLJ Programming

EclipseLink. Solutions Guide for EclipseLink Release 2.5

Object Relational Mapping for Database Integration

Object Oriented Databases. OOAD Fall 2012 Arjun Gopalakrishna Bhavya Udayashankar

Lag Sucks! R.J. Lorimer Director of Platform Engineering Electrotank, Inc. Robert Greene Vice President of Technology Versant Corporation

IBM WebSphere Server Administration

Cache Database: Introduction to a New Generation Database

Applets, RMI, JDBC Exam Review

WebSphere Server Administration Course

Administering batch environments

Using the DataDirect Connect for JDBC Drivers with WebLogic 8.1

OTN Developer Day Enterprise Java. Hands on Lab Manual JPA 2.0 and Object Relational Mapping Basics

Java SE 7 Programming

MANDARAX + ORYX An Open-Source Rule Platform

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

Course Number: IAC-SOFT-WDAD Web Design and Application Development

Table of Content. Introduction to ObjectDB and JPA. Object Model: Types, Entities, Primary Keys. Database Connections

Bryan Tuft Sr. Sales Consultant Global Embedded Business Unit

Table of contents. Reverse-engineers a database to Grails domain classes.

WebSphere Application Server V7: Deploying Applications

1. Introduction What is Slice? Background Why Slice? Purpose of this Document Intended Audience...

Why Is This Important? Database Application Development. SQL in Application Code. Overview. SQL in Application Code (Contd.

Cocoon Field Day. Cocoon & Persistence

CHAPTER 1 - JAVA EE OVERVIEW FOR ADMINISTRATORS

Oracle WebLogic Server 11g Administration

applications. JBoss Enterprise Application Platform

Rapid Application Development. and Application Generation Tools. Walter Knesel

Java DB2 Developers Performance Best Practices

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. Introduction to Databases. Why databases? Why not use XML?

Customer Bank Account Management System Technical Specification Document

OptimalJ Foundation. PSM EJB Model. Roadmap. What is the EJB model? EJB model as a PSM model Mapping the EJB model Model elements and code generation

Portals, Portlets & Liferay Platform

What is a database? COSC 304 Introduction to Database Systems. Database Introduction. Example Problem. Databases in the Real-World

GlassFish v3. Building an ex tensible modular Java EE application server. Jerome Dochez and Ludovic Champenois Sun Microsystems, Inc.

Migrating JEE Applications from WLS/WAS to SpringSource tc Server. A Technical Perspective

Database Access Through Java Technologies

Operations and Monitoring with Spring

Java and Databases. COMP514 Distributed Information Systems. Java Database Connectivity. Standards and utilities. Java and Databases

Database Access from a Programming Language: Database Access from a Programming Language

Database Access from a Programming Language:

IBM WebSphere Application Server Network Deployment for Distributed Platforms, Version 8.5. Establishing highly available services for applications

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

Configuring Apache Derby for Performance and Durability Olav Sandstå

AD-HOC QUERY BUILDER

Hibernate Language Binding Guide For The Connection Cloud Using Java Persistence API (JAP)

The end. Carl Nettelblad

How graph databases started the multi-model revolution

UltraQuest Cloud Server. White Paper Version 1.0

Course Name: Course in JSP Course Code: P5

Service Oriented Architectures

PL/SQL Programming Workbook

Course Description. Course Audience. Course Outline. Course Page - Page 1 of 5

Component Middleware. Sophie Chabridon. INT - INF Department - Distributed Systems team 2006

Transcription:

GSE NL DB2 working group Bussum - 28/10/2010 Gie Indesteege - ABIS Training & Consulting ABIS Training & Consulting 1

Welcome ABIS Training & Consulting www.abis.be Gie Indesteege trainer and consultant president of BeNeLux GSE working group EGL/RDZ 2

Contents Java for enterprise critical applications! business requirements: functional, performance, security,... and consistent and correct data Java and DB2 connection between Java application and DB2 Java functionality inside DB2 An overview of the architecture and possibilities of the Java - DB2 combination 3

Agenda Java Database Connectivity Object Relational Mapping Java Persistency Architecture Persistence Frameworks Java in DB2: Stored Procedures and User Defined Functions Q & A 4

Java Database Connectivity Connection between Java application and (local or remote) DB Web browser HTML Web server Java Servlet z/os JDBC Application Driver DB2 dynamic access to DB via standard JDBC API Note: embedded (static) SQL possible via SQLJ 5

JDBC (Java Database Connectivity) API Driver - types - 1: JDBC - ODBC - 2: app driver (*) local connection - 3: net driver - 4: universal driver (*) remote connection (*) DB2 for z/os supports the IBM Data Server Driver for JDBC 6

JDBC API (cont.) Set up connection via DriverManager Connection Connection connection = DriverManager.getConnection(databaseUrl, userid, password); or use DataSource DataSource ds = (DataSource)ctx.lookup("jdbc/inventoryDB"); connection = ds.getconnection(); via Java Naming and Directory Interface (JNDI) 7

JDBC API (cont.) Create SQL query via - dynamic statement Statement PreparedStatement CallableStatement (for Stored Procedures) PreparedStatement preparedsqlstatement = connection.preparestatement( select email from person where id =? ); - static statement (see SQLJ) Execute query and analyse result via preparedsqlstatement.setint( 1, personnr ); ResultSet resultset = preparedsqlstatement.executequery(); Error handling via SQLException SQLWarning 8

SQLJ support for embedded static SQL initially developed by IBM, Oracle, and Tandem Example #sql context EzSqljCtx; #sql iterator EzSqljNameIter (String EMAIL);... #sql [ctx] iter = { SELECT email FROM person }; while (iter.next()) { System.out.println(iter.EMAIL());... } Profile file Profile customizer Source Java SQLJ Translator Java code Java compiler Java class 9

JDBC additional considerations Datasource configuration via Java EE container Transaction processing local vs distributed application vs database transaction isolation -> locking (UR, CS, RS, RR) commit/rollback Resultset processing Scrollable resultsets Updateable resultsets Disconnected resultsets -> rowsets Connection control Metadata 10

Agenda Java Database Connectivity Object Relational Mapping Java Persistency Architecture Persistence Frameworks Java in DB2: Stored Procedures and User Defined Functions 11

Object Relational Mapping OO-applications are composed of objects which consist of data and behaviour are connected to each other send messages to each other 2 [OK]: minus(m) 1: check() :Person xfer(m:money, a2) a1:account 3: plus(m) a2:account How to persist objects? 12

Object Relational Mapping (cont.) The big impedance mismatch : objects in memory << >> relational data on disk OO RDBMS class table object row object identity primary key attribute column association foreign key accessors & other methods SQL, triggers, stored procedures hopping (traversal) joining generalization combination 13

Object Relational Mapping - structural problems inheritance trees - tree to multiple tables - tree to single table identity field - primary key vs object ID mapping relationships - direction of relation? - uni/bidirectional? - one-to-many? - many-to-many? Books book_id title Book title ISBN chapters: Collection * * Author firstname lastname Book-Author-Map book_id author_id Authors author_id firstname lastname OO RDBMS IQ Student pno IQ 1 99...... name Person Instructor domain pno pname ptype 1 John S 2 Mary I 3... pno domain 2 java...... 14

Object Relational Mapping - behavioural problems avoid to load complete database in memory how to load and save (persist) object in database concurrency problem keep track of changed objects for later storage in database 15

Object Relational Mapping - architectural problems class modelling of data tables where to code SQL (in which tier)? DB schema in Java source? in XML configuration? who dictates: Class model - Database schema? 16

Persistence mechanisms persist - data (object attributes) - types - relationships (links between objects) - metadata driven! (XML configuration or Annotations) synchronise (memory - disk) - caching - (container) service concurrency control Objects Cache Mapping Business Layer Persistence Layer (+ transactions, security,...) - different users/applications must reach the same data at the same time SQL -... while keeping the data in a consistent state RDBMS 17

Persistence mechanisms (cont.) transactional - set of actions that move data from one consistent state to another - key features: Atomicity, Consistency, Isolation, Durability query language: - retrieve data selective from the data store - SQL, OQL, xxxxql identity support - avoid multiple copies of the same data security - unauthorized people must not see sensitive data performance... 18

Agenda Java Database Connectivity Object Relational Mapping Java Persistency Architecture Persistence Frameworks Java in DB2: Stored Procedures and User Defined Functions 19

Java Persistency Architecture (JPA) since Java EE 5.0 transparent persistency framework for POJOs (Plain Old Java Objects) -> persistent entity objects Object-relational mapping framework - persistent fields - entity relationships - entity inheritance entity manager -> control of persistence unit configuration by exception (XML and/or annotations) transactional support native query support (Java Persistence Query Language - JPQL) detached entities -> serializable possibility to work inside or outside of a container 20

Java Persistency Architecture (JPA) - Architecture JPA javax.persistence EntityManagerFactory obtain Persistence 1 EntityTransaction * EntityManager * * Query Entity Java EE containers provide services for factory and transaction management 21

Java Persistence Architecture terminology Persistence: get EntityManagerFactory instances (vendor-neutral) EntityManagerFactory: factory for EntityManagers EntityManager: manages a set of persistent objects acts also as factory for Query instances Entity: persistent object that represents datastore records EntityTransaction: (associated with 1 EntityManager) group operations on persistent data into consistent units of work Query: interface to find persistent objects that meet certain criteria uses both the Java Persistence Query Language (JPQL) and the Structured Query Language (SQL) 22

JPA configuration data source + persistent entities -> persistence.xml <persistence-unit name="demojpa" transaction-type="jta"> <jta-data-source>jdbc/mydb</jta-data-source> <class>be.abis.entities.course</class> </persistence-unit> object/relational mapping + default schema -> orm.xml or via annotations in Entity import javax.persistence.*; @Entity @Table (name = "TUTCOURSES") @NamedQuery (name = "findallcoursesbyname", query = "SELECT c FROM Course c WHERE c.cltitle LIKE :coursename ORDER BY c.cltitle") public class Course implements Serializable { @Id private String cid; @Column(name = CSTITLE ) private String coursetitle;... 23

Use of JPA in application Define persistence context @PersistenceContext(unitName = "DemoJPA") private EntityManager em; Use entity manager for persistence // looking for existing course entity Course crs = em.find(course.class, coursenr); // make modifications to course entity crs.settitle( Java Persistence Architecture ); // save to database em.persist(crs); 24

Agenda Java Database Connectivity Object Relational Mapping Java Persistency Architecture Persistence Frameworks Java in DB2: Stored Procedures and User Defined Functions 25

Persistence Frameworks alternative for or collaborating with JPA Examples: Enterprise Java Beans of type Entity (part of J2EE 1.4) -> obsolete - Bean Managed Persistence (BMP) or Container Managed Persistence (CMP) - O/R mapping of persistent fields and relations in (XML) deployment descriptor - EJBQL - container responsible for persistence, synchronisation, transaction, security,... Java Data Objects (JDO) - JSR 243 - Apache project http://db.apache.org/jdo/index.html - any datastore, not only RDBMS - superset of JPA - JDOQL 26

Persistence Frameworks (cont.) Hibernate (part of JBoss community) www.hibernate.org - transparent (open source) persistency framework for POJOs (Plain Old Java Objects) - Object-relational mapping - API with a lot of interfaces - additional tools - Possibility to work inside or outside of a container - HQL Query by Criteria Query by Example polymorphic queries - datastore independent 27

Persistence Frameworks (cont.) Hibernate architecture Transient Objects SessionFactory Transaction Factory Connection Provider Application Persistent Objects Session Transaction JNDI JDBC JTA Database Other (open source) persistence frameworks see http://java-source.net/open-source/persistence 28

Agenda Java Database Connectivity Object Relational Mapping Java Persistency Architecture Persistence Frameworks Java in DB2: Stored Procedures and User Defined Functions 29

Java in DB2: Stored Procedures and User Defined Functions 1. Calling a stored procedure Call independent from how the stored procedure is built Call dependent on INPUT and OUTPUT specifications use JDBC CallableStatement Example CallableStatement callablestmt = connection.preparecall("call STPROC(?,? )"); int companyid = 10023; callablestmt.setint(1, companyid); callablestmt.registeroutparameter(2, Types.CHAR); callablestmt.execute(); String companyname = callablestmt.getstring(2); System.out.println( Name of company + companyid + : + companyname); STPROC runs in stored procedure address space, controlled by WLM 30

Java in DB2: Stored Procedures and User Defined Functions 2. Create a DB2 stored procedure (or User Defined Function) - parameter style Java declare OUT and INOUT parameters as arrays - SQL access level CONTAINS SQL, READS SQL DATA or MODIFIES SQL DATA - use JDBC or SQLJ - multiple result sets can be returned Prepare stored procedure (or UDF) - compile Java class - bind package - put class in CLASSPATH or create JAR file - define JAR to DB2 (DB2_INSTALL_JAR utility) - register stored procedure (or UDF) to DB2 with DDL 31

Literature DB2 9.1 for z/os application programming guide and reference for Java - SC18-9842-03 IBM Redbook - SG24-6435-00 32

Literature (cont.) IBM Redbook - SG24-7604-00 33

Q & A ÿþý 34

Thank you Gie Indesteege Trainer and Consultant gindesteege@abis.be thanks you 35