Vladimir Bacvanski and Dan Galvin
Looking for a more flexible and efficient way for Java programs to access the database? Join us as we explore how you can
bridge the gap between Java and relational databases. Enhance your Java environment with access layer generation, data
access best practices, traceability between Java packages and SQL statements, improved impact analysis and more. And most importantly, see how new technology can improve not only new development, but existing applications as well. Be prepared to
see designs and code samples!
Scanning the Internet for External Cloud Exposures via SSL Certs
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2
1. 0 Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery Dr. Vladimir Bacvanski, Vice President, InferData, vladimir@inferdata.com Daniel Galvin, Consultant, Galvin Consulting, dang@galvinconsulting.com Session Number 2171
2. What is this revolution about? 1 NO SLOW APPS! NO BAD SQL! GET CONTROL BACK !
3. Show of Hands: What Data Access Technology Have You Used? 2 Hibernate EJB Entity Beans JDBC JPA iBatis SQLJ What’s most important to you? Productivity Performance Security Portability
4. Java Data Access – Two Views of the World Writing Java code is so easy with this eclipse environment.I wish it was that easy to get the SQL right. JSP QoS goals Spring Another runaway query! Where are these coming from? JDBC? Hmmm… Runstats XML http Partition strategy Stored Procedures mashup SQL Response Time! REORG JSON JDBC This ORM doesn’t allow me to leverage all my database’s SQL. Inconsistent response time? How long will it take me to find the offending application sending bad SQL this time? JDBC I can’t believe I got called out last week. I wish I could see how these queries will run in production. SQLJ JPA These ad-hoc queries are dangerous. We need a library of tested SQL interfaces. Application Developer Database Developer& Administrator Spring Why does this query take so long? iBatis, . . . Sometimes I need POJOs, sometime JSON, sometimes XML, what should I use? Static SQL? Sounds like another delay to getting my program deployed Another GRANT request? This security administration is out of control. Can I examine the SQL “before” the application is deployed?
5. Meet in the Middle 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 Top Down Persistence Layer Bottom Up 4
16. 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.” 5 5
17. Introducing pureQuery A high-performance, data access platform to simplify developing, managing, securing, and optimizing data access. 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/RSA) Integrated development environment with Java and SQL support Improve problem isolation and impact analysis Optim pureQuery Runtime Flexible static SQL deployment for DB2
18. Add basic OR mapping and annotated-method style pureQuery pureQuery Balances Productivity and Control Managed objects Object-relational mapping Full SQL control Code all your SQL JDBC / SQLJ Use SQL templates, inline only Spring templates iBATIS Complex OR mapping and persistence management, but loss of controls Hibernate Adds container management option OpenJPA (EJB3)
19.
20.
21.
22.
23. Code Example: pureQuery 10 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);
24. Why Should be the Data Specialists be interested in pureQuery? 11
45. Cost of Prepare CPU cost of Short Prepare on DB2 9 for z/OS – between 400µs and 1ms CPU cost of Full Prepare on DB2 9 for z/OS – approximately 30 to 50ms. Cost could be much higher and generally increase with complexity.
47. How well does it work? – Java applications In-house testing shows significant performance improvements IRWW – an OLTP workload, Type 4 driver Cache hit ratio between 70 and 85% 23 % improvement in throughput using pureQuery over dynamic JDBC 15% - 25% reduction on CPU per transaction over dynamic JDBC 18
48.
49. Application accesses DB2 for z/OS*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. 19
51. Homogeneous & Heterogeneous Batch Homogeneous Batch – all instances in the batch are the same statement and require only 1 line turn Heterogeneous Batch – allows different SQL statements to be included in batch. Both Utilize Multi-Row Insert Heterogeneous Batches may contain 0 to many Homogeneous Batches
53. Client Optimization Allows you to bind static SQL packages from existing JDBC code Avoids the cost of rewriting the application to code to the pureQuery API Allows Heterogeneous batch with minor changes to the code None of the productivity advantages are realized. Code is still maintained in JDBC. End-to-End monitoring lacks some introspective capability into the coding Creation of the static packages requires that you run the code. Some overhead at runtime related to resolution of statements to static packages
54. 24 Optimize Existing JDBC Applications Improve performance for DB2 – without changing a line of code Capture Configure Bind Execute pureQuery client optimization enables static execution for JDBC applications (custom-developed, framework-based, or packaged) Existing JDBC Application Captured SQL- related metadata JDBC Driver w/ pureQuery Dynamic SQL execution Static SQL execution DB2 Data Servers "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.
55. Design Develop Optimize Govern Models Policies Metadata Deploy Operate 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 collaboration Enhance security Limit user access Minimize SQL injection risk Improve audit readiness Developer Develop Code Debug Test Tune, Package Tester
56. 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
57. 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
58. 28 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
59. 29 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
60. 30 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 -- VitorRodrigues http://www.ibm.com/developerworks/db2/library/techarticle/dm-808rodrigues/?S_TACT=105AGX01&S_CMP=LP
61. 31 A TypicalApplication Architecture with pureQuery Presentation Layer Implements the U/I or network protocols using the business services Business Service Layer Never use the pureQuery API directly. Gets data from the Data Access Layer Data Access Layer Using the pure-query API to access the database. Provides a technology neutral API to the data used by the business services pureQuery pureQuery makes this layer easy, fast, consistent and traceable Database Sometimes additional layers are required Workflow Data federation Workspace
62. RAD or RSA / Optim Development Studio Data Centric Development Scenario 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 RAD WAS Feature Pack for Web 2.0
64. 34 Conclusion: pureQuery Revolutionary Advantages Excellent performance Static and dynamic SQL is captured during test and optimized before deployment Enables lock-in of access path Great productivity Excellent tool support through Optim Development Studio Shell share with Rational tools Mapping from SQL to Java captured and traceable Facilitates collaboration between DBA’s and developers Performance tuning, impact analysis Better security Limits SQL injection Controlled database access
65. Where to go Next? Resources and more… 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 35
66. Web, Blogs Integrated Data Management (Optim and Data Studio) http://www.ibm.com/developerworks/spaces/optim Vladimir’s Blog: On Building Software http://www.OnBuildingSoftware.com Twitter: http://twitter.com/OnSoftware 36
67. 37 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 37
Editor's Notes
What do the Data Specialists care about? Things like SQL tuning, CPU Costs, Capacity Planning and Hardware Resources. They want to easily identify the SQL statements in an application, obtain the information about the access path and make appropriate adjustments. So how can pureQuery help address these concerns? In several critical and impressive ways.
For SQL that is static in nature, it is advantageous to bind the SQL statically for many reasons. First, the bound package is easy to EXPLAIN. Second, the selected path is relatively assured and consistent. Third, the prepare process is eliminated. Each statement that is executed dynamically must be prepared on each execution. Statement caching in the container and on the DBMS can help reduce these costs, but still, the costs can be significant. The higher the volume of executions, the more pronounced the costs.
Here is an example of a method in a Data Access Object (DAO) that actually contains both a Heterogeneous and Homogeneous batch. Notice the data objects are instantiated and then the start batch is invoked. The methods in the pureQuery interfaces are invoked which actually contain the SQL and then the endBatch is executed. This causes the batch to be executed in one line turn.How does this help?