SlideShare a Scribd company logo
Omaha Java Users Group
   March 18, 2008
   Corey A. Spitzer
The Context



              • J2EE (with Spring)
              • OOP
              • SQL Relational Database
What is iBATIS?
Object Oriented



                  Object



  Logic / DAO
                           iBATIS           Database
     Code



                                    Query


                                             Relational
A More Detailed Look

              calls
   Code                       SqlMapClient
                                  insert()
                      loads      update()    calls
                                 delete()
                                  query()


     SQL Maps                                   javax.sql.DataSource
       Queries
     Result Maps

                                                      Magic
                                                      Magic




                                                     Database
The SQL Map Anatomy                               Code
                                                          calls SqlMapClient

                                                          loads                calls

                                                   SQL Maps                            DataSource



<sqlMap namespace="myNamespace">                                                         Magic
                                                                                          Magic

       <resultMap id="myClass" class="full.package.MyClass">
                                                                                       Database
                <result property="foo" column="col1"/>
                <result property="bar" column="col2"/>
                ...
       </resultMap>
       ...
       <!-- ===================================================== -->
       <sql id="myQuery" resultMap="myClass">
                SELECT col1, col2 FROM table1
       </sql>
       ...
</sqlMap>
The Code Anatomy                                 Code
                                                         calls SqlMapClient

                                                         loads                calls
import java.sql.SQLException;
                                                  SQL Maps                            DataSource
import com.ibatis.sqlmap.client.SqlMapClient;
...                                                                                     Magic
                                                                                         Magic

public class MyDAO
                                                                                      Database
{
       private SqlMapClient myDB;


       public void frobnicate(MyObject someObject) throws SQLException
       {
              List<MyClass> list = myDB.queryForList("myQuery");
              Foo myFoo = (Foo)myDB.queryForObject("getFooByID", 1337);
              myDB.update("myQuery3");
              myDB.insert("myQuery4", someObject);
              ...
       }
       ...
}
Any Questions so far?

              calls
   Code                       SqlMapClient
                                  insert()
                      loads      update()    calls
                                 delete()
                                  query()


     SQL Maps                                   javax.sql.DataSource
       Queries
     Result Maps

                                                      Magic
                                                      Magic




                                                     Database
Implicit Mapping

<sqlMap namespace="myNamespace">
       <resultMap id="myClass" class="full.package.Class">
                <result property="foo" column="col1"/>
                <result property="bar" column="col2"/>
                ...
       </resultMap>
       ...
       <!-- ===================================================== -->
       <sql id="myQuery" resultClass="full.package.Class">
                SELECT col1 as foo, col2 as bar FROM table1
       </sql>
       ...
</sqlMap>
Inheritance
    Object Oriented Code                      Relational Database

               Fruit                                     fruits
         id - int                             id - mediumint(7), PK
         dateBought - long                    date_bought - int(11)
                                              type - enum('a', 'o')



                                                       apples
    Apple                Orange               fruit_id - mediumint(7), FK
                                              worm_count - decimal(4,1)
wormCount - float   bioengineered - boolean

                                                      oranges
                                              fruit_id - mediumint(7), FK
                                              bioengineered - bool
Complex Members
  Object Oriented Code             Relational Database

             Cake                             cakes
    id - int                       id - mediumint(7), PK
    flavor - String                flavor - enum('chocolate', ...)
    toppings - List<CakeTopping>


                                   cakes_to_toppings
                                   cake_id - mediumint(7), FK
                                   topping_id - mediumint(7), FK
        CakeTopping
     id - int
     name - String                    cake_toppings
     containsHFCS - boolean
                                   id - mediumint(7), PK
                                   name - varchar(20)
                                   contains_hfcs - bool
Parameters & Dynamic Queries
Custom Type Handlers
public class YesNoBoolTypeHandler implements TypeHandlerCallback {
        public Object getResult(ResultGetter getter) throws SQLException {
                 if ("Y".equalsIgnoreCase(getter.getString())) {
                            return new Boolean (true);
                 } else if ("N".equalsIgnoreCase(getter.getString())) {
                            return new Boolean (false);
                 } else {
                            throw new SQLException();
                 }
        }
        public void setParameter(ParameterSetter setter, Object parameter)
        throws SQLException {
                 if (((Boolean)parameter).booleanValue()) setter.setString("Y");
                 else setter.setString("N");
        }
        public Object valueOf(String s) {
                 return new Boolean ("Y".equalsIgnoreCase(s));
        }
}
Custom Type Handlers

<resultMap id="myClass" class="my.package.MyClass">
   ...
   <result property="foo" column="bar"
   typeHandler="some.package.YesNoBoolTypeHandler"/>
   ...
</resultMap>




<insert id="myQuery" resultMap="myClass"
parameterClass="my.package.MyClass">
         INSERT INTO table1 SET bar =
         #foo,handler=some.package.YesNoBoolTypeHandler#
</insert>
Paging / Selecting a Range
selectKey

<insert id="addForumThread" parameterClass="java.util.HashMap">
   INSERT INTO forum_threads SET
   forum_id = #forumID#,
   title = #title#,
   created_time = #createdTime#,
   last_updated_time = #createdTime#,
   <selectKey resultClass="int">
       SELECT MAX(id) FROM forum_threads
   </selectKey>
</insert>
Caching Features
<cacheModel id="fooCache" type="{LRU|MEMORY|FIFO|OSCACHE}"
readOnly="{true|false}" serialize="{true|false}">
      <flushInterval hours="24"/>
      <flushOnExecute statement="insertFoo"/>
      <flushOnExecute statement="updateFoo"/>
      <flushOnExecute statement="deleteFoo"/>
      <property name="size" value="1000"/>
</cacheModel>


<select id="getFoo" cacheModel="fooCache">
         SELECT * FROM bar WHERE id = #value#
</select>


<insert id="insertFoo">
         INSERT INTO bar SET ...
</insert>
...
Transactions
public updateItemDescription(String itemId, String newDescription)
throws SQLException
{
       try
       {
               sqlMap.startTransaction();

                 Item item = (Item)
                        sqlMap.queryForObject("getItem", itemId);

                 item.setDescription (newDescription);

                 sqlMap.update("updateItem", item);

                 sqlMap.commitTransaction();
       }
       finally
       {

                 sqlMap.endTransaction();
       }
}
What About Hibernate?

            iBATIS                                    Hibernate
• Separation of code and SQL                • SQL alongside code

• Simpler configuration and setup*

• Total control over SQL queries            • Cross-DB query language (HQL)

• Shallow learning curve                    • ???

• Handles application complexities          • Works very well when data model
better**                                    closely resembles object model**



          **No Fluff Just Stuff's Mark Richards' two cents:
          http://www.nofluffjuststuff.com/media.jsp?mediaId=27


             *Source: http://www.devx.com/Java/Article/31481/0/page/1
Who is Using iBatis?

                       • CNet.com

                       • MySpace.com

                       • OfficeMax.com

                       • JPMorganChase.com

                       • 1up.com

                       • PowerSentry.com

                       (and more)


     Source: http://www.ociweb.com/mark/programming/iBATIS.html#WhoUses
Now What?


       http://ibatis.apache.org

More Related Content

What's hot

Java &amp; banco de dados
Java &amp; banco de dadosJava &amp; banco de dados
Java &amp; banco de dados
Fábio José da Silva
 
JavaFX and Scala in the Cloud
JavaFX and Scala in the CloudJavaFX and Scala in the Cloud
JavaFX and Scala in the Cloud
Stephen Chin
 
Developing for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQLDeveloping for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQL
John David Duncan
 
GR8Conf 2011: GORM Optimization
GR8Conf 2011: GORM OptimizationGR8Conf 2011: GORM Optimization
GR8Conf 2011: GORM Optimization
GR8Conf
 
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2
Ralph Schindler
 
Wed 1630 greene_robert_color
Wed 1630 greene_robert_colorWed 1630 greene_robert_color
Wed 1630 greene_robert_color
DATAVERSITY
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring Data
Oliver Gierke
 
Java FX 2.0 - A Developer's Guide
Java FX 2.0 - A Developer's GuideJava FX 2.0 - A Developer's Guide
Java FX 2.0 - A Developer's Guide
Stephen Chin
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database Jones
John David Duncan
 
Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0
Scott Leberknight
 
JPA 2.0
JPA 2.0JPA 2.0
React responsively, render responsibly - react meetup
React responsively, render responsibly - react meetupReact responsively, render responsibly - react meetup
React responsively, render responsibly - react meetup
Yoav Niran
 
PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2
eugenio pombi
 
JUG Berlin Brandenburg: What's new in Java EE 7?
JUG Berlin Brandenburg: What's new in Java EE 7?JUG Berlin Brandenburg: What's new in Java EE 7?
JUG Berlin Brandenburg: What's new in Java EE 7?
gedoplan
 
FormsKit: reactive forms driven by state. UA Mobile 2017.
FormsKit: reactive forms driven by state. UA Mobile 2017.FormsKit: reactive forms driven by state. UA Mobile 2017.
FormsKit: reactive forms driven by state. UA Mobile 2017.
UA Mobile
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
Jeevesh Pandey
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracle
yazidds2
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
Sunghyouk Bae
 

What's hot (19)

Java &amp; banco de dados
Java &amp; banco de dadosJava &amp; banco de dados
Java &amp; banco de dados
 
JavaFX and Scala in the Cloud
JavaFX and Scala in the CloudJavaFX and Scala in the Cloud
JavaFX and Scala in the Cloud
 
Developing for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQLDeveloping for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQL
 
GR8Conf 2011: GORM Optimization
GR8Conf 2011: GORM OptimizationGR8Conf 2011: GORM Optimization
GR8Conf 2011: GORM Optimization
 
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
 
Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2
 
Wed 1630 greene_robert_color
Wed 1630 greene_robert_colorWed 1630 greene_robert_color
Wed 1630 greene_robert_color
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring Data
 
Java FX 2.0 - A Developer's Guide
Java FX 2.0 - A Developer's GuideJava FX 2.0 - A Developer's Guide
Java FX 2.0 - A Developer's Guide
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database Jones
 
Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0
 
JPA 2.0
JPA 2.0JPA 2.0
JPA 2.0
 
React responsively, render responsibly - react meetup
React responsively, render responsibly - react meetupReact responsively, render responsibly - react meetup
React responsively, render responsibly - react meetup
 
PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2PHPUnit elevato alla Symfony2
PHPUnit elevato alla Symfony2
 
JUG Berlin Brandenburg: What's new in Java EE 7?
JUG Berlin Brandenburg: What's new in Java EE 7?JUG Berlin Brandenburg: What's new in Java EE 7?
JUG Berlin Brandenburg: What's new in Java EE 7?
 
FormsKit: reactive forms driven by state. UA Mobile 2017.
FormsKit: reactive forms driven by state. UA Mobile 2017.FormsKit: reactive forms driven by state. UA Mobile 2017.
FormsKit: reactive forms driven by state. UA Mobile 2017.
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracle
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
 

Viewers also liked

Cấu hình Hibernate
Cấu hình HibernateCấu hình Hibernate
Cấu hình Hibernate
Minh Quang
 
Hướng dẫn lập trình java hibernate cho người mới bắt đầu
Hướng dẫn lập trình java hibernate cho người mới bắt đầuHướng dẫn lập trình java hibernate cho người mới bắt đầu
Hướng dẫn lập trình java hibernate cho người mới bắt đầu
Thành Phạm Đức
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
Luis Goldster
 
Hibernate
HibernateHibernate
Hibernate
Ajay K
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
guest11106b
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate FrameworkPhuoc Nguyen
 

Viewers also liked (6)

Cấu hình Hibernate
Cấu hình HibernateCấu hình Hibernate
Cấu hình Hibernate
 
Hướng dẫn lập trình java hibernate cho người mới bắt đầu
Hướng dẫn lập trình java hibernate cho người mới bắt đầuHướng dẫn lập trình java hibernate cho người mới bắt đầu
Hướng dẫn lập trình java hibernate cho người mới bắt đầu
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
 
Hibernate
HibernateHibernate
Hibernate
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
 

Similar to iBATIS

NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love Story
Alexandre Morgaut
 
Using Spark to Load Oracle Data into Cassandra (Jim Hatcher, IHS Markit) | C*...
Using Spark to Load Oracle Data into Cassandra (Jim Hatcher, IHS Markit) | C*...Using Spark to Load Oracle Data into Cassandra (Jim Hatcher, IHS Markit) | C*...
Using Spark to Load Oracle Data into Cassandra (Jim Hatcher, IHS Markit) | C*...
DataStax
 
Using Spark to Load Oracle Data into Cassandra
Using Spark to Load Oracle Data into CassandraUsing Spark to Load Oracle Data into Cassandra
Using Spark to Load Oracle Data into Cassandra
Jim Hatcher
 
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
code for quiz in my sql
code for quiz  in my sql code for quiz  in my sql
code for quiz in my sql
JOYITAKUNDU1
 
JDBC Basics (In 20 Minutes Flat)
JDBC Basics (In 20 Minutes Flat)JDBC Basics (In 20 Minutes Flat)
JDBC Basics (In 20 Minutes Flat)
Craig Dickson
 
Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1
Zianed Hou
 
Jdbc
JdbcJdbc
Jdbc
lathasiva
 
Requery overview
Requery overviewRequery overview
Requery overview
Sunghyouk Bae
 
Paging Like A Pro
Paging Like A ProPaging Like A Pro
Paging Like A Pro
Gabor Varadi
 
Compact and safely: static DSL on Kotlin
Compact and safely: static DSL on KotlinCompact and safely: static DSL on Kotlin
Compact and safely: static DSL on Kotlin
Dmitry Pranchuk
 
JavaScript JQUERY AJAX
JavaScript JQUERY AJAXJavaScript JQUERY AJAX
JavaScript JQUERY AJAX
Makarand Bhatambarekar
 
3 database-jdbc(1)
3 database-jdbc(1)3 database-jdbc(1)
3 database-jdbc(1)
hameedkhan2017
 
Deeply Declarative Data Pipelines
Deeply Declarative Data PipelinesDeeply Declarative Data Pipelines
Deeply Declarative Data Pipelines
HostedbyConfluent
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.js
Jarod Ferguson
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
javatwo2011
 
SF Scala meet up, lighting talk: SPA -- Scala JDBC wrapper
SF Scala meet up, lighting talk: SPA -- Scala JDBC wrapperSF Scala meet up, lighting talk: SPA -- Scala JDBC wrapper
SF Scala meet up, lighting talk: SPA -- Scala JDBC wrapper
Chester Chen
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
Caridy Patino
 
Data Management 3: Bulletproof Data Management
Data Management 3: Bulletproof Data ManagementData Management 3: Bulletproof Data Management
Data Management 3: Bulletproof Data Management
MongoDB
 
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursors
info_zybotech
 

Similar to iBATIS (20)

NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love Story
 
Using Spark to Load Oracle Data into Cassandra (Jim Hatcher, IHS Markit) | C*...
Using Spark to Load Oracle Data into Cassandra (Jim Hatcher, IHS Markit) | C*...Using Spark to Load Oracle Data into Cassandra (Jim Hatcher, IHS Markit) | C*...
Using Spark to Load Oracle Data into Cassandra (Jim Hatcher, IHS Markit) | C*...
 
Using Spark to Load Oracle Data into Cassandra
Using Spark to Load Oracle Data into CassandraUsing Spark to Load Oracle Data into Cassandra
Using Spark to Load Oracle Data into Cassandra
 
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
 
code for quiz in my sql
code for quiz  in my sql code for quiz  in my sql
code for quiz in my sql
 
JDBC Basics (In 20 Minutes Flat)
JDBC Basics (In 20 Minutes Flat)JDBC Basics (In 20 Minutes Flat)
JDBC Basics (In 20 Minutes Flat)
 
Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1
 
Jdbc
JdbcJdbc
Jdbc
 
Requery overview
Requery overviewRequery overview
Requery overview
 
Paging Like A Pro
Paging Like A ProPaging Like A Pro
Paging Like A Pro
 
Compact and safely: static DSL on Kotlin
Compact and safely: static DSL on KotlinCompact and safely: static DSL on Kotlin
Compact and safely: static DSL on Kotlin
 
JavaScript JQUERY AJAX
JavaScript JQUERY AJAXJavaScript JQUERY AJAX
JavaScript JQUERY AJAX
 
3 database-jdbc(1)
3 database-jdbc(1)3 database-jdbc(1)
3 database-jdbc(1)
 
Deeply Declarative Data Pipelines
Deeply Declarative Data PipelinesDeeply Declarative Data Pipelines
Deeply Declarative Data Pipelines
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.js
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 
SF Scala meet up, lighting talk: SPA -- Scala JDBC wrapper
SF Scala meet up, lighting talk: SPA -- Scala JDBC wrapperSF Scala meet up, lighting talk: SPA -- Scala JDBC wrapper
SF Scala meet up, lighting talk: SPA -- Scala JDBC wrapper
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
 
Data Management 3: Bulletproof Data Management
Data Management 3: Bulletproof Data ManagementData Management 3: Bulletproof Data Management
Data Management 3: Bulletproof Data Management
 
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursors
 

More from techmonkey4u

Overview of Human and Computer Vision
Overview of Human and Computer VisionOverview of Human and Computer Vision
Overview of Human and Computer Vision
techmonkey4u
 
Robot Exploration with Combinatorial Auctions
Robot Exploration with Combinatorial AuctionsRobot Exploration with Combinatorial Auctions
Robot Exploration with Combinatorial Auctions
techmonkey4u
 
Brain Architecture
Brain ArchitectureBrain Architecture
Brain Architecture
techmonkey4u
 
Fundamental HTML and CSS
Fundamental HTML and CSSFundamental HTML and CSS
Fundamental HTML and CSS
techmonkey4u
 
A Brief Overview of OpenCV
A Brief Overview of OpenCVA Brief Overview of OpenCV
A Brief Overview of OpenCV
techmonkey4u
 
A Discussion on Automatic Programming
A Discussion on Automatic ProgrammingA Discussion on Automatic Programming
A Discussion on Automatic Programming
techmonkey4u
 

More from techmonkey4u (6)

Overview of Human and Computer Vision
Overview of Human and Computer VisionOverview of Human and Computer Vision
Overview of Human and Computer Vision
 
Robot Exploration with Combinatorial Auctions
Robot Exploration with Combinatorial AuctionsRobot Exploration with Combinatorial Auctions
Robot Exploration with Combinatorial Auctions
 
Brain Architecture
Brain ArchitectureBrain Architecture
Brain Architecture
 
Fundamental HTML and CSS
Fundamental HTML and CSSFundamental HTML and CSS
Fundamental HTML and CSS
 
A Brief Overview of OpenCV
A Brief Overview of OpenCVA Brief Overview of OpenCV
A Brief Overview of OpenCV
 
A Discussion on Automatic Programming
A Discussion on Automatic ProgrammingA Discussion on Automatic Programming
A Discussion on Automatic Programming
 

Recently uploaded

AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 

Recently uploaded (20)

AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 

iBATIS

  • 1. Omaha Java Users Group March 18, 2008 Corey A. Spitzer
  • 2. The Context • J2EE (with Spring) • OOP • SQL Relational Database
  • 3. What is iBATIS? Object Oriented Object Logic / DAO iBATIS Database Code Query Relational
  • 4. A More Detailed Look calls Code SqlMapClient insert() loads update() calls delete() query() SQL Maps javax.sql.DataSource Queries Result Maps Magic Magic Database
  • 5. The SQL Map Anatomy Code calls SqlMapClient loads calls SQL Maps DataSource <sqlMap namespace="myNamespace"> Magic Magic <resultMap id="myClass" class="full.package.MyClass"> Database <result property="foo" column="col1"/> <result property="bar" column="col2"/> ... </resultMap> ... <!-- ===================================================== --> <sql id="myQuery" resultMap="myClass"> SELECT col1, col2 FROM table1 </sql> ... </sqlMap>
  • 6. The Code Anatomy Code calls SqlMapClient loads calls import java.sql.SQLException; SQL Maps DataSource import com.ibatis.sqlmap.client.SqlMapClient; ... Magic Magic public class MyDAO Database { private SqlMapClient myDB; public void frobnicate(MyObject someObject) throws SQLException { List<MyClass> list = myDB.queryForList("myQuery"); Foo myFoo = (Foo)myDB.queryForObject("getFooByID", 1337); myDB.update("myQuery3"); myDB.insert("myQuery4", someObject); ... } ... }
  • 7. Any Questions so far? calls Code SqlMapClient insert() loads update() calls delete() query() SQL Maps javax.sql.DataSource Queries Result Maps Magic Magic Database
  • 8. Implicit Mapping <sqlMap namespace="myNamespace"> <resultMap id="myClass" class="full.package.Class"> <result property="foo" column="col1"/> <result property="bar" column="col2"/> ... </resultMap> ... <!-- ===================================================== --> <sql id="myQuery" resultClass="full.package.Class"> SELECT col1 as foo, col2 as bar FROM table1 </sql> ... </sqlMap>
  • 9. Inheritance Object Oriented Code Relational Database Fruit fruits id - int id - mediumint(7), PK dateBought - long date_bought - int(11) type - enum('a', 'o') apples Apple Orange fruit_id - mediumint(7), FK worm_count - decimal(4,1) wormCount - float bioengineered - boolean oranges fruit_id - mediumint(7), FK bioengineered - bool
  • 10. Complex Members Object Oriented Code Relational Database Cake cakes id - int id - mediumint(7), PK flavor - String flavor - enum('chocolate', ...) toppings - List<CakeTopping> cakes_to_toppings cake_id - mediumint(7), FK topping_id - mediumint(7), FK CakeTopping id - int name - String cake_toppings containsHFCS - boolean id - mediumint(7), PK name - varchar(20) contains_hfcs - bool
  • 12. Custom Type Handlers public class YesNoBoolTypeHandler implements TypeHandlerCallback { public Object getResult(ResultGetter getter) throws SQLException { if ("Y".equalsIgnoreCase(getter.getString())) { return new Boolean (true); } else if ("N".equalsIgnoreCase(getter.getString())) { return new Boolean (false); } else { throw new SQLException(); } } public void setParameter(ParameterSetter setter, Object parameter) throws SQLException { if (((Boolean)parameter).booleanValue()) setter.setString("Y"); else setter.setString("N"); } public Object valueOf(String s) { return new Boolean ("Y".equalsIgnoreCase(s)); } }
  • 13. Custom Type Handlers <resultMap id="myClass" class="my.package.MyClass"> ... <result property="foo" column="bar" typeHandler="some.package.YesNoBoolTypeHandler"/> ... </resultMap> <insert id="myQuery" resultMap="myClass" parameterClass="my.package.MyClass"> INSERT INTO table1 SET bar = #foo,handler=some.package.YesNoBoolTypeHandler# </insert>
  • 15. selectKey <insert id="addForumThread" parameterClass="java.util.HashMap"> INSERT INTO forum_threads SET forum_id = #forumID#, title = #title#, created_time = #createdTime#, last_updated_time = #createdTime#, <selectKey resultClass="int"> SELECT MAX(id) FROM forum_threads </selectKey> </insert>
  • 16. Caching Features <cacheModel id="fooCache" type="{LRU|MEMORY|FIFO|OSCACHE}" readOnly="{true|false}" serialize="{true|false}"> <flushInterval hours="24"/> <flushOnExecute statement="insertFoo"/> <flushOnExecute statement="updateFoo"/> <flushOnExecute statement="deleteFoo"/> <property name="size" value="1000"/> </cacheModel> <select id="getFoo" cacheModel="fooCache"> SELECT * FROM bar WHERE id = #value# </select> <insert id="insertFoo"> INSERT INTO bar SET ... </insert> ...
  • 17. Transactions public updateItemDescription(String itemId, String newDescription) throws SQLException { try { sqlMap.startTransaction(); Item item = (Item) sqlMap.queryForObject("getItem", itemId); item.setDescription (newDescription); sqlMap.update("updateItem", item); sqlMap.commitTransaction(); } finally { sqlMap.endTransaction(); } }
  • 18. What About Hibernate? iBATIS Hibernate • Separation of code and SQL • SQL alongside code • Simpler configuration and setup* • Total control over SQL queries • Cross-DB query language (HQL) • Shallow learning curve • ??? • Handles application complexities • Works very well when data model better** closely resembles object model** **No Fluff Just Stuff's Mark Richards' two cents: http://www.nofluffjuststuff.com/media.jsp?mediaId=27 *Source: http://www.devx.com/Java/Article/31481/0/page/1
  • 19. Who is Using iBatis? • CNet.com • MySpace.com • OfficeMax.com • JPMorganChase.com • 1up.com • PowerSentry.com (and more) Source: http://www.ociweb.com/mark/programming/iBATIS.html#WhoUses
  • 20. Now What? http://ibatis.apache.org