| Apache iBATIS | |
|---|---|
| Developed by | Apache Software Foundation |
| Written in | Java |
| OS | Cross-platform |
| Type | Persistence Framework |
| License | Apache License 2.0 |
| Website | http://ibatis.apache.org |
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.
For example, assume there is a database table PRODUCT (PROD_ID INTEGER, PROD_DESC VARCHAR(64)) and a Java object com.example.Product (id: int, description: String). To read the product record having the key PRD_ID into a new Product POJO, we would add the following mapping 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>
We then could read in a new Java Product object for product number 123 as follows:
Product resultProduct = sqlMapClient.queryForObject("getProduct", 123);
In the mapping file example, #value# refers to the Long passed in to the query. If the parameter were 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 were a com.example.Product which had a property called id, then #value# could be replaced with #id#. sqlMapClient is an instance of com.ibatis.sqlmap.client.SqlMapClient.
Other persistence frameworks such as Hibernate let you create an object model (in Java, say) and then create and maintain the relational database automatically. iBatis takes the reverse approach: you start with an SQL database and then iBatis automates the creation of the Java objects. Both approaches have advantages, and iBatis is a good choice when you don't have full control over the SQL database schema. For example, you may need to access an existing SQL database used by other software, or access a new database whose schema is not fully under your control: very often a specialized database design team creates the schema and carefully optimize it for high performance.
The founder of iBatis has publically stated his dismay with Java 5, but has continued to release new versions of iBatis for Java. Versions 2.3.1 and 2.3.2 came out in April 2008, and 2.3.3 in July. Work is also underway on release 3.0.0, whose features are being discussed here.
The framework is currently available in Java, .NET, and Ruby (RBatis) versions.
The Apache iBator tool is closely related: it connects to your database and uses SQL introspection to generate iBatis mapping files and Java classes.
|
||||||||||||||
No comments have been added.