In James version 2.3, we expose database connections via the javax.sql.DataSource. This document describes how to update code using James previous database connectivity (Avalon's DataSourceComponent).
- Remove references to DataSourceSelector.
- Change references of DataSourceComponent to DataSource
- Add imports:
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
- Change how the datasource is looked up
Replace:
ComponentManager componentManager = (ComponentManager)getMailetContext().getAttribute(Constants.AVALON_COMPONENT_MANAGER);
// Get the DataSourceSelector service
DataSourceSelector datasources = (DataSourceSelector)componentManager.lookup(DataSourceSelector.ROLE);
// Get the data-source required.
datasource = (DataSourceComponent)datasources.select(datasourceName);
with
InitialContext ctx = new InitialContext();
datasource = (DataSource) ctx.lookup("java:comp/env/jdbc/" + datasourceName);
Then update exception handling appropriately.
That's all there is to it. Enjoy!