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=”http://www.springframework.org/schema/beans&#8221;
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
xsi:schemaLocation=”
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd”&gt;

<bean id=”theRegistryDataSource” >
<property name=”jndiName” value=”myjndidatasourcename”/>
<property name=”resourceRef” value=”true”/>
</bean>
<bean id=”dasServerDAO” class=”org.biojava.services.das.dao.DasServerDAO”>
<property name=”dataSource” ref=”theRegistryDataSource”/>
</bean>
</beans>

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.

Advertisements