A Snippet is Worth a Thousand Words
There’s something to be said about simplicity…
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import roadrantz.model.Motorist;
public class IBatisRantDao extends SqlMapClientDaoSupport
implements RantDao {
public Motorist getMotoristById(long id) {
return (Motorist) getSqlMapClientTemplate().
queryForObject("getMotoristById", id);
}
public void saveMotorist(Motorist motorist) {
getSqlMapClientTemplate().insert("saveMotorist", motorist);
}
}
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!








October 6th, 2007 at 6:53 pm
You have hidden the complexity in the XML file
But yeah, it is simpler than hard coding it into the Java code. But Hibernate/Spring is just as simple.
October 6th, 2007 at 7:04 pm
Yep… if not simpler. I have been going through the Spring In Action book today, basically covering the chapters on persistence and transactions. I am really liking Spring/Hibernate3 annotations.
October 29th, 2007 at 9:44 pm
Oh, that’s supposed to be simple? You have a class named like an interface with a bunch of SqlMapClientTemplates?
Wouldn’t real simplicity be:
Motorist m = new Motorist(3);
m.ChangeSomething(”Blah”);
m.Save();
?
(Just sad I can’t rib you all in person anymore)
Cory
October 30th, 2007 at 7:48 am
Well, it’s as simple as you’re going to get in java. I’ve never been a fan of using ActiveRecord in java though… always feels dirty. And all I would be doing is hardwiring the calls to the dao directly within the domain object, or passing the dao interface in via a constructor or setter.
Either way, I’ve always it’s a violation of SRP to include both data store access and domain logic in the same entity.
November 27th, 2007 at 12:01 am
Heh… I actually didn’t notice that the “I” was in front of it. I don’t prefix my interfaces with the letter I… the implementation of the interface just happened to use iBatis.