|
Marcos: RE: Implementation of DAO factory. Here is a brief overview of ONE POSSIBLE
way of how you could implement this in ColdFusion: At application level…possibly in
your Application.cfm file you obtain a concrete
factory based on some configuration parameter which specifies the full CFC path
to a concrete implementation of the DAO factory i.e. it “implements”
the DAO factory interface which contains methods like getCustomerDAO(),
getOrderDAO() etc. So for example the configuration parameter
could be a string containing the value: “com.myCompany.dao.SQLServerDAOFactory” This allows you to provide different DAO
factories for different RDBMS’ or any other kind of data source at “configuration
time” or even change at run time if you so wish i.e. it is an implementation of the pluggable DAO design pattern. Example code: <cfif
NOT structKeyExists(application,"config")> ����������� <cflock scope="application"
type="exclusive" timeout="10"> ����������������������� <cfif NOT structKeyExists(application,"config")> ����������������������� ����������� <cfscript> ����������� ����������������������������������� //Create our
config CFC ����������������������� ����������������������� config = createObject("component","com.myCompany.config.Config"); ����������������������� ����������������������� //Initialise with configuration parameters e.g. datasource, concrete DAO CFC paths etc. ����������������������� ����������������������� config.init("web-app.xml"); ����������������������� ����������������������� //Put in application
scope ����������������������� ����������������������� application.config
= config; ����������������������������������������������������������� ����������������������� ����������������������� // Create an Abstract
DAO Factory... ����������������������� ����������������������� abstractDAOFactory = CreateObject("component","com.myCompany.dao.AbstractDAOFactory"); ����������������������� ����������������������� // Initialise with the config
CFC and thus give it access to the concrete DAO CFC path ����������������������� ����������������������� abstractDAOFactory.init(config); ����������������������� ����������������������� // Get a concrete DAO
Factory... ����������������������� ����������������������� daoFactory = abstractDAOFactory.getDAOFactory(); ����������������������� ����������������������� //Put in application
scope... ����������������������� ����������������������� application.daoFactory
= daoFactory; ����������������������� ����������� </cfscript>�������� ����������� ����������� </cfif> ����������� </cflock> </cfif> A rough outline of what you might have In
your getDAOFactory() method: <!--- getDAOFactory() ---> <cffunction
name="getDAOFactory"
access="public" output="false" returntype="any"
hint="Returns an appropriate DAO factory based on configuration"> ����������� <!--- Get the name of the DAO Factory CFC to use ---> ����������� <cfset daoFactoryName = variables.config.lookup("param/DAOFactory")> ����������� ����������� <!--- Create, initialise and
return the DAO Factory---> ����������� <cfscript> ����������������������� //Create ����������������������� daoFactory = CreateObject("component",daoFactoryName); ����������������������� //Initialise ����������������������� daoFactory.init(variables.config); ����������� </cfscript> ����������� ����������� <!--- Return the DAO ---> ����������� <cfreturn daoFactory> </cffunction> Then whenever you need to get a specific
DAO you simply use some code like this: <cfscript> customerDAO = application.daoFactory.getCustomerDAO() </cfscript> I’ve just realized that this has
answered more than you were asking because this is an implementation of an
abstract factory as well as the factory method design patterns and you are only
really interested in the latter? Andr� DISCLAIMER ------------------- Use the above code at your own risk! There
is MORE THAN ONE WAY to skin a cat. None of the above code has been spell
checked or syntax checked. Examples are for illustration purposes only i.e. do
your own work J -----Original Message----- Are you talking about a Dao Factory? I'm wondering to
construct one, but I dont know specifically where to start. Does anyone have any
kind of explanation to give me? Regards, Marcos Placon� Tesla tecnologia ----- Original Message ----- From: "Nando" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, October 15, 2003 9:04 AM Subject: [CFCDev] Calling another CFC from within a method > I'm working on my first DAO object and was wondering if
there is a |
- [CFCDev] log4cf random failures Thomas Chiverton
- [CFCDev] Calling another CFC from within a method Nando
- Re: [CFCDev] Calling another CFC from within a ... Marcos Placon�
- RE: [CFCDev] Calling another CFC from withi... Andre Mohamed
- RE: [CFCDev] Calling another CFC from within a ... Nathan Dintenfass
- Re: [CFCDev] Calling another CFC from withi... Aldo d'Aquino
