The objects I am copying from are persisted in the session scope. I would
like to be able to read from these objects at runtime without having to lock
them all over the place. Does creating a pointer in the request scope to an
object in session absolve you from locking? I'm not sure, and to be honest,
I haven't found a lot of information either way on the issue, so copying the
object seems to be playing it safe, no?

> -----Original Message-----
> From: Brian Kotek [mailto:[EMAIL PROTECTED] 
> Sent: Monday, October 29, 2007 3:43 PM
> To: CF-Talk
> Subject: Re: Copying a CFC Persisted in Session Scope
> 
> Yes, but why are you creating a copy in the first place? Why 
> do you think you need a copy and not a reference?
> 
> On 10/29/07, Ryan Heldt <[EMAIL PROTECTED]> wrote:
> >
> > Thanks everyone for responding. Unfortunately, the method 
> suggested by 
> > Rich below seemed to create a pointer rather than a 
> separate instance 
> > of the object, as I had hoped. However, after discussing 
> this with a 
> > co-worker, we seem to have cooked-up a viable solution.
> >
> > There were two objects I wanted to "copy" into the request 
> scope. So, 
> > in each of those objects, we added a copy() constructor 
> that took the 
> > initial object, then copied all of the properties over, for 
> instance:
> >
> > <cffunction name="copy" access="public" output="false"
> > returntype="AuthenticatedUser">
> >         <cfargument name="object" type="AuthenticatedUser" 
> required="true"
> > />
> >         <cfscript>
> >                 _userID = object.getUserID();
> >                 _username = object.getUsername();
> >                 _firstName = object.getFirstName();
> >                 _lastName = object.getLastName();
> >                 _email = object.getEmail();
> >                 _permissions = object.getPermissions();
> >                 _isAuthenticated = object.getIsAuthenticated();
> >         </cfscript>
> >         <cfreturn this />
> > </cffunction>
> >
> > Then, in Application.cfc, onRequestStart():
> >
> > <!--- Copy AuthenticatedUser object over to request scope 
> ---> <cflock 
> > timeout="10" throwontimeout="false" type="readonly"
> > scope="session">
> >         <cfset request.myAuthenticatedUser = 
> > createObject("component","AuthenticatedUser").copy(
> > session.myAuthenticatedUs
> > er) />
> > </cflock>
> >
> > Thanks!
> > Ryan
> >
> > > -----Original Message-----
> > > From: Rich [mailto:[EMAIL PROTECTED]
> > > Sent: Monday, October 29, 2007 12:40 PM
> > > To: CF-Talk
> > > Subject: RE: Copying a CFC Persisted in Session Scope
> > >
> > > > I realize this topic may have been covered on this list a
> > > while back,
> > > > but I'm having problems locating a good answer, so here goes.
> > > > Typically in our administrative web sites, on a request, we
> > > copy over
> > > > our session variables to the request scope so we can have
> > > read-access
> > > > to the information without having to place locks all 
> over the place.
> > >
> > > I would suggest that you create a Session Facade and then 
> have all 
> > > your objects reference the façade.  It is generally a bad idea to 
> > > have an object reference an external scope (session, 
> request, etc.), 
> > > and this technique hides the implementation from your business 
> > > objects.
> > >
> > > Assuming you wanted to return an 'admin' object, your 
> objects would 
> > > use a
> > > sessionFaçade.getAdminObject() and the function within the façade 
> > > would look like the following (excluding locks, etc.
> > > for the sake of simplicity):
> > >
> > > function getAdminObject() {
> > >       Return session.adminObject
> > > }
> > >
> > > HTH,
> > > Rich Kroll
> > >
> > >
> > >
> >
> > 
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Check out the new features and enhancements in the
latest product release - download the "What's New PDF" now
http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:292274
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to