SlideShare a Scribd company logo
IBatisGet to know iBatisAuthor: Rohit Prabhakarhttp://rohitprabhakar.com
Get to know iBatis from Rohit @ http://rohitprabhakar.comiBatisTopics:Introduction
Installation
Environment
Spring-iBatis Integration
SQL Mappings
ConclusioniBatis:IntroductioniBATIS is a Data Persistence Framework. iBATIS in other words is an additional layer of indirection between the classes and the tables allowing it in more flexibility in how classes and tables are mapped with out making any changes to the Data model and the Object model. The layer of indirection here is the SQL. This enables mapping SQL queries to POJOs-Plain Old Java Objects. This works like the same as JPA[Hibernate/Spring framework] but faster than that. The main advantages are- 1. Reduces the amount of Java code to access a DataBase with the use of XML files containing SQL queries. 2.Faster than JPA. 3.Uses existing SQL Stored Procedures. Get to know iBatis from Rohit @ http://rohitprabhakar.com
iBatis: InstallationiBATISis delivered in a single JAR file: ibatis-version.build.jarand should be copied and made available at runtime via the application's class path.This can be downloaded from iBatis homepage.Get to know iBatis from Rohit @ http://rohitprabhakar.com
iBatis:Environment ConfigurationUsing Spring - iBATIS with a stand-alone application:You should place the ibatis-x.x.x.x.jar in the application's classpath.
Define and place the following three configuration files in the classpathSpring config - This file defines the database connection parameters, the location of the SQL Map config file, and one or more Spring beans for use within the application. ( applicationContext.xml). SQL Map config - This file defines any iBATIS-specific configuration settings that you may need and declares the location for any SQL Map files that should be accessible through this config file. (SqlMapConfig.xml) SQL Map(s) One or more SQL Map files are declared in the SQL Map config and typically mapped to a single business entity within the application ,often represented by a single Java class (domainObject.xml). Using Spring - iBATIS with a web applicationSame as the above ,but just need one more xml (web.xml).Get to know iBatis from Rohit @ http://rohitprabhakar.com
Spring-iBatis IntegrationAdd to the iBatis jar to the project classpath
Create a package “com.test.ibatis”
Create a class “Student “package com.test.ibatis;public class Student {private long studentId;private String firstName;private String lastName;private String address;}Generate Getters and Setters for all the items in the BeanGet to know iBatis from Rohit @ http://rohitprabhakar.com
Spring-iBatis IntegrationCreate a table “STUDENT” with a table-per-class relationshipCREATE TABLE STUDENT(STUDENT_ID NUMBER (6, 0) NOT NULL,FIRST_NAME VARCHAR(50) NOT NULL,LAST_NAME VARCHAR(50) ,ADDRESS VARCHAR(200) NOT NULL,PRIMARY KEY (STUDENT_ID))Get to know iBatis from Rohit @ http://rohitprabhakar.com
Spring-iBatis Integration: applicationContext.xmlAdd the following<bean id="dataSource"class="org.apache.commons.dbcp.BasicDataSource"destroy-method="close"><property name="driverClassName"value="oracle.jdbc.driver.OracleDriver" /><property name="url"value="jdbc:oracle:thin:@127.0.0.1:1521:orcl" /><property name="username" value="scott" /><property name="password" value="tiger" /></bean><bean id="sqlMap"class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"><property name="configLocation"><value>classpath:SqlMapConfig.xml</value></property><property name="dataSource" ref="dataSource" /></bean><bean id="studentService"class="com.test.ibatis.StudentServiceImpl"><property name="sqlMapClient" ref="sqlMap" /></bean>Get to know iBatis from Rohit @ http://rohitprabhakar.com
Ad

More Related Content

What's hot (19)

Spring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggetsSpring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggets
Virtual Nuggets
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Hùng Nguyễn Huy
 
Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoC
Funnelll
 
Spring framework Introduction
Spring framework IntroductionSpring framework Introduction
Spring framework Introduction
Anuj Singh Rajput
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
ASG
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
JanmejayaPadhiary2
 
Spring framework
Spring frameworkSpring framework
Spring framework
vietduc17
 
Spring framework
Spring frameworkSpring framework
Spring framework
Aircon Chen
 
Spring notes
Spring notesSpring notes
Spring notes
Rajeev Uppala
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
Dzmitry Naskou
 
Java spring ppt
Java spring pptJava spring ppt
Java spring ppt
natashasweety7
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Raveendra R
 
Getting Started with Spring Framework
Getting Started with Spring FrameworkGetting Started with Spring Framework
Getting Started with Spring Framework
Edureka!
 
Spring framework-tutorial
Spring framework-tutorialSpring framework-tutorial
Spring framework-tutorial
vinayiqbusiness
 
Spring core module
Spring core moduleSpring core module
Spring core module
Raj Tomar
 
Spring ppt
Spring pptSpring ppt
Spring ppt
Mumbai Academisc
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
Syed Shahul
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Arjun Thakur
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
Hùng Nguyễn Huy
 
Spring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggetsSpring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggets
Virtual Nuggets
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Hùng Nguyễn Huy
 
Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoC
Funnelll
 
Spring framework Introduction
Spring framework IntroductionSpring framework Introduction
Spring framework Introduction
Anuj Singh Rajput
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
ASG
 
Spring framework
Spring frameworkSpring framework
Spring framework
vietduc17
 
Spring framework
Spring frameworkSpring framework
Spring framework
Aircon Chen
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
Dzmitry Naskou
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Raveendra R
 
Getting Started with Spring Framework
Getting Started with Spring FrameworkGetting Started with Spring Framework
Getting Started with Spring Framework
Edureka!
 
Spring framework-tutorial
Spring framework-tutorialSpring framework-tutorial
Spring framework-tutorial
vinayiqbusiness
 
Spring core module
Spring core moduleSpring core module
Spring core module
Raj Tomar
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
Syed Shahul
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Arjun Thakur
 

Similar to Introduction to Ibatis by Rohit (20)

Toms introtospring mvc
Toms introtospring mvcToms introtospring mvc
Toms introtospring mvc
Guo Albert
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
Wildan Maulana
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
Jeevesh Pandey
 
SpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptx
SUFYAN SATTAR
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
Gunith Devasurendra
 
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdfdokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
Appster1
 
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdfdokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
Appster1
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server Pages
John Brunswick
 
I Feel Pretty
I Feel PrettyI Feel Pretty
I Feel Pretty
John Quaglia
 
Spring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsSpring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applications
michaelaaron25322
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
ipolevoy
 
Apache Aries Blog Sample
Apache Aries Blog SampleApache Aries Blog Sample
Apache Aries Blog Sample
Skills Matter
 
Ibm
IbmIbm
Ibm
techbed
 
Php frameworks
Php frameworksPhp frameworks
Php frameworks
Anil Kumar Panigrahi
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
funkatron
 
Springboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with testSpringboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with test
HyukSun Kwon
 
Spring Boot
Spring BootSpring Boot
Spring Boot
Jaydeep Kale
 
Data access
Data accessData access
Data access
Joshua Yoon
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
wiradikusuma
 
Overview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company indiaOverview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company india
Jignesh Aakoliya
 
Toms introtospring mvc
Toms introtospring mvcToms introtospring mvc
Toms introtospring mvc
Guo Albert
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
Wildan Maulana
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
Jeevesh Pandey
 
SpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptx
SUFYAN SATTAR
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
Gunith Devasurendra
 
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdfdokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
Appster1
 
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdfdokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
Appster1
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server Pages
John Brunswick
 
Spring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsSpring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applications
michaelaaron25322
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
ipolevoy
 
Apache Aries Blog Sample
Apache Aries Blog SampleApache Aries Blog Sample
Apache Aries Blog Sample
Skills Matter
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
funkatron
 
Springboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with testSpringboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with test
HyukSun Kwon
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
wiradikusuma
 
Overview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company indiaOverview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company india
Jignesh Aakoliya
 
Ad

Recently uploaded (20)

Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Ad

Introduction to Ibatis by Rohit

  • 1. IBatisGet to know iBatisAuthor: Rohit Prabhakarhttp://rohitprabhakar.com
  • 2. Get to know iBatis from Rohit @ http://rohitprabhakar.comiBatisTopics:Introduction
  • 7. ConclusioniBatis:IntroductioniBATIS is a Data Persistence Framework. iBATIS in other words is an additional layer of indirection between the classes and the tables allowing it in more flexibility in how classes and tables are mapped with out making any changes to the Data model and the Object model. The layer of indirection here is the SQL. This enables mapping SQL queries to POJOs-Plain Old Java Objects. This works like the same as JPA[Hibernate/Spring framework] but faster than that. The main advantages are- 1. Reduces the amount of Java code to access a DataBase with the use of XML files containing SQL queries. 2.Faster than JPA. 3.Uses existing SQL Stored Procedures. Get to know iBatis from Rohit @ http://rohitprabhakar.com
  • 8. iBatis: InstallationiBATISis delivered in a single JAR file: ibatis-version.build.jarand should be copied and made available at runtime via the application's class path.This can be downloaded from iBatis homepage.Get to know iBatis from Rohit @ http://rohitprabhakar.com
  • 9. iBatis:Environment ConfigurationUsing Spring - iBATIS with a stand-alone application:You should place the ibatis-x.x.x.x.jar in the application's classpath.
  • 10. Define and place the following three configuration files in the classpathSpring config - This file defines the database connection parameters, the location of the SQL Map config file, and one or more Spring beans for use within the application. ( applicationContext.xml). SQL Map config - This file defines any iBATIS-specific configuration settings that you may need and declares the location for any SQL Map files that should be accessible through this config file. (SqlMapConfig.xml) SQL Map(s) One or more SQL Map files are declared in the SQL Map config and typically mapped to a single business entity within the application ,often represented by a single Java class (domainObject.xml). Using Spring - iBATIS with a web applicationSame as the above ,but just need one more xml (web.xml).Get to know iBatis from Rohit @ http://rohitprabhakar.com
  • 11. Spring-iBatis IntegrationAdd to the iBatis jar to the project classpath
  • 12. Create a package “com.test.ibatis”
  • 13. Create a class “Student “package com.test.ibatis;public class Student {private long studentId;private String firstName;private String lastName;private String address;}Generate Getters and Setters for all the items in the BeanGet to know iBatis from Rohit @ http://rohitprabhakar.com
  • 14. Spring-iBatis IntegrationCreate a table “STUDENT” with a table-per-class relationshipCREATE TABLE STUDENT(STUDENT_ID NUMBER (6, 0) NOT NULL,FIRST_NAME VARCHAR(50) NOT NULL,LAST_NAME VARCHAR(50) ,ADDRESS VARCHAR(200) NOT NULL,PRIMARY KEY (STUDENT_ID))Get to know iBatis from Rohit @ http://rohitprabhakar.com
  • 15. Spring-iBatis Integration: applicationContext.xmlAdd the following<bean id="dataSource"class="org.apache.commons.dbcp.BasicDataSource"destroy-method="close"><property name="driverClassName"value="oracle.jdbc.driver.OracleDriver" /><property name="url"value="jdbc:oracle:thin:@127.0.0.1:1521:orcl" /><property name="username" value="scott" /><property name="password" value="tiger" /></bean><bean id="sqlMap"class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"><property name="configLocation"><value>classpath:SqlMapConfig.xml</value></property><property name="dataSource" ref="dataSource" /></bean><bean id="studentService"class="com.test.ibatis.StudentServiceImpl"><property name="sqlMapClient" ref="sqlMap" /></bean>Get to know iBatis from Rohit @ http://rohitprabhakar.com
  • 16. Spring-iBatis IntegrationSqlMapConfig.xmlAs for the configLocation property, it should be configured with the path to an XML file that enumerates the locations of the iBATIS SQL maps.<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL MAP Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd"><sqlMapConfig><settings useStatementNamespaces="true" /><sqlMap resource="StudentSQLMap.xml" /></sqlMapConfig>Get to know iBatis from Rohit @ http://rohitprabhakar.com
  • 17. Spring-iBatis IntegrationStudentSQLMap.xml<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL MAP 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd"><sqlMap namespace="student"> <typeAlias alias="student" type="com.test.ibatis.Student"/> <resultMap id="studentResult" class="Student"> <result property="studentId" column="STUDENT_ID"/> <result property="firstName" column="FIRST_NAME"/> <result property="lastName" column="LAST_NAME"/> <result property="address" column="ADDRESS"/> </resultMap> <select id="getTrade" parameterClass="long" resultMap="studentResult"> SELECT STUDENT_ID, FIRST_NAME, FIRST_NAME, ADDRESS FROM STUDENT WHERE STUDENT_ID = #id# </select> </sqlMap>Get to know iBatis from Rohit @ http://rohitprabhakar.com
  • 18. Spring-iBatis IntegrationCreate an Interface StudentServicepackage com.test.ibatis;public interface StudentService {public Student getStudent(long studentId) throws Exception;}Get to know iBatis from Rohit @ http://rohitprabhakar.com
  • 19. Spring-iBatis IntegrationCreate an Implementation Classpackage com.test.ibatis;import com.ibatis.sqlmap.client.SqlMapClient;public class StudentServiceImpl implements StudentService {protected SqlMapClientsqlMapclient=null;public void setSqlMapclient(SqlMapClientsqlMapclient) {this.sqlMapclient = sqlMapclient;}public Student getStudent(long studentId) throws Exception { return (Student) sqlMapclient.queryForObject("student.getStudent", studentId);}}Get to know iBatis from Rohit @ http://rohitprabhakar.com
  • 20. Spring-iBatis Integration: Student Clientpackage com.test.ibatis;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class StudentClient {public static void Main(String[] args){// load spring beansApplicationContextctx= new ClassPathXmlApplicationContext("applicationContext.xml");StudentServicestudentService= (StudentService) ctx.getBean("studentService");//get Object StudentintstudentId=1;try {System.out.println("**********************************");System.out.println(studentService.getStudent(studentId));System.out.println("**********************************");} catch (Exception e) {e.printStackTrace();}}}Get to know iBatis from Rohit @ http://rohitprabhakar.com
  • 21. Spring-iBatis Integration: ExecuteRun the Client and check what it prints?Get to know iBatis from Rohit @ http://rohitprabhakar.com
  • 22. iBatis: ToolsIbatorIbator is a code generator and Eclipse plugin. It can be used to get a head start on your project by generating your Beans, Mappings and SQL from an existing database schema. Get to know iBatis from Rohit @ http://rohitprabhakar.com