I did not see this go though on http://www.houseoffusion.com/groups/cf-talk/
So i am re-posting it
Goal: to create a create a generic function to update database records
(CRUD) on multiple tables with out creating a function for each table.
Back ground. For various reasons I am using a coded generator to generate
the CFC's (in this case (Brian Rinaldi's Illudium CFC Generator).
So for all the tables let's assume that I have the following objects in the
application scope.
In the case of tbleUsers:
Application.tblusers
Application.tblusersDAO
Application.tblusersGateway
Application.tblusersService
What I want to do is create a generic function to update database records
(CRUD) using the above objects based on the following vars:
The action or event: (MyAction)
The table name (MyTable)
The struct, (MyStruct)
The Primary Key (MyPK)
To process a request the standard sequence of events would be something like
this:
myBeanObj = application.tblusers.Init(argumentCollection=
MyStruct);
if (MyEvent EQ "deletetblusers")
{
myResult =
Application.tblusersService.deletetblusers(myBeanObj.getUserID());
}
else
{
myResult =
Application.tblusersService.savetblusers(myBeanObj);
}
The function I have in mind is would look like this:
myResult = Application.MyDataObj.updatetable(MyAction, MyStruct, myBeanObj,
MyPK);
Normally (say with SQL) I would build a string based on the variables and
execute it. But being the good CFer that I am, I don't want to use Evaluate.
This is what I have working so far:
<cfif myEvent EQ "delete#MyTable#">
<cfset mystring =
"Application.#MyTable#Service.delete#MyTable#(myBeanObj.get#MyPK#())">
<cfelse>
<cfset mystring =
"Application.#MyTable#Service.save#MyTable#(myBeanObj)">
</cfif>
<cfset MyResult = evaluate(mystring)>
The code is posted here http://coz.pastebin.com/f7e3bcb42
What I want to do is eliminate "evaluate" from the mix even though it seems
to me to be doing exactly what it was designed to do, much like Execute or
Eval functions in other languages. Yeah, I know. Evaluate, like Napster, is
bad. http://www.youtube.com/watch?v=VIuR5TNyL8Y (NSFW Language)
I know you can avoid using Evaluate with Structs with something like
MyStruct[MyPK]
But how would I do this with Objects in the Application scope?
What would be the syntax to do this?
I have seen it done like so:
<cfset "get#Mytable#" = CreateObject("component",
"componenets.#Mytable#Gateway").init(MyDSN).getByAttributesQuery(argumentcollection=url)>
But I want to avoid the overhead of creating the objects.
Many TIA
~G~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;203748912;27390454;j
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:311861
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4