Web 2.0 Development with IBM DB2

39
October 25–29, 2009 • Mandalay Bay • Las Vegas, Nevada 1 Web 2.0 Development with DB2 Dr. Vladimir Bacvanski, Vice President, InferData, [email protected] Rafael Coss, Solutions Architect, IBM, [email protected] Session Number 2166

description

Vladimir Bacvanski and Rafael CossCommon demands for Web 2.0 application are rich interactivity and ability to handle large volumes of data. Join us to see how to integrate IBM DB2, IBM WebSphere sMash and high-performance data access through IBM Optim pureQuery. This combination provides a way to rapidly develop data-centric, scalable dynamic Web applications. See how we begin with a DB2 database, access the data with Optim pureQuery, use business objects in Groovy, and expose them to users through Dojo AJAX framework.

Transcript of Web 2.0 Development with IBM DB2

Page 1: Web 2.0 Development with IBM DB2

October 25–29, 2009 • Mandalay Bay • Las Vegas, Nevada1

Web 2.0 Development with DB2

Dr. Vladimir Bacvanski, Vice President, InferData, [email protected]

Rafael Coss, Solutions Architect, IBM, [email protected] Number 2166

Page 2: Web 2.0 Development with IBM DB2

Outline

Challenges of Enterprise Web 2.0 Systems

Some Side-Effects of O/R Mapping

Data-Driven Applications and pureQuery

Rich Internet Applications: Ajax and Dojo with RAD

pureQuery + JEE Applications with RAD

pureQuery + Situational Applications with WebSphere sMash

IBM Optim Development Studio

Integrating pureQuery and WebSphere sMash with RAD

Page 3: Web 2.0 Development with IBM DB2

3

Show of Hands!

How many are developers, managers,involved with databases, others?

Are you using Java, Ruby, Python, Groovy, PHP,?

How many are using EJB, plain JDBC, Hibernate?

What’s most important?– Productivity

– Reuse

– Availability

– Performance

– Shared Database

– Flexibility

Page 4: Web 2.0 Development with IBM DB2

Web 2.0

DATA

Software as aSERVICE

COMMUNITYParticipation

RICHUser Interfaces

Page 5: Web 2.0 Development with IBM DB2

What matters most to Enterprise Web 2.0 Systems?

MVC architecture?

Java vs. Python vs. [insert your favorite language]?

Ajax vs. Flash?

MASSIVE AMOUNTSOF DATA

Page 6: Web 2.0 Development with IBM DB2

mashuphttp Stored

Procedures

JSON

QoS goalsJSP

XML

JDBC

Runstats

Response Time!

SQL

Spring

REORG

Partition strategy

ApplicationDeveloper

SQLJ

JDBC

JPA

iBatis, . . .

SpringWhy does this query take so long?

I can’t believe I got called out last week. I wish I could see how these queries will run in production.

Writing Java code is so easy with this eclipse environment.I wish it was that easy to get the SQL right.

This ORM doesn’t allow me to leverage all my database’s SQL.

Static SQL? Sounds like another delay to getting my program deployed

Sometimes I need POJOs, sometime JSON, sometimes XML, what should I use?

Java Data Access – Two Views of the World

Database Developer& Administrator

Another runaway query! Where are these coming from? JDBC? Hmmm…

Inconsistent response time? How long will it take me to find the offending application sending bad SQL this time?

These ad-hoc queries are dangerous. We need a library of tested SQL interfaces.

Can I examine the SQL “before” the application is deployed?

Another GRANT request? This security administration is out of control.

Page 7: Web 2.0 Development with IBM DB2

7

Data Mapping Approaches

Application-Centric

– Top-Down– Start with Object

Domain Model– ORM Mapping– Well supported in

dynamic languages and frameworks

Hybrid

– Meet in the middle– Can be challenging w/o

comprising

Data-Centric

– Bottom-UP– Start with Relational

Data Model– Not well supported in

dynamic languages and frameworks

Persistence Layer

TopDown

BottomUp

Meet in theMiddle

Page 8: Web 2.0 Development with IBM DB2

88

EJB and Hibernate Side Effects

DBA and SQL developer Amnesia Where is the SQL coming from? What is it? Where is it? How do we tune it? How de we manage it?

Performance Concerns: Some App Server vendors claim

(unsurprisingly) that Managed objects performs fine.

There are many user claims of bad Managed object performance is bad on the web.

As always, the truth is in the middle. And will depend on your app server,

application, database, etc ..

“Our top story: Large Customer moves from COBOL to Java to become more agile. In other news, DBA develop amnesia.”

Page 9: Web 2.0 Development with IBM DB2

Introducing pureQuery

pureQuery Components:Simple and intuitive API– Enables SQL access to databases or in-memory Java objects– Facilitates best practices Optim Development Studio (integrates with RAD)– Integrated development environment with Java and SQL

support – Improve problem isolation and impact analysisOptim pureQuery Runtime– Flexible static SQL deployment for DB2

A high-performance, data access platform to simplify developing, managing, securing, and optimizing data access.

Page 10: Web 2.0 Development with IBM DB2

V2.2

Code Development Productivity• Code Generation, Content Assist• Database aware, Java SQL Editor

Design Phase pureQuery close-upModel Integration• Generate Object Model and code from Data Model

SQL Performance Metrics• Find and sort query elapsed time

from Java

Java to SQL Integration• Categorize by Java, SQL, Database ,

Packages, track back to line of code

SQL Injection Prevention• Lock down SQL for Dynamic

Static SQL• Lock in Access plans, Improve Security,

Consistent Performance

Problem Determination• Monitor WebSphere Connection

Pool, JDBC Driver, Network• Track back to SQL and line of

code in the application

SQL Replacement• Replace Query w/o changing source

Existing JDBC to Static• Reroute Dynamic Queries to Static

Jump Start Application Design• Generate SQL and Code from Database Objects • Setup basic DAO Pattern

Page 11: Web 2.0 Development with IBM DB2

Code Example: JDBC Table Column TypeEMP NAME CHAR(64)

EMP ADDRESS CHAR(128)

EMP PHONE_NUM CHAR(10)

class Employee { String name; String homeAddress; String homePhone; …}

java.sql.PreparedStatement ps = con.prepareStatement( "SELECT NAME, ADDRESS, PHONE_NUM FROM EMP WHERE NAME=?");ps.setString(1, name);java.sql.ResultSet rs= ps.executeQuery();names.next();Employee myEmp = new Employee();myEmp.setName(rs.getString(1));myEmp.setHomeAddress(rs.getString(2));myEmp.setHomePhone(rs.getString(3));names.close();

Page 12: Web 2.0 Development with IBM DB2

Code Example: pureQuery

12

Employee myEmp = db.queryFirst( "SELECT NAME, ADDRESS, PHONE_NUM FROM EMP WHERE NAME=?", Employee.class, name);

Even simpler, if we have a method getEmployee with a Java annotation or XML file with SQL for the query:

Employee myEmp = getEmployee(name);

Page 13: Web 2.0 Development with IBM DB2

Develop

Design

Deploy

Optimize

Operate

ModelsPolicies

Metadata

IBM Optim pureQuery

Reduce costs – Increase system throughput – Improve developer productivity– Move workload to zIIP and zAAP

Improve quality of service for new and existing Java applications

– Improve performance – Lock in access plans– Speed up problem resolution

Reduce development time for new Java applications

– Bridge Java and data– Balance productivity and control– Enhance developer and DBA

collaborationEnhance security

– Limit user access – Minimize SQL injection risk– Improve audit readiness

DevelopCode

DebugTest

Tune, Package

Tester

Developer

Page 14: Web 2.0 Development with IBM DB2

Why should DBAs care ?

DBAs have little to no visibility of application SQL before deployment, no opportunity for review and optimization

Problem isolation takes days with contemporary environments such as Java, PHP, .NET, etc due to inability to trace SQL to Java application and source code

Constantly increasing Java application workload taxes existing systems – need to fit more work into existing systems

SQL injection represents an increasing risk to data security

Page 15: Web 2.0 Development with IBM DB2

Why should Developers care ?

Get data access right the first time !

Get it done faster - Improved productivity

Single environment that spans Java application and database development

Improved problem isolation and resolution

Page 16: Web 2.0 Development with IBM DB2

16

How well does it work? – Java applications

In-house testing shows significant performance improvements

IRWW – an OLTP workload, Type 4 driverCache hit ratio between 70 and 85%23 % improvement in throughput using pureQuery over dynamic JDBC15% - 25% reduction on CPU per transaction over dynamic JDBC

274

360420 446

485524

0

100

200

300

400

500

No

rmalized

Th

rou

gh

pu

t (I

TR

)

Normalized Throughput by API for JDBC Type 4 Driver

-35%

-14%

6%15%

25%

-50%

% in

crea

se/r

edu

ctio

n in

CP

U p

er

tran

sn c

om

par

ed t

o J

DB

C

% increase/reduction in CPU per transaction compared to JDBC using Type 4 driver

Page 17: Web 2.0 Development with IBM DB2

17

How well does it work? - .Net applications

Throughput during static execution increased by 159% over dynamic SQL execution assuming a 79% statement cache hit ratio

*Any performance data contained in this document were determined in various controlled laboratory environments and are for reference purposes only. Customers should not adapt these performance numbers to their own environments as system performance standards. The results that may be obtained in other operating environments may vary significantly. Users of this document should verify the applicable data for their specific environment.

IRWW – OLTP application

Application accesses DB2 for z/OS

Page 18: Web 2.0 Development with IBM DB2

18

Control performance– Decide at deployment time how the SQL is executed– Understand and lock down the access plan for SQL– Replace suboptimal SQL without changing the application

Control security– Prevent SQL injection– Prevent execution of unauthorized SQL– Better manage database security

See inside applications that are driving your database– Understand where SQL comes from– Understand when frameworks and ORM’s are getting in the way

Simplify problem determination and troubleshooting– Correlate problem SQL with applications, ORM’s and frameworks

Optim pureQuery Runtime

Page 19: Web 2.0 Development with IBM DB2

19

How do I start with pureQuery

Existing applications– Optimize existing JDBC (and .NET!) applications

– No code changes needed

– Have to go through the client optimization process to get to static SQL

New applications– Use the pureQuery API

– Development codes using one API regardless of whether it is deployed dynamically or statically

– DBA deploys statically

– No need to go through client optimization process

Other – JPA, iBatis, Hibernate

Page 20: Web 2.0 Development with IBM DB2

20

Open Source Persistence API

Open Source Persistence

Engine

JPA API

JPA Persistence Engine

JDBC API

Hibernate, iBATIS, EclipseLink,...

JPA for WebSphere, Apache OpenJPA

pureQuery API

Optim pureQueryPlain JDBC

Web API

Data Web Services, Project Zero, sMash

pureQuery Gives You Options

JCC driver

JDBC

DB2 and Informix nowMore coming

.Net Applications

.Net applications

ADO .Net

V2.1 Feature

pureQuery

Page 21: Web 2.0 Development with IBM DB2

21

pureQuery Facilitates Best Practices

Supports both inline SQL and Java annotations (method) Intuitive interfaces for common data retrieval and manipulation scenarios hides JDBC complexity

– Query First– Homogeneous Batch

Reduce network trips to the database – Query Over Java Collections– Heterogeneous Batch

Use custom result handlers to map results to POJO’s, XML, JSON, …

Write high performance Java data access applications, Part 3: Data Studio pureQuery API best practices

-- Vitor Rodrigueshttp://www.ibm.com/developerworks/db2/library/techarticle/dm-808rodrigues/?S_TACT=105AGX01&S_CMP=LP

Page 22: Web 2.0 Development with IBM DB2

22

DB2 Data Servers

pureQuery client optimization enables static execution for JDBC applications (custom-developed, framework-based, or packaged) Existing JDBC Application

JDBC Driver w/ pureQuery

Dynamic SQL execution Static SQL execution

Optimize Existing JDBC Applications

Captured SQL- related

metadata

Capture Configure Bind Execute

"The ability to use static SQL with pureQuery is huge. Recently, I worked with a client who could reduce CPU usage by 7 percent thanks to this one feature."

— David Beulke, Pragmatic Solutions Inc.

Improve performance for DB2 – without changing a line of code

Page 23: Web 2.0 Development with IBM DB2

Rational

ClearQuest

Creates businessprocess model

Create & manage software delivery requirements

Create architectural model enabling

the tasks from BPM to be automated

Implement new& integrate existing services

Business Analyst

Software Architect

RequirementsAnalyst

Developer

WebSphereBusiness Modeler

RationalRequisitePro

RationalSoftware Modeler 7.5

RationalApplication Developer7.

5

RationalSoftware Architect 7.5

Transform Models to Code

Optim Development Studio

Data Architect

Data Access Developer

Implement newprocedures and services

Link requirements to data assets

Transform between business items and data model

InfosphereData Architect 7.5

Create or reverse engineer logical and physical models

Transform between software and data models

Optim Test Data Manager

Database Administrator

Extract test data from production systems

Integration with Rational

Page 24: Web 2.0 Development with IBM DB2

pureQuery Balances Productivity and Control

Managed objects Object-relational mapping

Spring templates

Full SQL control

Code all your SQL

Use SQL templates, inline only

Complex OR mapping and persistence management, but loss of controls

Adds container management option

JDBC / SQLJ

iBATIS

Hibernate

OpenJPA (EJB3)

Add basic OR mapping and annotated-method stylepureQuery

Page 25: Web 2.0 Development with IBM DB2

RAD / Development Studio Data Centric Development Scenario

Presentation

•Dojo, JSF, …

Application

•Business Logic

Objects

•Access to data

Tables

•Data

Write in JavaUsing RAD+WAS FP for Web 2.0

Write in Java with pureQueryUsing Optim Dev. Studio in RAD

Access generated Java data objects from code developed in RADWAS Feature

Pack for Web 2.0

Page 26: Web 2.0 Development with IBM DB2

RAD and Web 2.0 Rich Internet Applications

RAD supports development of Ajax applications

Essentially: HTML + JavaScript + Asynchronous communication– Uses Dojo Ajax libraries

– IBM Dojo extensions

Visual tools for Dojo UI development

Libraries and tools:– Invoking Java code from Dojo with RPC Adapter

– JSON4J

– Ajax messaging

26

Page 27: Web 2.0 Development with IBM DB2

Choosing the Right ToolsU

sage

Strategic, IT built applications.

Simple applications built by professionals

WebSphere sMashResponding to unplanned situations.Innovating around prospective business opportunities where agility is key and the outcome is still unknown.Enabling new insights by combining information from the web and enterprise data sources.

RAD + WASHeavily used, complex applications built by IT teams.

Page 28: Web 2.0 Development with IBM DB2

What is WebSphere sMash?

Groovy and PHP– Uses pureQuery for data access

– Can use Java codeConvention over configuration– Common tasks do not require

configurationApplication-centric runtime– Write the app, run it, and it’s ready for

use– No need for a separate application

server–Each app has its own JVM process–Fast start!

28

A complete platform for developing, assemblingand executing agile Web 2.0 apps quickly and simply.

Page 29: Web 2.0 Development with IBM DB2

RAD, WebSphere sMash and pureQuery in Data Centric Development

Development scenario:– A database already exist

– We want to use the productive Optim Development Studio development features

– We want to benefit from pureQuery features

– We may need to integrate with other already existing components and applications

Solution:– Use WebSphere sMash together with RAD + Development Studio

• Shell share

– Generate Java code from Development Studio functionality, use from Groovy

– Use RAD powerful features for GUI Dojo development and integration with other components and applications

Page 30: Web 2.0 Development with IBM DB2

Development and Execution: pureQuery and sMash

Create a WebSphere sMash project

Add pureQuery Support

Generate / write pureQuery DB code in Java

Code WebSphere sMash application

Run: sMash Application uses pureQuery

DB

Design

Execution

JEE/J2EEComponents

Existing Applications

RIA UI with Dojo

Develop mostly with RAD

Develop mostly w. Optim Dev. Studio + sMash

Page 31: Web 2.0 Development with IBM DB2

Start with the Database

Use Development Studio to explore the database

Then generate the pureQuery code

This will create the Java classes in the sMash project

Page 32: Web 2.0 Development with IBM DB2

Using pureQuery Code in WebSphere sMash

1. Using Development Studio, pureQuery code is generated in Java folders

2. pureQuery code is used from Groovy or PHP

Page 33: Web 2.0 Development with IBM DB2

Using Java pureQuery Code from Groovy• Access the database using

the pureQuery generated helper class

• Invoke generated method to list the employees

• Convert the result to JSON and send it to the client• Clients consume the result as e.g. RIA:

AJAX, Flex, …

• sMash function handles GET HTTP requests

Page 34: Web 2.0 Development with IBM DB2

34

Page 35: Web 2.0 Development with IBM DB2

Conclusion

• Excellent data development capabilities• Efficient data access

Dev. Studio & pureQuery

• Powerful Java, JEE tooling• Web 2.0: Dojo + integration with JEERAD• Agile Web Application Platform• Speed, agility, simplicity

WebSphere sMashData driven, agile

development of

Web 2.0 applications

Page 36: Web 2.0 Development with IBM DB2

Demo

36

Demo!

Page 37: Web 2.0 Development with IBM DB2

Where to go Next? Resources and more…

WebSphere sMash– http://www.ibm.com/websphere/smash

Optim Development Studio – http://www.ibm.com/software/data/optim/development-studio/

IBM pureQuery– http://www.ibm.com/software/data/optim/purequery-platform/faq.

html

pureQuery Custom Training – InferData, IBM Business Partner http://www.inferdata.com

– Course: Developing Database Applications with Optim Development Studio and pureQuery

– http://www.inferdata.com/training/data/optim_purequery_training.html

38

Page 38: Web 2.0 Development with IBM DB2

Web, Blogs

Project Zero

http://www.projectzero.org

Integrated Data Management (Optim and Data Studio)– http://www.ibm.com/developerworks/spaces/optim

Blogs: – On Building Software http://www.OnBuildingSoftware.com

– Data Life Cycle ++ http://datalifecycle.blogspot.com

Twitter:– http://twitter.com/OnSoftware

– http://twitter.com/racoss

39

Page 39: Web 2.0 Development with IBM DB2

4040

Thank You!Your Feedback is Important to Us

Please complete the survey for this session by:– Accessing the SmartSite on your smart phone or computer at:

iodsmartsite.com • Surveys / My Session Evaluations

– Visiting any onsite event kiosk• Surveys / My Session Evaluations

– Each completed survey increases your chance to win an Apple iPod Touch with daily drawling sponsored by Alliance Tech