Marcos,

 

This page here explains Data Access Objects and DAO Factories better than I could in an e-mail

 

http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html

 

Although the context is Java, just about everything can be applied to ColdFusion and CFC’s.

 

Andr�

 

 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Marcos Placon�
Sent:
15 October 2003 18:21
To: [EMAIL PROTECTED]
Subject: Fw: [CFCDev] Calling another CFC from within a method

 

 

Ok, I'll try it, but I did't understand very good, how do I will configurate this daofactory, 'cause here we call a method that have to read a componente with the database configurations right?

Then, I dont know how to create a database that have all this informations.

 

Thanks in adiction Andr�,

 

Marcos Placon�

 

Marcos Placon�
Cold Fusion Developer
Cel.: +55(11) 9560-3260

Tel.: +55(11) 3053-3510
www.tesla.com.br

Esta mensagem de e-mail e qualquer arquivo transmitido com ela s�o direcionados somente aos destinat�rios acima e podem conter informa��es privilegiadas e/ou confidenciais. Caso tenha recebido esta mensagem por engano, por favor notifique o remetente imediatamente e a seguir apague este e-mail de seu computador.

----- Original Message -----

Sent: Wednesday, October 15, 2003 10:46 AM

Subject: RE: [CFCDev] Calling another CFC from within a method

 

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-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Marcos Placon�
Sent:
15 October 2003 13:39
To: [EMAIL PROTECTED]
Subject: Re: [CFCDev] Calling another CFC from within a method

 

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]>

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
> recommended practice for calling another cfc from within a method of an
> object, along the lines of using cfinvoke or CreateObject or ...
>
>
>
> ----------------------------------------------------------
> You are subscribed to cfcdev. To unsubscribe, send an email
> to
[EMAIL PROTECTED] with the word 'unsubscribe cfcdev'
> in the message of the email.
>
> CFCDev is run by CFCZone (
www.cfczone.org) and supported
> by Mindtool, Corporation (
www.mindtool.com).
>
> An archive of the CFCDev list is available at
www.mail-archive.com/[EMAIL PROTECTED]
>

<<image001.gif>>

<<image002.gif>>

Reply via email to