Dynamic Datasources With Transfer – Using a Datasource Bean Instead of the Datasource.xml

By default Transfer expects a path to a datasource.xml file. However, the TransferFactory.init() method will accept a configuration bean. Which you can find in the transfer.com.config path. The Configuration.cfc init() method is only looking for paths as arguments, and sets the DSN username and password to blank on creation. The object does have a hasDatasourceName() method, so how do we utilize this?

Well, I extended the object and overwrite the init() method.
It now accepts a datasource bean and sets the DSN info in Transfer with it.
When Transfer natively calls hasDatasourceName() it will bypass checking the datasourcePath.







variables.instance = StructNew();

setConfigPathCollection(ArrayNew(1));

setDatasourceName(arguments.dsnBean.getName());
setDatasourceUsername(arguments.dsnBean.getUsername());
setDatasourcePassword(arguments.dsnBean.getPassword());

setDataSourcePath(arguments.datasourcePath);
setConfigPath(arguments.configPath);
setDefinitionPath(arguments.definitionPath);

return this;


Leave a Reply

Your email address will not be published. Required fields are marked *