Clinton R. Begin 2 Dealing with Enterprise Database Challenges Featuring the Apache iBATIS Data Mapping Framework Clinton Begin

Slides:



Advertisements
Similar presentations
An Object/Relational Mapping tool Free and open source Simplifies storage of object data in a relational database Removes the need to write and maintain.
Advertisements

Bruce Scharlau, University of Aberdeen, 2012 Data storage options for mobiles Mobile Computing.
Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
What is a Database By: Cristian Dubon.
Database Management3-1 L3 Database Management Santa R. Susarapu Ph.D. Student Virginia Commonwealth University.
MC365 JDBC and Server-Side Programming: Updating a database via JDBC & Connection Pooling.
Chapter 3 Database Management
1 JDBC Java Database Connectivity. 2 c.pdf
Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar.
CSC 2720 Building Web Applications Database and SQL.
State of Connecticut Core-CT Project Query 4 hrs Updated 1/21/2011.
Data Persistence and Object-Relational Mapping Slides by James Brucker, used with his permission 1.
Struts Petstore Struts University Series. Abstract Struts has always shipped with a simple example application. But for many teams, MailReader is a bit.
Embedded SQL Host Language (record-oriented) DBMS (set-oriented) 1. Query 3. Process a tuple at a time 4. Close Cursor 2. Evaluate query. Provide cursor.
Training - Day 3 OJB. What is OR Mapping? OR Mapping is the mapping of relational database tables to objects (Java Objects in our case) Many OR Mapping.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
Entity Framework Code First End to End
UPortal Developers MIT August 2004 Persistence Strategy for uPortal 3 Mike DeSimone the r-smart group
DBA Developer. Responsibilities  Designing Relational databases  Developing interface layer Environment Microsoft SQL Server,.NET SQL Layer: Stored.
Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.
1 Overview of Databases. 2 Content Databases Example: Access Structure Query language (SQL)
NHibernate in Action Web Seminar at UMLChina By Pierre Henri Kuaté 2008/08/27
Introduction to SQL Steve Perry
ADO.NET A2 Teacher Up skilling LECTURE 3. What’s to come today? ADO.NET What is ADO.NET? ADO.NET Objects SqlConnection SqlCommand SqlDataReader DataSet.
Dr. Magdi AMER Unit 2 Introduction to Database. Intro Many programs need to save information on disk. The role of DB system is to provide a layer of abstraction.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Object Oriented Analysis and Design 1 Chapter 7 Database Design  UML Specification for Data Modeling  The Relational Data Model and Object Model  Persistence.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
CS 160: Software Engineering October 1 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Introduction to the new mainframe © Copyright IBM Corp., All rights reserved. Chapter 12 Understanding database managers on z/OS.
CS 160: Software Engineering October 15 Class Meeting
JDBC Java and Databases. RHS – SOC 2 JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
Hibernate Persistence. What is Persistence Persist data to database or other storage.  In OO world, persistence means persist object to external storage.
Hibernate 3.0. What is Hibernate Hibernate is a free, open source Java package that makes it easy to work with relational databases. Hibernate makes it.
Chapter 8 Databases.
Chapter 25 Databases. Chapter Scope Database concepts Tables and queries SQL statements Managing data in a database Java Foundations, 3rd Edition, Lewis/DePasquale/Chase25.
Tallinna Tehnikaülikool Informaatikainstituut Javal baseeruv objektide püsivuse kiht Jakamar Bakalaureusetöö Üliõpilane:Erki Suurjaak Matrikli nr:
Copyright  Oracle Corporation, All rights reserved. 7 Accessing a Database Using SQLJ.
Copyright © 2002 ProsoftTraining. All rights reserved. Building Database Client Applications Using JDBC 2.0.
Creating competitive advantage Copyright © 2003 Enterprise Java Beans Presenter: Wickramanayake HMKSK Version:0.1 Last Updated:
Database Design Some of these slides are derived from IBM/Rational slides from courses on UML and object-oriented design and analysis. Copyright to the.
Presentation On How To Create Connection To A Database.
COMP 321 Week 4. Overview Normalization Entity-Relationship Diagrams SQL JDBC/JDBC Drivers hsqldb Lab 4-1 Introduction.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool The problem fixed by ORM Advantage Hibernate Hibernate Basic –Hibernate sessionFactory –Hibernate Session.
NSF DUE ; Wen M. Andrews J. Sargeant Reynolds Community College Richmond, Virginia.
DAT602 Database Application Development Lecture 8 Advanced JDBC.
Learningcomputer.com SQL Server 2008 –Views, Functions and Stored Procedures.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Data Access with Spring.
Basics of JDBC Session 14.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Spring JDBC Simplifying.
Fundamentals of MyBATIS
Chapter 3: Relational Databases
1 JDBC – Java Database Connectivity CS , Spring 2010.
Introduction to ORM Hibernate Hibernate vs JDBC. May 12, 2011 INTRODUCTION TO ORM ORM is a programming technique for converting data between relational.
JDBC I IS Why do we have databases?
Retele de senzori Curs 2 - 1st edition UNIVERSITATEA „ TRANSILVANIA ” DIN BRAŞOV FACULTATEA DE INGINERIE ELECTRICĂ ŞI ŞTIINŢA CALCULATOARELOR.
Data Resource Management Application Layer TPS A RCHITECTURE Data Layer Sales/MarketingHR Finance/Accounting Operations Spreadsheet Data MS Access Accounts.
CS422 Principles of Database Systems Object-Relational Mapping (ORM) Chengyu Sun California State University, Los Angeles.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
JSP/Database Connectivity Instructor: Dr. M. Anwar Hossain.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
SQL Basics Review Reviewing what we’ve learned so far…….
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
CompSci 280 S Introduction to Software Development
JDBC Database Management Database connectivity
Database Programming in Java
Introduction to .NetTiers
Computer Science Projects Database Theory / Prototypes
Presentation transcript:

Clinton R. Begin

2 Dealing with Enterprise Database Challenges Featuring the Apache iBATIS Data Mapping Framework Clinton Begin

3 Demo… Just move data from here to there.

4 Scope The Challenges Ownership, access, complexity, normalization, skinny design. iBATIS Data Mapping Framework Introduction, SQL Mapping defined, examples. SQL Is it still relevant? iBATIS is a hybrid solution Features, qualities, competition, other solutions.

5 The Challenges “Welcome, to the real world.” – go for the red pill

6 Challenges of Politics Database ownership and control Change management Cost allocation – who pays for changes? No “developer” access to design Proprietary/3 rd Party – legal issues Agile methods vs. legacy methods

7 iBATIS isolates the data model, the SQL, the work and the responsibility. In doing so, it isolates much of the politics surrounding the enterprise database as well.

8 Challenges of Imperfection Denormalized models Super-normalized models Modeled Value Entities Thin data models (rows vs. columns) Implicit relationships Overcomplicated relationships Null Values (?)

9 Thin data model GroupNameTypeValue 1StreetString12 Some St 1CityStringModesto 1StateStringCalifornia 1ZipString StreetString543 Other St 2CityStringFresno 2StateStringCalifornia 2ZipString34332

10 iBATIS works even when the data model does not map to the object model.

11 Challenges of Legacy and complexity Too many tables to map Encoded Fields No primary keys Hierarchical ERP systems Temporal databases “600 tables” – moderate size (?)

12 iBATIS allows you to build modern applications on top of legacy databases by allowing you more freedom to define and tune your mappings that deal with “unique” databases.

13 Challenges of Technology Distributed transactions Distributed caching Vendor specific database features Multiple databases w/ single object model

14 iBATIS supports advanced enterprise features and allows you to take full advantage of the investment you’ve made in your relational database management system.

15 An Introduction to Apache iBATIS SQL Mapping defined…

16 SQL Mapping Concept

17 SELECT FIRST_NAME, LAST_NAME FROM EMPLOYEE WHERE EMPLOYEE_NUMBER = ‘1234’ INPUT OUTPUT SQL as a Black Box

18 SQL Mapping Maps objects to SQL statements NOT Classes to Tables Fully functional SQL via named statements NOT generated SQL (although that’s possible) For example…

19 id : int total : BigDecimal pst : BigDecimal gst : BigDeciml lineItems : Collection date : Date Order id : int product : Product order : Order cost : BigDecimal retail : BigDecimal LineItem id : int name : String description : String cost : BigDecimal retail : BigDeciml Product Order LineItem Product Mapping Layer TABLES CLASSES

20 id : int total : BigDecimal pst : BigDecimal gst : BigDeciml lineItems : Collection date : Date Order id : int product : Product order : Order cost : BigDecimal retail : BigDecimal LineItem id : int name : String description : String cost : BigDecimal retail : BigDeciml Product Order LineItem Product Mapping Layer SQL TABLES CLASSES

21 The Product Table PRODUCT PRODUCT_IDINTEGERPK, NN NAMEVARCHARNN DESCRIPTIONTEXTNN COSTMONEYNN RETAILMONEYNN

22 The Product Class public class Product { private int id; private String name; private String description; private BigDecimal cost; private BigDecimal retail; //…getters/setters implied }

23 The SQL SELECT PRODUCT_ID as id, NAME, DESCRIPTION, COST, RETAIL, FROM PRODUCT WHERE PRODUCT_ID = #id#

24 Simple Configuration String resource = “SqlMapConfig.xml”; Reader reader = Resources.getResourceAsReader (resource); SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);

25 Executing the Query Product product = (Product) sqlMap.queryForObject (“getProduct”, 5);

26 … Audience: OMG! Did you just hand code SQL? Clinton: Yes. …

27 SQL Is it still relevant?

28 SQL Structured Query Language Introduced in 1973 by IBM Based on relational model of 1970 Based on sound mathematical principles Significant industry investment Has withstood the test of time Nothing else has ever come close

29 “SQL is much more than a simple data update and retrieval mechanism. SQL's query processing can perform many tasks. By hiding SQL, application developers are excluding a powerful tool.”

30 Writing SQL is NOT a Sin!

31 Is SQL what we want to avoid? SELECT * FROM EMPLOYEE WHERE EMPLOYEE_NUMBER = 99

32 Or is it JDBC? public Employee getEmployee (int id) throws SQLException { Employee employee = null; String sql = "SELECT * FROM EMPLOYEE " + "WHERE EMPLOYEE_NUMBER = ?"; Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = dataSource.getConnection (); ps = conn.prepareStatement(sql); ps.setInt(1, id); rs = ps.executeQuery(); employee = null; while (rs.next()) { employee = new Employee(); employee.setId (rs.getInt("EMP_ID")); employee.setEmployeeNumber (rs.getInt("EMP_NUMBER")); employee.setFirstName (rs.getString("EMP_FIRST_NAME")); employee.setLastName (rs.getString("EMP_LAST_NAME")); employee.setTitle (rs.getString("EMP_TITLE")); } } finally { try { if (rs != null) rs.close(); } finally { try { if (ps != null) ps.close(); } finally { if (conn != null) conn.close(); } return employee; }

33 iBATIS is a hybrid solution Qualities, features and competition.

34 Options… Stored procedures Inline SQL Dynamic SQL Object Relational Mapping  iBATIS IS A HYBRID!

35 A Hybrid? Full support for stored procedures SQL is written just like inline SQL “Inline SQL for XML” Advanced dynamic SQL definition features A big problem even for the best ORM tools Shares many features with ORM Caching, lazy loading, join mapping, bytecode enhancement etc.

36 Apache iBATIS… Is tolerant of complex/bad database designs Isolates the data model Separates concerns Divides labor Saves time Reduces code

37 Advanced iBATIS Features Supports all types Objects, Primitives, Arrays, Collections Caching (use case vs. holistic) Lazy Loading or Join Mapping (1:1, 1:M, M:N) Bytecode enhancement (ifaces AND classes) XML parameters and results Transaction Management (Local/Global)

38 But yes…SQL Coding is Required Many people consider this an advantage Many others eventually realize it’s required Few people consider it a problem SQL can be done fast and done well Use good tools (there are plenty) Generation is an option (but not a best practice) The SQL may already exist (consider app rewrites or ports)

39 Other “SQL Mapper-Like” Tools JDBC PreparedStatement Embedded SQL as a language feature Pro*C, Forte TOOL, SQLJ Spring framework Voruta SQLC (iBATIS inspired?) O/R Broker (iBATIS inspired) Mr. Persister (iBATIS inspired) Aximol SQL Library (iBATIS inspired)

40 iBATIS 3 Years ago JPetStore posted on TSS iBATIS noticed in the persistence layer Architectural reviewer said: “Use Torque” Why not just use ORM for everything? What kept it going…?

41 What drives open source? Frustration / Anger / Need Confidence / Ego Pride Duty Community

42 iBATIS Today ~10,000 users ~1.2 Million DTD hits per month from tools Apache Software Foundation 12 Developers Java,.NET, Ruby

43 Audience Response Questions?

44 More simple examples… To inspire questions or support answers.

45 select PRODUCT_ID as id, NAME as name, DESCN as description, CATEGORY as category from PRODUCT where PRODUCTID = #id#

46 select * from PRODUCT where PRODUCTID = #id#

47 select PRODUCT_ID as id, NAME as name, DESCN as description, CATEGORY as category from PRODUCT where PRODUCTID = ?

48 insert into PRODUCT values (#id#,#name#,#description#,#category#) update PRODUCT set NAME = #name#,DESC = #description#,CATEGORY=#category# where PRODUCT_ID = #id# delete PRODUCT where PRODUCT_ID = #id#

49 Simple Query Product product =(Product) sqlMap.queryForObject (“getProduct”, 23);

50 Insert, Update, Delete Product product = new Product(); product.setId(324); product.setName(“Shih Tzu”); Product.setDescription(“Some longer description.”); product.setCategory(“DOG”); sqlMap.insert(“insertProduct”, product); product.setCategory(“CAT”); sqlMap.update(“updateProduct”, product); product.delete(“deleteProduct”, product);

51 Transaction Handling try { sqlMap.startTransaction(); sqlMap.insert(“insertProduct”, product); sqlMap.update(“updateProduct”, product); product.delete(“deleteProduct”, product); sqlMap.commitTransaction(); } finally { sqlMap.endTransaction(); }

52 What does an application using SQL Maps look like? See JPetStore 4