SlideShare une entreprise Scribd logo
1  sur  21
1
Introduction to iBatis
Kunal Umrigar
2
3
Problems
 Tight integration of SQL code and Java code.
 Redundant JDBC code consumes a lot of development time.
 Is our DAO really a DAO?
4
Solutions?
5
Hibernate (ORM)
Object-Relational Mapping
??
6
Hibernate/Object-Relational Mapping
 Tools/techniques to store and retrieve objects from
a database
 From the code perspective it behaves like a
virtual object database
 A complete ORM solution provide:
 Basic CRUD functionality
 An Object-Oriented Query Facility
 Mapping Metadata support
 Transactional Capability
7
Hibernate pros and cons
Pros:
 No SQL coding required
 Database vendor independent
 Provides caching mechanisms
Cons:
 Requires learning of quite a lot of stuff
 Limits queries to HQL syntax
 Debugging and performance tuning is sometimes quite
complected
 Does not fit with legacy or complex Database.
8
An Introduction to Apache iBATIS
(i)nternet + A(batis)
SQL Mapping defined...
9
About iBATIS
 Open source framework that reduces the complexity to
read/save Java objects from a database (persistence)
 Decouples Java code from SQL
 Avoids the necessity to use JDBC
 It is NOT an object-relational mapper (such as
Hibernate)
 Simplifies the developer’s life ☺
10
iBatis Components
iBATIS usage is divided into two main components:
 SQLMaps
Permits to read/save Java objects into relational
DBMS without using JDBC and without mixing
Java and SQL code
 DAO <Spring framework DAO>
“Is an abstraction layer that hides the details of
your persistence solution and provides a common
API to the rest of your application”
Note: previous versions of iBatis had separate DAO component which is deprecated in the
latest version iBatis 3.
11
12
Sql Mapping
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...
13
The Product Class
public class Product
{
private int id;
private String name;
private String description;
private BigDecimal cost;
private BigDecimal retail;
// ...getters/setters implied
}
14
The SQL
<select id=“getProduct" parameterClass=“int”
resultClass="examples.domain.Product">
SELECT
PRODUCT_ID as id,
NAME,
DESCRIPTION,
COST,
RETAIL,
FROM PRODUCT
WHERE PRODUCT_ID = #id#
</select>
15
<bean id="productDAO"
class="examples.domain.dao.ProductDAO">
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
<property name="dataSource">
<ref bean="myDataSource" />
</property>
</bean>
The Spring DAO Bean
16
public class ProductDAOImpl extends SqlMapClientDaoSupport
implements
ProductDao
{
@SuppressWarnings("unchecked")
public List<Product> getAllProducts(int id)
{
List<Product> productList =
getSqlMapClientTemplate().queryForList(
"getProduct" , id );
return productList;
}
.....
The Product DAO Implementation
17
...
“WTF!! Do you mean we need to hand
code XML configurations?”
“Yeah!! That's true..”
...
18
JDBC
 Obtain the db Connection
 Create the statement
 Set the input parameters
 Execute the statement
 Create the result Collection
 For each row fetched:
 Create an object
 Set object’s properties using
row’s colums
 Add the object to the
Collection
 Release resources
 Close the Connection
 Return the Collection
IBATIS
Obtain the SqlMap object
Prepare complex parameters
(optional)
Invoke the query passing the
parameters
Return the result
JDBC-iBatis Comparison
19
5 Reasons to use iBatis
1. Works with any database that has a JDBC driver
(can re-use existing MySQL queries ) & You already
know SQL, why waste timelearning something else?
2. Supports Map, Collection, List and Primitive
Wrappers (Integer, String etc.)
3. Easy integration with Spring DAO.
4. Works well with legacy DB and complex relational
mappings between DB tables.
5. Supports complex object mappings (populating
lists, complex object models etc.), Transactions, Lazy
Loading or Join Mapping (1:1, 1:M, M:N), and caching.
20
- Full power of real SQL
- Works with complex, enterprise, ERP or
even poorly designed databases
- Fully supports composite keys and
complex relationships
- Complete stored procedure support
- JavaBeans support
- Primitive wrappers (Integer, String,
Date etc.)
- HashMap, List, Collection, and array[]
- XML text and DOM Support
- Null value translation
- Auto-mapping bean properties to
columns
- Dynamic SQL using conditional XML
tags
- Caching and dependency management
- Centralized data source configuration
- Local and global (JTA) transaction
support
- Small footprint 300k (minimum)
- Minimal dependencies (only common-
logging required)
- Spring DAO Templates available
iBATIS SQL Mapping Framework
21
Books:
 iBATIS In Action - Clinton Begin (Manning)
Links for reference:
 http://en.wikipedia.org/wiki/IBATIS
 http://ibatis.apache.org/onlinehelp.html
 http://www.javabeat.net/articles/52-spring-ibatis-integration-1.html
 http://www.learntechnology.net/content/ibatis/spring_ibatis.jsp
 Using-iBatis-SQL-Maps-for-Java-Data-Access

Contenu connexe

Similaire à fdocuments.in_introduction-to-ibatis.ppt

Hibernate in XPages
Hibernate in XPagesHibernate in XPages
Hibernate in XPages
Toby Samples
 
Hw09 Sqoop Database Import For Hadoop
Hw09   Sqoop Database Import For HadoopHw09   Sqoop Database Import For Hadoop
Hw09 Sqoop Database Import For Hadoop
Cloudera, Inc.
 
android sqlite
android sqliteandroid sqlite
android sqlite
Deepa Rani
 
Spring db-access mod03
Spring db-access mod03Spring db-access mod03
Spring db-access mod03
Guo Albert
 

Similaire à fdocuments.in_introduction-to-ibatis.ppt (20)

NoSql Databases
NoSql DatabasesNoSql Databases
NoSql Databases
 
BITM3730Week13.pptx
BITM3730Week13.pptxBITM3730Week13.pptx
BITM3730Week13.pptx
 
Run Oracle Apps in the Cloud with dashDB
Run Oracle Apps in the Cloud with dashDBRun Oracle Apps in the Cloud with dashDB
Run Oracle Apps in the Cloud with dashDB
 
Trivadis TechEvent 2017 Oracle to My SQL Migration - Challenges by Robert Bia...
Trivadis TechEvent 2017 Oracle to My SQL Migration - Challenges by Robert Bia...Trivadis TechEvent 2017 Oracle to My SQL Migration - Challenges by Robert Bia...
Trivadis TechEvent 2017 Oracle to My SQL Migration - Challenges by Robert Bia...
 
Midao JDBC presentation
Midao JDBC presentationMidao JDBC presentation
Midao JDBC presentation
 
Java database programming with jdbc
Java database programming with jdbcJava database programming with jdbc
Java database programming with jdbc
 
Dao pattern
Dao patternDao pattern
Dao pattern
 
Hibernate in Action
Hibernate in ActionHibernate in Action
Hibernate in Action
 
Hibernate in XPages
Hibernate in XPagesHibernate in XPages
Hibernate in XPages
 
Hw09 Sqoop Database Import For Hadoop
Hw09   Sqoop Database Import For HadoopHw09   Sqoop Database Import For Hadoop
Hw09 Sqoop Database Import For Hadoop
 
Jdbc
JdbcJdbc
Jdbc
 
ADBA (Asynchronous Database Access)
ADBA (Asynchronous Database Access)ADBA (Asynchronous Database Access)
ADBA (Asynchronous Database Access)
 
android sqlite
android sqliteandroid sqlite
android sqlite
 
Sqlite
SqliteSqlite
Sqlite
 
Introduction to Apache Spark
Introduction to Apache SparkIntroduction to Apache Spark
Introduction to Apache Spark
 
Sql no sql
Sql no sqlSql no sql
Sql no sql
 
Spring db-access mod03
Spring db-access mod03Spring db-access mod03
Spring db-access mod03
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 
NoSQL and MySQL: News about JSON
NoSQL and MySQL: News about JSONNoSQL and MySQL: News about JSON
NoSQL and MySQL: News about JSON
 
Jdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.comJdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.com
 

Plus de BruceLee275640 (7)

Git_new.pptx
Git_new.pptxGit_new.pptx
Git_new.pptx
 
introductiontogitandgithub-120702044048-phpapp01.pdf
introductiontogitandgithub-120702044048-phpapp01.pdfintroductiontogitandgithub-120702044048-phpapp01.pdf
introductiontogitandgithub-120702044048-phpapp01.pdf
 
68837.ppt
68837.ppt68837.ppt
68837.ppt
 
Utility.ppt
Utility.pptUtility.ppt
Utility.ppt
 
springtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdfspringtraning-7024840-phpapp01.pdf
springtraning-7024840-phpapp01.pdf
 
java150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxjava150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptx
 
life science.pptx
life science.pptxlife science.pptx
life science.pptx
 

Dernier

Call Girls in Yamuna Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Yamuna Vihar  (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Yamuna Vihar  (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Yamuna Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
MASTERING FOREX: STRATEGIES FOR SUCCESS.pdf
MASTERING FOREX: STRATEGIES FOR SUCCESS.pdfMASTERING FOREX: STRATEGIES FOR SUCCESS.pdf
MASTERING FOREX: STRATEGIES FOR SUCCESS.pdf
Cocity Enterprises
 

Dernier (20)

CBD Belapur((Thane)) Charming Call Girls📞❤9833754194 Kamothe Beautiful Call G...
CBD Belapur((Thane)) Charming Call Girls📞❤9833754194 Kamothe Beautiful Call G...CBD Belapur((Thane)) Charming Call Girls📞❤9833754194 Kamothe Beautiful Call G...
CBD Belapur((Thane)) Charming Call Girls📞❤9833754194 Kamothe Beautiful Call G...
 
20240419-SMC-submission-Annual-Superannuation-Performance-Test-–-design-optio...
20240419-SMC-submission-Annual-Superannuation-Performance-Test-–-design-optio...20240419-SMC-submission-Annual-Superannuation-Performance-Test-–-design-optio...
20240419-SMC-submission-Annual-Superannuation-Performance-Test-–-design-optio...
 
Dubai Call Girls Deira O525547819 Dubai Call Girls Bur Dubai Multiple
Dubai Call Girls Deira O525547819 Dubai Call Girls Bur Dubai MultipleDubai Call Girls Deira O525547819 Dubai Call Girls Bur Dubai Multiple
Dubai Call Girls Deira O525547819 Dubai Call Girls Bur Dubai Multiple
 
7 steps to achieve financial freedom.pdf
7 steps to achieve financial freedom.pdf7 steps to achieve financial freedom.pdf
7 steps to achieve financial freedom.pdf
 
Thane Call Girls , 07506202331 Kalyan Call Girls
Thane Call Girls , 07506202331 Kalyan Call GirlsThane Call Girls , 07506202331 Kalyan Call Girls
Thane Call Girls , 07506202331 Kalyan Call Girls
 
Female Escorts Service in Hyderabad Starting with 5000/- for Savita Escorts S...
Female Escorts Service in Hyderabad Starting with 5000/- for Savita Escorts S...Female Escorts Service in Hyderabad Starting with 5000/- for Savita Escorts S...
Female Escorts Service in Hyderabad Starting with 5000/- for Savita Escorts S...
 
Call Girls in Benson Town / 8250092165 Genuine Call girls with real Photos an...
Call Girls in Benson Town / 8250092165 Genuine Call girls with real Photos an...Call Girls in Benson Town / 8250092165 Genuine Call girls with real Photos an...
Call Girls in Benson Town / 8250092165 Genuine Call girls with real Photos an...
 
W.D. Gann Theory Complete Information.pdf
W.D. Gann Theory Complete Information.pdfW.D. Gann Theory Complete Information.pdf
W.D. Gann Theory Complete Information.pdf
 
falcon-invoice-discounting-unlocking-prime-investment-opportunities
falcon-invoice-discounting-unlocking-prime-investment-opportunitiesfalcon-invoice-discounting-unlocking-prime-investment-opportunities
falcon-invoice-discounting-unlocking-prime-investment-opportunities
 
Call Girls in Yamuna Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Yamuna Vihar  (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Yamuna Vihar  (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Yamuna Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Significant AI Trends for the Financial Industry in 2024 and How to Utilize Them
Significant AI Trends for the Financial Industry in 2024 and How to Utilize ThemSignificant AI Trends for the Financial Industry in 2024 and How to Utilize Them
Significant AI Trends for the Financial Industry in 2024 and How to Utilize Them
 
Solution Manual For Financial Statement Analysis, 13th Edition By Charles H. ...
Solution Manual For Financial Statement Analysis, 13th Edition By Charles H. ...Solution Manual For Financial Statement Analysis, 13th Edition By Charles H. ...
Solution Manual For Financial Statement Analysis, 13th Edition By Charles H. ...
 
Benefits & Risk Of Stock Loans
Benefits & Risk Of Stock LoansBenefits & Risk Of Stock Loans
Benefits & Risk Of Stock Loans
 
Kopar Khairane Cheapest Call Girls✔✔✔9833754194 Nerul Premium Call Girls-Navi...
Kopar Khairane Cheapest Call Girls✔✔✔9833754194 Nerul Premium Call Girls-Navi...Kopar Khairane Cheapest Call Girls✔✔✔9833754194 Nerul Premium Call Girls-Navi...
Kopar Khairane Cheapest Call Girls✔✔✔9833754194 Nerul Premium Call Girls-Navi...
 
Webinar on E-Invoicing for Fintech Belgium
Webinar on E-Invoicing for Fintech BelgiumWebinar on E-Invoicing for Fintech Belgium
Webinar on E-Invoicing for Fintech Belgium
 
logistics industry development power point ppt.pdf
logistics industry development power point ppt.pdflogistics industry development power point ppt.pdf
logistics industry development power point ppt.pdf
 
MASTERING FOREX: STRATEGIES FOR SUCCESS.pdf
MASTERING FOREX: STRATEGIES FOR SUCCESS.pdfMASTERING FOREX: STRATEGIES FOR SUCCESS.pdf
MASTERING FOREX: STRATEGIES FOR SUCCESS.pdf
 
Explore Dual Citizenship in Africa | Citizenship Benefits & Requirements
Explore Dual Citizenship in Africa | Citizenship Benefits & RequirementsExplore Dual Citizenship in Africa | Citizenship Benefits & Requirements
Explore Dual Citizenship in Africa | Citizenship Benefits & Requirements
 
Turbhe Fantastic Escorts📞📞9833754194 Kopar Khairane Marathi Call Girls-Kopar ...
Turbhe Fantastic Escorts📞📞9833754194 Kopar Khairane Marathi Call Girls-Kopar ...Turbhe Fantastic Escorts📞📞9833754194 Kopar Khairane Marathi Call Girls-Kopar ...
Turbhe Fantastic Escorts📞📞9833754194 Kopar Khairane Marathi Call Girls-Kopar ...
 
2999,Vashi Fantastic Ellete Call Girls📞📞9833754194 CBD Belapur Genuine Call G...
2999,Vashi Fantastic Ellete Call Girls📞📞9833754194 CBD Belapur Genuine Call G...2999,Vashi Fantastic Ellete Call Girls📞📞9833754194 CBD Belapur Genuine Call G...
2999,Vashi Fantastic Ellete Call Girls📞📞9833754194 CBD Belapur Genuine Call G...
 

fdocuments.in_introduction-to-ibatis.ppt

  • 2. 2
  • 3. 3 Problems  Tight integration of SQL code and Java code.  Redundant JDBC code consumes a lot of development time.  Is our DAO really a DAO?
  • 6. 6 Hibernate/Object-Relational Mapping  Tools/techniques to store and retrieve objects from a database  From the code perspective it behaves like a virtual object database  A complete ORM solution provide:  Basic CRUD functionality  An Object-Oriented Query Facility  Mapping Metadata support  Transactional Capability
  • 7. 7 Hibernate pros and cons Pros:  No SQL coding required  Database vendor independent  Provides caching mechanisms Cons:  Requires learning of quite a lot of stuff  Limits queries to HQL syntax  Debugging and performance tuning is sometimes quite complected  Does not fit with legacy or complex Database.
  • 8. 8 An Introduction to Apache iBATIS (i)nternet + A(batis) SQL Mapping defined...
  • 9. 9 About iBATIS  Open source framework that reduces the complexity to read/save Java objects from a database (persistence)  Decouples Java code from SQL  Avoids the necessity to use JDBC  It is NOT an object-relational mapper (such as Hibernate)  Simplifies the developer’s life ☺
  • 10. 10 iBatis Components iBATIS usage is divided into two main components:  SQLMaps Permits to read/save Java objects into relational DBMS without using JDBC and without mixing Java and SQL code  DAO <Spring framework DAO> “Is an abstraction layer that hides the details of your persistence solution and provides a common API to the rest of your application” Note: previous versions of iBatis had separate DAO component which is deprecated in the latest version iBatis 3.
  • 11. 11
  • 12. 12 Sql Mapping 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...
  • 13. 13 The Product Class public class Product { private int id; private String name; private String description; private BigDecimal cost; private BigDecimal retail; // ...getters/setters implied }
  • 14. 14 The SQL <select id=“getProduct" parameterClass=“int” resultClass="examples.domain.Product"> SELECT PRODUCT_ID as id, NAME, DESCRIPTION, COST, RETAIL, FROM PRODUCT WHERE PRODUCT_ID = #id# </select>
  • 15. 15 <bean id="productDAO" class="examples.domain.dao.ProductDAO"> <property name="sqlMapClient"> <ref bean="sqlMapClient" /> </property> <property name="dataSource"> <ref bean="myDataSource" /> </property> </bean> The Spring DAO Bean
  • 16. 16 public class ProductDAOImpl extends SqlMapClientDaoSupport implements ProductDao { @SuppressWarnings("unchecked") public List<Product> getAllProducts(int id) { List<Product> productList = getSqlMapClientTemplate().queryForList( "getProduct" , id ); return productList; } ..... The Product DAO Implementation
  • 17. 17 ... “WTF!! Do you mean we need to hand code XML configurations?” “Yeah!! That's true..” ...
  • 18. 18 JDBC  Obtain the db Connection  Create the statement  Set the input parameters  Execute the statement  Create the result Collection  For each row fetched:  Create an object  Set object’s properties using row’s colums  Add the object to the Collection  Release resources  Close the Connection  Return the Collection IBATIS Obtain the SqlMap object Prepare complex parameters (optional) Invoke the query passing the parameters Return the result JDBC-iBatis Comparison
  • 19. 19 5 Reasons to use iBatis 1. Works with any database that has a JDBC driver (can re-use existing MySQL queries ) & You already know SQL, why waste timelearning something else? 2. Supports Map, Collection, List and Primitive Wrappers (Integer, String etc.) 3. Easy integration with Spring DAO. 4. Works well with legacy DB and complex relational mappings between DB tables. 5. Supports complex object mappings (populating lists, complex object models etc.), Transactions, Lazy Loading or Join Mapping (1:1, 1:M, M:N), and caching.
  • 20. 20 - Full power of real SQL - Works with complex, enterprise, ERP or even poorly designed databases - Fully supports composite keys and complex relationships - Complete stored procedure support - JavaBeans support - Primitive wrappers (Integer, String, Date etc.) - HashMap, List, Collection, and array[] - XML text and DOM Support - Null value translation - Auto-mapping bean properties to columns - Dynamic SQL using conditional XML tags - Caching and dependency management - Centralized data source configuration - Local and global (JTA) transaction support - Small footprint 300k (minimum) - Minimal dependencies (only common- logging required) - Spring DAO Templates available iBATIS SQL Mapping Framework
  • 21. 21 Books:  iBATIS In Action - Clinton Begin (Manning) Links for reference:  http://en.wikipedia.org/wiki/IBATIS  http://ibatis.apache.org/onlinehelp.html  http://www.javabeat.net/articles/52-spring-ibatis-integration-1.html  http://www.learntechnology.net/content/ibatis/spring_ibatis.jsp  Using-iBatis-SQL-Maps-for-Java-Data-Access