Re: Can application scope gateways/DAOs returning an array of Objects?
I tried this, and I'm not seeing any of non-local scoped vars showing up. I see each of my DAOs and Gateways and each of their internal methods, but I don't see any reference to the non-local vars (of which, I know there are many). I'm just doing a , correct? Jonathan > Jonathan Price wrote: > > Thanks for the reply! I'm definitely trying to get a handle on this > as I don't want to chase down the repercussions in the future! Thank > so much for your help. It almost makes sense to me now... > > > > A useful trick if you are creating your CFC in any persistent scope, > like the application scope in this case, is to do a of that > scope at the end of the page. Look at all of the vars showing in there. > > If you have failed to properly local scope a var in a CFC function you > > will see it sitting there at the top level of the dump. > > > -- > > Yours, > > Kym Kovan > mbcomms.net.au ~| Want to reach the ColdFusion community with something they want? Let them know on the House of Fusion mailing lists Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329875 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: Can application scope gateways/DAOs returning an array of Objects?
Thanks for the reply! I'm definitely trying to get a handle on this as I don't want to chase down the repercussions in the future! Thank so much for your help. It almost makes sense to me now... > > should I not worry about running 'createObject' on the same local. > o_program structure member everytime? > > The fact that createObject is INSIDE the loop is precisely why it is > working now and that is good. When you posted your first "real" code > sample (the second one) with the createObject outside the loop you > were > only creating one instance of your CFC and reusing it over and over. > That is not what you wanted. If you have 7 "programs", than you need > to > create 7 objects. > > > It's not completely obvious to me how 'local' magic is working. > > It's not magic really. When you place anything (like a CFC) in the > application scope it is shared by all running requests. This is the > same as a database table that is being used by several requests at > once. > Changes made by one request will be visible to any other request > looking in the table. Think of a CFC in the application scope the > same > way. There are 3 main scopes in a CFC-- this, variables, and local. > This and variables are shared by everyone calling methods on that CFC. > > Local is specific to a particular method call. If this still does > not > make sense, PLEASE ask questions now and get it cleared up or you > will > be asking for pain down the road when your app starts crashing under > load due to concurrency issues because you didn't understand how to > make > thread-safe singletons. Print this off, read it, and post it on your > cube wall: http://www.coldfusionjedi.com/downloads/cfcscopes.pdf > > > And is there not a memory leak issue with running createObject on > every iteration? > > I'm not sure what you're asking here but the short answer is "no". > Now, > creating objects DOES consume a nominal amount of memory-- this is > true, > but that is not a "memory leak". There was a recent memory leak > fixed > in the last cumulative hot fix for CF8 that had to do with placing > CFCs > in shared scopes. I don't see how it would affect your code, but if > you > want to, you can install the hot fix. > > > Should my previous version have worked? > > Which one? > *The very first code you posted was somewhat usable. It would have > created a separate object for each record except for the fact that > you > had some syntax errors [arrayNew()] and didn't locally var your > variables. > *The second code sample you sent only used one program object and > still > didn't use locally-scoped variables. > *Your third code sample is getting closer yet, but still not correct. > > You need to locally scope ALL VARIABLES THAT ARE SPECIFIC TO THAT > METHOD > CALL. This includes "q_programs". Otherwise two people running this > code at the exact same time will be sharing the exact same contents > of > the q_programs variable since is in the variables scope by default. > > > I don't mind doing this 'local' trick everywhere, but I am curious > about why the original wasn't working properly. > > It's hard to say since your first code sample seemed to be > altered-to-protect-the-innocent to the point that you significantly > changed the flow of the code. However, I would guess that your first > iteration of the code did not work because you were not creating a > new > program object for every record in your result set. > > One more thing, I would stay away from duplicating your CFCs. It > might > work in some scenarios, but duplicate is a deep-copy and that can > mean > bad things if your CFC has references to a framework or some other > complex variable that you do not actually wish to copy. > > ~Brad > ~| Want to reach the ColdFusion community with something they want? Let them know on the House of Fusion mailing lists Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329660 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: Can application scope gateways/DAOs returning an array of Objects?
So the worked fine in our CF8 environment, but CF7 is complaining about it. Is {} just a CF8 shorthand for struct? I replaced the {} with StructNew(), and it seems to work. I'm just terrified of screwing this up and having to chase down some phantom bugs three months from now. ~| Want to reach the ColdFusion community with something they want? Let them know on the House of Fusion mailing lists Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329659 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: Can application scope gateways/DAOs returning an array of Objects?
Yeah, we're on CF8 for better or worse. So I redid the previous function to look like this: And I'm getting the correct info back now. Last two questions. 1) should I not worry about running 'createObject' on the same local.o_program structure member everytime? It's not completely obvious to me how 'local' magic is working. And is there not a memory leak issue with running createObject on every iteration? 2) Should my previous version have worked? I don't mind doing this 'local' trick everywhere, but I am curious about why the original wasn't working properly. Thanks! > > If you're on CF9 things may a little different in that you may not > need to explicitly var > > scope, > > If you are on CF9, use the local scope as it is inherently "varred": > > > ... > > 'Contact').init(...insert init info here...)> > > > > If you are not on CF9, I could recommend still getting in the habit > of > pretending there is a local scope and putting > at > the top of your method. Just make sure you reference all of your > "local" variables as local.varName and this will ensure that multiple > people hitting that code at the exact same time will all have their > own > special versions of each of those variables and no one will be > overwriting another. > > ~Brad ~| Want to reach the ColdFusion community with something they want? Let them know on the House of Fusion mailing lists Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329656 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: Can application scope gateways/DAOs returning an array of Objects?
Right, I tried this but it behaved weirdly - as thought the ArrayAppend were passing just a pointer to the one object each time so that after appending all my objects, the array was full replicas of whichever object was loaded last instead of a bunch of different objects. To clarify, here's some code: So, when I call this function, I get an array back that has seven objects as I'd expect (as there are 7 programs in the database). However, each object in the array has the same values in it. If I do a dump of the of the o_program object just before the append in the above function, I see the different programs displayed individually as I'd expect. But when I look at the Array that's returned in the calling page, I see seven identical programs. Thanks again for the help >Hi Jonathon, > >There's only one thisContact variable, which is being reused each time >through the loop. So all you need to do is put: > > > >right at the start. There's an indeterminate number of values that are >passing through that one variable on their way into the array, but it's >still one variable. > >And of course var scope returnArray and q_Contacts as well. If you're on >CF9 things may a little different in that you may not need to explicitly var >scope, but I'll let the CF9 gurus pick that one up. > > >Jaime >On Thu, Jan 14, 2010 at 4:26 PM, Jonathan Price < >jonat...@imakehthissound.com> wrote: > >> ~| Want to reach the ColdFusion community with something they want? Let them know on the House of Fusion mailing lists Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329655 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Can application scope gateways/DAOs returning an array of Objects?
So, I'm relatively new to OO in ColdFusion, and I'm banging my head against one issue in particular. Let's say I've got a DAO or Gateway object in my APPLICATION scope that needs to return a collection of beans, I'm having trouble understanding the need to VAR scope all internally used variables when I've got a dynamic number of objects being returned. That's not very clear, so let's say this is the function in question: SELECT * FROM Contacts So, my concern is with the inability to create the Contact objects in the VAR scope since I don't know how many I'll be creating before hand. If I do it like this (i.e. without the VAR on the createObject), am I setting myself up problems? If so, how should I handle this? Thanks again, and I hope it's not to ridiculous a question. ~| Want to reach the ColdFusion community with something they want? Let them know on the House of Fusion mailing lists Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329652 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4