ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Hurst" <jbhu...@attglobal.net>
Subject RE: Ibatis and Spring Framework
Date Thu, 04 Aug 2005 20:24:13 GMT
Hi,

I use iBATIS with Spring.  In fact I learned about iBATIS via Spring; I
think the two together work very well.

In addition to Richard's comments, I would add:

  - Common configuration mechanism across your whole project, and separation
of configuration from your code.

With Spring, your DAOs can be provided with what they need via dependency
injection.  You put for example a setDataSource() in your class, and you can
configure Spring to wire up the DataSource at runtime.  This is incredibly
powerful.

  - The SqlMapClientDaoSupport provides a great base class for DAOs to make
use of Spring facilities, such as transparent transaction control.  It
already has the setters necessary to configure DataSource or SqlMapClient.
It also provides the SqlMapClientTemplate, a smart way to do operations
requiring resources.

For example the iBATIS developer guide example

public void 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 ();
  }
}

Could look like this with Spring:

public void updateDescription(String itemId, String newDescription) {
  Item item = (Item) getSqlMapClientTemplate().queryForObject("getItem",
itemId);
  Item.setDescription(newDescription);
  getSqlMapClientTemplate().update("updateItem", item);
}

Many fully transactional DAO methods become one-liners with Spring.

The iBATIS API is very clean; the advantage of the Spring XxxTemplate
classes becomes all the more clearer with an API like raw JDBC.

Regards

John Hurst


> -----Original Message-----
> From: rich oates [mailto:oates1@gmail.com]
> Sent: Friday, 5 August 2005 07:18
> To: user-java@ibatis.apache.org
> Subject: Re: Ibatis and Spring Framework
> 
> The Spring JDBC wrapper offers at least the following:
> 
> - a further abstraction away from iBatis (which is useful if you wish
> to change the underlying persistence framework in the future)
> 
> - common data access exceptions (i.e. the iBatis exceptions are mapped
> to spring exceptions. Again, useful if you want to reduce dependency
> on iBatis).
> 
> There are other benefits, especially when the rest of what Spring
> offers is taken into account, e.g. transparent transaction handling.
> 
> I recommend having a look at chapter 11 of the Spring reference
> documentation.
> 
> regards
> richard


Mime
View raw message