Escape Keys - TomdeMan's Blog

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.

<cfcomponent displayname="TransferConfig" hint="This is a TransferConfig Bean" output="false" extends="transfer.com.config.Configuration">
   
   <cffunction name="init" hint="Constructor" access="public" returntype="model.TransferConfig" output="false">
      <cfargument name="dsnBean"            type="any"      required="no"   default="" />
      <cfargument name="datasourcePath"      type="string"   required="no"   default="" />
      <cfargument name="configPath"         type="string"   required="no"   default="" />
      <cfargument name="definitionPath"      type="string"   required="no"   default="" />
      
      <cfscript>
         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;
      </cfscript>
   </cffunction>
   
</cfcomponent>

Comments:

[Add Comment]

Jared Langdon says:

I'm missing something here. I've done this exactly, but it still seems to be taking the DatasourceName from the XML file referenced in the datasourcePath. Can you expand on the part about bypassing checking the datasourcePath? Thanks.

10/23/08 12:28 AM

Jared Langdon says:

Never mind. Just don't pass a datasourcePath and it works. Brilliant. Thanks very much.

10/23/08 12:41 PM

[Add Comment]