What does it do?

Developers often create maps between objects within an application. One definition of a Mapper is an "object that sets up communication between two independent objects." A Data Mapper is a "layer of mappers that moves data between objects and a database while keeping them independent of each other and the mapper itself. " [Patterns of Enterprise Architecture, ISBN 0-321-12742-0]. You provide the database and the objects; iBATIS provides the mapping layer that goes between the two..

How does it work?

Your programming platform already provides a capable library for accessing databases, whether through SQL statements or stored procedures. But developers find several things are still hard to do well when using "stock" JDBC or ADO.NET, including:

Separating SQL code from programming code Passing input parameters to the library classes and extracting the output Separating data access classes from business logic classes Caching often-used data until it changes Managing transactions and threading

1 Provide a parameter, either as an object or a native type. The parameter can be used to set runtime values in your SQL statement or stored procedure. If a runtime value is not needed, the parameter can be omitted.

2 Execute the mapping by passing the parameter and the name you gave the statement or procedure in your XML descriptor. This step is where the magic happens. The framework will prepare the SQL statement or stored procedure, set any runtime values using your parameter, execute the procedure or statement, and return the result.

3 In the case of an update, the number of rows affected is returned. In the case of a query, a single object, or a collection of objects is returned. Like the parameter, the result object, or collection of objects, can be a plain-old object or a native type. The result can also be given as XML (Java only).

What is iBATIS?

iBATIS is a persistence framework which automates the mapping between SQL databases and objects in Java, .NET, and Ruby on Rails. In Java, the objects are POJOs (Plain Old Java Objects). The mappings are decoupled from the application logic by packaging the SQL statements in XML configuration files. The result is a significant reduction in the amount of code that a developer needs to access a relational database using lower level APIs like JDBC and ODBC.

Other persistence frameworks such as Hibernate allow the creation of an object model (in Java, say) by the user, and create and maintain the relational database automatically. iBATIS takes the reverse approach: the developer starts with a SQL database and iBATIS automates the creation of the Java objects. Both approaches have advantages, and iBATIS is a good choice when the developer does not have full control over the SQL database schema. For example, an application may need to access an existing SQL database used by other software, or access a new database whose schema is not fully under the application developer control, such as when a specialized database design team has created the schema and carefully optimized it for high performance.

Usage of iBATIS?

For example, assume there is a database table PRODUCT (PROD_ID INTEGER, PROD_DESC VARCHAR(64)) and a Java class com.example.Product (id: int, description: String). To read the product record having the key PROD_ID into a new Product POJO, the following mapping is added into an iBATIS XML mapping file:

    <select id="getProduct" parameterClass="java.lang.Long" resultClass="com.example.Product">
 	select PROD_ID as id,
               PROD_DESC as description
          from PRODUCT
         where PROD_ID = #value#
    </select>

A new Java Product object can then be retrieved from the database for product number 123 as follows:

Product resultProduct = (Product) sqlMapClient.queryForObject("getProduct", 123); In the mapping file example, #value# refers to the long integer value passed into the query. If the parameter is a Java object, then values from properties on that object can be inserted into the query using a similar # notation. For example, if the parameter class is a com.example.Product which has a property called id, then #value# can be replaced with #id#. The sqlMapClient object is an instance of class com.ibatis.sqlmap.client.SqlMapClient.

History of IBATIS?

In 2001 a project called iBATIS was started by Clinton Begin. Originally the focus was on the development of cryptographic software solutions. The first product to be released by iBATIS was Secrets,[1] a personal data encryption and signing tool much like PGP. Secrets was written entirely in Java and was released under an open source license.

That year Microsoft published a paper[2] to demonstrate that its recent .NET 1.0 framework was more productive than Java. For that purpose Microsoft built its own version of Sun Web Pet Store, a Web project that Sun had used to show Java best practices (Java BluePrints). Microsoft claimed that .NET was 10 times faster and 4 times more productive than Java.

In 2002 Clinton developed an application called JPetStore[3] to demonstrate that Java could be more productive than .NET and could also do so while achieving a better architecture than was used in the Microsoft implementation.

JPetStore 1.0 had a big impact[4] and the database layer that Clinton used attracted the attention of the community. Soon, iBATIS Database Layer 1.0 project started, composed by two components: iBATIS DAO and iBATIS SQL Maps.

iBATIS 2.0 was released in June 2004.[5] It was a complete redesign while keeping the same features. Clinton donated the iBATIS name and code to Apache Software Foundation and the project stayed in the ASF for six years.

Eventually iBATIS DAO was deprecated, considering that better DAO frameworks were available, such as Spring Framework.

On May 19, 2010 iBATIS 3.0 was published and simultaneously the development team decided to continue the development of the framework at Google Code.[6] under a new project called MyBatis.

Link
Eng. Ravi Kumar Verma

Simple and dept learning technology is very important part in software development. Same story has been implemented at this site, so learn and implement the inovative things, Thanks

Ravi Kumar Verma