Archive for October, 2010

Spring templates

After the DAS registry has grown considerably over the last couple of years since I’ve been running it the sql code with it try catch blocks for connection managment has been getting bigger and bigger. The web service has extra requests and responses and with them more DAO code. In a bid to remove much of the bloat I’ve started using Spring Templates. Another option would be to use Hibernate or JPA or iBatis- however as this would be a retrofit I’m not sure it’s a good idea to go that far. So for the moment I’m sticking with Spring Templates.

The code has been reduced substantially all we have now is a config like this:

<?xml version=”1.0″ encoding=”UTF-8″?>
<beans xmlns=”;

<bean id=”theRegistryDataSource” >
<property name=”jndiName” value=”myjndidatasourcename”/>
<property name=”resourceRef” value=”true”/>
<bean id=”dasServerDAO” class=””>
<property name=”dataSource” ref=”theRegistryDataSource”/>

a class that extends JdbcDasoSupport with very simple methods like one below:

public class DasServerDAO extends NamedParameterJdbcDaoSupport{

public int getServerIdForServerUrl(URL url) {
String sqlMirrors = “select server_id from server where url=:url”;
SqlParameterSource namedParameters = new MapSqlParameterSource(“url”,url.toString());
return getNamedParameterJdbcTemplate().queryForInt(sqlMirrors,namedParameters);


most of the exceptions being thrown and caught only printed the stack trace – so now we have eleminated this bloat.